From 48556dd603cac0107143f3cdc815c765baa640a9 Mon Sep 17 00:00:00 2001 From: ayumi Date: Wed, 23 Apr 2025 22:21:25 +0200 Subject: Avoid branching up to two times per sample in the WavPack decoder. In my limited tests this improves decoding speed by around 3%. --- src/codecs/wavpack.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/codecs') diff --git a/src/codecs/wavpack.cpp b/src/codecs/wavpack.cpp index 7990e4d6..709302e6 100644 --- a/src/codecs/wavpack.cpp +++ b/src/codecs/wavpack.cpp @@ -154,8 +154,14 @@ auto WavPackDecoder::DecodeTo(std::span output) ESP_LOGE(kTag, "CRC error"); return cpp::fail(Error::kMalformedData); } - for (size_t i = 0; i < samples; i++) - output[i] = sample::FromSigned(buf_[i], bitdepth_); + if (bitdepth_ == 16) + for (size_t i = 0; i < samples; i++) + output[i] = buf_[i]; + else if (bitdepth_ > 16) + for (size_t i = 0; i < samples; i++) + output[i] = sample::shiftWithDither(buf_[i], bitdepth_ - 16); + else for (size_t i = 0; i < samples; i++) + output[i] = buf_[i] << (16 - bitdepth_); return OutputInfo{ .samples_written = samples, .is_stream_finished = samples == 0, -- cgit v1.2.3