Skip to content

Commit bc7334c

Browse files
committed
OutputMixer: support allocator; use RAM by default
1 parent 3a9bcc5 commit bc7334c

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/AudioTools/CoreAudio/AudioBasic/Collections/Allocator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,5 +172,6 @@ class AllocatorPSRAM : public Allocator {
172172
#endif
173173

174174
static AllocatorExt DefaultAllocator;
175+
static AllocatorExt DefaultAllocatorRAM;
175176

176177
} // namespace audio_tools

src/AudioTools/CoreAudio/AudioOutput.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,9 @@ class HexDumpOutput : public AudioOutput {
365365
template <typename T>
366366
class OutputMixer : public Print {
367367
public:
368-
OutputMixer() = default;
368+
OutputMixer(Allocator &allocator = DefaultAllocatorRAM) : allocator(allocator) {}
369369

370-
OutputMixer(Print &finalOutput, int outputStreamCount) {
370+
OutputMixer(Print &finalOutput, int outputStreamCount, Allocator &allocator = DefaultAllocatorRAM) : OutputMixer(allocator) {
371371
setOutput(finalOutput);
372372
setOutputCount(outputStreamCount);
373373
}
@@ -574,9 +574,10 @@ class OutputMixer : public Print {
574574
}
575575

576576
protected:
577-
Vector<BaseBuffer<T> *> buffers{0};
578-
Vector<T> output{0};
579-
Vector<float> weights{0};
577+
Vector<float> weights{0, DefaultAllocatorRAM};
578+
Vector<BaseBuffer<T> *> buffers{0, DefaultAllocatorRAM};
579+
Allocator &allocator;
580+
Vector<T> output{0, allocator};
580581
Print *p_final_output = nullptr;
581582
float total_weights = 0.0;
582583
bool is_active = false;
@@ -585,11 +586,11 @@ class OutputMixer : public Print {
585586
int output_count = 0;
586587
void *p_memory = nullptr;
587588
bool is_auto_index = true;
588-
BaseBuffer<T>* (*create_buffer_cb)(int size) = create_buffer;
589+
BaseBuffer<T>* (*create_buffer_cb)(int size, Allocator &allocator) = create_buffer;
589590

590591
/// Creates a default ring buffer of the specified size
591-
static BaseBuffer<T>* create_buffer(int size) {
592-
return new RingBuffer<T>(size / sizeof(T));
592+
static BaseBuffer<T>* create_buffer(int size, Allocator &allocator) {
593+
return new RingBuffer<T>(size / sizeof(T), allocator);
593594
}
594595

595596
/// Recalculates the total weights for normalization
@@ -607,7 +608,7 @@ class OutputMixer : public Print {
607608
if (buffers[j] != nullptr) {
608609
delete buffers[j];
609610
}
610-
buffers[j] = create_buffer(size);
611+
buffers[j] = create_buffer(size, allocator);
611612
}
612613
}
613614

0 commit comments

Comments
 (0)