arduino-audio-tools
Loading...
Searching...
No Matches
AudioOutput.h
Go to the documentation of this file.
1#pragma once
5#include "AudioToolsConfig.h"
6#if defined(USE_ESP32_DSP)
7#include "esp_dsp.h"
8#endif
9
10namespace audio_tools {
11
12#if USE_PRINT_FLUSH
13#define PRINT_FLUSH_OVERRIDE override
14#else
15#define PRINT_FLUSH_OVERRIDE
16#endif
17
23class AudioOutput : public Print,
24 public AudioInfoSupport,
25 public AudioInfoSource {
26 public:
27 virtual ~AudioOutput() = default;
28
29 virtual size_t write(const uint8_t *data, size_t len) override = 0;
30
31 virtual size_t write(uint8_t ch) override {
32 if (tmp.isFull()) {
33 flush();
34 }
35 return tmp.write(ch);
36 }
37
38 virtual int availableForWrite() override { return DEFAULT_BUFFER_SIZE; }
39
40 // removed override because some old implementation did not define this method
41 // as virtual
42 virtual void flush() PRINT_FLUSH_OVERRIDE {
43 if (tmp.available() > 0) {
44 write((const uint8_t *)tmp.address(), tmp.available());
45 }
46 }
47
48 // overwrite to do something useful
49 virtual void setAudioInfo(AudioInfo newInfo) override {
50 TRACED();
51 if (cfg != newInfo) {
52 cfg = newInfo;
53 cfg.logInfo();
54 }
55 AudioInfo out = audioInfoOut();
56 if (out) notifyAudioChange(out);
57 }
58
60 virtual bool isDeletable() { return false; }
61
62 virtual AudioInfo audioInfo() override { return cfg; }
63
66 virtual void writeSilence(size_t len) {
67 int16_t zero = 0;
68 for (int j = 0; j < len / 2; j++) {
69 write((uint8_t *)&zero, 2);
70 }
71 }
72
73 virtual bool begin(AudioInfo info) {
74 setAudioInfo(info);
75 return begin();
76 }
77
78 virtual bool begin() {
79 is_active = true;
80 return true;
81 }
82 virtual void end() { is_active = false; }
83
84 virtual operator bool() { return is_active; }
85
86 protected:
87 int tmpPos = 0;
90 bool is_active = false;
91};
92
101 public:
103 virtual void setOutput(Print &out) = 0;
104};
105
115template <typename T = int16_t>
116class CsvOutput : public AudioOutput {
117 public:
118 CsvOutput(int buffer_size = DEFAULT_BUFFER_SIZE, bool active = true) {
119 this->is_active = active;
120 }
121
123 CsvOutput(Print &out, int channels = 2, int buffer_size = DEFAULT_BUFFER_SIZE,
124 bool active = true) {
125 this->out_ptr = &out;
126 this->is_active = active;
127 cfg.channels = channels;
128 }
129
131 void setDelimiter(const char *del) { delimiter_str = del; }
132
134 const char *delimiter() { return delimiter_str; }
135
137
140 AudioInfo info;
141 info.channels = 2;
142 info.sample_rate = 44100;
143 info.bits_per_sample = sizeof(T) * 8;
144 return info;
145 }
146
148 bool begin(AudioInfo info) override { return begin(info.channels); }
149
151 bool begin(int channels) {
152 TRACED();
153 cfg.channels = channels;
154 return begin();
155 }
156
158 bool begin() override {
159 this->is_active = true;
160 // if (out_ptr == &Serial){
161 // Serial.setTimeout(60000);
162 // }
163 return true;
164 }
165
167 virtual void setAudioInfo(AudioInfo info) override {
168 TRACEI();
169 this->is_active = true;
170 info.logInfo();
171 cfg = info;
172 };
173
175 virtual size_t write(const uint8_t *data, size_t len) override {
176 LOGD("CsvOutput::write: %d", (int)len);
177 if (!is_active) {
178 LOGE("is not active");
179 return 0;
180 }
181
182 if (len == 0) {
183 return 0;
184 }
185
186 if (cfg.channels == 0) {
187 LOGW("Channels not defined: using 2");
188 cfg.channels = 2;
189 }
190 size_t lenChannels = len / (sizeof(T) * cfg.channels);
191 if (lenChannels > 0) {
192 writeFrames((T *)data, lenChannels);
193 } else if (len == sizeof(T)) {
194 // if the write contains less then a frame we buffer the data
195 T *data_value = (T *)data;
196 out_ptr->print(data_value[0]);
197 channel++;
198 if (channel == cfg.channels) {
199 out_ptr->println();
200 channel = 0;
201 } else {
202 out_ptr->print(delimiter_str);
203 }
204 } else {
205 LOGE("Unsupported size: %d for channels %d and bits: %d", (int)len,
207 }
208#if USE_PRINT_FLUSH
209 out_ptr->flush();
210#endif
211 return len;
212 }
213
214 int availableForWrite() override { return 1024; }
215
216 protected:
219 int channel = 0;
220 const char *delimiter_str = ",";
221
223 for (size_t j = 0; j < frameCount; j++) {
224 for (int ch = 0; ch < cfg.channels; ch++) {
225 if (out_ptr != nullptr && data_ptr != nullptr) {
226 T value = *data_ptr;
227 out_ptr->print(value);
228 }
229 data_ptr++;
230 if (ch < cfg.channels - 1) this->out_ptr->print(delimiter_str);
231 }
232 this->out_ptr->println();
233 }
234 }
235};
236
244 public:
245 HexDumpOutput(int buffer_size = DEFAULT_BUFFER_SIZE, bool active = true) {
246 this->is_active = active;
247 }
248
250 HexDumpOutput(Print &out, int buffer_size = DEFAULT_BUFFER_SIZE,
251 bool active = true) {
252 this->out_ptr = &out;
253 this->is_active = active;
254 }
255
256 bool begin() override {
257 TRACED();
258 this->is_active = true;
259 pos = 0;
260 return is_active;
261 }
262
263 void flush() override {
264 out_ptr->println();
265 pos = 0;
266 }
267
268 virtual size_t write(const uint8_t *data, size_t len) override {
269 if (!is_active) return 0;
270 TRACED();
271 for (size_t j = 0; j < len; j++) {
272 out_ptr->print(data[j], HEX);
273 out_ptr->print(" ");
274 pos++;
275 if (pos == 8) {
276 out_ptr->print(" - ");
277 }
278 if (pos == 16) {
279 out_ptr->println();
280 pos = 0;
281 }
282 }
283 return len;
284 }
285
286 //
288 AudioInfo info;
289 return info;
290 }
291
292 protected:
294 int pos = 0;
295};
296
368template <typename T = int16_t>
369class OutputMixer : public Print {
370 public:
379
395
398
400 void setOutputCount(int count) {
401 output_count = count;
402 buffers.resize(count);
403 for (int i = 0; i < count; i++) {
404 buffers[i] = nullptr;
405 }
406 weights.resize(count);
407 for (int i = 0; i < count; i++) {
408 weights[i] = 1.0;
409 }
410
412 }
413
416 void setWeight(int channel, float weight) {
417 if (channel < size()) {
418 weights[channel] = weight;
419 } else {
420 LOGE("Invalid channel %d - max is %d", channel, size() - 1);
421 }
423 }
424
433
435 void end() {
436 total_weights = 0.0;
437 is_active = false;
438 // release memory for buffers
439 free_buffers();
440 }
441
443 int size() { return output_count; }
444
446 size_t write(uint8_t) override { return 0; }
447
450 size_t write(const uint8_t *data, size_t len) override {
451 size_t result = write(stream_idx, data, len);
452 // after writing the last stream we flush
453 if (is_auto_index) {
454 stream_idx++;
455 if (stream_idx >= output_count) {
456 flushMixer();
457 }
458 }
459 return result;
460 }
461
463 size_t write(int idx, const uint8_t *buffer_c, size_t bytes) {
464 LOGD("write idx %d: %d", idx, (int)bytes);
465 size_t result = 0;
466 BaseBuffer<T> *p_buffer = idx < output_count ? buffers[idx] : nullptr;
467 assert(p_buffer != nullptr);
468 size_t samples = bytes / sizeof(T);
469 if (p_buffer->availableForWrite() >= samples) {
470 result = p_buffer->writeArray((T *)buffer_c, samples) * sizeof(T);
471 } else {
472 LOGW(
473 "Available Buffer %d too small %d: requested: %d -> increase the "
474 "buffer size",
475 (int)idx, static_cast<int>(p_buffer->availableForWrite() * sizeof(T)),
476 (int)bytes);
477 }
478 return result;
479 }
480
482 int availableForWrite() override {
484 }
485
487 int availableForWrite(int idx) {
488 BaseBuffer<T> *p_buffer = buffers[idx];
489 if (p_buffer == nullptr) return 0;
490 return p_buffer->availableForWrite() * sizeof(T);
491 }
492
494 int available(int idx) {
495 BaseBuffer<T> *p_buffer = buffers[idx];
496 if (p_buffer == nullptr) return 0;
497 return p_buffer->available() * sizeof(T);
498 }
499
501 int availablePercent(int idx) { return 100.0 * available(idx) / size_bytes; }
502
504 bool flushMixer() {
505 LOGD("flush");
506 if (p_final_output == nullptr) {
507 return false;
508 }
509 bool result = false;
510
511 // determine ringbuffer with mininum available data
512 size_t samples = availableSamples();
513 // sum up samples
514 if (samples > 0) {
515 result = true;
516 mixSamples(samples);
517 // write output
518 LOGD("write to final out: %d", static_cast<int>(samples * sizeof(T)));
519 p_final_output->write((uint8_t *)output.data(), samples * sizeof(T));
520 }
521 stream_idx = 0;
522 return result;
523 }
524
525
526
529 size_t samples = 0;
530 for (int j = 0; j < output_count; j++) {
531 int available_samples = buffers[j]->available();
532 if (available_samples > 0) {
533 samples = MIN(size_bytes / sizeof(T), (size_t)available_samples);
534 }
535 }
536 return samples;
537 }
538
540 void resize(int sizeBytes) {
541 if (sizeBytes != size_bytes) {
543 }
545 }
546
548 size_t writeSilence(size_t bytes) {
549 if (bytes == 0) return 0;
551 memset(silence, 0, bytes);
552 return write(stream_idx, silence, bytes);
553 }
554
556 size_t writeSilence(int idx, size_t bytes) {
557 if (bytes == 0) return 0;
559 memset(silence, 0, bytes);
560 return write(idx, silence, bytes);
561 }
562
565
567 void setIndex(int idx) { stream_idx = idx; }
568
570 void next() { stream_idx++; }
571
574 create_buffer_cb = cb;
575 }
576
579 return idx < output_count ? buffers[idx] : nullptr;
580 }
581
582 protected:
588 float total_weights = 0.0;
589 bool is_active = false;
590 int stream_idx = 0;
591 int size_bytes = 0;
593 void *p_memory = nullptr;
594 bool is_auto_index = true;
595 BaseBuffer<T> *(*create_buffer_cb)(int size,
597
600 return new RingBuffer<T>(sizeBytes / sizeof(T), allocator);
601 }
602
604 inline void mixSamples(size_t samples) {
605#if defined(USE_ESP32_DSP)
606 // Temporary float buffers for mixing
607 float mix_out[samples] = {0.0f};
608 float temp[samples] = {0.0f};
609
610 for (uint8_t j = 0; j < output_count; j++) {
611 const float factor = weights[j] / total_weights;
612 // Read int16_t samples and convert to float
613 for (uint16_t i = 0; i < samples; i++) {
614 T s = 0;
615 buffers[j]->read(s);
616 temp[i] = static_cast<float>(s) * factor;
617 }
618 // Add to output
619 dsps_add_f32(mix_out, temp, mix_out, samples, 1, 1, 1);
620 }
621 // Convert back to int16_t with clamping
622 output.resize(samples);
623 for (size_t i = 0; i < samples; i++) {
624 float v = mix_out[i];
625 output[i] = static_cast<T>(v);
626 }
627#else
628 // Fallback: original scalar code
629 output.resize(samples);
630 memset(output.data(), 0, samples * sizeof(T));
631 for (int j = 0; j < output_count; j++) {
632 float factor = weights[j] / total_weights;
633 for (int i = 0; i < samples; i++) {
634 T sample = 0;
635 buffers[j]->read(sample);
636 output[i] += static_cast<T>(factor * sample);
637 }
638 }
639#endif
640 }
641
644 total_weights = 0.0;
645 for (int j = 0; j < weights.size(); j++) {
647 }
648 }
649
652 // allocate ringbuffers for each output
653 for (int j = 0; j < output_count; j++) {
654 if (buffers[j] != nullptr) {
655 delete buffers[j];
656 }
658 }
659 }
660
663 // allocate ringbuffers for each output
664 for (int j = 0; j < output_count; j++) {
665 if (buffers[j] != nullptr) {
666 delete buffers[j];
667 buffers[j] = nullptr;
668 }
669 }
670 }
671};
672
677class MemoryOutput : public AudioOutput {
678 public:
679 MemoryOutput(uint8_t *start, int len) {
680 p_start = start;
681 p_next = start;
682 max_size = len;
683 is_active = true;
684 if (p_next == nullptr) {
685 LOGE("start must not be null");
686 }
687 }
688
689 bool begin() override {
690 is_active = true;
691 p_next = p_start;
692 pos = 0;
693 return true;
694 }
695
696 size_t write(const uint8_t *data, size_t len) override {
697 if (p_next == nullptr) return 0;
698 if (pos + len <= max_size) {
699 memcpy(p_next, data, len);
700 pos += len;
701 p_next += len;
702 return len;
703 } else {
704 LOGE("Buffer too small: pos:%d, size: %d ", pos, (int)max_size);
705 return 0;
706 }
707 }
708
709 int availableForWrite() override { return max_size - pos; }
710
711 int size() { return max_size; }
712
713 protected:
714 int pos = 0;
715 uint8_t *p_start = nullptr;
716 uint8_t *p_next = nullptr;
717 size_t max_size;
718};
719
729 public:
731
732 ChannelSplitOutput(Print &out, int channel) { addOutput(out, channel); }
733
736 void addOutput(Print &out, int channel) {
738 def.channel = channel;
739 def.p_out = &out;
740 out_channels.push_back(def);
741 }
742
743 size_t write(const uint8_t *data, size_t len) override {
744 switch (cfg.bits_per_sample) {
745 case 16:
746 return writeT<int16_t>(data, len);
747 case 24:
748 return writeT<int24_t>(data, len);
749 case 32:
750 return writeT<int32_t>(data, len);
751 default:
752 return 0;
753 }
754 }
755
756 protected:
758 Print *p_out = nullptr;
760 };
762
763 template <typename T = int16_t>
764 size_t writeT(const uint8_t *buffer, size_t size) {
765 int sample_count = size / sizeof(T);
766 int result_size = sample_count / cfg.channels;
767 T *data = (T *)buffer;
768 T result[result_size];
769
770 for (int ch = 0; ch < out_channels.size(); ch++) {
772 // extract mono result
773 int i = 0;
774 for (int j = def.channel; j < sample_count; j += cfg.channels) {
775 result[i++] = data[j];
776 }
777 // write mono result
778 size_t written =
779 def.p_out->write((uint8_t *)result, result_size * sizeof(T));
780 if (written != result_size * sizeof(T)) {
781 LOGW("Could not write all samples");
782 }
783 }
784 return size;
785 }
786};
787
788} // namespace audio_tools
#define LOGW(...)
Definition AudioLoggerIDF.h:29
#define TRACEI()
Definition AudioLoggerIDF.h:32
#define TRACED()
Definition AudioLoggerIDF.h:31
#define LOGD(...)
Definition AudioLoggerIDF.h:27
#define LOGE(...)
Definition AudioLoggerIDF.h:30
#define PRINT_FLUSH_OVERRIDE
Definition AudioOutput.h:15
#define MAX_SINGLE_CHARS
Definition AudioToolsConfig.h:138
#define MIN(A, B)
Definition AudioTypes.h:17
@ HEX
Definition NoArduino.h:58
#define DEFAULT_BUFFER_SIZE
Definition avr.h:20
#define assert(T)
Definition avr.h:10
Memory allocateator which uses malloc.
Definition Allocator.h:23
Supports the subscription to audio change notifications.
Definition AudioTypes.h:150
void notifyAudioChange(AudioInfo info)
Definition AudioTypes.h:178
Supports changes to the sampling rate, bits and channels.
Definition AudioTypes.h:135
virtual AudioInfo audioInfoOut()
Definition AudioTypes.h:143
Abstract Audio Ouptut class.
Definition AudioOutput.h:25
SingleBuffer< uint8_t > tmp
Definition AudioOutput.h:89
AudioInfo cfg
Definition AudioOutput.h:88
virtual bool isDeletable()
If true we need to release the related memory in the destructor.
Definition AudioOutput.h:60
bool is_active
Definition AudioOutput.h:90
virtual bool begin(AudioInfo info)
Definition AudioOutput.h:73
virtual bool begin()
Definition AudioOutput.h:78
int tmpPos
Definition AudioOutput.h:87
virtual int availableForWrite() override
Definition AudioOutput.h:38
virtual ~AudioOutput()=default
virtual void setAudioInfo(AudioInfo newInfo) override
Defines the input AudioInfo.
Definition AudioOutput.h:49
virtual void flush()
Definition AudioOutput.h:42
virtual void writeSilence(size_t len)
Definition AudioOutput.h:66
virtual void end()
Definition AudioOutput.h:82
virtual size_t write(uint8_t ch) override
Definition AudioOutput.h:31
virtual size_t write(const uint8_t *data, size_t len) override=0
virtual AudioInfo audioInfo() override
provides the actual input AudioInfo
Definition AudioOutput.h:62
Shared functionality of all buffers.
Definition Buffers.h:22
virtual int writeArray(const T data[], int len)
Fills the buffer data.
Definition Buffers.h:55
virtual int availableForWrite()=0
provides the number of entries that are available to write
virtual int available()=0
provides the number of entries that are available to read
Simple functionality to extract mono streams from a multichannel (e.g. stereo) signal.
Definition AudioOutput.h:728
Vector< ChannelSelectionOutputDef > out_channels
Definition AudioOutput.h:761
ChannelSplitOutput(Print &out, int channel)
Definition AudioOutput.h:732
size_t write(const uint8_t *data, size_t len) override
Definition AudioOutput.h:743
void addOutput(Print &out, int channel)
Definition AudioOutput.h:736
size_t writeT(const uint8_t *buffer, size_t size)
Definition AudioOutput.h:764
Stream Wrapper which can be used to print the values as readable ASCII to the screen to be analyzed i...
Definition AudioOutput.h:116
virtual size_t write(const uint8_t *data, size_t len) override
Writes the data - formatted as CSV - to the output stream.
Definition AudioOutput.h:175
void writeFrames(T *data_ptr, int frameCount)
Definition AudioOutput.h:222
CsvOutput(int buffer_size=DEFAULT_BUFFER_SIZE, bool active=true)
Definition AudioOutput.h:118
const char * delimiter_str
Definition AudioOutput.h:220
AudioInfo defaultConfig()
Provides the default configuration.
Definition AudioOutput.h:139
bool begin(int channels)
Starts the processing with the defined number of channels.
Definition AudioOutput.h:151
int availableForWrite() override
Definition AudioOutput.h:214
CsvOutput(Print &out, int channels=2, int buffer_size=DEFAULT_BUFFER_SIZE, bool active=true)
Constructor.
Definition AudioOutput.h:123
AudioInfo defaultConfig(RxTxMode mode)
Definition AudioOutput.h:136
Print * out_ptr
Definition AudioOutput.h:218
virtual void setAudioInfo(AudioInfo info) override
defines the number of channels
Definition AudioOutput.h:167
T * data_ptr
Definition AudioOutput.h:217
bool begin(AudioInfo info) override
Starts the processing with the defined number of channels.
Definition AudioOutput.h:148
bool begin() override
(Re)start (e.g. if channels is set in constructor)
Definition AudioOutput.h:158
int channel
Definition AudioOutput.h:219
void setDelimiter(const char *del)
Defines an alternative (column) delimiter. The default is ,.
Definition AudioOutput.h:131
const char * delimiter()
Provides the current column delimiter.
Definition AudioOutput.h:134
Creates a Hex Dump.
Definition AudioOutput.h:243
virtual size_t write(const uint8_t *data, size_t len) override
Definition AudioOutput.h:268
void flush() override
Definition AudioOutput.h:263
int pos
Definition AudioOutput.h:294
AudioInfo defaultConfig(RxTxMode mode=TX_MODE)
Definition AudioOutput.h:287
HexDumpOutput(Print &out, int buffer_size=DEFAULT_BUFFER_SIZE, bool active=true)
Constructor.
Definition AudioOutput.h:250
Print * out_ptr
Definition AudioOutput.h:293
bool begin() override
Definition AudioOutput.h:256
HexDumpOutput(int buffer_size=DEFAULT_BUFFER_SIZE, bool active=true)
Definition AudioOutput.h:245
Writes to a preallocated memory.
Definition AudioOutput.h:677
int pos
Definition AudioOutput.h:714
uint8_t * p_start
Definition AudioOutput.h:715
uint8_t * p_next
Definition AudioOutput.h:716
MemoryOutput(uint8_t *start, int len)
Definition AudioOutput.h:679
size_t write(const uint8_t *data, size_t len) override
Definition AudioOutput.h:696
int availableForWrite() override
Definition AudioOutput.h:709
bool begin() override
Definition AudioOutput.h:689
size_t max_size
Definition AudioOutput.h:717
int size()
Definition AudioOutput.h:711
Abstract class: Objects can be put into a pipleline.
Definition AudioOutput.h:100
virtual void setOutput(Print &out)=0
Defines/Changes the output target.
Mixing of multiple audio input streams into a single output stream.
Definition AudioOutput.h:369
void next()
Moves to the next mixing index.
Definition AudioOutput.h:570
size_t writeSilence(size_t bytes)
Writes silence to the current stream buffer.
Definition AudioOutput.h:548
bool flushMixer()
Force output to final destination.
Definition AudioOutput.h:504
void setIndex(int idx)
Sets the Output Stream index.
Definition AudioOutput.h:567
int size_bytes
Definition AudioOutput.h:591
void mixSamples(size_t samples)
Mixes the samples from all input streams into the output buffer.
Definition AudioOutput.h:604
bool is_active
Definition AudioOutput.h:589
int availableSamples()
Returns the minimum number of samples available across all buffers.
Definition AudioOutput.h:528
OutputMixer(Print &finalOutput, int outputStreamCount, Allocator &allocator=DefaultAllocatorRAM)
Constructor with output stream, number of input streams, and allocator.
Definition AudioOutput.h:389
int stream_idx
Definition AudioOutput.h:590
Vector< T > output
Definition AudioOutput.h:586
size_t writeSilence(int idx, size_t bytes)
Writes silence to the specified stream buffer.
Definition AudioOutput.h:556
size_t write(int idx, const uint8_t *buffer_c, size_t bytes)
Write the data for an individual stream idx which will be mixed together.
Definition AudioOutput.h:463
bool is_auto_index
Definition AudioOutput.h:594
size_t write(const uint8_t *data, size_t len) override
Definition AudioOutput.h:450
int available(int idx)
Provides the available bytes in the buffer.
Definition AudioOutput.h:494
BaseBuffer< T > * getBuffer(int idx)
Provides the write buffer for the indicated index.
Definition AudioOutput.h:578
Vector< float > weights
Definition AudioOutput.h:583
void setCreateBufferCallback(BaseBuffer< T > *(*cb)(int size))
Define callback to allocate custum buffer types.
Definition AudioOutput.h:573
int availableForWrite() override
Provides the bytes available to write for the current stream buffer.
Definition AudioOutput.h:482
int availablePercent(int idx)
Provides the % fill level of the buffer for the indicated index.
Definition AudioOutput.h:501
Allocator & allocator
Definition AudioOutput.h:585
void update_total_weights()
Recalculates the total weights for normalization.
Definition AudioOutput.h:643
Print * p_final_output
Definition AudioOutput.h:587
void free_buffers()
Releases memory for all ring buffers.
Definition AudioOutput.h:662
OutputMixer(Allocator &allocator=DefaultAllocatorRAM)
Default constructor. You must call setOutput() and setOutputCount() before use.
Definition AudioOutput.h:377
void end()
Remove all input streams.
Definition AudioOutput.h:435
void setOutput(Print &finalOutput)
Sets the final output destination for mixed audio.
Definition AudioOutput.h:397
void setWeight(int channel, float weight)
Definition AudioOutput.h:416
int output_count
Definition AudioOutput.h:592
BaseBuffer< T > *(* create_buffer_cb)(int size, Allocator &allocator)
Definition AudioOutput.h:595
Vector< BaseBuffer< T > * > buffers
Definition AudioOutput.h:584
int availableForWrite(int idx)
Provides the bytes available to write for the indicated stream index.
Definition AudioOutput.h:487
void resize(int sizeBytes)
Resizes the buffer to the indicated number of bytes.
Definition AudioOutput.h:540
static BaseBuffer< T > * create_buffer(int sizeBytes, Allocator &allocator)
Creates a default ring buffer of the specified size.
Definition AudioOutput.h:599
void setAutoIndex(bool flag)
Automatically increment mixing index after each write.
Definition AudioOutput.h:564
bool begin(int copy_buffer_size_bytes=DEFAULT_BUFFER_SIZE)
Starts the processing.
Definition AudioOutput.h:426
void * p_memory
Definition AudioOutput.h:593
float total_weights
Definition AudioOutput.h:588
int size()
Number of stremams to which are mixed together.
Definition AudioOutput.h:443
void setOutputCount(int count)
Sets the number of input streams to mix.
Definition AudioOutput.h:400
size_t write(uint8_t) override
Single byte write - not supported, returns 0.
Definition AudioOutput.h:446
void allocate_buffers(int sizeBytes)
Allocates ring buffers for all input streams.
Definition AudioOutput.h:651
Definition NoArduino.h:62
virtual size_t write(const uint8_t *data, size_t len)
Definition NoArduino.h:126
virtual void flush()
Definition NoArduino.h:136
Implements a typed Ringbuffer.
Definition Buffers.h:341
A simple Buffer implementation which just uses a (dynamically sized) array.
Definition Buffers.h:172
bool write(T sample) override
write add an entry to the buffer
Definition Buffers.h:206
int available() override
provides the number of entries that are available to read
Definition Buffers.h:233
T * address() override
Provides address to beginning of the buffer.
Definition Buffers.h:281
bool isFull() override
checks if the buffer is full
Definition Buffers.h:240
Vector implementation which provides the most important methods as defined by std::vector....
Definition Vector.h:21
bool resize(int newSize, T value)
Definition Vector.h:266
int size()
Definition Vector.h:178
RxTxMode
The Microcontroller is the Audio Source (TX_MODE) or Audio Sink (RX_MODE). RXTX_MODE is Source and Si...
Definition AudioTypes.h:30
@ TX_MODE
Definition AudioTypes.h:30
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition AudioCodecsBase.h:10
static Allocator DefaultAllocatorRAM
Definition Allocator.h:177
static HardwareSerial Serial
Definition NoArduino.h:186
size_t writeData(Print *p_out, T *data, int samples, int maxSamples=512)
Definition AudioTypes.h:512
Basic Audio information which drives e.g. I2S.
Definition AudioTypes.h:55
sample_rate_t sample_rate
Sample Rate: e.g 44100.
Definition AudioTypes.h:57
uint16_t channels
Number of channels: 2=stereo, 1=mono.
Definition AudioTypes.h:59
uint8_t bits_per_sample
Number of bits per sample (int16_t = 16 bits)
Definition AudioTypes.h:61
virtual void logInfo(const char *source="")
Definition AudioTypes.h:125