code wiki / (root) / nx_audio_pcm.nx

nx_audio_pcm.nx

buildroot/runtime/nx_audio_pcm.nx

5713 B155 linesdepth 2pulls 2 transitivereach 2 importersview sourcekind librarytopic audio
docsdependenciesstructsconstsfunctions

about

nx_audio_pcm.nx -- 8-bit PCM audio buffer + DSP helpers. Substrate for sample-based audio. T1 ESP32 has PWM-based audio output that's adequate for 8-bit PCM at 8-22 kHz (chimes, family voice clips, footstep sound effects). This primitive holds the sample buffer + provides resampling + amplitude scaling. Composes: nx_palette -- audio is "1D voxels"; both are byte streams w/ semantics nx_brane -- CAP_HARDWARE_IO required for audio output nx_voicebank (queued) -- audio-reader roadmap's voice corpus is a collection of these PCM buffers V1 ships: - struct NxPcmBuffer { samples (u8), n_samples, sample_rate_hz } - linear_resample to a target sample rate - amplitude_scale_q10 (volume control) - mix_into (additive mixing to dest buffer with clipping)

dependencies 2 imports · 2 importers

nx_syscalls.nx nx_tier.nx nx_audio_pcm.nx nx_audio_pcm_test.nx nx_game_runtime_compose_test.nx

imports: nx_syscalls.nxnx_tier.nx

imported by: nx_audio_pcm_test.nxnx_game_runtime_compose_test.nx

structs

32struct NxPcmBuffer

consts

22const NX_MAGIC_1024: i64 = 1024
23const NX_MAGIC_1000000: i64 = 1000000
25const NX_PCM_OK: nx_int = 0
26const NX_PCM_ERR_BAD_RATE: nx_int = 1
27const NX_PCM_ERR_DST_TOO_SMALL: nx_int = 2
28const NX_PCM_ERR_BAD_SCALE: nx_int = 3

functions

38func nx_pcm_buffer_new(samples: *u8, n_samples: nx_size, sample_rate_hz: nx_int) -> *NxPcmBuffer
called by 2: mainmain calls 1: sys_mmap
56func nx_pcm_resample_linear(src: *NxPcmBuffer,
called by 2: mainmain
90func nx_pcm_amplitude_scale_q10(b: *NxPcmBuffer, scale_q10: nx_int) -> nx_int
called by 2: mainmain
113func nx_pcm_mix_into(dst: *NxPcmBuffer, src: *NxPcmBuffer) -> nx_int
called by 1: main
137func nx_pcm_peak_amplitude(b: *NxPcmBuffer) -> nx_int
called by 2: mainmain
152func nx_pcm_duration_us(b: *NxPcmBuffer) -> nx_size
called by 2: mainmain