Skip to content

Commit d1f8422

Browse files
committed
class OutputMixer: index management
1 parent efea685 commit d1f8422

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/AudioTools/AudioOutput.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ class OutputMixer : public Print {
367367
size_t write(const uint8_t *buffer_c, size_t bytes) override {
368368
size_t result = write(stream_idx, buffer_c, bytes);
369369
// after writing the last stream we flush
370-
stream_idx++;
370+
if (is_auto_index) stream_idx++;
371371
if (stream_idx >= output_count) {
372372
flushMixer();
373373
}
@@ -444,12 +444,8 @@ class OutputMixer : public Print {
444444
size_bytes = size;
445445
}
446446

447-
/// Sets the Output Stream index
448-
void setIndex(int idx){
449-
stream_idx = idx;
450-
}
451447

452-
size_t writeSilence(size_t bytes) override {
448+
size_t writeSilence(size_t bytes) {
453449
if (bytes == 0) return 0;
454450
byte silence[bytes] = {0};
455451
return write(stream_idx, silence, bytes);
@@ -461,6 +457,21 @@ class OutputMixer : public Print {
461457
return write(idx, silence, bytes);
462458
}
463459

460+
/// Automatically increment mixing index after each write
461+
void setAutoIndex(bool flag){
462+
is_auto_index = flag;
463+
}
464+
465+
/// Sets the Output Stream index
466+
void setIndex(int idx){
467+
stream_idx = idx;
468+
}
469+
470+
/// Moves to the next mixing index
471+
void next() {
472+
stream_idx++;
473+
}
474+
464475
protected:
465476
Vector<RingBuffer<T> *> buffers{0};
466477
Vector<T> output{0};
@@ -473,6 +484,7 @@ class OutputMixer : public Print {
473484
int output_count;
474485
MemoryType memory_type;
475486
void *p_memory = nullptr;
487+
bool is_auto_index = true;
476488

477489
void update_total_weights() {
478490
total_weights = 0.0;

0 commit comments

Comments
 (0)