summaryrefslogtreecommitdiffstats
path: root/src/pulsecore/sample-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2008-08-11 15:19:52 +0200
committerLennart Poettering <lennart@poettering.net>2008-08-11 15:19:52 +0200
commit5b2a83733dc8a0e1cb1cef5beb0e3ca646da0a0a (patch)
treefe6d9076630d651d8bb1da1ca41da3f625f62120 /src/pulsecore/sample-util.c
parentb604290803a0832ac337faf7619b93b2968e8d50 (diff)
optimize volume changing a bit by only using a single counter for the inner loops instead of two
Diffstat (limited to 'src/pulsecore/sample-util.c')
-rw-r--r--src/pulsecore/sample-util.c67
1 files changed, 36 insertions, 31 deletions
diff --git a/src/pulsecore/sample-util.c b/src/pulsecore/sample-util.c
index 5a93367e..ac7de624 100644
--- a/src/pulsecore/sample-util.c
+++ b/src/pulsecore/sample-util.c
@@ -620,14 +620,15 @@ void pa_volume_memchunk(
switch (spec->format) {
case PA_SAMPLE_S16NE: {
- int16_t *d;
- size_t n;
+ int16_t *d, *e;
unsigned channel;
int32_t linear[PA_CHANNELS_MAX];
calc_linear_integer_volume(linear, volume);
- for (channel = 0, d = ptr, n = c->length/sizeof(int16_t); n > 0; d++, n--) {
+ e = (int16_t*) ptr + c->length/sizeof(int16_t);
+
+ for (channel = 0, d = ptr; d < e; d++) {
int32_t t;
t = (int32_t)(*d);
@@ -642,17 +643,18 @@ void pa_volume_memchunk(
}
case PA_SAMPLE_S16RE: {
- int16_t *d;
- size_t n;
+ int16_t *d, *e;
unsigned channel;
int32_t linear[PA_CHANNELS_MAX];
calc_linear_integer_volume(linear, volume);
- for (channel = 0, d = ptr, n = c->length/sizeof(int16_t); n > 0; d++, n--) {
+ e = (int16_t*) ptr + c->length/sizeof(int16_t);
+
+ for (channel = 0, d = ptr; d < e; d++) {
int32_t t;
- t = (int32_t)(PA_INT16_SWAP(*d));
+ t = (int32_t) PA_INT16_SWAP(*d);
t = (t * linear[channel]) / 0x10000;
t = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF);
*d = PA_INT16_SWAP((int16_t) t);
@@ -665,14 +667,15 @@ void pa_volume_memchunk(
}
case PA_SAMPLE_S32NE: {
- int32_t *d;
- size_t n;
+ int32_t *d, *e;
unsigned channel;
int32_t linear[PA_CHANNELS_MAX];
calc_linear_integer_volume(linear, volume);
- for (channel = 0, d = ptr, n = c->length/sizeof(int32_t); n > 0; d++, n--) {
+ e = (int32_t*) ptr + c->length/sizeof(int32_t);
+
+ for (channel = 0, d = ptr; d < e; d++) {
int64_t t;
t = (int64_t)(*d);
@@ -687,17 +690,18 @@ void pa_volume_memchunk(
}
case PA_SAMPLE_S32RE: {
- int32_t *d;
- size_t n;
+ int32_t *d, *e;
unsigned channel;
int32_t linear[PA_CHANNELS_MAX];
calc_linear_integer_volume(linear, volume);
- for (channel = 0, d = ptr, n = c->length/sizeof(int32_t); n > 0; d++, n--) {
+ e = (int32_t*) ptr + c->length/sizeof(int32_t);
+
+ for (channel = 0, d = ptr; d < e; d++) {
int64_t t;
- t = (int64_t)(PA_INT32_SWAP(*d));
+ t = (int64_t) PA_INT32_SWAP(*d);
t = (t * linear[channel]) / 0x10000;
t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL);
*d = PA_INT32_SWAP((int32_t) t);
@@ -710,14 +714,15 @@ void pa_volume_memchunk(
}
case PA_SAMPLE_U8: {
- uint8_t *d;
- size_t n;
+ uint8_t *d, *e;
unsigned channel;
int32_t linear[PA_CHANNELS_MAX];
calc_linear_integer_volume(linear, volume);
- for (channel = 0, d = ptr, n = c->length; n > 0; d++, n--) {
+ e = (uint8_t*) ptr + c->length;
+
+ for (channel = 0, d = ptr; d < e; d++) {
int32_t t;
t = (int32_t) *d - 0x80;
@@ -732,14 +737,15 @@ void pa_volume_memchunk(
}
case PA_SAMPLE_ULAW: {
- uint8_t *d;
- size_t n;
+ uint8_t *d, *e;
unsigned channel;
int32_t linear[PA_CHANNELS_MAX];
calc_linear_integer_volume(linear, volume);
- for (channel = 0, d = ptr, n = c->length; n > 0; d++, n--) {
+ e = (uint8_t*) ptr + c->length;
+
+ for (channel = 0, d = ptr; d < e; d++) {
int32_t t;
t = (int32_t) st_ulaw2linear16(*d);
@@ -754,14 +760,15 @@ void pa_volume_memchunk(
}
case PA_SAMPLE_ALAW: {
- uint8_t *d;
- size_t n;
+ uint8_t *d, *e;
unsigned channel;
int32_t linear[PA_CHANNELS_MAX];
calc_linear_integer_volume(linear, volume);
- for (channel = 0, d = ptr, n = c->length; n > 0; d++, n--) {
+ e = (uint8_t*) ptr + c->length;
+
+ for (channel = 0, d = ptr; d < e; d++) {
int32_t t;
t = (int32_t) st_alaw2linear16(*d);
@@ -799,22 +806,20 @@ void pa_volume_memchunk(
}
case PA_SAMPLE_FLOAT32RE: {
- uint32_t *d;
- size_t n;
+ float *d, *e;
unsigned channel;
float linear[PA_CHANNELS_MAX];
calc_linear_float_volume(linear, volume);
- for (channel = 0, d = ptr, n = c->length/sizeof(float); n > 0; d++, n--) {
+ e = (float*) ptr + c->length/sizeof(float);
+
+ for (channel = 0, d = ptr; d < e; d++) {
float t;
- uint32_t z;
- z = PA_UINT32_SWAP(*d);
- t = *(float*) &z;
+ t = PA_FLOAT32_SWAP(*d);
t *= linear[channel];
- z = *(uint32_t*) &t;
- *d = PA_UINT32_SWAP(z);
+ *d = PA_FLOAT32_SWAP(t);
if (PA_UNLIKELY(++channel >= spec->channels))
channel = 0;