From d11a0c9f14dcabf9ddbf8e38379dc7d6d890b02b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 23 Dec 2013 10:50:42 +0100 Subject: pcm/Volume: apply volume into destination buffer --- src/pcm/Volume.cxx | 58 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 21 deletions(-) (limited to 'src/pcm/Volume.cxx') 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> 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(sample, volume); + while (src < end) { + const auto sample = *src++; + *dest++ = pcm_volume_sample(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(buffer, end, volume); + pcm_volume_change(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(buffer, end, volume); + pcm_volume_change(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(buffer, end, volume); + pcm_volume_change(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(buffer, end, volume); + pcm_volume_change(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; } -- cgit v1.2.3