From 2c9da1b671d5515de1116b5a1d389dc83c2bc33d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 8 May 2022 20:22:25 -0700 Subject: Avoid an ugly and confusing generate_n --- examples/alffplay.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'examples') diff --git a/examples/alffplay.cpp b/examples/alffplay.cpp index 6847f8da..fef83707 100644 --- a/examples/alffplay.cpp +++ b/examples/alffplay.cpp @@ -694,21 +694,15 @@ static void sample_dup(uint8_t *out, const uint8_t *in, size_t count, size_t fra { auto *sample = reinterpret_cast(in); auto *dst = reinterpret_cast(out); - if(frame_size == sizeof(T)) + + /* NOTE: frame_size is a multiple of sizeof(T). */ + size_t type_mult{frame_size / sizeof(T)}; + if(type_mult == 1) std::fill_n(dst, count, *sample); - else + else for(size_t i{0};i < count;++i) { - /* NOTE: frame_size is a multiple of sizeof(T). */ - size_t type_mult{frame_size / sizeof(T)}; - size_t i{0}; - std::generate_n(dst, count*type_mult, - [sample,type_mult,&i]() -> T - { - T ret = sample[i]; - i = (i+1)%type_mult; - return ret; - } - ); + for(size_t j{0};j < type_mult;++j) + dst[i*type_mult + j] = sample[j]; } } -- cgit v1.2.3