summaryrefslogtreecommitdiff
path: root/src/codecs/mad.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/codecs/mad.cpp')
-rw-r--r--src/codecs/mad.cpp11
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;