From 7be2abe6b5bae45fb91b79aa232db0392ec1046f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 23 Dec 2013 10:07:28 +0100 Subject: pcm/Volume: convert i386 code to template specialization --- src/pcm/Volume.cxx | 84 +++++++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/pcm/Volume.cxx b/src/pcm/Volume.cxx index 8a2ec13b6..f4e750bf7 100644 --- a/src/pcm/Volume.cxx +++ b/src/pcm/Volume.cxx @@ -40,31 +40,8 @@ pcm_volume_sample(typename Traits::value_type _sample, return PcmClamp(sample); } -template> -static void -pcm_volume_change(typename Traits::pointer_type buffer, - typename Traits::const_pointer_type end, - int volume) -{ - while (buffer < end) { - const auto sample = *buffer; - *buffer++ = pcm_volume_sample(sample, volume); - } -} - -static void -pcm_volume_change_8(int8_t *buffer, const int8_t *end, int volume) -{ - pcm_volume_change(buffer, end, volume); -} - -static void -pcm_volume_change_16(int16_t *buffer, const int16_t *end, int volume) -{ - pcm_volume_change(buffer, end, volume); -} - #ifdef __i386__ + /** * Optimized volume function for i386. Use the EDX:EAX 2*32 bit * multiplication result instead of emulating 64 bit multiplication. @@ -93,37 +70,60 @@ pcm_volume_sample_24(int32_t sample, int32_t volume, gcc_unused int32_t dither) return result; } + +template<> +inline int32_t +pcm_volume_sample>(int32_t sample, + int volume) +{ + return pcm_volume_sample_24(sample, volume, pcm_volume_dither()); +} + +template<> +inline int32_t +pcm_volume_sample>(int32_t sample, int volume) +{ + return pcm_volume_sample_24(sample, volume, pcm_volume_dither()); +} + #endif +template> static void -pcm_volume_change_24(int32_t *buffer, const int32_t *end, int volume) +pcm_volume_change(typename Traits::pointer_type buffer, + typename Traits::const_pointer_type end, + int volume) { -#ifdef __i386__ while (buffer < end) { - /* assembly version for i386 */ - int32_t sample = *buffer; - - sample = pcm_volume_sample_24(sample, volume, - pcm_volume_dither()); + const auto sample = *buffer; + *buffer++ = pcm_volume_sample(sample, volume); } -#else +} + +static void +pcm_volume_change_8(int8_t *buffer, const int8_t *end, int volume) +{ + pcm_volume_change(buffer, end, volume); +} + +static void +pcm_volume_change_16(int16_t *buffer, const int16_t *end, int volume) +{ + pcm_volume_change(buffer, end, volume); +} + +static void +pcm_volume_change_24(int32_t *buffer, const int32_t *end, int volume) +{ pcm_volume_change(buffer, end, volume); -#endif } static void pcm_volume_change_32(int32_t *buffer, const int32_t *end, int volume) { -#ifdef __i386__ - while (buffer < end) { - /* assembly version for i386 */ - int32_t sample = *buffer; - - *buffer++ = pcm_volume_sample_24(sample, volume, 0); - } -#else pcm_volume_change(buffer, end, volume); -#endif } static void -- cgit v1.2.3