summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorayumi <ayumi@noreply.codeberg.org>2025-04-15 03:15:16 +0200
committerayumi <ayumi@noreply.codeberg.org>2025-04-23 22:14:31 +0200
commit5d437513d0eec0ceddd50f1a60c5abdba5da97b9 (patch)
tree33295d1988514291f3d04b1b8f4b2f6625b1cbf6
parent79c9f0b6ccfec97f23563010f134d842c4240582 (diff)
downloadtangara-fw-5d437513d0eec0ceddd50f1a60c5abdba5da97b9.tar.gz
Make WavPack seeking faster
It turns out that “seeking to a first sample in a not–first block” is actually very common, because Tangara only seeks to exact seconds and the reference encoder tends to size blocks in a way that makes the first sample in a block likely be the sample that the firmware wants to seek to.
-rw-r--r--src/codecs/wavpack.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/codecs/wavpack.cpp b/src/codecs/wavpack.cpp
index 21865785..7990e4d6 100644
--- a/src/codecs/wavpack.cpp
+++ b/src/codecs/wavpack.cpp
@@ -73,7 +73,7 @@ auto WavPackDecoder::OpenStream(std::shared_ptr<IStream> input, uint32_t offset)
);
const auto rate = WavpackGetSampleRate(&wavpack_);
if (offset && total && input_.get()->CanSeek()) {
- const uint32_t want = offset * rate - 1;
+ const uint32_t want = offset * rate;
if (total < want) {
ESP_LOGE(kTag, "seeking: offset points beyond the end of the file");
return cpp::fail(Error::kInternalError);
@@ -96,7 +96,11 @@ auto WavPackDecoder::OpenStream(std::shared_ptr<IStream> input, uint32_t offset)
}
const uint32_t blockIndex = loadLe32(header + 16);
const uint32_t blockSamples = loadLe32(header + 20);
- if (want >= blockIndex && want <= blockIndex + blockSamples) {
+ if (want >= blockIndex && want == blockIndex + blockSamples) {
+ input_->SeekTo(size - 24, IStream::SeekFrom::kCurrentPosition);
+ target = 0;
+ break;
+ } else if (want >= blockIndex && want < blockIndex + blockSamples) {
input_->SeekTo(-32, IStream::SeekFrom::kCurrentPosition);
target = want - blockIndex;
break;