|
| | 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 () |
| |
| bool | 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.
|
| |
| bool | resize (size_t 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.
|
| |
template<typename T = int16_t>
class audio_tools::OutputMixer< T >
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:
- Multiple input streams with individual weight control
- Automatic or manual stream indexing for simplified writing
- Configurable buffer sizes per stream
- Real-time mixing with sample-accurate synchronization
- Memory-efficient ring buffer implementation
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:
- Writes data to the current stream index (starting at 0)
- Increments to the next stream index after each write
- Automatically calls flushMixer() after writing to the last stream
- Resets the index back to 0 for the next cycle
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):
mixer.begin(1024);
mixer.write(audio_data1, length);
mixer.write(audio_data2, length);
mixer.write(audio_data3, length);
static HardwareSerial Serial
Definition Arduino.h:179
Manual Index Mode:
mixer.begin(1024);
mixer.setAutoIndex(false);
mixer.setWeight(0, 0.8f);
mixer.setWeight(1, 1.0f);
mixer.setWeight(2, 0.5f);
mixer.write(0, audio_data1, length);
mixer.write(1, audio_data2, length);
mixer.write(2, audio_data3, length);
mixer.flushMixer();
- Note
- By default uses RingBuffer as the buffer type. Buffer type can be customized using setCreateBufferCallback().
-
All input streams must have the same sample format (bit depth, sample rate).
-
The mixer normalizes output by dividing by the total weight sum.
-
In auto-index mode, ensure you write to all streams in each cycle for proper mixing.
- Author
- Phil Schatzmann
- Copyright
- GPLv3
- Template Parameters
-
| T | Audio sample data type (e.g., int16_t, int32_t, float) |