diff options
author | Chris Robinson <[email protected]> | 2022-05-08 20:22:25 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2022-05-08 20:22:25 -0700 |
commit | 2c9da1b671d5515de1116b5a1d389dc83c2bc33d (patch) | |
tree | 79295be70e9bb8e1342a96cd3b3e8a621174c01d /examples | |
parent | 6f116381625b3869e0d80ac558e40572d6ff14ac (diff) |
Avoid an ugly and confusing generate_n
Diffstat (limited to 'examples')
-rw-r--r-- | examples/alffplay.cpp | 20 |
1 files changed, 7 insertions, 13 deletions
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<const T*>(in); auto *dst = reinterpret_cast<T*>(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]; } } |