diff options
Diffstat (limited to 'src/codecs')
| -rw-r--r-- | src/codecs/include/codec.hpp | 12 | ||||
| -rw-r--r-- | src/codecs/mad.cpp | 8 |
2 files changed, 17 insertions, 3 deletions
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<const std::byte> 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<std::byte>((sample_24 >> 16) & 0xFF); - output[output_byte++] = static_cast<std::byte>((sample_24 >> 8) & 0xFF); - output[output_byte++] = static_cast<std::byte>((sample_24)&0xFF); + // 24 bit samples must still be aligned to 32 bits. The LSB is ignored. output[output_byte++] = static_cast<std::byte>(0); + + output[output_byte++] = static_cast<std::byte>((sample_24)&0xFF); + output[output_byte++] = static_cast<std::byte>((sample_24 >> 8) & 0xFF); + output[output_byte++] = static_cast<std::byte>((sample_24 >> 16) & 0xFF); } current_sample_++; } |
