diff options
author | Max Kellermann <max@duempel.org> | 2008-11-11 16:32:32 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-11-11 16:32:32 +0100 |
commit | edcd45df94bf69b78342943cd319d8ceb43ed6d1 (patch) | |
tree | d70e37392d8f51131563e16bf33668ba56f28d3e /src/pcm_utils.c | |
parent | ad77a3e0ace2bb082bc619de1c6d8732715e8977 (diff) | |
download | mpd-edcd45df94bf69b78342943cd319d8ceb43ed6d1.tar.gz mpd-edcd45df94bf69b78342943cd319d8ceb43ed6d1.tar.xz mpd-edcd45df94bf69b78342943cd319d8ceb43ed6d1.zip |
pcm_volume: added constant PCM_VOLUME_1
It may be desirable to change the range of integer volume levels
(e.g. to 1024, which may utilize shifts instead of expensive integer
divisions). Introduce the constant PCM_VOLUME_1 which describes the
integer value for "100% volume". This is currently 1000.
Diffstat (limited to 'src/pcm_utils.c')
-rw-r--r-- | src/pcm_utils.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/pcm_utils.c b/src/pcm_utils.c index c06c7e1ab..a68542f4a 100644 --- a/src/pcm_utils.c +++ b/src/pcm_utils.c @@ -53,7 +53,8 @@ pcm_volume_change_8(int8_t *buffer, unsigned num_samples, int volume) while (num_samples > 0) { int32_t sample = *buffer; - sample = (sample * volume + pcm_dither() + 500) / 1000; + sample = (sample * volume + pcm_dither() + PCM_VOLUME_1 / 2) + / PCM_VOLUME_1; *buffer++ = pcm_range(sample, 8); --num_samples; @@ -66,7 +67,8 @@ pcm_volume_change_16(int16_t *buffer, unsigned num_samples, int volume) while (num_samples > 0) { int32_t sample = *buffer; - sample = (sample * volume + pcm_dither() + 500) / 1000; + sample = (sample * volume + pcm_dither() + PCM_VOLUME_1 / 2) + / PCM_VOLUME_1; *buffer++ = pcm_range(sample, 16); --num_samples; @@ -79,7 +81,8 @@ pcm_volume_change_24(int32_t *buffer, unsigned num_samples, int volume) while (num_samples > 0) { int64_t sample = *buffer; - sample = (sample * volume + pcm_dither() + 500) / 1000; + sample = (sample * volume + pcm_dither() + PCM_VOLUME_1 / 2) + / PCM_VOLUME_1; *buffer++ = pcm_range(sample, 24); --num_samples; @@ -90,7 +93,7 @@ void pcm_volume(char *buffer, int bufferSize, const struct audio_format *format, int volume) { - if (volume >= 1000) + if (volume >= PCM_VOLUME_1) return; if (volume <= 0) { @@ -128,7 +131,7 @@ pcm_add_8(int8_t *buffer1, const int8_t *buffer2, int32_t sample2 = *buffer2++; sample1 = ((sample1 * volume1 + sample2 * volume2) + - pcm_dither() + 500) / 1000; + pcm_dither() + PCM_VOLUME_1 / 2) / PCM_VOLUME_1; *buffer1++ = pcm_range(sample1, 8); --num_samples; @@ -144,7 +147,7 @@ pcm_add_16(int16_t *buffer1, const int16_t *buffer2, int32_t sample2 = *buffer2++; sample1 = ((sample1 * volume1 + sample2 * volume2) + - pcm_dither() + 500) / 1000; + pcm_dither() + PCM_VOLUME_1 / 2) / PCM_VOLUME_1; *buffer1++ = pcm_range(sample1, 16); --num_samples; @@ -160,7 +163,7 @@ pcm_add_24(int32_t *buffer1, const int32_t *buffer2, int64_t sample2 = *buffer2++; sample1 = ((sample1 * volume1 + sample2 * volume2) + - pcm_dither() + 500) / 1000; + pcm_dither() + PCM_VOLUME_1 / 2) / PCM_VOLUME_1; *buffer1++ = pcm_range(sample1, 24); --num_samples; @@ -200,10 +203,10 @@ void pcm_mix(char *buffer1, const char *buffer2, size_t size, float s = sin(M_PI_2 * portion1); s *= s; - vol1 = s * 1000 + 0.5; - vol1 = vol1 > 1000 ? 1000 : (vol1 < 0 ? 0 : vol1); + vol1 = s * PCM_VOLUME_1 + 0.5; + vol1 = vol1 > PCM_VOLUME_1 ? PCM_VOLUME_1 : (vol1 < 0 ? 0 : vol1); - pcm_add(buffer1, buffer2, size, vol1, 1000 - vol1, format); + pcm_add(buffer1, buffer2, size, vol1, PCM_VOLUME_1 - vol1, format); } void pcm_convert_init(struct pcm_convert_state *state) |