summaryrefslogtreecommitdiff
path: root/src/codecs/mad.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-01-18 14:50:05 +1100
committerjacqueline <me@jacqueline.id.au>2024-01-18 14:50:05 +1100
commit2d7f9fc775c4a959f17f225f5231ec9a40ceaf95 (patch)
tree04a94c9efbf123d07c6e74e619f1eec8dd7eaa62 /src/codecs/mad.cpp
parent200a43fad309813c3ebbc3da35dbb97367bde7ac (diff)
downloadtangara-fw-2d7f9fc775c4a959f17f225f5231ec9a40ceaf95.tar.gz
calculate length for CBR mp3 files
Diffstat (limited to 'src/codecs/mad.cpp')
-rw-r--r--src/codecs/mad.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/codecs/mad.cpp b/src/codecs/mad.cpp
index 247e33bc..f36636a1 100644
--- a/src/codecs/mad.cpp
+++ b/src/codecs/mad.cpp
@@ -109,8 +109,9 @@ auto MadMp3Decoder::OpenStream(std::shared_ptr<IStream> input)
auto vbr_length = GetVbrLength(header);
if (vbr_length) {
output.total_samples = vbr_length.value() * channels;
- } else {
- // FIXME: calculate length using the filesize, assuming CBR.
+ } else if (input->Size() && header.bitrate > 0) {
+ auto cbr_length = input->Size().value() / (header.bitrate / 8);
+ output.total_samples = cbr_length * output.sample_rate_hz * channels;
}
return output;
}