From 30c4136c4d67953d643626fcb1aceb6782ac35f8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 2 Dec 2013 08:58:40 +0100 Subject: pcm/PcmVolume: use the SampleTraits library --- src/pcm/PcmVolume.cxx | 52 ++++++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/pcm/PcmVolume.cxx b/src/pcm/PcmVolume.cxx index 564880633..fafec2d60 100644 --- a/src/pcm/PcmVolume.cxx +++ b/src/pcm/PcmVolume.cxx @@ -20,37 +20,41 @@ #include "config.h" #include "PcmVolume.hxx" #include "PcmUtils.hxx" +#include "Traits.hxx" #include "AudioFormat.hxx" #include #include +template> static void -pcm_volume_change_8(int8_t *buffer, const int8_t *end, int volume) +pcm_volume_change(typename Traits::pointer_type buffer, + typename Traits::const_pointer_type end, + int volume) { while (buffer < end) { - int32_t sample = *buffer; + typename Traits::long_type sample = *buffer; sample = (sample * volume + pcm_volume_dither() + PCM_VOLUME_1 / 2) / PCM_VOLUME_1; - *buffer++ = PcmClamp(sample); + *buffer++ = PcmClamp(sample); } } static void -pcm_volume_change_16(int16_t *buffer, const int16_t *end, int volume) +pcm_volume_change_8(int8_t *buffer, const int8_t *end, int volume) { - while (buffer < end) { - int32_t sample = *buffer; - - sample = (sample * volume + pcm_volume_dither() + - PCM_VOLUME_1 / 2) - / PCM_VOLUME_1; + pcm_volume_change(buffer, end, volume); +} - *buffer++ = PcmClamp(sample); - } +static void +pcm_volume_change_16(int16_t *buffer, const int16_t *end, int volume) +{ + pcm_volume_change(buffer, end, volume); } #ifdef __i386__ @@ -87,44 +91,32 @@ pcm_volume_sample_24(int32_t sample, int32_t volume, gcc_unused int32_t dither) static void pcm_volume_change_24(int32_t *buffer, const int32_t *end, int volume) { - while (buffer < end) { #ifdef __i386__ + while (buffer < end) { /* assembly version for i386 */ int32_t sample = *buffer; sample = pcm_volume_sample_24(sample, volume, pcm_volume_dither()); + } #else - /* portable version */ - int64_t sample = *buffer; - - sample = (sample * volume + pcm_volume_dither() + - PCM_VOLUME_1 / 2) - / PCM_VOLUME_1; + pcm_volume_change(buffer, end, volume); #endif - *buffer++ = PcmClamp(sample); - } } static void pcm_volume_change_32(int32_t *buffer, const int32_t *end, int volume) { - while (buffer < end) { #ifdef __i386__ + while (buffer < end) { /* assembly version for i386 */ int32_t sample = *buffer; *buffer++ = pcm_volume_sample_24(sample, volume, 0); + } #else - /* portable version */ - int64_t sample = *buffer; - - sample = (sample * volume + pcm_volume_dither() + - PCM_VOLUME_1 / 2) - / PCM_VOLUME_1; - *buffer++ = PcmClamp(sample); + pcm_volume_change(buffer, end, volume); #endif - } } static void -- cgit v1.2.3