Skip to content

Commit 3477de5

Browse files
committed
OutputMixer: improve docu
1 parent a53052e commit 3477de5

File tree

1 file changed

+62
-3
lines changed

1 file changed

+62
-3
lines changed

src/AudioTools/CoreAudio/AudioOutput.h

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,71 @@ class HexDumpOutput : public AudioOutput {
296296

297297

298298
/**
299-
* @brief Mixing of multiple outputs to one final output.
300-
* By default a RingBuffer is used as buffer type.
299+
* @brief Mixing of multiple audio input streams into a single output stream.
300+
*
301+
* The OutputMixer allows you to combine multiple audio streams by summing their samples
302+
* with configurable weights per channel. Each input stream is buffered independently
303+
* using ring buffers, and the mixer outputs the combined result when all buffers
304+
* have sufficient data available.
305+
*
306+
* Features:
307+
* - Multiple input streams with individual weight control
308+
* - Automatic or manual stream indexing for simplified writing
309+
* - Configurable buffer sizes per stream
310+
* - Real-time mixing with sample-accurate synchronization
311+
* - Memory-efficient ring buffer implementation
312+
*
313+
* Auto Index Functionality:
314+
* By default, auto-indexing is enabled (setAutoIndex(true)). When using the basic
315+
* write() method without specifying a stream index, the mixer automatically:
316+
* 1. Writes data to the current stream index (starting at 0)
317+
* 2. Increments to the next stream index after each write
318+
* 3. Automatically calls flushMixer() after writing to the last stream
319+
* 4. Resets the index back to 0 for the next cycle
320+
*
321+
* This enables simple round-robin writing where you just call write() repeatedly
322+
* and the mixer handles stream distribution and output flushing automatically.
323+
*
324+
* Usage Examples:
325+
*
326+
* Auto Index Mode (default):
327+
* @code
328+
* OutputMixer<int16_t> mixer(Serial, 3); // 3 input streams to Serial output
329+
* mixer.begin(1024); // 1KB buffer per stream
330+
*
331+
* // Simple round-robin writing - auto-increments stream index
332+
* mixer.write(audio_data1, length); // -> stream 0, index = 1
333+
* mixer.write(audio_data2, length); // -> stream 1, index = 2
334+
* mixer.write(audio_data3, length); // -> stream 2, auto-flush, index = 0
335+
* // Process repeats automatically
336+
* @endcode
337+
*
338+
* Manual Index Mode:
339+
* @code
340+
* OutputMixer<int16_t> mixer(Serial, 3);
341+
* mixer.begin(1024);
342+
* mixer.setAutoIndex(false); // Disable auto-indexing
343+
* mixer.setWeight(0, 0.8f); // Stream 0 at 80% volume
344+
* mixer.setWeight(1, 1.0f); // Stream 1 at 100% volume
345+
* mixer.setWeight(2, 0.5f); // Stream 2 at 50% volume
346+
*
347+
* // Write data to specific streams manually
348+
* mixer.write(0, audio_data1, length); // Write to stream 0
349+
* mixer.write(1, audio_data2, length); // Write to stream 1
350+
* mixer.write(2, audio_data3, length); // Write to stream 2
351+
* mixer.flushMixer(); // Manually trigger mix and output
352+
* @endcode
353+
*
354+
* @note By default uses RingBuffer as the buffer type. Buffer type can be customized
355+
* using setCreateBufferCallback().
356+
* @note All input streams must have the same sample format (bit depth, sample rate).
357+
* @note The mixer normalizes output by dividing by the total weight sum.
358+
* @note In auto-index mode, ensure you write to all streams in each cycle for proper mixing.
359+
*
301360
* @ingroup transform
302361
* @author Phil Schatzmann
303362
* @copyright GPLv3
304-
* @tparam T
363+
* @tparam T Audio sample data type (e.g., int16_t, int32_t, float)
305364
*/
306365
template <typename T>
307366
class OutputMixer : public Print {

0 commit comments

Comments
 (0)