ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
client_audio_pipeline.h
Go to the documentation of this file.
1
47#pragma once
48
49#include <stdbool.h>
50#include <stdint.h>
51
52// C11 stdatomic.h conflicts with MSVC's C++ <atomic> header on Windows.
53// When compiling C++ with MSVC runtime headers (even with Clang), we must not
54// include stdatomic.h as the MSVC <atomic> header already provides the same
55// functionality and the declarations conflict.
56#if defined(__cplusplus) && defined(_WIN32)
57// C++ mode on Windows: use <atomic> from MSVC runtime
58#include <atomic>
59#else
60#include <stdatomic.h>
61#endif
62
63#include "audio/mixer.h"
64#include "platform/mutex.h"
65
66// Forward declarations for SpeexDSP types
67typedef struct SpeexPreprocessState_ SpeexPreprocessState;
68typedef struct JitterBuffer_ JitterBuffer;
69
70// Forward declarations for WebRTC types (opaque pointers for C compatibility)
72
73// Forward declarations for Opus types
74typedef struct OpusEncoder OpusEncoder;
75typedef struct OpusDecoder OpusDecoder;
76
77#ifdef __cplusplus
78extern "C" {
79#endif
80
87#define CLIENT_AUDIO_PIPELINE_SAMPLE_RATE 48000
88
90#define CLIENT_AUDIO_PIPELINE_FRAME_MS 20
91
93#define CLIENT_AUDIO_PIPELINE_FRAME_SIZE (CLIENT_AUDIO_PIPELINE_SAMPLE_RATE * CLIENT_AUDIO_PIPELINE_FRAME_MS / 1000)
94
96#define CLIENT_AUDIO_PIPELINE_ECHO_REF_SIZE (CLIENT_AUDIO_PIPELINE_SAMPLE_RATE / 2)
97
99#define CLIENT_AUDIO_PIPELINE_MAX_OPUS_PACKET 4000
100
129
133#define CLIENT_AUDIO_PIPELINE_FLAGS_ALL \
134 ((client_audio_pipeline_flags_t){ \
135 .echo_cancel = true, \
136 .noise_suppress = true, \
137 .agc = true, \
138 .vad = true, \
139 .jitter_buffer = true, \
140 .compressor = true, \
141 .noise_gate = true, \
142 .highpass = true, \
143 .lowpass = true, \
144 })
145
149#define CLIENT_AUDIO_PIPELINE_FLAGS_MINIMAL \
150 ((client_audio_pipeline_flags_t){ \
151 .echo_cancel = false, \
152 .noise_suppress = false, \
153 .agc = false, \
154 .vad = false, \
155 .jitter_buffer = false, \
156 .compressor = false, \
157 .noise_gate = false, \
158 .highpass = false, \
159 .lowpass = false, \
160 })
161
216
222
229typedef struct {
232
237
244
249
260
263
266
268 int16_t *work_i16;
270 int16_t *echo_i16;
273
274 // No mutex needed - full-duplex means single callback thread handles all AEC3
275
278
281
283 void *debug_wav_aec3_in; // Microphone input before AEC3
284 void *debug_wav_aec3_out; // Microphone output after AEC3
285
290 void *aec3_render_buffer; // Persistent render AudioBuffer
291 void *aec3_capture_buffer; // Persistent capture AudioBuffer
293
308
317
333
340
368int client_audio_pipeline_capture(client_audio_pipeline_t *pipeline, const float *input, int num_samples,
369 uint8_t *opus_out, int opus_out_size);
370
396int client_audio_pipeline_playback(client_audio_pipeline_t *pipeline, const uint8_t *opus_in, int opus_len,
397 float *output, int max_samples);
398
409int client_audio_pipeline_get_playback_frame(client_audio_pipeline_t *pipeline, float *output, int num_samples);
410
437void client_audio_pipeline_process_duplex(client_audio_pipeline_t *pipeline, const float *render_samples,
438 int render_count, const float *capture_samples, int capture_count,
439 float *processed_output);
440
454
461
470
473#ifdef __cplusplus
474}
475#endif
struct SpeexPreprocessState_ SpeexPreprocessState
client_audio_pipeline_t * client_audio_pipeline_create(const client_audio_pipeline_config_t *config)
Create a new client audio pipeline.
void client_audio_pipeline_process_duplex(client_audio_pipeline_t *pipeline, const float *render_samples, int render_count, const float *capture_samples, int capture_count, float *processed_output)
Process AEC3 inline in full-duplex callback.
client_audio_pipeline_flags_t client_audio_pipeline_get_flags(client_audio_pipeline_t *pipeline)
Get current component enable flags.
bool client_audio_pipeline_voice_detected(client_audio_pipeline_t *pipeline)
Check if VAD detected voice activity in last capture.
int client_audio_pipeline_jitter_margin(client_audio_pipeline_t *pipeline)
Get jitter buffer margin (buffered time in ms)
struct OpusDecoder OpusDecoder
int client_audio_pipeline_get_playback_frame(client_audio_pipeline_t *pipeline, float *output, int num_samples)
Get audio frame from jitter buffer for playback callback.
client_audio_pipeline_config_t client_audio_pipeline_default_config(void)
Get default configuration.
int client_audio_pipeline_playback(client_audio_pipeline_t *pipeline, const uint8_t *opus_in, int opus_len, float *output, int max_samples)
Decode Opus packet and process for playback.
struct webrtc_EchoCanceller3 webrtc_EchoCanceller3
void client_audio_pipeline_set_flags(client_audio_pipeline_t *pipeline, client_audio_pipeline_flags_t flags)
Set component enable flags.
void client_audio_pipeline_destroy(client_audio_pipeline_t *pipeline)
Destroy a client audio pipeline.
int client_audio_pipeline_capture(client_audio_pipeline_t *pipeline, const float *input, int num_samples, uint8_t *opus_out, int opus_out_size)
Process captured audio and encode to Opus.
struct JitterBuffer_ JitterBuffer
struct OpusEncoder OpusEncoder
void client_audio_pipeline_reset(client_audio_pipeline_t *pipeline)
Reset pipeline state.
unsigned int uint32_t
Definition common.h:58
unsigned char uint8_t
Definition common.h:56
Multi-Source Audio Mixing and Processing System.
Cross-platform mutex interface for ascii-chat.
Pipeline configuration parameters.
client_audio_pipeline_flags_t flags
Component enable/disable flags.
Client audio pipeline state.
client_audio_pipeline_config_t config
client_audio_pipeline_flags_t flags
SpeexPreprocessState * preprocess
Dynamic range compressor settings and state.
Definition mixer.h:137
High-pass filter settings and state.
Definition mixer.h:218
Low-pass filter state.
Definition mixer.h:241
Noise gate settings and state.
Definition mixer.h:180