From 04ba40981f559a1847403f4ef2975cd7c50761ff Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 1 Dec 2013 20:37:30 +0100 Subject: pcm/PcmMix: use the SampleTraits library --- src/pcm/PcmMix.cxx | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/pcm/PcmMix.cxx b/src/pcm/PcmMix.cxx index 21080bc5f..d7183f01d 100644 --- a/src/pcm/PcmMix.cxx +++ b/src/pcm/PcmMix.cxx @@ -22,40 +22,48 @@ #include "PcmVolume.hxx" #include "PcmUtils.hxx" #include "AudioFormat.hxx" +#include "Traits.hxx" #include #include -template -static T -PcmAddVolume(T _a, T _b, int volume1, int volume2) +template> +static typename Traits::value_type +PcmAddVolume(typename Traits::value_type _a, typename Traits::value_type _b, + int volume1, int volume2) { - U a(_a), b(_b); + typename Traits::long_type a(_a), b(_b); - U c = ((a * volume1 + b * volume2) + + typename Traits::value_type c = ((a * volume1 + b * volume2) + pcm_volume_dither() + PCM_VOLUME_1 / 2) / PCM_VOLUME_1; - return PcmClamp(c); + return PcmClamp(c); } -template +template> static void -PcmAddVolume(T *a, const T *b, unsigned n, int volume1, int volume2) +PcmAddVolume(typename Traits::pointer_type a, + typename Traits::const_pointer_type b, + size_t n, int volume1, int volume2) { for (size_t i = 0; i != n; ++i) - a[i] = PcmAddVolume(a[i], b[i], volume1, volume2); + a[i] = PcmAddVolume(a[i], b[i], volume1, volume2); } -template +template> static void PcmAddVolumeVoid(void *a, const void *b, size_t size, int volume1, int volume2) { - constexpr size_t sample_size = sizeof(T); + constexpr size_t sample_size = Traits::SAMPLE_SIZE; assert(size % sample_size == 0); - PcmAddVolume((T *)a, (const T *)b, size / sample_size, - volume1, volume2); + PcmAddVolume(typename Traits::pointer_type(a), + typename Traits::const_pointer_type(b), + size / sample_size, + volume1, volume2); } static void @@ -84,23 +92,23 @@ pcm_add_vol(void *buffer1, const void *buffer2, size_t size, return false; case SampleFormat::S8: - PcmAddVolumeVoid(buffer1, buffer2, size, - vol1, vol2); + PcmAddVolumeVoid(buffer1, buffer2, size, + vol1, vol2); return true; case SampleFormat::S16: - PcmAddVolumeVoid(buffer1, buffer2, size, - vol1, vol2); + PcmAddVolumeVoid(buffer1, buffer2, size, + vol1, vol2); return true; case SampleFormat::S24_P32: - PcmAddVolumeVoid(buffer1, buffer2, size, - vol1, vol2); + PcmAddVolumeVoid(buffer1, buffer2, size, + vol1, vol2); return true; case SampleFormat::S32: - PcmAddVolumeVoid(buffer1, buffer2, size, - vol1, vol2); + PcmAddVolumeVoid(buffer1, buffer2, size, + vol1, vol2); return true; case SampleFormat::FLOAT: -- cgit v1.2.3