WIP track down new pipeline memory issues

custom
jacqueline 2 years ago
parent 40a9734b04
commit 7a54ff0df9
  1. 18
      src/audio/audio_decoder.cpp
  2. 6
      src/audio/audio_task.cpp
  3. 2
      src/audio/fatfs_audio_input.cpp
  4. 2
      src/drivers/include/dac.hpp

@ -66,20 +66,13 @@ auto AudioDecoder::ProcessStreamInfo(const StreamInfo& info) -> bool {
auto AudioDecoder::Process(const std::vector<InputStream>& inputs, auto AudioDecoder::Process(const std::vector<InputStream>& inputs,
OutputStream* output) -> void { OutputStream* output) -> void {
// We don't really expect multiple inputs, so just pick the first that auto input = inputs.begin();
// 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();
}
const StreamInfo& info = input->info(); const StreamInfo& info = input->info();
if (std::holds_alternative<std::monostate>(info.format)) { if (std::holds_alternative<std::monostate>(info.format) || info.bytes_in_stream == 0) {
output->prepare({});
return; return;
} }
if (!current_input_format_ || *current_input_format_ != info.format) { if (!current_input_format_ || *current_input_format_ != info.format) {
// The input stream has changed! Immediately throw everything away and // The input stream has changed! Immediately throw everything away and
// start from scratch. // start from scratch.
@ -133,7 +126,8 @@ auto AudioDecoder::Process(const std::vector<InputStream>& inputs,
} }
} }
input->consume(current_codec_->GetInputPosition()); ESP_LOGI(kTag, "decoded %u bytes", current_codec_->GetInputPosition() - 1);
input->consume(current_codec_->GetInputPosition() - 1);
} }
} // namespace audio } // namespace audio

@ -130,9 +130,7 @@ void AudioTaskMain(void* args) {
continue; continue;
} }
if ((!output_format || output_format != sink_stream.info().format) && if (!output_format || output_format != sink_stream.info().format) {
!std::holds_alternative<std::monostate>(
sink_stream.info().format)) {
// The format of the stream within the sink stream has changed. We // 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 // need to reconfigure the sink, but shouldn't do so until we've fully
// drained the current buffer. // drained the current buffer.
@ -145,7 +143,7 @@ void AudioTaskMain(void* args) {
// We've reconfigured the sink, or it was already configured correctly. // We've reconfigured the sink, or it was already configured correctly.
// Send through some data. // Send through some data.
if (output_format == sink_stream.info().format) { if (output_format == sink_stream.info().format && !std::holds_alternative<std::monostate>(*output_format)) {
// TODO: tune the delay on this, as it's currently the only way to // 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 // throttle this task's CPU time. Maybe also hold off on the pipeline
// if the buffer is already close to full? // if the buffer is already close to full?

@ -4,6 +4,7 @@
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
#include <string> #include <string>
#include <variant>
#include "arena.hpp" #include "arena.hpp"
#include "esp_heap_caps.h" #include "esp_heap_caps.h"
@ -47,6 +48,7 @@ auto FatfsAudioInput::OpenFile(const std::string& path) -> void {
auto FatfsAudioInput::Process(const std::vector<InputStream>& inputs, auto FatfsAudioInput::Process(const std::vector<InputStream>& inputs,
OutputStream* output) -> void { OutputStream* output) -> void {
if (!is_file_open_) { if (!is_file_open_) {
output->prepare({});
return; return;
} }

@ -26,7 +26,7 @@ class Register {
uint8_t page; uint8_t page;
uint8_t reg; 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); constexpr Register RESET(0, 1);

Loading…
Cancel
Save