From acccd822f0147147dd8b16f059578df073c088c2 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 19 Jun 2023 15:36:43 +1000 Subject: back to back flac playback is working :) --- src/codecs/mad.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/codecs/mad.cpp') diff --git a/src/codecs/mad.cpp b/src/codecs/mad.cpp index 8b9897eb..f3f3cffe 100644 --- a/src/codecs/mad.cpp +++ b/src/codecs/mad.cpp @@ -44,6 +44,7 @@ MadMp3Decoder::~MadMp3Decoder() { } auto MadMp3Decoder::GetInputPosition() -> std::size_t { + assert(stream_.next_frame >= stream_.buffer); return stream_.next_frame - stream_.buffer; } @@ -51,7 +52,7 @@ auto MadMp3Decoder::BeginStream(const cpp::span input) -> Result { mad_stream_buffer(&stream_, reinterpret_cast(input.data()), - input.size()); + input.size_bytes()); // Whatever was last synthesized is now invalid, so ensure we don't try to // send it. current_sample_ = -1; @@ -65,11 +66,11 @@ auto MadMp3Decoder::BeginStream(const cpp::span input) // Recoverable errors are usually malformed parts of the stream. // We can recover from them by just retrying the decode. continue; - } else { - // Don't bother checking for other errors; if the first part of the stream - // doesn't even contain a header then something's gone wrong. - return {GetInputPosition(), cpp::fail(Error::kMalformedData)}; } + if (stream_.error == MAD_ERROR_BUFLEN) { + return {GetInputPosition(), cpp::fail(Error::kOutOfInput)}; + } + return {GetInputPosition(), cpp::fail(Error::kMalformedData)}; } uint8_t channels = MAD_NCHANNELS(&header); -- cgit v1.2.3