From 7c6fd654f50e6665efa4226c6b927f9762734182 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Sat, 1 Apr 2023 13:22:21 +1100 Subject: New pipeline building, still needs proper control --- src/codecs/mad.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/codecs/mad.cpp') diff --git a/src/codecs/mad.cpp b/src/codecs/mad.cpp index 1112bd62..eec2d633 100644 --- a/src/codecs/mad.cpp +++ b/src/codecs/mad.cpp @@ -5,6 +5,7 @@ #include "mad.h" #include "codec.hpp" +#include "types.hpp" namespace codecs { @@ -35,8 +36,8 @@ MadMp3Decoder::~MadMp3Decoder() { mad_header_finish(&header_); } -auto MadMp3Decoder::CanHandleFile(const std::string& path) -> bool { - return true; // TODO. +auto MadMp3Decoder::CanHandleType(StreamType type) -> bool { + return type == STREAM_MP3; } auto MadMp3Decoder::GetOutputFormat() -> OutputFormat { @@ -52,7 +53,7 @@ auto MadMp3Decoder::ResetForNewStream() -> void { has_decoded_header_ = false; } -auto MadMp3Decoder::SetInput(cpp::span input) -> void { +auto MadMp3Decoder::SetInput(cpp::span input) -> void { mad_stream_buffer(&stream_, reinterpret_cast(input.data()), input.size()); -- cgit v1.2.3 From 40a9734b04c48339cfdf6ed9043aa3f6f0dda62d Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 4 Apr 2023 09:46:52 +1000 Subject: Redo pcm registers to include pages --- src/codecs/mad.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/codecs/mad.cpp') diff --git a/src/codecs/mad.cpp b/src/codecs/mad.cpp index eec2d633..020e0d57 100644 --- a/src/codecs/mad.cpp +++ b/src/codecs/mad.cpp @@ -114,7 +114,7 @@ auto MadMp3Decoder::WriteOutputSamples(cpp::span output) } while (current_sample_ < synth_.pcm.length) { - if (output_byte + (3 * synth_.pcm.channels) >= output.size()) { + if (output_byte + (2 * synth_.pcm.channels) >= output.size()) { return std::make_pair(output_byte, false); } -- cgit v1.2.3 From 4c77950e702a329f3136456a932efbea36e03d42 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 19 Apr 2023 16:45:50 +1000 Subject: Pipeline working and outputting correctly, but noisy --- src/codecs/mad.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/codecs/mad.cpp') diff --git a/src/codecs/mad.cpp b/src/codecs/mad.cpp index 020e0d57..7e5b350b 100644 --- a/src/codecs/mad.cpp +++ b/src/codecs/mad.cpp @@ -9,7 +9,7 @@ namespace codecs { -static int scaleTo24Bits(mad_fixed_t sample) { +static int scaleTo16Bits(mad_fixed_t sample) { // Round the bottom bits. sample += (1L << (MAD_F_FRACBITS - 16)); @@ -19,7 +19,7 @@ static int scaleTo24Bits(mad_fixed_t sample) { else if (sample < -MAD_F_ONE) sample = -MAD_F_ONE; - /* quantize */ + // Quantize. return sample >> (MAD_F_FRACBITS + 1 - 16); } @@ -119,10 +119,10 @@ auto MadMp3Decoder::WriteOutputSamples(cpp::span output) } for (int channel = 0; channel < synth_.pcm.channels; channel++) { - uint32_t sample_24 = - scaleTo24Bits(synth_.pcm.samples[channel][current_sample_]); - output[output_byte++] = static_cast((sample_24 >> 8) & 0xFF); - output[output_byte++] = static_cast((sample_24)&0xFF); + uint16_t sample_16 = + scaleTo16Bits(synth_.pcm.samples[channel][current_sample_]); + output[output_byte++] = static_cast((sample_16 >> 8) & 0xFF); + output[output_byte++] = static_cast((sample_16)&0xFF); } current_sample_++; } -- cgit v1.2.3 From 27c63ebb957aa5b942939aea33431ac50d101a26 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 20 Apr 2023 21:25:22 +1000 Subject: Switch to an MVP-ready 16bit three wire DAC setup --- src/codecs/mad.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/codecs/mad.cpp') diff --git a/src/codecs/mad.cpp b/src/codecs/mad.cpp index 7e5b350b..dd839537 100644 --- a/src/codecs/mad.cpp +++ b/src/codecs/mad.cpp @@ -1,4 +1,5 @@ #include "mad.hpp" +#include #include @@ -9,9 +10,9 @@ namespace codecs { -static int scaleTo16Bits(mad_fixed_t sample) { +static uint32_t scaleToBits(mad_fixed_t sample, uint8_t bits) { // Round the bottom bits. - sample += (1L << (MAD_F_FRACBITS - 16)); + sample += (1L << (MAD_F_FRACBITS - bits)); // Clip the leftover bits to within range. if (sample >= MAD_F_ONE) @@ -20,7 +21,7 @@ static int scaleTo16Bits(mad_fixed_t sample) { sample = -MAD_F_ONE; // Quantize. - return sample >> (MAD_F_FRACBITS + 1 - 16); + return sample >> (MAD_F_FRACBITS + 1 - bits); } MadMp3Decoder::MadMp3Decoder() { @@ -119,8 +120,19 @@ auto MadMp3Decoder::WriteOutputSamples(cpp::span output) } for (int channel = 0; channel < synth_.pcm.channels; channel++) { + // TODO(jacqueline): output 24 bit samples when (if?) we have a downmix + // step in the pipeline. + /* + uint32_t sample_24 = + scaleToBits(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); + */ uint16_t sample_16 = - scaleTo16Bits(synth_.pcm.samples[channel][current_sample_]); + scaleToBits(synth_.pcm.samples[channel][current_sample_], 16); output[output_byte++] = static_cast((sample_16 >> 8) & 0xFF); output[output_byte++] = static_cast((sample_16)&0xFF); } -- cgit v1.2.3