104#define MIXER_MAX_SOURCES 32
114#define MIXER_FRAME_SIZE 256
549float clamp_float(
float value,
float min,
float max);
965void fade_buffer(
float *buffer,
int count,
float start_gain,
float end_gain);
1021float soft_clip(
float sample,
float threshold,
float steepness);
1034void soft_clip_buffer(
float *buffer,
int num_samples,
float threshold,
float steepness);
⚠️‼️ Error and/or exit() when things go bad.
float hysteresis
Hysteresis factor (0-1, prevents gate chatter)
float release_coeff
Release coefficient (converted from release_ms)
bool noise_gate_is_open(const noise_gate_t *gate)
Check if noise gate is currently open.
float base_gain
Base gain before crowd scaling is applied.
void copy_buffer_with_gain(const float *src, float *dst, int count, float gain)
Copy buffer with gain scaling.
float leader_margin_dB
Leader margin in dB (sources within this of loudest are leaders)
void noise_gate_process_buffer(noise_gate_t *gate, float *buffer, int num_samples)
Process a buffer of samples through noise gate.
void buffer_float_to_int16(const float *src, int16_t *dst, int count)
Convert float buffer to int16 buffer.
float alpha
Filter coefficient alpha (calculated from cutoff_hz)
float release_coeff
Release coefficient (converted from release_ms)
float clamp_float(float value, float min, float max)
Clamp a float value to a range.
float ratio
Compression ratio (e.g., 4.0 for 4:1 compression)
void highpass_filter_reset(highpass_filter_t *filter)
Reset high-pass filter state.
float sample_rate
Sample rate in Hz (set during initialization)
void soft_clip_buffer(float *buffer, int num_samples, float threshold, float steepness)
Apply soft clipping to a buffer.
float prev_input
Previous input sample (filter state)
float prev_output
Previous output sample (filter state)
float highpass_filter_process_sample(highpass_filter_t *filter, float input)
Process a single sample through high-pass filter.
float envelope
Current envelope follower state (linear, 0-1)
bool * source_active
Array of active flags (true if source is active)
float cutoff_hz
Cutoff frequency in Hz (frequencies above this are attenuated)
void apply_gain_buffer(float *buffer, int count, float gain)
Apply gain to buffer in-place.
float atten_dB
Attenuation in dB for non-leader sources.
rwlock_t source_lock
Reader-writer lock protecting source arrays and bitset.
void mixer_set_source_active(mixer_t *mixer, uint32_t client_id, bool active)
Set whether a source is active (receiving audio)
float * gain
Per-source ducking gain (linear, calculated from envelope)
float attack_coeff
Attack coefficient (converted from attack_ms)
void ducking_set_params(ducking_t *duck, float threshold_dB, float leader_margin_dB, float atten_dB, float attack_ms, float release_ms)
Set ducking parameters.
float release_ms
Release time in milliseconds (how fast gate closes)
void ducking_free(ducking_t *duck)
Free ducking system resources.
float threshold_dB
Speaking threshold in dB (sources below this are not "speaking")
void ducking_process_frame(ducking_t *duck, float *envelopes, float *gains, int num_sources)
Process a frame of audio through ducking system.
void noise_gate_init(noise_gate_t *gate, float sample_rate)
Initialize a noise gate.
float crowd_alpha
Crowd scaling exponent (typically 0.5 for sqrt scaling)
float buffer_peak(const float *buffer, int count)
Find peak absolute value in buffer.
ducking_t ducking
Ducking system (active speaker detection and attenuation)
float cutoff_hz
Cutoff frequency in Hz (frequencies below this are attenuated)
int num_sources
Current number of active audio sources.
float soft_clip(float sample, float threshold, float steepness)
Apply soft clipping to a sample.
float sample_rate
Sample rate in Hz (set during initialization)
float knee_dB
Knee width in dB for soft knee (e.g., 2.0)
float attack_ms
Attack time in milliseconds (how fast compression kicks in)
void compressor_set_params(compressor_t *comp, float threshold_dB, float ratio, float attack_ms, float release_ms, float makeup_dB)
Set compressor parameters.
void fade_buffer(float *buffer, int count, float start_gain, float end_gain)
Apply linear fade to buffer in-place.
void compressor_init(compressor_t *comp, float sample_rate)
Initialize a compressor.
float alpha
Filter coefficient alpha (calculated from cutoff_hz)
int ducking_init(ducking_t *duck, int num_sources, float sample_rate)
Initialize ducking system.
void highpass_filter_init(highpass_filter_t *filter, float cutoff_hz, float sample_rate)
Initialize a high-pass filter.
uint32_t * source_ids
Array of client IDs (one per source slot)
uint64_t active_sources_mask
Bitset of active sources (bit i = source i is active, O(1) iteration)
float int16_to_float(int16_t sample)
Convert int16 sample to float.
float * envelope
Per-source envelope follower state (linear, allocated per source)
float threshold_dB
Compression threshold in dB (e.g., -10.0)
float release_ms
Release time in milliseconds (how fast compression releases)
int max_sources
Maximum number of sources (allocated array sizes)
float * mix_buffer
Temporary buffer for mixing operations (pre-allocated)
float attack_ms
Attack time in milliseconds (how fast gate opens)
float envelope
Current envelope follower state (linear, 0-1)
float sample_rate
Sample rate in Hz (set during initialization)
bool gate_open
True if gate is currently open (allowing audio through)
float smoothstep(float t)
Compute smoothstep interpolation.
void fade_buffer_smooth(float *buffer, int count, bool fade_in)
Apply smoothstep fade to buffer in-place.
float attack_ms
Ducking attack time in milliseconds.
int mixer_add_source(mixer_t *mixer, uint32_t client_id, audio_ring_buffer_t *buffer)
Add an audio source to the mixer.
int16_t float_to_int16(float sample)
Convert float sample to int16 (WebRTC format)
compressor_t compressor
Compressor (dynamic range compression)
float sample_rate
Sample rate in Hz (set during initialization)
void lowpass_filter_init(lowpass_filter_t *filter, float cutoff_hz, float sample_rate)
Initialize a low-pass filter.
mixer_t * mixer_create(int max_sources, int sample_rate)
Create a new audio mixer.
int mixer_process_excluding_source(mixer_t *mixer, float *output, int num_samples, uint32_t exclude_client_id)
Process audio from all sources except one (for per-client output)
float db_to_linear(float db)
Convert decibels to linear gain.
void lowpass_filter_process_buffer(lowpass_filter_t *filter, float *buffer, int num_samples)
Process a buffer of samples through low-pass filter.
void highpass_filter_process_buffer(highpass_filter_t *filter, float *buffer, int num_samples)
Process a buffer of samples through high-pass filter.
float release_ms
Ducking release time in milliseconds.
audio_ring_buffer_t ** source_buffers
Array of pointers to client audio ring buffers.
void noise_gate_set_params(noise_gate_t *gate, float threshold, float attack_ms, float release_ms, float hysteresis)
Set noise gate parameters.
float makeup_dB
Makeup gain in dB (compensates for gain reduction)
float compressor_process_sample(compressor_t *comp, float sidechain)
Process a single sample through compressor.
void mixer_destroy(mixer_t *mixer)
Destroy a mixer and free all resources.
int sample_rate
Sample rate in Hz (e.g., 44100)
float lowpass_filter_process_sample(lowpass_filter_t *filter, float input)
Process a single sample through low-pass filter.
float linear_to_db(float linear)
Convert linear gain to decibels.
void lowpass_filter_reset(lowpass_filter_t *filter)
Reset low-pass filter state.
float attack_coeff
Attack coefficient (converted from attack_ms)
int mixer_process(mixer_t *mixer, float *output, int num_samples)
Process audio from all active sources.
void mixer_remove_source(mixer_t *mixer, uint32_t client_id)
Remove an audio source from the mixer.
void buffer_int16_to_float(const int16_t *src, float *dst, int count)
Convert int16 buffer to float buffer.
float threshold
Gate threshold in linear units (e.g., 0.01f for -40dB)
float prev_output
Previous output sample (filter state)
float release_coeff
Release coefficient (converted from release_ms)
float gain_lin
Current gain multiplier (linear, calculated from envelope)
float attack_coeff
Attack coefficient (converted from attack_ms)
float noise_gate_process_sample(noise_gate_t *gate, float input, float peak_amplitude)
Process a single sample through noise gate.
unsigned long long uint64_t
Lock-Free Ring Buffer and Frame Buffer Management.
Cross-platform read-write lock interface for ascii-chat.
Audio ring buffer for real-time audio streaming.
Dynamic range compressor settings and state.
Ducking system settings and state.
High-pass filter settings and state.
Main mixer structure for multi-source audio processing.
Noise gate settings and state.