From cdaa2ac97ac663de7c0c2b0361871c97269b1675 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 31 Jul 2023 11:00:17 +1000 Subject: Add duration for flacs --- src/codecs/foxenflac.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/codecs') diff --git a/src/codecs/foxenflac.cpp b/src/codecs/foxenflac.cpp index ce18975c..3a727ce2 100644 --- a/src/codecs/foxenflac.cpp +++ b/src/codecs/foxenflac.cpp @@ -6,6 +6,7 @@ #include "foxenflac.hpp" #include +#include #include @@ -44,13 +45,20 @@ auto FoxenFlacDecoder::BeginStream(const cpp::span input) return {bytes_used, cpp::fail(Error::kMalformedData)}; } - return {bytes_used, - OutputFormat{ - .num_channels = static_cast(channels), - .bits_per_sample = 32, // libfoxenflac output is fixed-size. - .sample_rate_hz = static_cast(fs), - .duration_seconds = {}, - }}; + OutputFormat format{ + .num_channels = static_cast(channels), + .bits_per_sample = 32, // libfoxenflac output is fixed-size. + .sample_rate_hz = static_cast(fs), + .duration_seconds = {}, + .bits_per_second = {}, + }; + + uint64_t num_samples = fx_flac_get_streaminfo(flac_, FLAC_KEY_N_SAMPLES); + if (num_samples > 0) { + format.duration_seconds = num_samples / fs; + } + + return {bytes_used, format}; } auto FoxenFlacDecoder::ContinueStream(cpp::span input, -- cgit v1.2.3