diff options
author | Max Kellermann <max@duempel.org> | 2013-12-23 10:50:42 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-12-23 10:55:29 +0100 |
commit | d11a0c9f14dcabf9ddbf8e38379dc7d6d890b02b (patch) | |
tree | 175b500b1f89b1b324fc63a9d4ce00a5c761f41b /src/pcm | |
parent | 7be2abe6b5bae45fb91b79aa232db0392ec1046f (diff) | |
download | mpd-d11a0c9f14dcabf9ddbf8e38379dc7d6d890b02b.tar.gz mpd-d11a0c9f14dcabf9ddbf8e38379dc7d6d890b02b.tar.xz mpd-d11a0c9f14dcabf9ddbf8e38379dc7d6d890b02b.zip |
pcm/Volume: apply volume into destination buffer
Diffstat (limited to 'src/pcm')
-rw-r--r-- | src/pcm/Volume.cxx | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/src/pcm/Volume.cxx b/src/pcm/Volume.cxx index f4e750bf7..410df7695 100644 --- a/src/pcm/Volume.cxx +++ b/src/pcm/Volume.cxx @@ -92,47 +92,53 @@ pcm_volume_sample<SampleFormat::S32, template<SampleFormat F, class Traits=SampleTraits<F>> static void -pcm_volume_change(typename Traits::pointer_type buffer, +pcm_volume_change(typename Traits::pointer_type dest, + typename Traits::const_pointer_type src, typename Traits::const_pointer_type end, int volume) { - while (buffer < end) { - const auto sample = *buffer; - *buffer++ = pcm_volume_sample<F, Traits>(sample, volume); + while (src < end) { + const auto sample = *src++; + *dest++ = pcm_volume_sample<F, Traits>(sample, volume); } } static void -pcm_volume_change_8(int8_t *buffer, const int8_t *end, int volume) +pcm_volume_change_8(int8_t *dest, const int8_t *src, const int8_t *end, + int volume) { - pcm_volume_change<SampleFormat::S8>(buffer, end, volume); + pcm_volume_change<SampleFormat::S8>(dest, src, end, volume); } static void -pcm_volume_change_16(int16_t *buffer, const int16_t *end, int volume) +pcm_volume_change_16(int16_t *dest, const int16_t *src, const int16_t *end, + int volume) { - pcm_volume_change<SampleFormat::S16>(buffer, end, volume); + pcm_volume_change<SampleFormat::S16>(dest, src, end, volume); } static void -pcm_volume_change_24(int32_t *buffer, const int32_t *end, int volume) +pcm_volume_change_24(int32_t *dest, const int32_t *src, const int32_t *end, + int volume) { - pcm_volume_change<SampleFormat::S24_P32>(buffer, end, volume); + pcm_volume_change<SampleFormat::S24_P32>(dest, src, end, volume); } static void -pcm_volume_change_32(int32_t *buffer, const int32_t *end, int volume) +pcm_volume_change_32(int32_t *dest, const int32_t *src, const int32_t *end, + int volume) { - pcm_volume_change<SampleFormat::S32>(buffer, end, volume); + pcm_volume_change<SampleFormat::S32>(dest, src, end, volume); } static void -pcm_volume_change_float(float *buffer, const float *end, float volume) +pcm_volume_change_float(float *dest, const float *src, const float *end, + float volume) { - while (buffer < end) { - float sample = *buffer; + while (src < end) { + float sample = *src++; sample *= volume; - *buffer++ = sample; + *dest++ = sample; } } @@ -157,27 +163,37 @@ pcm_volume(void *buffer, size_t length, return false; case SampleFormat::S8: - pcm_volume_change_8((int8_t *)buffer, (const int8_t *)end, + pcm_volume_change_8((int8_t *)buffer, + (const int8_t *)buffer, + (const int8_t *)end, volume); return true; case SampleFormat::S16: - pcm_volume_change_16((int16_t *)buffer, (const int16_t *)end, + pcm_volume_change_16((int16_t *)buffer, + (const int16_t *)buffer, + (const int16_t *)end, volume); return true; case SampleFormat::S24_P32: - pcm_volume_change_24((int32_t *)buffer, (const int32_t *)end, + pcm_volume_change_24((int32_t *)buffer, + (const int32_t *)buffer, + (const int32_t *)end, volume); return true; case SampleFormat::S32: - pcm_volume_change_32((int32_t *)buffer, (const int32_t *)end, + pcm_volume_change_32((int32_t *)buffer, + (const int32_t *)buffer, + (const int32_t *)end, volume); return true; case SampleFormat::FLOAT: - pcm_volume_change_float((float *)buffer, (const float *)end, + pcm_volume_change_float((float *)buffer, + (const float *)buffer, + (const float *)end, pcm_volume_to_float(volume)); return true; } |