From 80d7df910987db5201402fe987124f29f09344f3 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 25 Jul 2023 17:42:36 +1000 Subject: fuck off --- src/codecs/include/codec.hpp | 12 ++++++++++++ src/codecs/mad.cpp | 8 +++++--- 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'src/codecs') diff --git a/src/codecs/include/codec.hpp b/src/codecs/include/codec.hpp index 299b16e4..e8be8f0a 100644 --- a/src/codecs/include/codec.hpp +++ b/src/codecs/include/codec.hpp @@ -40,6 +40,18 @@ class ICodec { kInternalError, }; + static auto ErrorString(Error err) -> std::string { + switch (err) { + case Error::kOutOfInput: + return "out of input"; + case Error::kMalformedData: + return "malformed data"; + case Error::kInternalError: + return "internal error"; + } + return "uhh"; + } + /* * Alias for more readable return types. All codec methods, success or * failure, should also return the number of bytes they consumed. diff --git a/src/codecs/mad.cpp b/src/codecs/mad.cpp index 8b4e2561..29e34a0f 100644 --- a/src/codecs/mad.cpp +++ b/src/codecs/mad.cpp @@ -145,11 +145,13 @@ auto MadMp3Decoder::ContinueStream(cpp::span input, for (int channel = 0; channel < synth_.pcm.channels; channel++) { uint32_t sample_24 = mad_fixed_to_pcm(synth_.pcm.samples[channel][current_sample_], 24); - output[output_byte++] = static_cast((sample_24 >> 16) & 0xFF); - output[output_byte++] = static_cast((sample_24 >> 8) & 0xFF); - output[output_byte++] = static_cast((sample_24)&0xFF); + // 24 bit samples must still be aligned to 32 bits. The LSB is ignored. output[output_byte++] = static_cast(0); + + output[output_byte++] = static_cast((sample_24)&0xFF); + output[output_byte++] = static_cast((sample_24 >> 8) & 0xFF); + output[output_byte++] = static_cast((sample_24 >> 16) & 0xFF); } current_sample_++; } -- cgit v1.2.3