ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
mixer_t Struct Reference

For ducking, this is the live record that ties threshold_dB, leader_margin_dB, atten_dB, attack_ns together. The owning code creates it, updates it while work is active, and releases its handles and pointed-to storage before freeing the record. More...

#include <include/ascii-chat/audio/mixer.h>

Data Fields

int num_sources
 Current number of active audio sources.
atomic_t active_sources
int max_sources
 Maximum number of sources (allocated array sizes).
int sample_rate
 Sample rate in Hz (e.g., 44100).
unsigned channels
struct spectral_processor * spectral_left [128+1]
struct spectral_processor * spectral_right [128+1]
audio_ring_buffer_t ** source_buffers
 Array of pointers to client audio ring buffers.
struct mixer_listener_buffer * listener_buffers [128][128]
const char ** source_ids
 Array of client ID strings (one per source slot).
bool * source_active
 Array of active flags (true if source is active).
uint64_t active_sources_mask [((128+63)/64)]
 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 strings).
const char * source_id_at_hash [256]
 Client ID strings 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).
float * mix_buffer
 Temporary buffer for mixing operations (pre-allocated).

Detailed Description

For ducking, this is the live record that ties threshold_dB, leader_margin_dB, atten_dB, attack_ns together. The owning code creates it, updates it while work is active, and releases its handles and pointed-to storage before freeing the record.

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 332 of file mixer.h.


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