From f357f743a33de9b7c0fcc7ff783d2742d5cb5590 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 5 Jul 2019 21:05:44 +0200 Subject: [PATCH] pcm/Volume: use transform_n() --- src/pcm/Volume.cxx | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/pcm/Volume.cxx b/src/pcm/Volume.cxx index 985da0b5b..4efb8eeca 100644 --- a/src/pcm/Volume.cxx +++ b/src/pcm/Volume.cxx @@ -23,6 +23,7 @@ #include "util/ConstBuffer.hxx" #include "util/WritableBuffer.hxx" #include "util/RuntimeError.hxx" +#include "util/TransformN.hxx" #include "Dither.cxx" // including the .cxx file to get inlined templates @@ -94,8 +95,11 @@ pcm_volume_change(PcmDither &dither, size_t n, int volume) noexcept { - for (size_t i = 0; i != n; ++i) - dest[i] = pcm_volume_sample(dither, src[i], volume); + transform_n(src, n, dest, + [&dither, volume](auto x){ + return pcm_volume_sample(dither, x, + volume); + }); } static void @@ -118,10 +122,12 @@ static void PcmVolumeChange16to32(int32_t *dest, const int16_t *src, size_t n, int volume) noexcept { - for (size_t i = 0; i != n; ++i) - dest[i] = PcmVolumeConvert(src[i], - volume); + transform_n(src, n, dest, + [volume](auto x){ + return PcmVolumeConvert(x, + volume); + }); } static void @@ -145,8 +151,8 @@ static void pcm_volume_change_float(float *dest, const float *src, size_t n, float volume) noexcept { - for (size_t i = 0; i != n; ++i) - dest[i] = src[i] * volume; + transform_n(src, n, dest, + [volume](float x){ return x * volume; }); } SampleFormat