Skip to content

Commit

Permalink
class OutputMixer: index management
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Jun 18, 2024
1 parent efea685 commit d1f8422
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/AudioTools/AudioOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ class OutputMixer : public Print {
size_t write(const uint8_t *buffer_c, size_t bytes) override {
size_t result = write(stream_idx, buffer_c, bytes);
// after writing the last stream we flush
stream_idx++;
if (is_auto_index) stream_idx++;
if (stream_idx >= output_count) {
flushMixer();
}
Expand Down Expand Up @@ -444,12 +444,8 @@ class OutputMixer : public Print {
size_bytes = size;
}

/// Sets the Output Stream index
void setIndex(int idx){
stream_idx = idx;
}

size_t writeSilence(size_t bytes) override {
size_t writeSilence(size_t bytes) {
if (bytes == 0) return 0;
byte silence[bytes] = {0};
return write(stream_idx, silence, bytes);
Expand All @@ -461,6 +457,21 @@ class OutputMixer : public Print {
return write(idx, silence, bytes);
}

/// Automatically increment mixing index after each write
void setAutoIndex(bool flag){
is_auto_index = flag;
}

/// Sets the Output Stream index
void setIndex(int idx){
stream_idx = idx;
}

/// Moves to the next mixing index
void next() {
stream_idx++;
}

protected:
Vector<RingBuffer<T> *> buffers{0};
Vector<T> output{0};
Expand All @@ -473,6 +484,7 @@ class OutputMixer : public Print {
int output_count;
MemoryType memory_type;
void *p_memory = nullptr;
bool is_auto_index = true;

void update_total_weights() {
total_weights = 0.0;
Expand Down

0 comments on commit d1f8422

Please sign in to comment.