Drop himem audio buffers (for now?)

For some reason the spinlocks required now block forever? Very odd.

On the plus side, this turned out to be the issue that was stopping the
audio pipeline from running on the app core.
custom
jacqueline 2 years ago
parent ecee01fe97
commit 4bff06c76c
  1. 35
      src/audio/audio_task.cpp
  2. 8
      src/audio/include/pipeline.hpp
  3. 12
      src/audio/pipeline.cpp

@ -40,34 +40,12 @@ void AudioTaskMain(std::unique_ptr<Pipeline> pipeline, IAudioSink* sink) {
std::optional<StreamInfo::Format> output_format; std::optional<StreamInfo::Format> output_format;
std::vector<Pipeline*> elements = pipeline->GetIterationOrder(); std::vector<Pipeline*> elements = pipeline->GetIterationOrder();
std::size_t max_inputs =
(*std::max_element(elements.begin(), elements.end(),
[](Pipeline const* first, Pipeline const* second) {
return first->NumInputs() < second->NumInputs();
}))
->NumInputs();
// We need to be able to simultaneously map all of an element's inputs, plus
// its output. So preallocate that many ranges.
std::vector<MappableRegion<kPipelineBufferSize>> in_regions(max_inputs);
MappableRegion<kPipelineBufferSize> out_region;
std::for_each(in_regions.begin(), in_regions.end(),
[](const auto& region) { assert(region.is_valid); });
assert(out_region.is_valid);
// Each element has exactly one output buffer.
std::vector<HimemAlloc<kPipelineBufferSize>> buffers(elements.size());
std::vector<StreamInfo> buffer_infos(buffers.size());
std::for_each(buffers.begin(), buffers.end(),
[](const HimemAlloc<kPipelineBufferSize>& alloc) {
assert(alloc.is_valid);
});
while (1) { while (1) {
for (int i = 0; i < elements.size(); i++) { for (int i = 0; i < elements.size(); i++) {
std::vector<RawStream> raw_in_streams; std::vector<RawStream> raw_in_streams;
elements.at(i)->InStreams(&in_regions, &raw_in_streams); elements.at(i)->InStreams(&raw_in_streams);
RawStream raw_out_stream = elements.at(i)->OutStream(&out_region); RawStream raw_out_stream = elements.at(i)->OutStream();
// Crop the input and output streams to the ranges that are safe to // Crop the input and output streams to the ranges that are safe to
// touch. For the input streams, this is the region that contains // touch. For the input streams, this is the region that contains
@ -79,17 +57,12 @@ void AudioTaskMain(std::unique_ptr<Pipeline> pipeline, IAudioSink* sink) {
OutputStream out_stream(&raw_out_stream); OutputStream out_stream(&raw_out_stream);
elements.at(i)->OutputElement()->Process(in_streams, &out_stream); elements.at(i)->OutputElement()->Process(in_streams, &out_stream);
std::for_each(in_regions.begin(), in_regions.end(),
[](auto&& r) { r.Unmap(); });
out_region.Unmap();
} }
RawStream raw_sink_stream = elements.front()->OutStream(&out_region); RawStream raw_sink_stream = elements.front()->OutStream();
InputStream sink_stream(&raw_sink_stream); InputStream sink_stream(&raw_sink_stream);
if (sink_stream.info().bytes_in_stream == 0) { if (sink_stream.info().bytes_in_stream == 0) {
out_region.Unmap();
vTaskDelay(pdMS_TO_TICKS(100)); vTaskDelay(pdMS_TO_TICKS(100));
continue; continue;
} }
@ -121,8 +94,6 @@ void AudioTaskMain(std::unique_ptr<Pipeline> pipeline, IAudioSink* sink) {
} }
sink_stream.consume(sent); sink_stream.consume(sent);
} }
out_region.Unmap();
} }
} }

@ -8,7 +8,6 @@
#include "freertos/portmacro.h" #include "freertos/portmacro.h"
#include "audio_element.hpp" #include "audio_element.hpp"
#include "himem.hpp"
#include "stream_info.hpp" #include "stream_info.hpp"
namespace audio { namespace audio {
@ -25,10 +24,9 @@ class Pipeline {
auto NumInputs() const -> std::size_t; auto NumInputs() const -> std::size_t;
auto InStreams(std::vector<MappableRegion<kPipelineBufferSize>>*, auto InStreams(std::vector<RawStream>*) -> void;
std::vector<RawStream>*) -> void;
auto OutStream(MappableRegion<kPipelineBufferSize>*) -> RawStream; auto OutStream() -> RawStream;
auto GetIterationOrder() -> std::vector<Pipeline*>; auto GetIterationOrder() -> std::vector<Pipeline*>;
@ -36,7 +34,7 @@ class Pipeline {
IAudioElement* root_; IAudioElement* root_;
std::vector<std::unique_ptr<Pipeline>> subtrees_; std::vector<std::unique_ptr<Pipeline>> subtrees_;
HimemAlloc<kPipelineBufferSize> output_buffer_; std::array<std::byte, kPipelineBufferSize> output_buffer_;
StreamInfo output_info_; StreamInfo output_info_;
}; };

@ -23,18 +23,14 @@ auto Pipeline::NumInputs() const -> std::size_t {
return subtrees_.size(); return subtrees_.size();
} }
auto Pipeline::InStreams( auto Pipeline::InStreams(std::vector<RawStream>* out) -> void {
std::vector<MappableRegion<kPipelineBufferSize>>* regions,
std::vector<RawStream>* out) -> void {
for (int i = 0; i < subtrees_.size(); i++) { for (int i = 0; i < subtrees_.size(); i++) {
RawStream s = subtrees_[i]->OutStream(&regions->at(i)); out->push_back(subtrees_[i]->OutStream());
out->push_back(s);
} }
} }
auto Pipeline::OutStream(MappableRegion<kPipelineBufferSize>* region) auto Pipeline::OutStream() -> RawStream {
-> RawStream { return {&output_info_, output_buffer_};
return {&output_info_, region->Map(output_buffer_)};
} }
auto Pipeline::GetIterationOrder() -> std::vector<Pipeline*> { auto Pipeline::GetIterationOrder() -> std::vector<Pipeline*> {

Loading…
Cancel
Save