diff options
author | Max Kellermann <max@duempel.org> | 2013-12-23 10:03:05 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-12-23 10:35:23 +0100 |
commit | 4a62cd4ad89405f34a15bc4eb914d8ff97f9a7ae (patch) | |
tree | 7e073259fada3f1adb3f763c91be1e7915e85228 /src | |
parent | 6d21b9448a0d337b449ce22f68802670c911ca40 (diff) |
pcm/Volume: move code to template pcm_volume_sample()
Diffstat (limited to 'src')
-rw-r--r-- | src/pcm/Volume.cxx | 23 |
1 files changed, 16 insertions, 7 deletions
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 @@ -27,19 +27,28 @@ #include <string.h> template<SampleFormat F, class Traits=SampleTraits<F>> +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<F, Traits>(sample); +} + +template<SampleFormat F, class Traits=SampleTraits<F>> static void pcm_volume_change(typename Traits::pointer_type buffer, typename Traits::const_pointer_type end, 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<F, Traits>(sample); + const auto sample = *buffer; + *buffer++ = pcm_volume_sample<F, Traits>(sample, volume); } } |