Commit f357f743 authored by Max Kellermann's avatar Max Kellermann

pcm/Volume: use transform_n()

parent 91e565d9
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "util/ConstBuffer.hxx" #include "util/ConstBuffer.hxx"
#include "util/WritableBuffer.hxx" #include "util/WritableBuffer.hxx"
#include "util/RuntimeError.hxx" #include "util/RuntimeError.hxx"
#include "util/TransformN.hxx"
#include "Dither.cxx" // including the .cxx file to get inlined templates #include "Dither.cxx" // including the .cxx file to get inlined templates
...@@ -94,8 +95,11 @@ pcm_volume_change(PcmDither &dither, ...@@ -94,8 +95,11 @@ pcm_volume_change(PcmDither &dither,
size_t n, size_t n,
int volume) noexcept int volume) noexcept
{ {
for (size_t i = 0; i != n; ++i) transform_n(src, n, dest,
dest[i] = pcm_volume_sample<F, Traits>(dither, src[i], volume); [&dither, volume](auto x){
return pcm_volume_sample<F, Traits>(dither, x,
volume);
});
} }
static void static void
...@@ -118,10 +122,12 @@ static void ...@@ -118,10 +122,12 @@ static void
PcmVolumeChange16to32(int32_t *dest, const int16_t *src, size_t n, PcmVolumeChange16to32(int32_t *dest, const int16_t *src, size_t n,
int volume) noexcept int volume) noexcept
{ {
for (size_t i = 0; i != n; ++i) transform_n(src, n, dest,
dest[i] = PcmVolumeConvert<SampleFormat::S16, [volume](auto x){
SampleFormat::S24_P32>(src[i], return PcmVolumeConvert<SampleFormat::S16,
volume); SampleFormat::S24_P32>(x,
volume);
});
} }
static void static void
...@@ -145,8 +151,8 @@ static void ...@@ -145,8 +151,8 @@ static void
pcm_volume_change_float(float *dest, const float *src, size_t n, pcm_volume_change_float(float *dest, const float *src, size_t n,
float volume) noexcept float volume) noexcept
{ {
for (size_t i = 0; i != n; ++i) transform_n(src, n, dest,
dest[i] = src[i] * volume; [volume](float x){ return x * volume; });
} }
SampleFormat SampleFormat
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment