summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorayumi <ayumi@noreply.codeberg.org>2025-04-23 22:21:25 +0200
committerayumi <ayumi@noreply.codeberg.org>2025-04-23 22:21:25 +0200
commit48556dd603cac0107143f3cdc815c765baa640a9 (patch)
treed27effa87cccb1a3f3977942c3deae0d04c07744
parent5d437513d0eec0ceddd50f1a60c5abdba5da97b9 (diff)
downloadtangara-fw-48556dd603cac0107143f3cdc815c765baa640a9.tar.gz
Avoid branching up to two times per sample in the WavPack decoder.
In my limited tests this improves decoding speed by around 3%.
-rw-r--r--src/codecs/wavpack.cpp10
1 files changed, 8 insertions, 2 deletions
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<sample::Sample> 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,