diff --git a/src/pcm/Volume.cxx b/src/pcm/Volume.cxx index eaba84a59..8a2ec13b6 100644 --- a/src/pcm/Volume.cxx +++ b/src/pcm/Volume.cxx @@ -26,6 +26,20 @@ #include #include +template> +static inline typename Traits::value_type +pcm_volume_sample(typename Traits::value_type _sample, + int volume) +{ + typename Traits::long_type sample(_sample); + + sample = (sample * volume + pcm_volume_dither() + + PCM_VOLUME_1S / 2) + >> PCM_VOLUME_BITS; + + return PcmClamp(sample); +} + template> static void pcm_volume_change(typename Traits::pointer_type buffer, @@ -33,13 +47,8 @@ pcm_volume_change(typename Traits::pointer_type buffer, int volume) { while (buffer < end) { - typename Traits::long_type sample = *buffer; - - sample = (sample * volume + pcm_volume_dither() + - PCM_VOLUME_1S / 2) - >> PCM_VOLUME_BITS; - - *buffer++ = PcmClamp(sample); + const auto sample = *buffer; + *buffer++ = pcm_volume_sample(sample, volume); } }