|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
🔊 Audio system for real-time audio capture and playback More...
Files | |
| file | analysis.c |
| Audio Analysis Implementation. | |
| file | analysis.h |
| Audio Analysis and Debugging Interface. | |
| file | audio.c |
| 🔊 Audio capture and playback using PortAudio with buffer management | |
| file | audio.h |
| 🔊 Audio Capture and Playback Interface for ascii-chat | |
| file | client_audio_pipeline.h |
| Unified client-side audio processing pipeline. | |
| file | mixer.c |
| 🎚️ Real-time audio mixer with ducking, gain control, and multi-stream blending | |
| file | mixer.h |
| Multi-Source Audio Mixing and Processing System. | |
| file | opus_codec.c |
| Opus audio codec implementation. | |
| file | opus_codec.h |
| Opus audio codec wrapper for real-time encoding/decoding. | |
Data Structures | |
| struct | audio_context_t |
| Audio context for full-duplex capture and playback. More... | |
| struct | audio_device_info_t |
| Audio device information structure. More... | |
| struct | audio_batch_info_t |
| Parsed audio batch packet header information. More... | |
| struct | compressor_t |
| Dynamic range compressor settings and state. More... | |
| struct | noise_gate_t |
| Noise gate settings and state. More... | |
| struct | highpass_filter_t |
| High-pass filter settings and state. More... | |
| struct | lowpass_filter_t |
| Low-pass filter state. More... | |
| struct | ducking_t |
| Ducking system settings and state. More... | |
| struct | mixer_t |
| Main mixer structure for multi-source audio processing. More... | |
| struct | opus_codec_t |
| Opus codec context for encoding or decoding. More... | |
Macros | |
| #define | AUDIO_SAMPLE_RATE 48000 |
| Audio sample rate (48kHz professional quality, Opus-compatible) | |
| #define | AUDIO_FRAMES_PER_BUFFER 480 |
| Audio frames per buffer (480 = 10ms at 48kHz, matches WebRTC AEC3 frame size) | |
| #define | AUDIO_CHANNELS 1 |
| Number of audio channels (1 = mono) | |
| #define | AUDIO_BUFFER_SIZE (AUDIO_FRAMES_PER_BUFFER * AUDIO_CHANNELS) |
| Total audio buffer size (frames × channels) | |
Typedefs | |
| typedef struct OpusEncoder | OpusEncoder |
| typedef struct OpusDecoder | OpusDecoder |
Enumerations | |
| enum | opus_application_t { OPUS_APPLICATION_VOIP = 2048 , OPUS_APPLICATION_AUDIO = 2049 , OPUS_APPLICATION_RESTRICTED_LOWDELAY = 2051 } |
| Application mode for opus encoder. More... | |
Functions | |
| asciichat_error_t | audio_init (audio_context_t *ctx) |
| Initialize audio context and PortAudio. | |
| void | audio_destroy (audio_context_t *ctx) |
| Destroy audio context and clean up resources. | |
| void | audio_set_pipeline (audio_context_t *ctx, void *pipeline) |
| Set audio pipeline for echo cancellation. | |
| asciichat_error_t | audio_start_duplex (audio_context_t *ctx) |
| Start full-duplex audio (simultaneous capture and playback) | |
| asciichat_error_t | audio_stop_duplex (audio_context_t *ctx) |
| Stop full-duplex audio. | |
| asciichat_error_t | audio_read_samples (audio_context_t *ctx, float *buffer, int num_samples) |
| Read captured audio samples from capture buffer. | |
| asciichat_error_t | audio_write_samples (audio_context_t *ctx, const float *buffer, int num_samples) |
| Write audio samples to playback buffer. | |
| asciichat_error_t | audio_set_realtime_priority (void) |
| Request real-time priority for current thread. | |
| asciichat_error_t | audio_list_input_devices (audio_device_info_t **out_devices, unsigned int *out_count) |
| List available audio input devices (microphones) | |
| asciichat_error_t | audio_list_output_devices (audio_device_info_t **out_devices, unsigned int *out_count) |
| List available audio output devices (speakers) | |
| void | audio_free_device_list (audio_device_info_t *devices) |
| Free device list allocated by audio_list_input_devices/audio_list_output_devices. | |
| asciichat_error_t | audio_dequantize_samples (const uint8_t *samples_ptr, uint32_t total_samples, float *out_samples) |
| Dequantize network audio samples from int32 to float. | |
| audio_ring_buffer_t * | audio_ring_buffer_create (void) |
| Create a new audio ring buffer (for playback with jitter buffering) | |
| audio_ring_buffer_t * | audio_ring_buffer_create_for_capture (void) |
| Create a new audio ring buffer for capture (without jitter buffering) | |
| void | audio_ring_buffer_destroy (audio_ring_buffer_t *rb) |
| Destroy an audio ring buffer. | |
| void | audio_ring_buffer_clear (audio_ring_buffer_t *rb) |
| Clear all audio samples from ring buffer. | |
| asciichat_error_t | audio_ring_buffer_write (audio_ring_buffer_t *rb, const float *data, int samples) |
| Write audio samples to ring buffer. | |
| size_t | audio_ring_buffer_read (audio_ring_buffer_t *rb, float *data, size_t samples) |
| Read audio samples from ring buffer. | |
| size_t | audio_ring_buffer_peek (audio_ring_buffer_t *rb, float *data, size_t samples) |
| Peek at available samples without consuming them (for AEC3 render signal) | |
| size_t | audio_ring_buffer_available_read (audio_ring_buffer_t *rb) |
| Get number of samples available for reading. | |
| size_t | audio_ring_buffer_available_write (audio_ring_buffer_t *rb) |
| Get number of sample slots available for writing. | |
| void | resample_linear (const float *src, size_t src_samples, float *dst, size_t dst_samples, double src_rate, double dst_rate) |
| Resample audio using linear interpolation. | |
| asciichat_error_t | audio_parse_batch_header (const void *data, size_t len, audio_batch_info_t *out_batch) |
| Parse an audio batch packet header from raw packet data. | |
| asciichat_error_t | audio_validate_batch_params (const audio_batch_info_t *batch) |
| Validate audio batch parameters for sanity. | |
| bool | audio_is_supported_sample_rate (uint32_t sample_rate) |
| Check if a sample rate is a standard/supported rate. | |
| opus_codec_t * | opus_codec_create_encoder (opus_application_t application, int sample_rate, int bitrate) |
| Create an Opus encoder. | |
| opus_codec_t * | opus_codec_create_decoder (int sample_rate) |
| Create an Opus decoder. | |
| size_t | opus_codec_encode (opus_codec_t *codec, const float *samples, int num_samples, uint8_t *out_data, size_t out_size) |
| Encode audio frame with Opus. | |
| int | opus_codec_decode (opus_codec_t *codec, const uint8_t *data, size_t data_len, float *out_samples, int out_num_samples) |
| Decode Opus audio frame. | |
| asciichat_error_t | opus_codec_set_bitrate (opus_codec_t *codec, int bitrate) |
| Set encoder bitrate. | |
| int | opus_codec_get_bitrate (opus_codec_t *codec) |
| Get current encoder bitrate. | |
| asciichat_error_t | opus_codec_set_dtx (opus_codec_t *codec, int enable) |
| Enable/disable DTX (Discontinuous Transmission) | |
| void | opus_codec_destroy (opus_codec_t *codec) |
| Destroy an Opus codec instance. | |
Variables | |
| float | compressor_t::threshold_dB |
| Compression threshold in dB (e.g., -10.0) | |
| float | compressor_t::knee_dB |
| Knee width in dB for soft knee (e.g., 2.0) | |
| float | compressor_t::ratio |
| Compression ratio (e.g., 4.0 for 4:1 compression) | |
| float | compressor_t::attack_ms |
| Attack time in milliseconds (how fast compression kicks in) | |
| float | compressor_t::release_ms |
| Release time in milliseconds (how fast compression releases) | |
| float | compressor_t::makeup_dB |
| Makeup gain in dB (compensates for gain reduction) | |
| float | compressor_t::sample_rate |
| Sample rate in Hz (set during initialization) | |
| float | compressor_t::envelope |
| Current envelope follower state (linear, 0-1) | |
| float | compressor_t::gain_lin |
| Current gain multiplier (linear, calculated from envelope) | |
| float | compressor_t::attack_coeff |
| Attack coefficient (converted from attack_ms) | |
| float | compressor_t::release_coeff |
| Release coefficient (converted from release_ms) | |
| float | noise_gate_t::threshold |
| Gate threshold in linear units (e.g., 0.01f for -40dB) | |
| float | noise_gate_t::attack_ms |
| Attack time in milliseconds (how fast gate opens) | |
| float | noise_gate_t::release_ms |
| Release time in milliseconds (how fast gate closes) | |
| float | noise_gate_t::hysteresis |
| Hysteresis factor (0-1, prevents gate chatter) | |
| float | noise_gate_t::sample_rate |
| Sample rate in Hz (set during initialization) | |
| float | noise_gate_t::envelope |
| Current envelope follower state (linear, 0-1) | |
| float | noise_gate_t::attack_coeff |
| Attack coefficient (converted from attack_ms) | |
| float | noise_gate_t::release_coeff |
| Release coefficient (converted from release_ms) | |
| bool | noise_gate_t::gate_open |
| True if gate is currently open (allowing audio through) | |
| float | highpass_filter_t::cutoff_hz |
| Cutoff frequency in Hz (frequencies below this are attenuated) | |
| float | highpass_filter_t::sample_rate |
| Sample rate in Hz (set during initialization) | |
| float | highpass_filter_t::alpha |
| Filter coefficient alpha (calculated from cutoff_hz) | |
| float | highpass_filter_t::prev_input |
| Previous input sample (filter state) | |
| float | highpass_filter_t::prev_output |
| Previous output sample (filter state) | |
| float | lowpass_filter_t::cutoff_hz |
| Cutoff frequency in Hz (frequencies above this are attenuated) | |
| float | lowpass_filter_t::sample_rate |
| Sample rate in Hz (set during initialization) | |
| float | lowpass_filter_t::alpha |
| Filter coefficient alpha (calculated from cutoff_hz) | |
| float | lowpass_filter_t::prev_output |
| Previous output sample (filter state) | |
| float | ducking_t::threshold_dB |
| Speaking threshold in dB (sources below this are not "speaking") | |
| float | ducking_t::leader_margin_dB |
| Leader margin in dB (sources within this of loudest are leaders) | |
| float | ducking_t::atten_dB |
| Attenuation in dB for non-leader sources. | |
| float | ducking_t::attack_ms |
| Ducking attack time in milliseconds. | |
| float | ducking_t::release_ms |
| Ducking release time in milliseconds. | |
| float | ducking_t::attack_coeff |
| Attack coefficient (converted from attack_ms) | |
| float | ducking_t::release_coeff |
| Release coefficient (converted from release_ms) | |
| float * | ducking_t::envelope |
| Per-source envelope follower state (linear, allocated per source) | |
| float * | ducking_t::gain |
| Per-source ducking gain (linear, calculated from envelope) | |
| int | mixer_t::num_sources |
| Current number of active audio sources. | |
| int | mixer_t::max_sources |
| Maximum number of sources (allocated array sizes) | |
| int | mixer_t::sample_rate |
| Sample rate in Hz (e.g., 44100) | |
| audio_ring_buffer_t ** | mixer_t::source_buffers |
| Array of pointers to client audio ring buffers. | |
| uint32_t * | mixer_t::source_ids |
| Array of client IDs (one per source slot) | |
| bool * | mixer_t::source_active |
| Array of active flags (true if source is active) | |
| uint64_t | mixer_t::active_sources_mask |
| Bitset of active sources (bit i = source i is active, O(1) iteration) | |
| uint8_t | mixer_t::source_id_to_index [256] |
| Hash table mapping client_id → mixer source index (uses hash function for 32-bit IDs) | |
| uint32_t | mixer_t::source_id_at_hash [256] |
| Client IDs stored at each hash index for collision detection. | |
| rwlock_t | mixer_t::source_lock |
| Reader-writer lock protecting source arrays and bitset. | |
| float | mixer_t::crowd_alpha |
| Crowd scaling exponent (typically 0.5 for sqrt scaling) | |
| float | mixer_t::base_gain |
| Base gain before crowd scaling is applied. | |
| ducking_t | mixer_t::ducking |
| Ducking system (active speaker detection and attenuation) | |
| compressor_t | mixer_t::compressor |
| Compressor (dynamic range compression) | |
| float * | mixer_t::mix_buffer |
| Temporary buffer for mixing operations (pre-allocated) | |
Mixer Lifecycle Functions | |
| mixer_t * | mixer_create (int max_sources, int sample_rate) |
| Create a new audio mixer. | |
| void | mixer_destroy (mixer_t *mixer) |
| Destroy a mixer and free all resources. | |
Source Management Functions | |
| int | mixer_add_source (mixer_t *mixer, uint32_t client_id, audio_ring_buffer_t *buffer) |
| Add an audio source to the mixer. | |
| void | mixer_remove_source (mixer_t *mixer, uint32_t client_id) |
| Remove an audio source from the mixer. | |
| void | mixer_set_source_active (mixer_t *mixer, uint32_t client_id, bool active) |
| Set whether a source is active (receiving audio) | |
Audio Processing Functions | |
| int | mixer_process (mixer_t *mixer, float *output, int num_samples) |
| Process audio from all active sources. | |
| 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) | |
Utility Functions | |
| float | db_to_linear (float db) |
| Convert decibels to linear gain. | |
| float | linear_to_db (float linear) |
| Convert linear gain to decibels. | |
| float | clamp_float (float value, float min, float max) |
| Clamp a float value to a range. | |
Compressor Functions | |
| void | compressor_init (compressor_t *comp, float sample_rate) |
| Initialize a compressor. | |
| void | compressor_set_params (compressor_t *comp, float threshold_dB, float ratio, float attack_ms, float release_ms, float makeup_dB) |
| Set compressor parameters. | |
| float | compressor_process_sample (compressor_t *comp, float sidechain) |
| Process a single sample through compressor. | |
Ducking Functions | |
| int | ducking_init (ducking_t *duck, int num_sources, float sample_rate) |
| Initialize ducking system. | |
| void | ducking_free (ducking_t *duck) |
| Free ducking system resources. | |
| 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. | |
| void | ducking_process_frame (ducking_t *duck, float *envelopes, float *gains, int num_sources) |
| Process a frame of audio through ducking system. | |
Noise Gate Functions | |
| void | noise_gate_init (noise_gate_t *gate, float sample_rate) |
| Initialize a noise gate. | |
| void | noise_gate_set_params (noise_gate_t *gate, float threshold, float attack_ms, float release_ms, float hysteresis) |
| Set noise gate parameters. | |
| float | noise_gate_process_sample (noise_gate_t *gate, float input, float peak_amplitude) |
| Process a single sample through noise gate. | |
| void | noise_gate_process_buffer (noise_gate_t *gate, float *buffer, int num_samples) |
| Process a buffer of samples through noise gate. | |
| bool | noise_gate_is_open (const noise_gate_t *gate) |
| Check if noise gate is currently open. | |
High-Pass Filter Functions | |
| void | highpass_filter_init (highpass_filter_t *filter, float cutoff_hz, float sample_rate) |
| Initialize a high-pass filter. | |
| void | highpass_filter_reset (highpass_filter_t *filter) |
| Reset high-pass filter state. | |
| float | highpass_filter_process_sample (highpass_filter_t *filter, float input) |
| Process a single sample through high-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. | |
Low-Pass Filter Functions | |
| void | lowpass_filter_init (lowpass_filter_t *filter, float cutoff_hz, float sample_rate) |
| Initialize a low-pass filter. | |
| void | lowpass_filter_reset (lowpass_filter_t *filter) |
| Reset low-pass filter state. | |
| float | lowpass_filter_process_sample (lowpass_filter_t *filter, float input) |
| Process a single sample through low-pass filter. | |
| void | lowpass_filter_process_buffer (lowpass_filter_t *filter, float *buffer, int num_samples) |
| Process a buffer of samples through low-pass filter. | |
Buffer Utility Functions | |
| float | smoothstep (float t) |
| Compute smoothstep interpolation. | |
| int16_t | float_to_int16 (float sample) |
| Convert float sample to int16 (WebRTC format) | |
| float | int16_to_float (int16_t sample) |
| Convert int16 sample to float. | |
| void | buffer_float_to_int16 (const float *src, int16_t *dst, int count) |
| Convert float buffer to int16 buffer. | |
| void | buffer_int16_to_float (const int16_t *src, float *dst, int count) |
| Convert int16 buffer to float buffer. | |
| float | buffer_peak (const float *buffer, int count) |
| Find peak absolute value in buffer. | |
| void | apply_gain_buffer (float *buffer, int count, float gain) |
| Apply gain to buffer in-place. | |
| void | fade_buffer (float *buffer, int count, float start_gain, float end_gain) |
| Apply linear fade to buffer in-place. | |
| void | fade_buffer_smooth (float *buffer, int count, bool fade_in) |
| Apply smoothstep fade to buffer in-place. | |
| void | copy_buffer_with_gain (const float *src, float *dst, int count, float gain) |
| Copy buffer with gain scaling. | |
Soft Clipping Functions | |
| float | soft_clip (float sample, float threshold, float steepness) |
| Apply soft clipping to a sample. | |
| void | soft_clip_buffer (float *buffer, int num_samples, float threshold, float steepness) |
| Apply soft clipping to a buffer. | |
Audio Mixing Configuration | |
| #define | MIXER_MAX_SOURCES 32 |
| Maximum number of simultaneous audio sources. | |
| #define | MIXER_FRAME_SIZE 256 |
| Number of samples processed per audio frame. | |
🔊 Audio system for real-time audio capture and playback
This header provides audio capture and playback functionality using PortAudio, enabling real-time audio streaming for ascii-chat video chat sessions.
The audio system uses PortAudio for cross-platform audio I/O:
This header provides professional-quality audio mixing for ascii-chat's multi-client audio chat functionality. The mixer combines audio from multiple clients with advanced processing including compression, ducking, noise gating, and high-pass filtering.
The mixer processes audio through the following stages:
The ducking system automatically:
The compressor provides:
Provides high-level interface to libopus for encoding and decoding audio frames with configurable bitrate and frame sizes.
Welcome to the Audio System! This is where all the audio magic happens—capturing your voice from the microphone, playing back audio from other participants, and making sure everything runs smoothly in real-time. We use PortAudio for cross-platform audio I/O, which means everything works the same way on Linux, macOS, and Windows.
The Audio System provides real-time audio capture and playback functionality for ascii-chat video chat sessions. Here's what it gives you:
Implementation: lib/audio.h
The audio system is built around a few key concepts: PortAudio for cross-platform audio I/O, ring buffers for efficient data transfer, and thread-safe operations so everything can run in parallel. Let's walk through how everything fits together.
We use PortAudio for cross-platform audio I/O because it handles all the platform-specific details for us—we write the same code and it works on Linux, macOS, and Windows. PortAudio provides:
Audio Streams:
Ring Buffers:
Thread Safety:
Audio parameters control the quality and latency of audio. The defaults are tuned for good quality with low latency, but you can adjust them for your needs.
Default Configuration:
Configurable Options:
Create Audio Context:
Configure Audio Parameters:
Start Capture:
Read Captured Samples:
Start Playback:
Write Playback Samples:
Stop Audio:
Destroy Audio Context:
Windows:
Linux:
macOS:
Audio performance is all about balancing latency, CPU usage, and bandwidth. We've tuned the defaults for good performance across all three dimensions, but let's look at what you can expect:
Latency:
50-60ms is quite good for networked audio—it's comparable to phone calls and way better than most video conferencing software. The jitter buffering helps smooth out network hiccups, so you get smooth audio even when the network is a bit flaky.
CPU Usage:
Audio is pretty lightweight—you probably won't even notice the CPU usage unless you're monitoring it closely.
Bandwidth:
Audio bandwidth is pretty reasonable—even stereo at 48kHz is only about 384 KB/s, which is much less than video. You could stream audio over a decent cellular connection without any problems.
The audio system uses ring buffers for efficient producer-consumer audio transfer:
Capture Ring Buffer:
Playback Ring Buffer:
Audio Threads:
Priority Scheduling:
Network Integration:
Ring Buffer Integration:
Welcome to the audio mixer—where all the magic happens when multiple people are talking at once!
Picture yourself in a group video call. Person A is talking, Person B laughs, Person C asks a question—all happening simultaneously. Your speakers don't have three separate outputs (well, most don't). So how does your computer play all three audio streams at once? That's where the mixer comes in!
The mixer takes multiple audio streams (one from each client) and combines them into a single output stream that gets sent to everyone. It's like a real mixing board at a concert—each microphone is a separate input, and the mixer blends them into one cohesive sound that goes to the speakers.
But here's the cool part: when lots of people are talking at once, the mixer automatically applies "ducking" (volume reduction) so the combined audio doesn't clip or distort. It's like how a good sound engineer knows to turn down each microphone a bit when everyone's singing together—the mix stays clear and balanced.
Implementation: lib/mixer.h
Mixer Design:
Audio Flow:
Create Mixer:
Add Audio Source (client with audio ring buffer):
Remove Audio Source:
The mixer reads audio directly from each client's audio ring buffer. Clients write their audio samples to their ring buffer, and the mixer reads and mixes them during processing.
Mix Audio (reads from all source ring buffers):
Mix Audio Excluding a Source (for echo cancellation):
Destroy Mixer:
The ducking system automatically identifies who's speaking and attenuates background sources to improve clarity. This is more sophisticated than simple volume scaling.
How It Works:
The ducking uses dB-based audio analysis:
Practical Example:
This allows multiple people to have a natural conversation while suppressing background noise from inactive participants.
Reader-Writer Lock Protection:
Thread Model:
Mixing Algorithm:
CPU Usage:
Latency:
Per-Client Buffers:
Buffer Configuration:
Overflow Handling:
Underrun Handling:
Complete Server Integration:
DO:
DON'T:
| #define AUDIO_BUFFER_SIZE (AUDIO_FRAMES_PER_BUFFER * AUDIO_CHANNELS) |
#include <audio.h>
Total audio buffer size (frames × channels)
Definition at line 93 of file lib/audio/audio.h.
| #define AUDIO_CHANNELS 1 |
#include <audio.h>
Number of audio channels (1 = mono)
Definition at line 91 of file lib/audio/audio.h.
| #define AUDIO_FRAMES_PER_BUFFER 480 |
#include <audio.h>
Audio frames per buffer (480 = 10ms at 48kHz, matches WebRTC AEC3 frame size)
Definition at line 89 of file lib/audio/audio.h.
| #define AUDIO_SAMPLE_RATE 48000 |
#include <audio.h>
Audio sample rate (48kHz professional quality, Opus-compatible)
Definition at line 87 of file lib/audio/audio.h.
| #define MIXER_FRAME_SIZE 256 |
| #define MIXER_MAX_SOURCES 32 |
| typedef struct OpusDecoder OpusDecoder |
#include <opus_codec.h>
Definition at line 66 of file opus_codec.h.
| typedef struct OpusEncoder OpusEncoder |
#include <opus_codec.h>
Definition at line 65 of file opus_codec.h.
| enum opus_application_t |
#include <opus_codec.h>
Application mode for opus encoder.
| Enumerator | |
|---|---|
| OPUS_APPLICATION_VOIP | Voice over IP (optimized for speech) |
| OPUS_APPLICATION_AUDIO | General audio (optimized for music) |
| OPUS_APPLICATION_RESTRICTED_LOWDELAY | Low-latency mode. |
Definition at line 76 of file opus_codec.h.
| void apply_gain_buffer | ( | float * | buffer, |
| int | count, | ||
| float | gain | ||
| ) |
#include <mixer.h>
Apply gain to buffer in-place.
| buffer | Audio buffer (modified in-place) |
| count | Number of samples |
| gain | Gain multiplier to apply |
Multiplies all samples by gain factor.
Definition at line 1096 of file mixer.c.
| asciichat_error_t audio_dequantize_samples | ( | const uint8_t * | samples_ptr, |
| uint32_t | total_samples, | ||
| float * | out_samples | ||
| ) |
#include <audio.h>
Dequantize network audio samples from int32 to float.
| samples_ptr | Pointer to quantized samples (network byte order uint32_t values) |
| total_samples | Number of samples to convert |
| out_samples | Output buffer for float samples (must be pre-allocated) |
Converts quantized audio samples from network byte order (uint32_t) to floating point format. Performs the following transformation:
This helper eliminates code duplication between server and client handlers.
Definition at line 1359 of file lib/audio/audio.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, NET_TO_HOST_U32, and SET_ERRNO.
Referenced by handle_audio_batch_packet().
| void audio_destroy | ( | audio_context_t * | ctx | ) |
#include <audio.h>
Destroy audio context and clean up resources.
| ctx | Audio context to destroy (can be NULL) |
Stops all audio streams, destroys ring buffers, and cleans up PortAudio resources. Safe to call multiple times or with NULL pointer.
Definition at line 894 of file lib/audio/audio.c.
References audio_ring_buffer_destroy(), audio_stop_duplex(), audio_context_t::capture_buffer, audio_context_t::initialized, log_info, mutex_destroy(), mutex_lock, mutex_unlock, audio_context_t::playback_buffer, audio_context_t::running, and audio_context_t::state_mutex.
Referenced by audio_cleanup(), and audio_client_init().
| void audio_free_device_list | ( | audio_device_info_t * | devices | ) |
#include <audio.h>
Free device list allocated by audio_list_input_devices/audio_list_output_devices.
| devices | Device array to free (can be NULL) |
Frees the device array allocated by audio_list_input_devices() or audio_list_output_devices(). Safe to call with NULL.
Definition at line 1355 of file lib/audio/audio.c.
References SAFE_FREE.
Referenced by action_list_microphones(), and action_list_speakers().
| asciichat_error_t audio_init | ( | audio_context_t * | ctx | ) |
#include <audio.h>
Initialize audio context and PortAudio.
| ctx | Audio context to initialize (must not be NULL) |
Initializes the audio context and PortAudio library. Creates ring buffers for capture and playback but does not start streams. Must be called before any other audio functions.
Definition at line 773 of file lib/audio/audio.c.
References ASCIICHAT_OK, audio_ring_buffer_create(), audio_ring_buffer_create_for_capture(), audio_ring_buffer_destroy(), audio_context_t::capture_buffer, ERROR_AUDIO, ERROR_INVALID_PARAM, ERROR_MEMORY, ERROR_THREAD, audio_context_t::initialized, log_debug, log_info, log_warn, mutex_destroy(), mutex_init(), platform_open(), audio_context_t::playback_buffer, SAFE_MEMSET, SET_ERRNO, audio_context_t::shutting_down, and audio_context_t::state_mutex.
Referenced by audio_client_init().
#include <audio.h>
Check if a sample rate is a standard/supported rate.
Supported rates: 8000, 16000, 24000, 32000, 44100, 48000, 96000, 192000
| sample_rate | Sample rate in Hz |
Usage:
Definition at line 1455 of file lib/audio/audio.c.
Referenced by audio_validate_batch_params().
| asciichat_error_t audio_list_input_devices | ( | audio_device_info_t ** | out_devices, |
| unsigned int * | out_count | ||
| ) |
#include <audio.h>
List available audio input devices (microphones)
| out_devices | Pointer to store allocated array of devices (must not be NULL) |
| out_count | Pointer to store device count (must not be NULL) |
Enumerates all audio input devices (microphones) available on the system. The caller is responsible for freeing the returned array with audio_free_device_list().
Definition at line 1347 of file lib/audio/audio.c.
Referenced by action_list_microphones().
| asciichat_error_t audio_list_output_devices | ( | audio_device_info_t ** | out_devices, |
| unsigned int * | out_count | ||
| ) |
#include <audio.h>
List available audio output devices (speakers)
| out_devices | Pointer to store allocated array of devices (must not be NULL) |
| out_count | Pointer to store device count (must not be NULL) |
Enumerates all audio output devices (speakers/headphones) available on the system. The caller is responsible for freeing the returned array with audio_free_device_list().
Definition at line 1351 of file lib/audio/audio.c.
Referenced by action_list_speakers().
| asciichat_error_t audio_parse_batch_header | ( | const void * | data, |
| size_t | len, | ||
| audio_batch_info_t * | out_batch | ||
| ) |
#include <audio.h>
Parse an audio batch packet header from raw packet data.
Performs the following validations:
| data | Pointer to packet data (must not be NULL) | |
| len | Length of packet data in bytes | |
| [out] | out_batch | Pointer to audio_batch_info_t struct to fill with parsed data |
Usage:
Definition at line 1389 of file lib/audio/audio.c.
References ASCIICHAT_OK, audio_batch_info_t::batch_count, audio_batch_packet_t::batch_count, audio_batch_info_t::channels, audio_batch_packet_t::channels, ERROR_INVALID_PARAM, audio_batch_info_t::sample_rate, audio_batch_packet_t::sample_rate, SET_ERRNO, audio_batch_info_t::total_samples, and audio_batch_packet_t::total_samples.
Referenced by handle_audio_batch_packet().
| asciichat_error_t audio_read_samples | ( | audio_context_t * | ctx, |
| float * | buffer, | ||
| int | num_samples | ||
| ) |
#include <audio.h>
Read captured audio samples from capture buffer.
| ctx | Audio context (must not be NULL) |
| buffer | Output buffer for audio samples (must not be NULL) |
| num_samples | Number of samples to read (must be > 0) |
Reads audio samples from the capture ring buffer. Samples are in floating point format (-1.0 to 1.0 range). This function is non-blocking and returns whatever samples are available up to num_samples.
Definition at line 1156 of file lib/audio/audio.c.
References ASCIICHAT_OK, audio_ring_buffer_read(), audio_context_t::capture_buffer, ERROR_AUDIO, ERROR_INVALID_PARAM, audio_context_t::initialized, and SET_ERRNO.
| size_t audio_ring_buffer_available_read | ( | audio_ring_buffer_t * | rb | ) |
#include <audio.h>
Get number of samples available for reading.
| rb | Audio ring buffer (must not be NULL) |
Returns the current number of samples available in the ring buffer for reading. Useful for determining if enough samples are available before calling audio_ring_buffer_read().
Definition at line 747 of file lib/audio/audio.c.
References AUDIO_RING_BUFFER_SIZE, audio_ring_buffer::read_index, and audio_ring_buffer::write_index.
Referenced by audio_process_received_samples(), audio_ring_buffer_available_write(), client_audio_render_thread(), and mixer_process_excluding_source().
| size_t audio_ring_buffer_available_write | ( | audio_ring_buffer_t * | rb | ) |
#include <audio.h>
Get number of sample slots available for writing.
| rb | Audio ring buffer (must not be NULL) |
Returns the current number of sample slots available in the ring buffer for writing. Useful for determining if enough space is available before calling audio_ring_buffer_write().
Definition at line 764 of file lib/audio/audio.c.
References audio_ring_buffer_available_read(), AUDIO_RING_BUFFER_SIZE, ERROR_INVALID_PARAM, and SET_ERRNO.
| void audio_ring_buffer_clear | ( | audio_ring_buffer_t * | rb | ) |
#include <audio.h>
Clear all audio samples from ring buffer.
| rb | Audio ring buffer (must not be NULL) |
Resets the ring buffer to empty state, clearing all samples. Used during shutdown to prevent stale audio from playing.
Definition at line 447 of file lib/audio/audio.c.
References audio_ring_buffer::data, audio_ring_buffer::last_sample, audio_ring_buffer::mutex, mutex_lock, mutex_unlock, audio_ring_buffer::read_index, SAFE_MEMSET, and audio_ring_buffer::write_index.
Referenced by audio_stop_duplex().
| audio_ring_buffer_t * audio_ring_buffer_create | ( | void | ) |
#include <audio.h>
Create a new audio ring buffer (for playback with jitter buffering)
Creates a new audio ring buffer for storing audio samples. The buffer has a fixed size defined by AUDIO_RING_BUFFER_SIZE and is optimized for real-time audio streaming with jitter buffering support (enabled by default).
Definition at line 431 of file lib/audio/audio.c.
Referenced by audio_init().
| audio_ring_buffer_t * audio_ring_buffer_create_for_capture | ( | void | ) |
#include <audio.h>
Create a new audio ring buffer for capture (without jitter buffering)
Creates an audio ring buffer optimized for direct microphone input from PortAudio. Unlike playback buffers, capture buffers disable jitter buffering since PortAudio writes directly from the microphone with no network latency.
Definition at line 435 of file lib/audio/audio.c.
Referenced by audio_init(), and audio_start_duplex().
| void audio_ring_buffer_destroy | ( | audio_ring_buffer_t * | rb | ) |
#include <audio.h>
Destroy an audio ring buffer.
| rb | Audio ring buffer to destroy (can be NULL) |
Destroys an audio ring buffer and frees all associated resources. Safe to call multiple times or with NULL pointer.
Definition at line 439 of file lib/audio/audio.c.
References buffer_pool_free(), audio_ring_buffer::mutex, and mutex_destroy().
Referenced by audio_destroy(), audio_init(), audio_start_duplex(), audio_stop_duplex(), and cleanup_client_media_buffers().
| size_t audio_ring_buffer_peek | ( | audio_ring_buffer_t * | rb, |
| float * | data, | ||
| size_t | samples | ||
| ) |
#include <audio.h>
Peek at available samples without consuming them (for AEC3 render signal)
This function reads samples from the jitter buffer WITHOUT advancing the read_index. Used to feed audio to AEC3 for echo cancellation even during jitter buffer fill period.
| rb | Ring buffer to peek from |
| data | Output buffer for samples |
| samples | Number of samples to peek |
Definition at line 710 of file lib/audio/audio.c.
References AUDIO_RING_BUFFER_SIZE, audio_ring_buffer::data, audio_ring_buffer::read_index, SAFE_MEMCPY, and audio_ring_buffer::write_index.
| size_t audio_ring_buffer_read | ( | audio_ring_buffer_t * | rb, |
| float * | data, | ||
| size_t | samples | ||
| ) |
#include <audio.h>
Read audio samples from ring buffer.
| rb | Audio ring buffer (must not be NULL) |
| data | Output buffer for audio samples (must not be NULL) |
| samples | Maximum number of samples to read |
Reads audio samples from the ring buffer. Samples are in floating point format (-1.0 to 1.0 range). This function is non-blocking and returns whatever samples are available up to the requested count.
Definition at line 549 of file lib/audio/audio.c.
References AUDIO_CROSSFADE_SAMPLES, AUDIO_JITTER_BUFFER_THRESHOLD, AUDIO_JITTER_LOW_WATER_MARK, AUDIO_RING_BUFFER_SIZE, audio_ring_buffer::crossfade_fade_in, audio_ring_buffer::crossfade_samples_remaining, audio_ring_buffer::data, ERROR_INVALID_PARAM, audio_ring_buffer::jitter_buffer_enabled, audio_ring_buffer::jitter_buffer_filled, audio_ring_buffer::last_sample, log_debug, log_debug_every, log_info, LOG_RATE_FAST, log_warn_every, audio_ring_buffer::read_index, SAFE_MEMCPY, SAFE_MEMSET, SET_ERRNO, audio_ring_buffer::underrun_count, and audio_ring_buffer::write_index.
Referenced by audio_read_samples(), client_audio_render_thread(), mixer_process(), and mixer_process_excluding_source().
| asciichat_error_t audio_ring_buffer_write | ( | audio_ring_buffer_t * | rb, |
| const float * | data, | ||
| int | samples | ||
| ) |
#include <audio.h>
Write audio samples to ring buffer.
| rb | Audio ring buffer (must not be NULL) |
| data | Audio samples to write (must not be NULL) |
| samples | Number of samples to write |
Writes audio samples to the ring buffer. Samples should be in floating point format (-1.0 to 1.0 range). This function is non-blocking and writes as many samples as buffer space allows.
Definition at line 461 of file lib/audio/audio.c.
References ASCIICHAT_OK, AUDIO_JITTER_HIGH_WATER_MARK, AUDIO_JITTER_TARGET_LEVEL, AUDIO_RING_BUFFER_SIZE, audio_ring_buffer::data, ERROR_BUFFER, ERROR_INVALID_PARAM, LOG_RATE_FAST, log_warn_every, audio_ring_buffer::read_index, SAFE_MEMCPY, SET_ERRNO, and audio_ring_buffer::write_index.
Referenced by audio_write_samples(), handle_audio_batch_packet(), handle_audio_opus_batch_packet(), handle_audio_opus_packet(), and handle_audio_packet().
| void audio_set_pipeline | ( | audio_context_t * | ctx, |
| void * | pipeline | ||
| ) |
#include <audio.h>
Set audio pipeline for echo cancellation.
| ctx | Audio context (must not be NULL) |
| pipeline | Client audio pipeline pointer (opaque, can be NULL) |
Associates an audio pipeline with the context for echo cancellation. The pipeline is fed playback samples from the output callback, allowing AEC3 to properly synchronize render and capture signals.
Definition at line 927 of file lib/audio/audio.c.
References audio_context_t::audio_pipeline.
Referenced by audio_cleanup(), and audio_client_init().
| asciichat_error_t audio_set_realtime_priority | ( | void | ) |
#include <audio.h>
Request real-time priority for current thread.
Requests real-time priority scheduling for the current thread. This reduces audio latency and glitches by ensuring audio threads get scheduled promptly. Platform-specific implementation (SCHED_FIFO on Linux, thread priority on Windows/macOS).
Definition at line 1375 of file lib/audio/audio.c.
References ASCIICHAT_OK, asciichat_thread_set_realtime_priority(), and log_info.
Referenced by audio_start_duplex().
| asciichat_error_t audio_start_duplex | ( | audio_context_t * | ctx | ) |
#include <audio.h>
Start full-duplex audio (simultaneous capture and playback)
| ctx | Audio context (must not be NULL, must be initialized) |
Opens a single PortAudio stream that handles BOTH input (microphone) and output (speakers) simultaneously. This is CRITICAL for proper AEC3 echo cancellation because:
The duplex callback:
Definition at line 933 of file lib/audio/audio.c.
References ASCIICHAT_OK, AUDIO_CHANNELS, AUDIO_FRAMES_PER_BUFFER, audio_ring_buffer_create_for_capture(), audio_ring_buffer_destroy(), AUDIO_SAMPLE_RATE, audio_set_realtime_priority(), audio_context_t::duplex_stream, ERROR_AUDIO, ERROR_INVALID_STATE, ERROR_MEMORY, GET_OPTION, audio_context_t::initialized, audio_context_t::input_device_rate, audio_context_t::input_stream, log_info, log_warn, mutex_lock, mutex_unlock, audio_context_t::output_device_rate, audio_context_t::output_stream, audio_context_t::render_buffer, audio_context_t::running, audio_context_t::sample_rate, audio_context_t::separate_streams, SET_ERRNO, and audio_context_t::state_mutex.
Referenced by audio_client_init().
| asciichat_error_t audio_stop_duplex | ( | audio_context_t * | ctx | ) |
#include <audio.h>
Stop full-duplex audio.
| ctx | Audio context (must not be NULL) |
Stops the full-duplex audio stream and closes the stream.
Definition at line 1108 of file lib/audio/audio.c.
References ASCIICHAT_OK, audio_ring_buffer_clear(), audio_ring_buffer_destroy(), audio_context_t::duplex_stream, ERROR_INVALID_STATE, audio_context_t::initialized, audio_context_t::input_stream, log_info, mutex_lock, mutex_unlock, audio_context_t::output_stream, audio_context_t::playback_buffer, audio_context_t::render_buffer, audio_context_t::running, audio_context_t::separate_streams, SET_ERRNO, audio_context_t::shutting_down, and audio_context_t::state_mutex.
Referenced by audio_cleanup(), and audio_destroy().
| asciichat_error_t audio_validate_batch_params | ( | const audio_batch_info_t * | batch | ) |
#include <audio.h>
Validate audio batch parameters for sanity.
Checks that parsed batch parameters are within acceptable ranges. Performs these checks:
| batch | Pointer to audio_batch_info_t struct to validate |
Usage:
Definition at line 1414 of file lib/audio/audio.c.
References ASCIICHAT_OK, audio_is_supported_sample_rate(), audio_batch_info_t::batch_count, audio_batch_info_t::channels, ERROR_INVALID_PARAM, audio_batch_info_t::sample_rate, SET_ERRNO, and audio_batch_info_t::total_samples.
| asciichat_error_t audio_write_samples | ( | audio_context_t * | ctx, |
| const float * | buffer, | ||
| int | num_samples | ||
| ) |
#include <audio.h>
Write audio samples to playback buffer.
| ctx | Audio context (must not be NULL) |
| buffer | Input buffer of audio samples (must not be NULL) |
| num_samples | Number of samples to write (must be > 0) |
Writes audio samples to the playback ring buffer for playback. Samples should be in floating point format (-1.0 to 1.0 range). This function is non-blocking and writes as many samples as buffer space allows.
Definition at line 1167 of file lib/audio/audio.c.
References ASCIICHAT_OK, audio_ring_buffer_write(), ERROR_INVALID_PARAM, audio_context_t::initialized, audio_context_t::playback_buffer, SET_ERRNO, and audio_context_t::shutting_down.
Referenced by audio_process_received_samples().
| void buffer_float_to_int16 | ( | const float * | src, |
| int16_t * | dst, | ||
| int | count | ||
| ) |
#include <mixer.h>
Convert float buffer to int16 buffer.
| src | Source float buffer |
| dst | Destination int16 buffer |
| count | Number of samples to convert |
Batch converts float samples to int16 format for WebRTC.
Definition at line 1067 of file mixer.c.
References float_to_int16().
| void buffer_int16_to_float | ( | const int16_t * | src, |
| float * | dst, | ||
| int | count | ||
| ) |
#include <mixer.h>
Convert int16 buffer to float buffer.
| src | Source int16 buffer |
| dst | Destination float buffer |
| count | Number of samples to convert |
Batch converts int16 samples to float format.
Definition at line 1075 of file mixer.c.
References int16_to_float().
| float buffer_peak | ( | const float * | buffer, |
| int | count | ||
| ) |
#include <mixer.h>
Find peak absolute value in buffer.
| buffer | Audio buffer |
| count | Number of samples |
Scans buffer for the sample with highest absolute value. Useful for level metering and gain staging.
Definition at line 1083 of file mixer.c.
| float clamp_float | ( | float | value, |
| float | min, | ||
| float | max | ||
| ) |
#include <mixer.h>
Clamp a float value to a range.
| value | Value to clamp |
| min | Minimum value |
| max | Maximum value |
Clamps a float value to the specified range. Useful for preventing audio overflow and ensuring parameters stay within valid ranges.
Definition at line 31 of file mixer.c.
| void compressor_init | ( | compressor_t * | comp, |
| float | sample_rate | ||
| ) |
#include <mixer.h>
Initialize a compressor.
| comp | Compressor structure |
| sample_rate | Sample rate in Hz |
Initializes compressor state and converts time-based parameters (attack_ms, release_ms) to coefficients for sample-by-sample processing.
Definition at line 42 of file mixer.c.
References compressor_set_params(), compressor_t::envelope, compressor_t::gain_lin, and compressor_t::sample_rate.
Referenced by client_audio_pipeline_create(), and mixer_create().
| float compressor_process_sample | ( | compressor_t * | comp, |
| float | sidechain | ||
| ) |
#include <mixer.h>
Process a single sample through compressor.
| comp | Compressor structure |
| sidechain | Input level for gain reduction calculation |
Processes sidechain input through compressor to calculate gain reduction. Returns compressed output level (not actual audio sample - use for sidechain).
Definition at line 87 of file mixer.c.
References compressor_t::attack_coeff, db_to_linear(), compressor_t::envelope, compressor_t::gain_lin, linear_to_db(), compressor_t::makeup_dB, and compressor_t::release_coeff.
Referenced by client_audio_pipeline_process_duplex(), mixer_process(), and mixer_process_excluding_source().
| void compressor_set_params | ( | compressor_t * | comp, |
| float | threshold_dB, | ||
| float | ratio, | ||
| float | attack_ms, | ||
| float | release_ms, | ||
| float | makeup_dB | ||
| ) |
#include <mixer.h>
Set compressor parameters.
| comp | Compressor structure |
| threshold_dB | Compression threshold in dB |
| ratio | Compression ratio (e.g., 4.0 for 4:1) |
| attack_ms | Attack time in milliseconds |
| release_ms | Release time in milliseconds |
| makeup_dB | Makeup gain in dB |
Updates compressor parameters. Time-based parameters are converted to coefficients internally.
Definition at line 53 of file mixer.c.
References compressor_t::attack_coeff, compressor_t::attack_ms, compressor_t::knee_dB, compressor_t::makeup_dB, compressor_t::ratio, compressor_t::release_coeff, compressor_t::release_ms, compressor_t::sample_rate, and compressor_t::threshold_dB.
Referenced by client_audio_pipeline_create(), and compressor_init().
| void copy_buffer_with_gain | ( | const float * | src, |
| float * | dst, | ||
| int | count, | ||
| float | gain | ||
| ) |
#include <mixer.h>
Copy buffer with gain scaling.
| src | Source buffer |
| dst | Destination buffer |
| count | Number of samples |
| gain | Gain multiplier to apply during copy |
Copies samples from src to dst while applying gain. Useful for format conversion (e.g., scale by 32768 for WebRTC).
Definition at line 1128 of file mixer.c.
Referenced by client_audio_pipeline_process_duplex().
| float db_to_linear | ( | float | db | ) |
#include <mixer.h>
Convert decibels to linear gain.
| db | Decibel value |
Converts decibel value to linear gain multiplier for audio processing.
Definition at line 23 of file mixer.c.
Referenced by compressor_process_sample(), ducking_process_frame(), mixer_process(), and mixer_process_excluding_source().
| void ducking_free | ( | ducking_t * | duck | ) |
#include <mixer.h>
Free ducking system resources.
| duck | Ducking structure |
Frees per-source arrays allocated by ducking_init().
Definition at line 166 of file mixer.c.
References ducking_t::envelope, ducking_t::gain, and SAFE_FREE.
Referenced by mixer_destroy().
| int ducking_init | ( | ducking_t * | duck, |
| int | num_sources, | ||
| float | sample_rate | ||
| ) |
#include <mixer.h>
Initialize ducking system.
| duck | Ducking structure |
| num_sources | Number of sources to support |
| sample_rate | Sample rate in Hz |
Allocates per-source arrays (envelope, gain) for ducking system. Time-based parameters are converted to coefficients.
Definition at line 111 of file mixer.c.
References ASCIICHAT_OK, ducking_t::attack_coeff, ducking_t::attack_ms, ducking_t::atten_dB, ducking_t::envelope, ERROR_BUFFER_OVERFLOW, ERROR_INVALID_PARAM, ERROR_MEMORY, ducking_t::gain, ducking_t::leader_margin_dB, ducking_t::release_coeff, ducking_t::release_ms, SAFE_FREE, SAFE_MALLOC, SAFE_MEMSET, SET_ERRNO, and ducking_t::threshold_dB.
Referenced by mixer_create().
| void ducking_process_frame | ( | ducking_t * | duck, |
| float * | envelopes, | ||
| float * | gains, | ||
| int | num_sources | ||
| ) |
#include <mixer.h>
Process a frame of audio through ducking system.
| duck | Ducking structure |
| envelopes | Array of per-source envelope levels (input) |
| gains | Array of per-source ducking gains (output) |
| num_sources | Number of sources to process |
Calculates ducking gains for each source based on envelope levels. Outputs per-source gain multipliers to apply to audio samples.
Definition at line 184 of file mixer.c.
References ducking_t::attack_coeff, ducking_t::atten_dB, db_to_linear(), ducking_t::leader_margin_dB, linear_to_db(), MIXER_MAX_SOURCES, ducking_t::release_coeff, and ducking_t::threshold_dB.
Referenced by mixer_process(), and mixer_process_excluding_source().
| void ducking_set_params | ( | ducking_t * | duck, |
| float | threshold_dB, | ||
| float | leader_margin_dB, | ||
| float | atten_dB, | ||
| float | attack_ms, | ||
| float | release_ms | ||
| ) |
#include <mixer.h>
Set ducking parameters.
| duck | Ducking structure |
| threshold_dB | Speaking threshold in dB |
| leader_margin_dB | Leader margin in dB |
| atten_dB | Attenuation in dB for non-leaders |
| attack_ms | Attack time in milliseconds |
| release_ms | Release time in milliseconds |
Updates ducking parameters. Time-based parameters are converted to coefficients internally.
Definition at line 175 of file mixer.c.
References ducking_t::attack_ms, ducking_t::atten_dB, ducking_t::leader_margin_dB, ducking_t::release_ms, and ducking_t::threshold_dB.
| void fade_buffer | ( | float * | buffer, |
| int | count, | ||
| float | start_gain, | ||
| float | end_gain | ||
| ) |
#include <mixer.h>
Apply linear fade to buffer in-place.
| buffer | Audio buffer (modified in-place) |
| count | Number of samples |
| start_gain | Gain at start of buffer |
| end_gain | Gain at end of buffer |
Applies linear interpolation from start_gain to end_gain across buffer. Use start_gain=0, end_gain=1 for fade-in; start_gain=1, end_gain=0 for fade-out.
Definition at line 1105 of file mixer.c.
| void fade_buffer_smooth | ( | float * | buffer, |
| int | count, | ||
| bool | fade_in | ||
| ) |
#include <mixer.h>
Apply smoothstep fade to buffer in-place.
| buffer | Audio buffer (modified in-place) |
| count | Number of samples |
| fade_in | If true, fade from 0 to 1; if false, fade from 1 to 0 |
Applies smoothstep curve for more natural-sounding fades.
Definition at line 1117 of file mixer.c.
References smoothstep().
| int16_t float_to_int16 | ( | float | sample | ) |
#include <mixer.h>
Convert float sample to int16 (WebRTC format)
| sample | Float sample in [-1.0, 1.0] range |
Scales float audio sample to 16-bit integer format used by WebRTC. Values outside [-1.0, 1.0] are clamped before scaling.
Definition at line 1054 of file mixer.c.
Referenced by buffer_float_to_int16().
| void highpass_filter_init | ( | highpass_filter_t * | filter, |
| float | cutoff_hz, | ||
| float | sample_rate | ||
| ) |
#include <mixer.h>
Initialize a high-pass filter.
| filter | High-pass filter structure |
| cutoff_hz | Cutoff frequency in Hz |
| sample_rate | Sample rate in Hz |
Initializes filter state and calculates filter coefficient alpha from cutoff frequency.
Definition at line 920 of file mixer.c.
References highpass_filter_t::alpha, highpass_filter_t::cutoff_hz, highpass_filter_reset(), M_PI, and highpass_filter_t::sample_rate.
Referenced by client_audio_pipeline_create().
| void highpass_filter_process_buffer | ( | highpass_filter_t * | filter, |
| float * | buffer, | ||
| int | num_samples | ||
| ) |
#include <mixer.h>
Process a buffer of samples through high-pass filter.
| filter | High-pass filter structure |
| buffer | Audio buffer (modified in-place) |
| num_samples | Number of samples to process |
Processes entire buffer through high-pass filter. Buffer is modified in-place.
Definition at line 956 of file mixer.c.
References highpass_filter_process_sample().
Referenced by client_audio_pipeline_process_duplex().
| float highpass_filter_process_sample | ( | highpass_filter_t * | filter, |
| float | input | ||
| ) |
#include <mixer.h>
Process a single sample through high-pass filter.
| filter | High-pass filter structure |
| input | Input sample value |
Processes input sample through first-order IIR high-pass filter. Filter state is updated for next sample.
Definition at line 942 of file mixer.c.
References highpass_filter_t::alpha, highpass_filter_t::prev_input, and highpass_filter_t::prev_output.
Referenced by highpass_filter_process_buffer().
| void highpass_filter_reset | ( | highpass_filter_t * | filter | ) |
#include <mixer.h>
Reset high-pass filter state.
| filter | High-pass filter structure |
Resets filter state (prev_input, prev_output) to zero. Useful for starting fresh processing or removing DC offset.
Definition at line 934 of file mixer.c.
References highpass_filter_t::prev_input, and highpass_filter_t::prev_output.
Referenced by highpass_filter_init().
| float int16_to_float | ( | int16_t | sample | ) |
#include <mixer.h>
Convert int16 sample to float.
| sample | Int16 sample in [-32768, 32767] range |
Scales 16-bit integer audio sample to float format.
Definition at line 1063 of file mixer.c.
Referenced by buffer_int16_to_float().
| float linear_to_db | ( | float | linear | ) |
#include <mixer.h>
Convert linear gain to decibels.
| linear | Linear gain multiplier |
Converts linear gain multiplier to decibel value for display/logging.
Definition at line 27 of file mixer.c.
Referenced by compressor_process_sample(), and ducking_process_frame().
| void lowpass_filter_init | ( | lowpass_filter_t * | filter, |
| float | cutoff_hz, | ||
| float | sample_rate | ||
| ) |
#include <mixer.h>
Initialize a low-pass filter.
| filter | Low-pass filter structure |
| cutoff_hz | Cutoff frequency in Hz |
| sample_rate | Sample rate in Hz |
Initializes filter state and calculates filter coefficient alpha from cutoff frequency. Frequencies above cutoff are attenuated.
Definition at line 970 of file mixer.c.
References lowpass_filter_t::alpha, lowpass_filter_t::cutoff_hz, lowpass_filter_reset(), M_PI, and lowpass_filter_t::sample_rate.
Referenced by client_audio_pipeline_create().
| void lowpass_filter_process_buffer | ( | lowpass_filter_t * | filter, |
| float * | buffer, | ||
| int | num_samples | ||
| ) |
#include <mixer.h>
Process a buffer of samples through low-pass filter.
| filter | Low-pass filter structure |
| buffer | Audio buffer (modified in-place) |
| num_samples | Number of samples to process |
Processes entire buffer through low-pass filter. Buffer is modified in-place.
Definition at line 1005 of file mixer.c.
References lowpass_filter_process_sample().
Referenced by client_audio_pipeline_process_duplex().
| float lowpass_filter_process_sample | ( | lowpass_filter_t * | filter, |
| float | input | ||
| ) |
#include <mixer.h>
Process a single sample through low-pass filter.
| filter | Low-pass filter structure |
| input | Input sample value |
Processes input sample through first-order IIR low-pass filter. Filter state is updated for next sample.
Definition at line 993 of file mixer.c.
References lowpass_filter_t::alpha, and lowpass_filter_t::prev_output.
Referenced by lowpass_filter_process_buffer().
| void lowpass_filter_reset | ( | lowpass_filter_t * | filter | ) |
#include <mixer.h>
Reset low-pass filter state.
| filter | Low-pass filter structure |
Resets filter state (prev_output) to zero.
Definition at line 986 of file mixer.c.
References lowpass_filter_t::prev_output.
Referenced by lowpass_filter_init().
| int mixer_add_source | ( | mixer_t * | mixer, |
| uint32_t | client_id, | ||
| audio_ring_buffer_t * | buffer | ||
| ) |
#include <mixer.h>
Add an audio source to the mixer.
| mixer | Audio mixer |
| client_id | Client ID for this source |
| buffer | Pointer to client's audio ring buffer |
Adds a new audio source to the mixer. Client ID is mapped to a mixer source index for efficient lookup during processing.
Definition at line 363 of file mixer.c.
References mixer_t::active_sources_mask, log_info, log_warn, mixer_t::max_sources, mixer_t::num_sources, rwlock_wrlock, rwlock_wrunlock, mixer_t::source_active, mixer_t::source_buffers, mixer_t::source_id_to_index, mixer_t::source_ids, and mixer_t::source_lock.
| mixer_t * mixer_create | ( | int | max_sources, |
| int | sample_rate | ||
| ) |
#include <mixer.h>
Create a new audio mixer.
| max_sources | Maximum number of audio sources to support |
| sample_rate | Sample rate in Hz (e.g., 44100) |
Creates a new mixer with pre-allocated source arrays and processing buffers. All audio processing components are initialized.
Definition at line 218 of file mixer.c.
References mixer_t::active_sources_mask, ASCIICHAT_OK, mixer_t::base_gain, mixer_t::compressor, compressor_init(), mixer_t::crowd_alpha, mixer_t::ducking, ducking_init(), ERROR_BUFFER_OVERFLOW, ERROR_INVALID_PARAM, ERROR_MEMORY, ERROR_THREAD, log_info, mixer_t::max_sources, mixer_t::mix_buffer, MIXER_FRAME_SIZE, MIXER_MAX_SOURCES, mixer_t::num_sources, rwlock_destroy(), rwlock_init(), SAFE_FREE, SAFE_MALLOC, SAFE_MEMSET, mixer_t::sample_rate, SET_ERRNO, mixer_t::source_active, mixer_t::source_buffers, mixer_t::source_id_to_index, mixer_t::source_ids, and mixer_t::source_lock.
Referenced by server_main().
| void mixer_destroy | ( | mixer_t * | mixer | ) |
#include <mixer.h>
Destroy a mixer and free all resources.
| mixer | Mixer to destroy (can be NULL) |
Frees all allocated memory including source arrays, processing buffers, and ducking system allocations.
Definition at line 346 of file mixer.c.
References mixer_t::ducking, ducking_free(), log_info, mixer_t::mix_buffer, rwlock_destroy(), SAFE_FREE, mixer_t::source_active, mixer_t::source_buffers, mixer_t::source_ids, and mixer_t::source_lock.
Referenced by server_main().
| int mixer_process | ( | mixer_t * | mixer, |
| float * | output, | ||
| int | num_samples | ||
| ) |
#include <mixer.h>
Process audio from all active sources.
| mixer | Audio mixer |
| output | Output buffer for mixed audio (must have num_samples elements) |
| num_samples | Number of samples to process |
Reads audio from all active sources, applies processing pipeline (ducking, mixing, compression, noise gate, high-pass filter), and writes mixed output to output buffer.
Definition at line 459 of file mixer.c.
References ducking_t::attack_coeff, audio_ring_buffer_read(), mixer_t::base_gain, mixer_t::compressor, compressor_process_sample(), mixer_t::crowd_alpha, db_to_linear(), mixer_t::ducking, ducking_process_frame(), ducking_t::envelope, ducking_t::gain, mixer_t::max_sources, mixer_t::mix_buffer, MIXER_FRAME_SIZE, MIXER_MAX_SOURCES, ducking_t::release_coeff, rwlock_rdlock, rwlock_rdunlock, SAFE_MEMSET, soft_clip(), mixer_t::source_active, mixer_t::source_buffers, mixer_t::source_ids, and mixer_t::source_lock.
| int mixer_process_excluding_source | ( | mixer_t * | mixer, |
| float * | output, | ||
| int | num_samples, | ||
| uint32_t | exclude_client_id | ||
| ) |
#include <mixer.h>
Process audio from all sources except one (for per-client output)
| mixer | Audio mixer |
| output | Output buffer for mixed audio |
| num_samples | Number of samples to process |
| exclude_client_id | Client ID to exclude from mixing |
Same as mixer_process() but excludes one client's audio from the mix. Used to generate per-client output that doesn't include their own audio (prevents echo and feedback).
Definition at line 604 of file mixer.c.
References mixer_t::active_sources_mask, ducking_t::attack_coeff, audio_ring_buffer_available_read(), audio_ring_buffer_read(), AUDIO_RING_BUFFER_SIZE, mixer_t::base_gain, mixer_t::compressor, compressor_process_sample(), mixer_t::crowd_alpha, db_to_linear(), mixer_t::ducking, ducking_process_frame(), ducking_t::envelope, format_duration_ns(), ducking_t::gain, log_debug_every, log_info_every, LOG_RATE_DEFAULT, log_warn, log_warn_every, mixer_t::max_sources, mixer_t::mix_buffer, MIXER_FRAME_SIZE, MIXER_MAX_SOURCES, audio_ring_buffer::read_index, ducking_t::release_coeff, rwlock_rdlock, rwlock_rdunlock, SAFE_MEMSET, soft_clip(), mixer_t::source_buffers, mixer_t::source_id_to_index, mixer_t::source_ids, mixer_t::source_lock, START_TIMER, and STOP_TIMER.
Referenced by client_audio_render_thread().
#include <mixer.h>
Remove an audio source from the mixer.
| mixer | Audio mixer |
| client_id | Client ID to remove |
Removes the audio source associated with the given client ID. Source slot is freed for reuse by another client.
Definition at line 400 of file mixer.c.
References mixer_t::active_sources_mask, mixer_t::ducking, ducking_t::envelope, ducking_t::gain, log_info, mixer_t::max_sources, mixer_t::num_sources, rwlock_wrlock, rwlock_wrunlock, mixer_t::source_active, mixer_t::source_buffers, mixer_t::source_id_to_index, mixer_t::source_ids, and mixer_t::source_lock.
#include <mixer.h>
Set whether a source is active (receiving audio)
| mixer | Audio mixer |
| client_id | Client ID |
| active | true to mark source as active, false to mark inactive |
Updates the active status of a source. Inactive sources are excluded from mixing operations for efficiency.
Definition at line 432 of file mixer.c.
References mixer_t::active_sources_mask, log_debug, mixer_t::max_sources, rwlock_wrlock, rwlock_wrunlock, mixer_t::source_active, mixer_t::source_ids, and mixer_t::source_lock.
| void noise_gate_init | ( | noise_gate_t * | gate, |
| float | sample_rate | ||
| ) |
#include <mixer.h>
Initialize a noise gate.
| gate | Noise gate structure |
| sample_rate | Sample rate in Hz |
Initializes noise gate state and converts time-based parameters to coefficients.
Definition at line 838 of file mixer.c.
References noise_gate_t::envelope, noise_gate_t::gate_open, noise_gate_set_params(), and noise_gate_t::sample_rate.
Referenced by client_audio_pipeline_create().
| bool noise_gate_is_open | ( | const noise_gate_t * | gate | ) |
#include <mixer.h>
Check if noise gate is currently open.
| gate | Noise gate structure |
Returns current gate state. Useful for debugging and monitoring.
Definition at line 911 of file mixer.c.
References noise_gate_t::gate_open.
| void noise_gate_process_buffer | ( | noise_gate_t * | gate, |
| float * | buffer, | ||
| int | num_samples | ||
| ) |
#include <mixer.h>
Process a buffer of samples through noise gate.
| gate | Noise gate structure |
| buffer | Audio buffer (modified in-place) |
| num_samples | Number of samples to process |
Processes entire buffer through noise gate. Buffer is modified in-place.
Definition at line 892 of file mixer.c.
References noise_gate_process_sample().
Referenced by client_audio_pipeline_playback(), and client_audio_pipeline_process_duplex().
| float noise_gate_process_sample | ( | noise_gate_t * | gate, |
| float | input, | ||
| float | peak_amplitude | ||
| ) |
#include <mixer.h>
Process a single sample through noise gate.
| gate | Noise gate structure |
| input | Input sample value |
| peak_amplitude | Peak amplitude for gate decision |
Processes input sample through noise gate. Gate opens/closes based on peak_amplitude compared to threshold (with hysteresis).
Definition at line 867 of file mixer.c.
References noise_gate_t::attack_coeff, noise_gate_t::envelope, noise_gate_t::gate_open, noise_gate_t::hysteresis, noise_gate_t::release_coeff, and noise_gate_t::threshold.
Referenced by noise_gate_process_buffer().
| void noise_gate_set_params | ( | noise_gate_t * | gate, |
| float | threshold, | ||
| float | attack_ms, | ||
| float | release_ms, | ||
| float | hysteresis | ||
| ) |
#include <mixer.h>
Set noise gate parameters.
| gate | Noise gate structure |
| threshold | Gate threshold in linear units |
| attack_ms | Attack time in milliseconds |
| release_ms | Release time in milliseconds |
| hysteresis | Hysteresis factor (0-1) to prevent chatter |
Updates noise gate parameters. Time-based parameters are converted to coefficients internally.
Definition at line 852 of file mixer.c.
References noise_gate_t::attack_coeff, noise_gate_t::attack_ms, noise_gate_t::hysteresis, noise_gate_t::release_coeff, noise_gate_t::release_ms, noise_gate_t::sample_rate, and noise_gate_t::threshold.
Referenced by client_audio_pipeline_create(), and noise_gate_init().
| opus_codec_t * opus_codec_create_decoder | ( | int | sample_rate | ) |
#include <opus_codec.h>
Create an Opus decoder.
| sample_rate | Sample rate in Hz (must match encoder) |
Creates a new Opus decoder instance for decompressing audio.
Definition at line 62 of file opus_codec.c.
References opus_codec_t::bitrate, opus_codec_t::decoder, opus_codec_t::encoder, ERROR_AUDIO, ERROR_INVALID_PARAM, ERROR_MEMORY, log_debug, SAFE_FREE, SAFE_MALLOC, opus_codec_t::sample_rate, SET_ERRNO, and opus_codec_t::tmp_buffer.
Referenced by handle_stream_start_packet().
| opus_codec_t * opus_codec_create_encoder | ( | opus_application_t | application, |
| int | sample_rate, | ||
| int | bitrate | ||
| ) |
#include <opus_codec.h>
Create an Opus encoder.
| application | Application mode (OPUS_APPLICATION_VOIP for voice) |
| sample_rate | Sample rate in Hz (8000, 12000, 16000, 24000, or 48000) |
| bitrate | Target bitrate in bits per second (6000-128000 typical) |
Creates a new Opus encoder instance for compressing audio.
Definition at line 18 of file opus_codec.c.
References opus_codec_t::bitrate, opus_codec_t::decoder, opus_codec_t::encoder, ERROR_AUDIO, ERROR_INVALID_PARAM, ERROR_MEMORY, log_debug, SAFE_FREE, SAFE_MALLOC, opus_codec_t::sample_rate, SET_ERRNO, and opus_codec_t::tmp_buffer.
Referenced by client_audio_render_thread().
| int opus_codec_decode | ( | opus_codec_t * | codec, |
| const uint8_t * | data, | ||
| size_t | data_len, | ||
| float * | out_samples, | ||
| int | out_num_samples | ||
| ) |
#include <opus_codec.h>
Decode Opus audio frame.
| codec | Opus decoder (created with opus_codec_create_decoder) |
| data | Compressed audio data (or NULL for PLC) |
| data_len | Length of compressed data in bytes |
| out_samples | Output buffer for decoded samples (float) |
| out_num_samples | Maximum number of output samples |
Decodes a compressed Opus frame back to PCM audio samples.
Definition at line 128 of file opus_codec.c.
References opus_codec_t::decoder, ERROR_AUDIO, ERROR_INVALID_PARAM, log_debug_every, LOG_RATE_VERY_FAST, and SET_ERRNO.
Referenced by handle_audio_opus_batch_packet(), and handle_audio_opus_packet().
| void opus_codec_destroy | ( | opus_codec_t * | codec | ) |
#include <opus_codec.h>
Destroy an Opus codec instance.
| codec | Codec to destroy (can be NULL) |
Frees all resources associated with the codec. Safe to call multiple times or with NULL pointer.
Definition at line 215 of file opus_codec.c.
References opus_codec_t::decoder, opus_codec_t::encoder, SAFE_FREE, and opus_codec_t::tmp_buffer.
Referenced by cleanup_client_media_buffers(), and client_audio_render_thread().
| size_t opus_codec_encode | ( | opus_codec_t * | codec, |
| const float * | samples, | ||
| int | num_samples, | ||
| uint8_t * | out_data, | ||
| size_t | out_size | ||
| ) |
#include <opus_codec.h>
Encode audio frame with Opus.
| codec | Opus encoder (created with opus_codec_create_encoder) |
| samples | Input audio samples (float, -1.0 to 1.0 range) |
| num_samples | Number of input samples (882 for 20ms @ 44.1kHz) |
| out_data | Output buffer for compressed audio |
| out_size | Maximum output buffer size in bytes |
Encodes a frame of audio samples using Opus compression.
Definition at line 97 of file opus_codec.c.
References opus_codec_t::encoder, ERROR_AUDIO, ERROR_INVALID_PARAM, log_debug_every, LOG_RATE_VERY_FAST, and SET_ERRNO.
Referenced by client_audio_render_thread().
| int opus_codec_get_bitrate | ( | opus_codec_t * | codec | ) |
#include <opus_codec.h>
Get current encoder bitrate.
| codec | Opus encoder |
Definition at line 180 of file opus_codec.c.
References opus_codec_t::encoder, ERROR_AUDIO, ERROR_INVALID_PARAM, and SET_ERRNO.
| asciichat_error_t opus_codec_set_bitrate | ( | opus_codec_t * | codec, |
| int | bitrate | ||
| ) |
#include <opus_codec.h>
Set encoder bitrate.
| codec | Opus encoder (created with opus_codec_create_encoder) |
| bitrate | New bitrate in bits per second |
Changes the bitrate of an active encoder. This can be used to dynamically adjust quality based on network conditions.
Definition at line 163 of file opus_codec.c.
References ASCIICHAT_OK, opus_codec_t::bitrate, opus_codec_t::encoder, ERROR_AUDIO, ERROR_INVALID_PARAM, log_debug, and SET_ERRNO.
| asciichat_error_t opus_codec_set_dtx | ( | opus_codec_t * | codec, |
| int | enable | ||
| ) |
#include <opus_codec.h>
Enable/disable DTX (Discontinuous Transmission)
| codec | Opus encoder |
| enable | 1 to enable DTX, 0 to disable |
DTX allows the encoder to produce zero-byte frames during silence, reducing bandwidth usage significantly for voice communication.
Definition at line 196 of file opus_codec.c.
References ASCIICHAT_OK, opus_codec_t::encoder, ERROR_AUDIO, ERROR_INVALID_PARAM, log_debug, and SET_ERRNO.
| void resample_linear | ( | const float * | src, |
| size_t | src_samples, | ||
| float * | dst, | ||
| size_t | dst_samples, | ||
| double | src_rate, | ||
| double | dst_rate | ||
| ) |
#include <audio.h>
Resample audio using linear interpolation.
| src | Source samples at src_rate |
| src_samples | Number of source samples |
| dst | Destination buffer at dst_rate |
| dst_samples | Number of destination samples to produce |
| src_rate | Source sample rate (e.g., 48000) |
| dst_rate | Destination sample rate (e.g., 44100) |
Performs simple linear interpolation resampling from one sample rate to another. Suitable for real-time audio where computational efficiency is more important than perfect audio quality. For higher quality, consider a polyphase resampler.
Example usage:
Simple linear interpolation resampler. Resamples from src_rate to dst_rate using linear interpolation.
| src | Source samples at src_rate |
| src_samples | Number of source samples |
| dst | Destination buffer at dst_rate |
| dst_samples | Number of destination samples to produce |
| src_rate | Source sample rate (e.g., 48000) |
| dst_rate | Destination sample rate (e.g., 44100) |
Definition at line 165 of file lib/audio/audio.c.
References SAFE_MEMSET.
| float smoothstep | ( | float | t | ) |
#include <mixer.h>
Compute smoothstep interpolation.
| t | Input value (typically 0.0 to 1.0) |
Standard smoothstep function providing smooth fade-in/fade-out curves. Output is clamped to [0, 1] range.
Definition at line 1046 of file mixer.c.
Referenced by client_audio_pipeline_process_duplex(), and fade_buffer_smooth().
| float soft_clip | ( | float | sample, |
| float | threshold, | ||
| float | steepness | ||
| ) |
#include <mixer.h>
Apply soft clipping to a sample.
| sample | Input sample value |
| threshold | Clipping threshold (e.g., 0.7 for 3dB headroom) |
| steepness | How aggressively the curve bends (1.0 = gentle, 10.0 = sharp) |
Applies soft clipping using tanh curve. The formula is: output = threshold + (1.0 - threshold) * tanh((sample - threshold) * steepness)
This maps samples above threshold asymptotically toward 1.0, preventing hard clipping artifacts while maintaining perceptual loudness.
Common parameter combinations:
Definition at line 1019 of file mixer.c.
Referenced by client_audio_pipeline_process_duplex(), mixer_process(), mixer_process_excluding_source(), and soft_clip_buffer().
| void soft_clip_buffer | ( | float * | buffer, |
| int | num_samples, | ||
| float | threshold, | ||
| float | steepness | ||
| ) |
#include <mixer.h>
Apply soft clipping to a buffer.
| buffer | Audio buffer (modified in-place) |
| num_samples | Number of samples to process |
| threshold | Clipping threshold (e.g., 0.7 for 3dB headroom) |
| steepness | How aggressively the curve bends |
Processes entire buffer through soft_clip(). Buffer is modified in-place.
Definition at line 1032 of file mixer.c.
References soft_clip().
Referenced by client_audio_pipeline_process_duplex().
| uint64_t mixer_t::active_sources_mask |
Bitset of active sources (bit i = source i is active, O(1) iteration)
Definition at line 341 of file mixer.h.
Referenced by mixer_add_source(), mixer_create(), mixer_process_excluding_source(), mixer_remove_source(), and mixer_set_source_active().
| float highpass_filter_t::alpha |
Filter coefficient alpha (calculated from cutoff_hz)
Definition at line 225 of file mixer.h.
Referenced by highpass_filter_init(), and highpass_filter_process_sample().
| float lowpass_filter_t::alpha |
Filter coefficient alpha (calculated from cutoff_hz)
Definition at line 248 of file mixer.h.
Referenced by lowpass_filter_init(), and lowpass_filter_process_sample().
| float compressor_t::attack_coeff |
Attack coefficient (converted from attack_ms)
Definition at line 158 of file mixer.h.
Referenced by compressor_process_sample(), and compressor_set_params().
| float noise_gate_t::attack_coeff |
Attack coefficient (converted from attack_ms)
Definition at line 195 of file mixer.h.
Referenced by noise_gate_process_sample(), and noise_gate_set_params().
| float ducking_t::attack_coeff |
Attack coefficient (converted from attack_ms)
Definition at line 284 of file mixer.h.
Referenced by ducking_init(), ducking_process_frame(), mixer_process(), and mixer_process_excluding_source().
| float compressor_t::attack_ms |
Attack time in milliseconds (how fast compression kicks in)
Definition at line 145 of file mixer.h.
Referenced by compressor_set_params().
| float noise_gate_t::attack_ms |
Attack time in milliseconds (how fast gate opens)
Definition at line 184 of file mixer.h.
Referenced by noise_gate_set_params().
| float ducking_t::attack_ms |
Ducking attack time in milliseconds.
Definition at line 279 of file mixer.h.
Referenced by ducking_init(), and ducking_set_params().
| float ducking_t::atten_dB |
Attenuation in dB for non-leader sources.
Definition at line 277 of file mixer.h.
Referenced by ducking_init(), ducking_process_frame(), and ducking_set_params().
| float mixer_t::base_gain |
Base gain before crowd scaling is applied.
Definition at line 353 of file mixer.h.
Referenced by mixer_create(), mixer_process(), and mixer_process_excluding_source().
| compressor_t mixer_t::compressor |
Compressor (dynamic range compression)
Definition at line 358 of file mixer.h.
Referenced by mixer_create(), mixer_process(), and mixer_process_excluding_source().
| float mixer_t::crowd_alpha |
Crowd scaling exponent (typically 0.5 for sqrt scaling)
Definition at line 351 of file mixer.h.
Referenced by mixer_create(), mixer_process(), and mixer_process_excluding_source().
| float highpass_filter_t::cutoff_hz |
Cutoff frequency in Hz (frequencies below this are attenuated)
Definition at line 220 of file mixer.h.
Referenced by highpass_filter_init().
| float lowpass_filter_t::cutoff_hz |
Cutoff frequency in Hz (frequencies above this are attenuated)
Definition at line 243 of file mixer.h.
Referenced by lowpass_filter_init().
| ducking_t mixer_t::ducking |
Ducking system (active speaker detection and attenuation)
Definition at line 356 of file mixer.h.
Referenced by mixer_create(), mixer_destroy(), mixer_process(), mixer_process_excluding_source(), and mixer_remove_source().
| float compressor_t::envelope |
Current envelope follower state (linear, 0-1)
Definition at line 154 of file mixer.h.
Referenced by compressor_init(), and compressor_process_sample().
| float noise_gate_t::envelope |
Current envelope follower state (linear, 0-1)
Definition at line 193 of file mixer.h.
Referenced by noise_gate_init(), and noise_gate_process_sample().
| float* ducking_t::envelope |
Per-source envelope follower state (linear, allocated per source)
Definition at line 288 of file mixer.h.
Referenced by ducking_free(), ducking_init(), mixer_process(), mixer_process_excluding_source(), and mixer_remove_source().
| float* ducking_t::gain |
Per-source ducking gain (linear, calculated from envelope)
Definition at line 290 of file mixer.h.
Referenced by ducking_free(), ducking_init(), mixer_process(), mixer_process_excluding_source(), and mixer_remove_source().
| float compressor_t::gain_lin |
Current gain multiplier (linear, calculated from envelope)
Definition at line 156 of file mixer.h.
Referenced by compressor_init(), and compressor_process_sample().
| bool noise_gate_t::gate_open |
True if gate is currently open (allowing audio through)
Definition at line 199 of file mixer.h.
Referenced by noise_gate_init(), noise_gate_is_open(), and noise_gate_process_sample().
| float noise_gate_t::hysteresis |
Hysteresis factor (0-1, prevents gate chatter)
Definition at line 188 of file mixer.h.
Referenced by noise_gate_process_sample(), and noise_gate_set_params().
| float compressor_t::knee_dB |
Knee width in dB for soft knee (e.g., 2.0)
Definition at line 141 of file mixer.h.
Referenced by compressor_set_params().
| float ducking_t::leader_margin_dB |
Leader margin in dB (sources within this of loudest are leaders)
Definition at line 275 of file mixer.h.
Referenced by ducking_init(), ducking_process_frame(), and ducking_set_params().
| float compressor_t::makeup_dB |
Makeup gain in dB (compensates for gain reduction)
Definition at line 149 of file mixer.h.
Referenced by compressor_process_sample(), and compressor_set_params().
| int mixer_t::max_sources |
Maximum number of sources (allocated array sizes)
Definition at line 329 of file mixer.h.
Referenced by client_audio_render_thread(), mixer_add_source(), mixer_create(), mixer_process(), mixer_process_excluding_source(), mixer_remove_source(), and mixer_set_source_active().
| float* mixer_t::mix_buffer |
Temporary buffer for mixing operations (pre-allocated)
Definition at line 361 of file mixer.h.
Referenced by mixer_create(), mixer_destroy(), mixer_process(), and mixer_process_excluding_source().
| int mixer_t::num_sources |
Current number of active audio sources.
Definition at line 327 of file mixer.h.
Referenced by mixer_add_source(), mixer_create(), and mixer_remove_source().
| float highpass_filter_t::prev_input |
Previous input sample (filter state)
Definition at line 227 of file mixer.h.
Referenced by highpass_filter_process_sample(), and highpass_filter_reset().
| float highpass_filter_t::prev_output |
Previous output sample (filter state)
Definition at line 229 of file mixer.h.
Referenced by highpass_filter_process_sample(), and highpass_filter_reset().
| float lowpass_filter_t::prev_output |
Previous output sample (filter state)
Definition at line 250 of file mixer.h.
Referenced by lowpass_filter_process_sample(), and lowpass_filter_reset().
| float compressor_t::ratio |
Compression ratio (e.g., 4.0 for 4:1 compression)
Definition at line 143 of file mixer.h.
Referenced by compressor_set_params().
| float compressor_t::release_coeff |
Release coefficient (converted from release_ms)
Definition at line 160 of file mixer.h.
Referenced by compressor_process_sample(), and compressor_set_params().
| float noise_gate_t::release_coeff |
Release coefficient (converted from release_ms)
Definition at line 197 of file mixer.h.
Referenced by noise_gate_process_sample(), and noise_gate_set_params().
| float ducking_t::release_coeff |
Release coefficient (converted from release_ms)
Definition at line 286 of file mixer.h.
Referenced by ducking_init(), ducking_process_frame(), mixer_process(), and mixer_process_excluding_source().
| float compressor_t::release_ms |
Release time in milliseconds (how fast compression releases)
Definition at line 147 of file mixer.h.
Referenced by compressor_set_params().
| float noise_gate_t::release_ms |
Release time in milliseconds (how fast gate closes)
Definition at line 186 of file mixer.h.
Referenced by noise_gate_set_params().
| float ducking_t::release_ms |
Ducking release time in milliseconds.
Definition at line 281 of file mixer.h.
Referenced by ducking_init(), and ducking_set_params().
| float compressor_t::sample_rate |
Sample rate in Hz (set during initialization)
Definition at line 152 of file mixer.h.
Referenced by compressor_init(), and compressor_set_params().
| float noise_gate_t::sample_rate |
Sample rate in Hz (set during initialization)
Definition at line 191 of file mixer.h.
Referenced by noise_gate_init(), and noise_gate_set_params().
| float highpass_filter_t::sample_rate |
Sample rate in Hz (set during initialization)
Definition at line 222 of file mixer.h.
Referenced by highpass_filter_init().
| float lowpass_filter_t::sample_rate |
Sample rate in Hz (set during initialization)
Definition at line 245 of file mixer.h.
Referenced by lowpass_filter_init().
| int mixer_t::sample_rate |
Sample rate in Hz (e.g., 44100)
Definition at line 331 of file mixer.h.
Referenced by mixer_create().
| bool* mixer_t::source_active |
Array of active flags (true if source is active)
Definition at line 338 of file mixer.h.
Referenced by mixer_add_source(), mixer_create(), mixer_destroy(), mixer_process(), mixer_remove_source(), and mixer_set_source_active().
| audio_ring_buffer_t** mixer_t::source_buffers |
Array of pointers to client audio ring buffers.
Definition at line 334 of file mixer.h.
Referenced by client_audio_render_thread(), mixer_add_source(), mixer_create(), mixer_destroy(), mixer_process(), mixer_process_excluding_source(), and mixer_remove_source().
| uint32_t mixer_t::source_id_at_hash[256] |
| uint8_t mixer_t::source_id_to_index[256] |
Hash table mapping client_id → mixer source index (uses hash function for 32-bit IDs)
Definition at line 343 of file mixer.h.
Referenced by mixer_add_source(), mixer_create(), mixer_process_excluding_source(), and mixer_remove_source().
| uint32_t* mixer_t::source_ids |
Array of client IDs (one per source slot)
Definition at line 336 of file mixer.h.
Referenced by client_audio_render_thread(), mixer_add_source(), mixer_create(), mixer_destroy(), mixer_process(), mixer_process_excluding_source(), mixer_remove_source(), and mixer_set_source_active().
| rwlock_t mixer_t::source_lock |
Reader-writer lock protecting source arrays and bitset.
Definition at line 348 of file mixer.h.
Referenced by mixer_add_source(), mixer_create(), mixer_destroy(), mixer_process(), mixer_process_excluding_source(), mixer_remove_source(), and mixer_set_source_active().
| float noise_gate_t::threshold |
Gate threshold in linear units (e.g., 0.01f for -40dB)
Definition at line 182 of file mixer.h.
Referenced by noise_gate_process_sample(), and noise_gate_set_params().
| float compressor_t::threshold_dB |
Compression threshold in dB (e.g., -10.0)
Definition at line 139 of file mixer.h.
Referenced by compressor_set_params().
| float ducking_t::threshold_dB |
Speaking threshold in dB (sources below this are not "speaking")
Definition at line 273 of file mixer.h.
Referenced by ducking_init(), ducking_process_frame(), and ducking_set_params().