aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcm
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-07 00:42:02 +0100
committerMax Kellermann <max@duempel.org>2014-01-07 00:42:02 +0100
commit7eda72d4409dbed7bc40c61d105282f90527f16a (patch)
treee0952ed3d9f570304ee14f2f36646774acd25530 /src/pcm
parentc75339edcc8ced25a71ab96a309736986c04465b (diff)
downloadmpd-7eda72d4409dbed7bc40c61d105282f90527f16a.tar.gz
mpd-7eda72d4409dbed7bc40c61d105282f90527f16a.tar.xz
mpd-7eda72d4409dbed7bc40c61d105282f90527f16a.zip
pcm/Volume: use number of samples instead of end pointer
Diffstat (limited to 'src/pcm')
-rw-r--r--src/pcm/Volume.cxx44
1 files changed, 19 insertions, 25 deletions
diff --git a/src/pcm/Volume.cxx b/src/pcm/Volume.cxx
index 6347657c6..988d3fbbf 100644
--- a/src/pcm/Volume.cxx
+++ b/src/pcm/Volume.cxx
@@ -48,57 +48,52 @@ static void
pcm_volume_change(PcmDither &dither,
typename Traits::pointer_type dest,
typename Traits::const_pointer_type src,
- typename Traits::const_pointer_type end,
+ size_t n,
int volume)
{
- while (src < end) {
- const auto sample = *src++;
- *dest++ = pcm_volume_sample<F, Traits>(dither, sample, volume);
- }
+ for (size_t i = 0; i != n; ++i)
+ dest[i] = pcm_volume_sample<F, Traits>(dither, src[i], volume);
}
static void
pcm_volume_change_8(PcmDither &dither,
- int8_t *dest, const int8_t *src, const int8_t *end,
+ int8_t *dest, const int8_t *src, size_t n,
int volume)
{
- pcm_volume_change<SampleFormat::S8>(dither, dest, src, end, volume);
+ pcm_volume_change<SampleFormat::S8>(dither, dest, src, n, volume);
}
static void
pcm_volume_change_16(PcmDither &dither,
- int16_t *dest, const int16_t *src, const int16_t *end,
+ int16_t *dest, const int16_t *src, size_t n,
int volume)
{
- pcm_volume_change<SampleFormat::S16>(dither, dest, src, end, volume);
+ pcm_volume_change<SampleFormat::S16>(dither, dest, src, n, volume);
}
static void
pcm_volume_change_24(PcmDither &dither,
- int32_t *dest, const int32_t *src, const int32_t *end,
+ int32_t *dest, const int32_t *src, size_t n,
int volume)
{
- pcm_volume_change<SampleFormat::S24_P32>(dither, dest, src, end,
+ pcm_volume_change<SampleFormat::S24_P32>(dither, dest, src, n,
volume);
}
static void
pcm_volume_change_32(PcmDither &dither,
- int32_t *dest, const int32_t *src, const int32_t *end,
+ int32_t *dest, const int32_t *src, size_t n,
int volume)
{
- pcm_volume_change<SampleFormat::S32>(dither, dest, src, end, volume);
+ pcm_volume_change<SampleFormat::S32>(dither, dest, src, n, volume);
}
static void
-pcm_volume_change_float(float *dest, const float *src, const float *end,
+pcm_volume_change_float(float *dest, const float *src, size_t n,
float volume)
{
- while (src < end) {
- float sample = *src++;
- sample *= volume;
- *dest++ = sample;
- }
+ for (size_t i = 0; i != n; ++i)
+ dest[i] = src[i] * volume;
}
bool
@@ -142,7 +137,6 @@ PcmVolume::Apply(ConstBuffer<void> src)
return { data, src.size };
}
- const void *end = pcm_end_pointer(src.data, src.size);
switch (format) {
case SampleFormat::UNDEFINED:
case SampleFormat::DSD:
@@ -152,35 +146,35 @@ PcmVolume::Apply(ConstBuffer<void> src)
case SampleFormat::S8:
pcm_volume_change_8(dither, (int8_t *)data,
(const int8_t *)src.data,
- (const int8_t *)end,
+ src.size / sizeof(int8_t),
volume);
break;
case SampleFormat::S16:
pcm_volume_change_16(dither, (int16_t *)data,
(const int16_t *)src.data,
- (const int16_t *)end,
+ src.size / sizeof(int16_t),
volume);
break;
case SampleFormat::S24_P32:
pcm_volume_change_24(dither, (int32_t *)data,
(const int32_t *)src.data,
- (const int32_t *)end,
+ src.size / sizeof(int32_t),
volume);
break;
case SampleFormat::S32:
pcm_volume_change_32(dither, (int32_t *)data,
(const int32_t *)src.data,
- (const int32_t *)end,
+ src.size / sizeof(int32_t),
volume);
break;
case SampleFormat::FLOAT:
pcm_volume_change_float((float *)data,
(const float *)src.data,
- (const float *)end,
+ src.size / sizeof(float),
pcm_volume_to_float(volume));
break;
}