ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
mixer_t Struct Reference

Main mixer structure for multi-source audio processing. More...

#include <lib/audio/mixer.h>

Data Fields

int num_sources
 Current number of active audio sources.
 
int max_sources
 Maximum number of sources (allocated array sizes)
 
int sample_rate
 Sample rate in Hz (e.g., 44100)
 
audio_ring_buffer_t ** source_buffers
 Array of pointers to client audio ring buffers.
 
uint32_tsource_ids
 Array of client IDs (one per source slot)
 
boolsource_active
 Array of active flags (true if source is active)
 
uint64_t active_sources_mask
 Bitset of active sources (bit i = source i is active, O(1) iteration)
 
uint8_t source_id_to_index [256]
 Hash table mapping client_id → mixer source index (uses hash function for 32-bit IDs)
 
uint32_t source_id_at_hash [256]
 Client IDs stored at each hash index for collision detection.
 
rwlock_t source_lock
 Reader-writer lock protecting source arrays and bitset.
 
float crowd_alpha
 Crowd scaling exponent (typically 0.5 for sqrt scaling)
 
float base_gain
 Base gain before crowd scaling is applied.
 
ducking_t ducking
 Ducking system (active speaker detection and attenuation)
 
compressor_t compressor
 Compressor (dynamic range compression)
 
floatmix_buffer
 Temporary buffer for mixing operations (pre-allocated)
 

Detailed Description

Main mixer structure for multi-source audio processing.

Manages multiple audio sources (clients) and processes them through a professional audio processing pipeline. Supports up to MIXER_MAX_SOURCES simultaneous sources with automatic crowd scaling and active speaker detection.

MIXER ARCHITECTURE:

  • Source Management: Array of audio ring buffers, one per client
  • Optimized Lookup: Bitset + hash table for O(1) source exclusion
  • Thread Safety: Reader-writer locks for concurrent access
  • Crowd Scaling: Automatic volume adjustment based on participant count
  • Audio Processing: Ducking, compression, noise gate, high-pass filter

PERFORMANCE OPTIMIZATIONS:

  • Bitset-based active source tracking (O(1) exclusion)
  • Hash table for client ID to mixer index mapping
  • Pre-allocated mix buffer (no allocations in hot path)
  • Reader-writer locks for concurrent reads
Note
Each source is indexed by position in arrays (0 to max_sources-1). Client IDs are mapped to indices via source_id_to_index hash table.
Active sources are tracked in two ways:
  • source_active[] array for per-source status
  • active_sources_mask bitset for O(1) iteration exclusion
Warning
Source arrays must be locked (read or write) during iteration to prevent concurrent modifications.

Definition at line 325 of file mixer.h.


The documentation for this struct was generated from the following file: