diff options
| author | ailurux <ailuruxx@gmail.com> | 2024-09-23 14:42:25 +1000 |
|---|---|---|
| committer | ailurux <ailuruxx@gmail.com> | 2024-09-23 14:42:25 +1000 |
| commit | eba2ffc260f716ebe941c255800c2e42e061abac (patch) | |
| tree | 28f91a96f26d953a15cd31c9b4837eb3427266f7 /src/codecs/mad.cpp | |
| parent | fdcff74fb9e212706713d850d370515992373c59 (diff) | |
| download | tangara-fw-eba2ffc260f716ebe941c255800c2e42e061abac.tar.gz | |
Improve seeking for constant bitrate mp3
Diffstat (limited to 'src/codecs/mad.cpp')
| -rw-r--r-- | src/codecs/mad.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/codecs/mad.cpp b/src/codecs/mad.cpp index 01b2f721..a2ad1e4f 100644 --- a/src/codecs/mad.cpp +++ b/src/codecs/mad.cpp @@ -108,13 +108,22 @@ auto MadMp3Decoder::OpenStream(std::shared_ptr<IStream> input, uint32_t offset) }; auto vbr_length = GetVbrLength(header); + uint64_t cbr_length = 0; if (vbr_length) { output.total_samples = vbr_length.value() * channels; } else if (input->Size() && header.bitrate > 0) { - auto cbr_length = input->Size().value() / (header.bitrate / 8); + cbr_length = (input->Size().value() * 8) / header.bitrate; output.total_samples = cbr_length * output.sample_rate_hz * channels; } + if (offset > 1 && cbr_length > 0) { + // Constant bitrate seeking + uint64_t skip_bytes = header.bitrate * (offset - 1) / 8; + input->SeekTo(skip_bytes, IStream::SeekFrom::kCurrentPosition); + // Reset the offset so the next part will seek to the next second + offset = 1; + } + mad_timer_t timer; mad_timer_reset(&timer); bool need_refill = false; |
