diff --git a/src/audio/audio_decoder.cpp b/src/audio/audio_decoder.cpp index b829f959..faaadb3e 100644 --- a/src/audio/audio_decoder.cpp +++ b/src/audio/audio_decoder.cpp @@ -66,20 +66,13 @@ auto AudioDecoder::ProcessStreamInfo(const StreamInfo& info) -> bool { auto AudioDecoder::Process(const std::vector& inputs, OutputStream* output) -> void { - // We don't really expect multiple inputs, so just pick the first that - // contains data. If none of them contain data, then we can still flush - // pending samples. - auto input = std::find_if( - inputs.begin(), inputs.end(), - [](const InputStream& s) { return s.data().size_bytes() > 0; }); - if (input == inputs.end()) { - input = inputs.begin(); - } - + auto input = inputs.begin(); const StreamInfo& info = input->info(); - if (std::holds_alternative(info.format)) { + if (std::holds_alternative(info.format) || info.bytes_in_stream == 0) { + output->prepare({}); return; } + if (!current_input_format_ || *current_input_format_ != info.format) { // The input stream has changed! Immediately throw everything away and // start from scratch. @@ -133,7 +126,8 @@ auto AudioDecoder::Process(const std::vector& inputs, } } - input->consume(current_codec_->GetInputPosition()); + ESP_LOGI(kTag, "decoded %u bytes", current_codec_->GetInputPosition() - 1); + input->consume(current_codec_->GetInputPosition() - 1); } } // namespace audio diff --git a/src/audio/audio_task.cpp b/src/audio/audio_task.cpp index babe0a97..464879d8 100644 --- a/src/audio/audio_task.cpp +++ b/src/audio/audio_task.cpp @@ -130,9 +130,7 @@ void AudioTaskMain(void* args) { continue; } - if ((!output_format || output_format != sink_stream.info().format) && - !std::holds_alternative( - sink_stream.info().format)) { + if (!output_format || output_format != sink_stream.info().format) { // The format of the stream within the sink stream has changed. We // need to reconfigure the sink, but shouldn't do so until we've fully // drained the current buffer. @@ -145,7 +143,7 @@ void AudioTaskMain(void* args) { // We've reconfigured the sink, or it was already configured correctly. // Send through some data. - if (output_format == sink_stream.info().format) { + if (output_format == sink_stream.info().format && !std::holds_alternative(*output_format)) { // TODO: tune the delay on this, as it's currently the only way to // throttle this task's CPU time. Maybe also hold off on the pipeline // if the buffer is already close to full? diff --git a/src/audio/fatfs_audio_input.cpp b/src/audio/fatfs_audio_input.cpp index b9882711..b4e6db75 100644 --- a/src/audio/fatfs_audio_input.cpp +++ b/src/audio/fatfs_audio_input.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "arena.hpp" #include "esp_heap_caps.h" @@ -47,6 +48,7 @@ auto FatfsAudioInput::OpenFile(const std::string& path) -> void { auto FatfsAudioInput::Process(const std::vector& inputs, OutputStream* output) -> void { if (!is_file_open_) { + output->prepare({}); return; } diff --git a/src/drivers/include/dac.hpp b/src/drivers/include/dac.hpp index 6836cf59..b84f9bdb 100644 --- a/src/drivers/include/dac.hpp +++ b/src/drivers/include/dac.hpp @@ -26,7 +26,7 @@ class Register { uint8_t page; uint8_t reg; - constexpr Register(uint8_t page, uint8_t reg) : page(page), reg(reg) {} + constexpr Register(uint8_t p, uint8_t r) : page(p), reg(r) {} }; constexpr Register RESET(0, 1);