aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-12-02 08:58:40 +0100
committerMax Kellermann <max@duempel.org>2013-12-02 11:21:32 +0100
commit30c4136c4d67953d643626fcb1aceb6782ac35f8 (patch)
treee645d45e33db09faff1772736e22e190992c5aee /src
parent83e4475021317788028a58cf49d1801123de9829 (diff)
downloadmpd-30c4136c4d67953d643626fcb1aceb6782ac35f8.tar.gz
mpd-30c4136c4d67953d643626fcb1aceb6782ac35f8.tar.xz
mpd-30c4136c4d67953d643626fcb1aceb6782ac35f8.zip
pcm/PcmVolume: use the SampleTraits library
Diffstat (limited to 'src')
-rw-r--r--src/pcm/PcmVolume.cxx52
1 files changed, 22 insertions, 30 deletions
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 <stdint.h>
#include <string.h>
+template<SampleFormat F, class Traits=SampleTraits<F>>
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<int8_t, int16_t, 8>(sample);
+ *buffer++ = PcmClamp<typename Traits::value_type,
+ typename Traits::long_type,
+ Traits::BITS>(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<SampleFormat::S8>(buffer, end, volume);
+}
- *buffer++ = PcmClamp<int16_t, int32_t, 16>(sample);
- }
+static void
+pcm_volume_change_16(int16_t *buffer, const int16_t *end, int volume)
+{
+ pcm_volume_change<SampleFormat::S16>(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<SampleFormat::S24_P32>(buffer, end, volume);
#endif
- *buffer++ = PcmClamp<int32_t, int32_t, 24>(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<int32_t, int64_t, 32>(sample);
+ pcm_volume_change<SampleFormat::S32>(buffer, end, volume);
#endif
- }
}
static void