nx_audio_pcm.nx
buildroot/runtime/nx_audio_pcm.nx
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
imports: nx_syscalls.nxnx_tier.nx
imported by: nx_audio_pcm_test.nxnx_game_runtime_compose_test.nx
structs
| 32 | struct NxPcmBuffer |
consts
| 22 | const NX_MAGIC_1024: i64 = 1024 |
| 23 | const NX_MAGIC_1000000: i64 = 1000000 |
| 25 | const NX_PCM_OK: nx_int = 0 |
| 26 | const NX_PCM_ERR_BAD_RATE: nx_int = 1 |
| 27 | const NX_PCM_ERR_DST_TOO_SMALL: nx_int = 2 |
| 28 | const NX_PCM_ERR_BAD_SCALE: nx_int = 3 |
functions
| 38 | func nx_pcm_buffer_new(samples: *u8, n_samples: nx_size, sample_rate_hz: nx_int) -> *NxPcmBuffer |
| 56 | func nx_pcm_resample_linear(src: *NxPcmBuffer, |
| 90 | func nx_pcm_amplitude_scale_q10(b: *NxPcmBuffer, scale_q10: nx_int) -> nx_int |
| 113 | func nx_pcm_mix_into(dst: *NxPcmBuffer, src: *NxPcmBuffer) -> nx_int called by 1: main |
| 137 | func nx_pcm_peak_amplitude(b: *NxPcmBuffer) -> nx_int |
| 152 | func nx_pcm_duration_us(b: *NxPcmBuffer) -> nx_size |