arduino-audio-tools
|
Mixing of multiple audio input streams into a single output stream. More...
#include <AudioOutput.h>
Public Member Functions | |
OutputMixer (Allocator &allocator=DefaultAllocatorRAM) | |
Default constructor. You must call setOutput() and setOutputCount() before use. | |
OutputMixer (Print &finalOutput, int outputStreamCount, Allocator &allocator=DefaultAllocatorRAM) | |
Constructor with output stream, number of input streams, and allocator. | |
int | available (int idx) |
Provides the available bytes in the buffer. | |
int | availableForWrite () override |
Provides the bytes available to write for the current stream buffer. | |
int | availableForWrite (int idx) |
Provides the bytes available to write for the indicated stream index. | |
int | availablePercent (int idx) |
Provides the % fill level of the buffer for the indicated index. | |
int | availableSamples () |
Returns the minimum number of samples available across all buffers. | |
bool | begin (int copy_buffer_size_bytes=DEFAULT_BUFFER_SIZE) |
Starts the processing. | |
void | end () |
Remove all input streams. | |
virtual void | flush () |
void | flushMixer () |
Force output to final destination. | |
BaseBuffer< T > * | getBuffer (int idx) |
Provides the write buffer for the indicated index. | |
void | next () |
Moves to the next mixing index. | |
void | resize (int sizeBytes) |
Resizes the buffer to the indicated number of bytes. | |
void | setAutoIndex (bool flag) |
Automatically increment mixing index after each write. | |
void | setCreateBufferCallback (BaseBuffer< T > *(*cb)(int size)) |
Define callback to allocate custum buffer types. | |
void | setIndex (int idx) |
Sets the Output Stream index. | |
void | setOutput (Print &finalOutput) |
Sets the final output destination for mixed audio. | |
void | setOutputCount (int count) |
Sets the number of input streams to mix. | |
void | setWeight (int channel, float weight) |
int | size () |
Number of stremams to which are mixed together. | |
size_t | write (const uint8_t *data, size_t len) override |
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. | |
size_t | write (uint8_t) override |
Single byte write - not supported, returns 0. | |
size_t | writeSilence (int idx, size_t bytes) |
Writes silence to the specified stream buffer. | |
size_t | writeSilence (size_t bytes) |
Writes silence to the current stream buffer. | |
Static Protected Member Functions | |
static BaseBuffer< T > * | create_buffer (int sizeBytes, Allocator &allocator) |
Creates a default ring buffer of the specified size. | |
Protected Attributes | |
int | _timeout = 10 |
Allocator & | allocator |
Vector< BaseBuffer< T > * > | buffers {0, DefaultAllocatorRAM} |
BaseBuffer< T > *(* | create_buffer_cb )(int size, Allocator &allocator) = create_buffer |
bool | is_active = false |
bool | is_auto_index = true |
Vector< T > | output {0, allocator} |
int | output_count = 0 |
Print * | p_final_output = nullptr |
void * | p_memory = nullptr |
int | size_bytes = 0 |
int | stream_idx = 0 |
float | total_weights = 0.0 |
Vector< float > | weights {0, DefaultAllocatorRAM} |
Mixing of multiple audio input streams into a single output stream.
The OutputMixer allows you to combine multiple audio streams by summing their samples with configurable weights per channel. Each input stream is buffered independently using ring buffers, and the mixer outputs the combined result when all buffers have sufficient data available.
Features:
Auto Index Functionality: By default, auto-indexing is enabled (setAutoIndex(true)). When using the basic write() method without specifying a stream index, the mixer automatically:
This enables simple round-robin writing where you just call write() repeatedly and the mixer handles stream distribution and output flushing automatically.
Usage Examples:
Auto Index Mode (default):
Manual Index Mode:
T | Audio sample data type (e.g., int16_t, int32_t, float) |
|
inline |
Default constructor. You must call setOutput() and setOutputCount() before use.
allocator | Reference to the allocator to use for internal buffers (default: DefaultAllocatorRAM) |
|
inline |
Constructor with output stream, number of input streams, and allocator.
finalOutput | Reference to the Print object for mixed audio output |
outputStreamCount | Number of input streams to mix |
allocator | Reference to the allocator to use for internal buffers (default: DefaultAllocatorRAM) |
|
inlineoverridevirtual |
Provides the bytes available to write for the current stream buffer.
Reimplemented from Print.
|
inlinevirtualinherited |
Reimplemented in ResampleStream, HDLCStream, BufferedTaskStream, BufferedStream, and NamePrinter.
|
inline |
Defines a new weight for the indicated channel: If you set it to 0.0 it is muted. The initial value is 1.0
|
inlineoverridevirtual |
Write the data from a simgle stream which will be mixed together (the stream idx is increased)
Reimplemented from Print.