diff options
author | Lennart Poettering <lennart@poettering.net> | 2009-06-17 03:04:21 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2009-06-17 03:04:21 +0200 |
commit | 64b0f38b67ed221ac11d017bd27aa62c6b1a8c2b (patch) | |
tree | c4f58d6f6313bfbb0107220d0fffe82f8365c952 /src/pulse | |
parent | c6830bd9dc53ee745ac331c4ab1c55134562d114 (diff) |
volume: implement functions for multiplicating a cvolume with a scalar
Diffstat (limited to 'src/pulse')
-rw-r--r-- | src/pulse/volume.c | 36 | ||||
-rw-r--r-- | src/pulse/volume.h | 12 |
2 files changed, 45 insertions, 3 deletions
diff --git a/src/pulse/volume.c b/src/pulse/volume.c index 64688e0b..76ef7aa5 100644 --- a/src/pulse/volume.c +++ b/src/pulse/volume.c @@ -344,7 +344,7 @@ pa_cvolume *pa_sw_cvolume_multiply(pa_cvolume *dest, const pa_cvolume *a, const pa_return_val_if_fail(pa_cvolume_valid(a), NULL); pa_return_val_if_fail(pa_cvolume_valid(b), NULL); - for (i = 0; i < a->channels && i < b->channels && i < PA_CHANNELS_MAX; i++) + for (i = 0; i < a->channels && i < b->channels; i++) dest->values[i] = pa_sw_volume_multiply(a->values[i], b->values[i]); dest->channels = (uint8_t) i; @@ -352,6 +352,22 @@ pa_cvolume *pa_sw_cvolume_multiply(pa_cvolume *dest, const pa_cvolume *a, const return dest; } +pa_cvolume *pa_sw_cvolume_multiply_scalar(pa_cvolume *dest, const pa_cvolume *a, pa_volume_t b) { + unsigned i; + + pa_assert(dest); + pa_assert(a); + + pa_return_val_if_fail(pa_cvolume_valid(a), NULL); + + for (i = 0; i < a->channels; i++) + dest->values[i] = pa_sw_volume_multiply(a->values[i], b); + + dest->channels = (uint8_t) i; + + return dest; +} + pa_cvolume *pa_sw_cvolume_divide(pa_cvolume *dest, const pa_cvolume *a, const pa_cvolume *b) { unsigned i; @@ -362,7 +378,7 @@ pa_cvolume *pa_sw_cvolume_divide(pa_cvolume *dest, const pa_cvolume *a, const pa pa_return_val_if_fail(pa_cvolume_valid(a), NULL); pa_return_val_if_fail(pa_cvolume_valid(b), NULL); - for (i = 0; i < a->channels && i < b->channels && i < PA_CHANNELS_MAX; i++) + for (i = 0; i < a->channels && i < b->channels; i++) dest->values[i] = pa_sw_volume_divide(a->values[i], b->values[i]); dest->channels = (uint8_t) i; @@ -370,6 +386,22 @@ pa_cvolume *pa_sw_cvolume_divide(pa_cvolume *dest, const pa_cvolume *a, const pa return dest; } +pa_cvolume *pa_sw_cvolume_divide_scalar(pa_cvolume *dest, const pa_cvolume *a, pa_volume_t b) { + unsigned i; + + pa_assert(dest); + pa_assert(a); + + pa_return_val_if_fail(pa_cvolume_valid(a), NULL); + + for (i = 0; i < a->channels; i++) + dest->values[i] = pa_sw_volume_divide(a->values[i], b); + + dest->channels = (uint8_t) i; + + return dest; +} + int pa_cvolume_valid(const pa_cvolume *v) { unsigned c; diff --git a/src/pulse/volume.h b/src/pulse/volume.h index c07fd99a..05b7ebb4 100644 --- a/src/pulse/volume.h +++ b/src/pulse/volume.h @@ -216,16 +216,26 @@ pa_volume_t pa_sw_volume_multiply(pa_volume_t a, pa_volume_t b) PA_GCC_CONST; * *dest. This is only valid for software volumes! */ pa_cvolume *pa_sw_cvolume_multiply(pa_cvolume *dest, const pa_cvolume *a, const pa_cvolume *b); +/** Multiply a per-channel volume with a scalar volume and return the + * result in *dest. This is only valid for software volumes! \since + * 0.9.16 */ +pa_cvolume *pa_sw_cvolume_multiply_scalar(pa_cvolume *dest, const pa_cvolume *a, pa_volume_t b); + /** Divide two volume specifications, return the result. This uses * PA_VOLUME_NORM as neutral element of division. This is only valid * for software volumes! If a division by zero is tried the result * will be 0. \since 0.9.13 */ pa_volume_t pa_sw_volume_divide(pa_volume_t a, pa_volume_t b) PA_GCC_CONST; -/** Multiply to per-channel volumes and return the result in +/** Divide two per-channel volumes and return the result in * *dest. This is only valid for software volumes! \since 0.9.13 */ pa_cvolume *pa_sw_cvolume_divide(pa_cvolume *dest, const pa_cvolume *a, const pa_cvolume *b); +/** Divide a per-channel volume by a scalar volume and return the + * result in *dest. This is only valid for software volumes! \since + * 0.9.16 */ +pa_cvolume *pa_sw_cvolume_divide_scalar(pa_cvolume *dest, const pa_cvolume *a, pa_volume_t b); + /** Convert a decibel value to a volume (amplitude, not power). This is only valid for software volumes! */ pa_volume_t pa_sw_volume_from_dB(double f) PA_GCC_CONST; |