File syn_audio_mixer.h¶
FileList > audio > syn_audio_mixer.h
Go to the source code of this file
Zero-Heap Multi-Channel Q15 Fixed-Point Audio Mixer. More...
#include "../common/syn_defs.h"#include <stdbool.h>#include <stddef.h>#include <stdint.h>
Classes¶
| Type | Name |
|---|---|
| struct | SYN_Audio_Mixer Audio Mixer Instance State. |
| struct | SYN_Audio_Mixer_Channel State for a single mixer input channel. |
Public Functions¶
| Type | Name |
|---|---|
| SYN_Status | syn_audio_mixer_init (SYN_Audio_Mixer * mixer) Initialize an Audio Mixer instance. |
| SYN_Status | syn_audio_mixer_play (SYN_Audio_Mixer * mixer, uint8_t channel_idx, const int16_t * pcm_buf, size_t sample_count, uint16_t volume_q15, bool loop) Assign a PCM sample buffer to a mixer channel for playback. |
| size_t | syn_audio_mixer_render (SYN_Audio_Mixer * mixer, int16_t * out_pcm, size_t sample_count) Render mixed PCM audio into an output sample buffer. |
| SYN_Status | syn_audio_mixer_set_channel_volume (SYN_Audio_Mixer * mixer, uint8_t channel_idx, uint16_t volume_q15) Adjust gain for a specific channel. |
| SYN_Status | syn_audio_mixer_set_master_volume (SYN_Audio_Mixer * mixer, uint16_t volume_q15) Adjust master gain across all channels. |
| SYN_Status | syn_audio_mixer_stop (SYN_Audio_Mixer * mixer, uint8_t channel_idx) Stop channel playback immediately. |
Macros¶
| Type | Name |
|---|---|
| define | SYN_AUDIO_GAIN_UNITY 32768U |
| define | SYN_AUDIO_MIXER_MAX_CHANNELS 4U |
Detailed Description¶
Provides a zero-malloc multi-channel software PCM audio mixer. Blends multiple active 16-bit PCM audio channels into a single output buffer with per-channel gain, master gain, looping support, and Q15 saturation protection against clipping.
Public Functions Documentation¶
function syn_audio_mixer_init¶
Initialize an Audio Mixer instance.
Parameters:
mixerPointer to Audio Mixer instance.
Returns:
SYN_OK on success, or SYN_INVALID_PARAM.
function syn_audio_mixer_play¶
Assign a PCM sample buffer to a mixer channel for playback.
SYN_Status syn_audio_mixer_play (
SYN_Audio_Mixer * mixer,
uint8_t channel_idx,
const int16_t * pcm_buf,
size_t sample_count,
uint16_t volume_q15,
bool loop
)
Parameters:
mixerPointer to Audio Mixer instance.channel_idxChannel index (0 .. SYN_AUDIO_MIXER_MAX_CHANNELS - 1).pcm_bufPointer to 16-bit PCM sample array.sample_countSample count in pcm_buf.volume_q15Channel gain (Q15, 32768 = 1.0).loopTrue to restart automatically upon reaching buffer end.
Returns:
SYN_OK on success, or SYN_INVALID_PARAM.
function syn_audio_mixer_render¶
Render mixed PCM audio into an output sample buffer.
Accumulates active channels, applies Q15 scaling, saturates to [-32768, 32767], and writes to out_pcm.
Parameters:
mixerPointer to Audio Mixer instance.out_pcmOutput 16-bit PCM buffer pointer.sample_countOutput sample count to render.
Returns:
Number of samples actually generated (0 if no active channels or NULL).
function syn_audio_mixer_set_channel_volume¶
Adjust gain for a specific channel.
SYN_Status syn_audio_mixer_set_channel_volume (
SYN_Audio_Mixer * mixer,
uint8_t channel_idx,
uint16_t volume_q15
)
Parameters:
mixerPointer to Audio Mixer instance.channel_idxChannel index (0 .. SYN_AUDIO_MIXER_MAX_CHANNELS - 1).volume_q15New gain value (Q15).
Returns:
SYN_OK on success, or SYN_INVALID_PARAM / SYN_ERR_OUT_OF_BOUNDS.
function syn_audio_mixer_set_master_volume¶
Adjust master gain across all channels.
Parameters:
mixerPointer to Audio Mixer instance.volume_q15New master gain value (Q15).
Returns:
SYN_OK on success, or SYN_INVALID_PARAM.
function syn_audio_mixer_stop¶
Stop channel playback immediately.
Parameters:
mixerPointer to Audio Mixer instance.channel_idxChannel index (0 .. SYN_AUDIO_MIXER_MAX_CHANNELS - 1).
Returns:
SYN_OK on success, or SYN_INVALID_PARAM / SYN_ERR_OUT_OF_BOUNDS.
Macro Definition Documentation¶
define SYN_AUDIO_GAIN_UNITY¶
Q15 identity gain (1.0 = 32768)
define SYN_AUDIO_MIXER_MAX_CHANNELS¶
Maximum concurrent mixer channels
The documentation for this class was generated from the following file src/syntropic/audio/syn_audio_mixer.h