code wiki / (root) / nx_wav_header.nx

nx_wav_header.nx

buildroot/runtime/nx_wav_header.nx

6106 B183 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic wav
docsdependenciesstructsconstsfunctions

about

wav_header.nx -- parse RIFF WAVE (WAV) audio file headers. RIFF container with one "fmt " subchunk (mandatory, describes audio format) and one "data" subchunk (the PCM samples). The canonical 44-byte PCM header is: off size field 0 4 "RIFF" 4 4 chunk size (file size - 8) 8 4 "WAVE" 12 4 "fmt " 16 4 fmt subchunk size (16 for PCM) 20 2 audio format code (1 = PCM, 3 = IEEE float, ...) 22 2 num_channels 24 4 sample_rate 28 4 byte_rate = sample_rate * num_channels * bits/8 32 2 block_align = num_channels * bits/8 34 2 bits_per_sample 36 4 "data" 40 4 data_size (bytes of PCM samples) 44 N PCM samples Non-PCM formats may have a larger "fmt " chunk (extensions following the canonical 16 bytes) and other subchunks ("LIST", "fact", "INFO") interleaved before "data". We walk the chunk stream to find "fmt " and "data" by tag, so extra chunks are tolerated. Invariants: W1 "RIFF" + "WAVE" magic required. W2 Chunk walker returns both "fmt " and "data" offsets or WAV_ERR_FORMAT if either is missing. W3 Multi-byte integers are LITTLE-endian (RIFX variant is big-endian but we don't accept it here).

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_wav_header.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap wav_parse wav_tag_is wav_read_u32 wav_read_u16

structs

54struct WavHeader

consts

43const WAV_MAGIC_44100: i64 = 44100
45const WAV_ERR_FORMAT: i64 = -1
46const WAV_ERR_SHORT: i64 = -2
48const WAV_FMT_PCM: i64 = 1
49const WAV_FMT_IEEE_FLOAT: i64 = 3
50const WAV_FMT_ALAW: i64 = 6
51const WAV_FMT_MULAW: i64 = 7
52const WAV_FMT_EXTENSIBLE: i64 = 65534

functions

66func wav_read_u16(buf: *u8, off: i64) -> i64
called by 1: wav_parse
70func wav_read_u32(buf: *u8, off: i64) -> i64
called by 1: wav_parse
79func wav_tag_is(buf: *u8, off: i64,
called by 1: wav_parse
90func wav_parse(buf: *u8, n: i64, h: *WavHeader) -> i64
139func main() -> i64