summaryrefslogtreecommitdiff
path: root/src/audio/audio_task.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-07-31 09:41:49 +1000
committerjacqueline <me@jacqueline.id.au>2023-07-31 09:41:49 +1000
commit485eed28903a0bc23df9c1ced1417e35fd58c43c (patch)
treea363714c1b0f5074c48bea64f46a907b4aa45cfc /src/audio/audio_task.cpp
parent97bd3be892ce549dac8e0b9930607a282701653e (diff)
downloadtangara-fw-485eed28903a0bc23df9c1ced1417e35fd58c43c.tar.gz
use libtag duration where available
Diffstat (limited to 'src/audio/audio_task.cpp')
-rw-r--r--src/audio/audio_task.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/audio/audio_task.cpp b/src/audio/audio_task.cpp
index ca6a3824..4fad3114 100644
--- a/src/audio/audio_task.cpp
+++ b/src/audio/audio_task.cpp
@@ -61,10 +61,12 @@ Timer::Timer(StreamInfo::Pcm format)
auto Timer::SetLengthSeconds(uint32_t len) -> void {
total_duration_seconds_ = len;
+ has_duration_ = true;
}
auto Timer::SetLengthBytes(uint32_t len) -> void {
total_duration_seconds_ = bytes_to_samples(len) / format_.sample_rate;
+ has_duration_ = true;
}
auto Timer::AddBytes(std::size_t bytes) -> void {
@@ -135,8 +137,14 @@ void AudioTask::Main() {
if (ForwardPcmStream(*pcm, stream.data())) {
stream.consume(stream.data().size_bytes());
}
- timer_->SetLengthBytes(
- stream.info().total_length_bytes().value_or(0));
+ if (!timer_->has_duration()) {
+ if (stream.info().total_length_seconds()) {
+ timer_->SetLengthSeconds(*stream.info().total_length_seconds());
+ } else {
+ timer_->SetLengthBytes(
+ stream.info().total_length_bytes().value_or(0));
+ }
+ }
return;
}
@@ -233,6 +241,8 @@ auto AudioTask::BeginDecoding(InputStream& stream) -> bool {
if (format.duration_seconds) {
timer_->SetLengthSeconds(*format.duration_seconds);
+ } else if (stream.info().total_length_seconds()) {
+ timer_->SetLengthSeconds(*stream.info().total_length_seconds());
} else {
timer_->SetLengthBytes(stream.info().total_length_bytes().value_or(0));
}