ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
audio.h File Reference

Stub audio types for WASM builds (uses Web Audio API instead of PortAudio) More...

Go to the source code of this file.

Data Structures

struct  audio_batch_info_t
 
struct  audio_frame_t
 

Functions

asciichat_error_t audio_parse_batch_header (const void *data, size_t len, audio_batch_info_t *out_batch)
 
asciichat_error_t audio_validate_batch_params (const audio_batch_info_t *batch)
 
bool audio_is_supported_sample_rate (uint32_t sample_rate)
 

Detailed Description

Stub audio types for WASM builds (uses Web Audio API instead of PortAudio)

This header provides minimal audio type definitions for WASM builds. In WASM, audio is handled by Web Audio API via AudioPipeline.ts instead of PortAudio. This stub provides just enough definitions for network packet parsing to compile.

Definition in file lib/platform/wasm/stubs/audio.h.

Function Documentation

◆ audio_is_supported_sample_rate()

bool audio_is_supported_sample_rate ( uint32_t  sample_rate)

Definition at line 2014 of file lib/audio/audio.c.

2014 {
2015 // List of commonly supported audio sample rates
2016 static const uint32_t supported_rates[] = {
2017 8000, // Telephone quality
2018 16000, // Wideband telephony
2019 24000, // High quality speech
2020 32000, // Good for video
2021 44100, // CD quality (less common in VoIP)
2022 48000, // Standard professional
2023 96000, // High-end professional
2024 192000, // Ultra-high-end mastering
2025 };
2026
2027 const size_t rate_count = sizeof(supported_rates) / sizeof(supported_rates[0]);
2028 for (size_t i = 0; i < rate_count; i++) {
2029 if (sample_rate == supported_rates[i]) {
2030 return true;
2031 }
2032 }
2033
2034 return false;
2035}

Referenced by audio_validate_batch_params().

◆ audio_parse_batch_header()

asciichat_error_t audio_parse_batch_header ( const void *  data,
size_t  len,
audio_batch_info_t out_batch 
)

Definition at line 1948 of file lib/audio/audio.c.

1948 {
1949 if (!data) {
1950 return SET_ERRNO(ERROR_INVALID_PARAM, "Audio batch header data pointer is NULL");
1951 }
1952
1953 if (!out_batch) {
1954 return SET_ERRNO(ERROR_INVALID_PARAM, "Audio batch info output pointer is NULL");
1955 }
1956
1957 if (len < sizeof(audio_batch_packet_t)) {
1958 return SET_ERRNO(ERROR_INVALID_PARAM, "Audio batch header too small (len=%zu, expected=%zu)", len,
1959 sizeof(audio_batch_packet_t));
1960 }
1961
1962 const audio_batch_packet_t *batch_header = (const audio_batch_packet_t *)data;
1963
1964 // Unpack network byte order values to host byte order
1965 out_batch->batch_count = ntohl(batch_header->batch_count);
1966 out_batch->total_samples = ntohl(batch_header->total_samples);
1967 out_batch->sample_rate = ntohl(batch_header->sample_rate);
1968 out_batch->channels = ntohl(batch_header->channels);
1969
1970 return ASCIICHAT_OK;
1971}

References audio_batch_info_t::batch_count, audio_batch_info_t::channels, audio_batch_info_t::sample_rate, and audio_batch_info_t::total_samples.

Referenced by handle_audio_batch_packet().

◆ audio_validate_batch_params()

asciichat_error_t audio_validate_batch_params ( const audio_batch_info_t batch)

Definition at line 1973 of file lib/audio/audio.c.

1973 {
1974 if (!batch) {
1975 return SET_ERRNO(ERROR_INVALID_PARAM, "Audio batch info pointer is NULL");
1976 }
1977
1978 // Validate batch_count
1979 if (batch->batch_count == 0) {
1980 return SET_ERRNO(ERROR_INVALID_PARAM, "Audio batch count cannot be zero");
1981 }
1982
1983 // Check for reasonable max (256 frames per batch is very generous)
1984 if (batch->batch_count > 256) {
1985 return SET_ERRNO(ERROR_INVALID_PARAM, "Audio batch count too large (batch_count=%u, max=256)", batch->batch_count);
1986 }
1987
1988 // Validate channels (1=mono, 2=stereo, max 8 for multi-channel)
1989 if (batch->channels == 0 || batch->channels > 8) {
1990 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid channel count (channels=%u, valid=1-8)", batch->channels);
1991 }
1992
1993 // Validate sample rate
1995 return SET_ERRNO(ERROR_INVALID_PARAM, "Unsupported sample rate (sample_rate=%u)", batch->sample_rate);
1996 }
1997
1998 // Check for reasonable sample counts
1999 if (batch->total_samples == 0) {
2000 return SET_ERRNO(ERROR_INVALID_PARAM, "Audio batch has zero samples");
2001 }
2002
2003 // Each batch typically has samples_per_frame worth of samples
2004 // For 48kHz at 20ms per frame: 48000 * 0.02 = 960 samples per frame
2005 // With max 256 frames, that's up to ~245k samples per batch
2006 if (batch->total_samples > 1000000) {
2007 return SET_ERRNO(ERROR_INVALID_PARAM, "Audio batch sample count suspiciously large (total_samples=%u)",
2008 batch->total_samples);
2009 }
2010
2011 return ASCIICHAT_OK;
2012}
bool audio_is_supported_sample_rate(uint32_t sample_rate)

References audio_is_supported_sample_rate(), audio_batch_info_t::batch_count, audio_batch_info_t::channels, audio_batch_info_t::sample_rate, and audio_batch_info_t::total_samples.