code wiki / (root) / wav_header.nx

wav_header.nx

buildroot/runtime/wav_header.nx

5973 B176 linesdepth 3pulls 3 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

syscalls.nx wav_header.nx

imports: syscalls.nx

imported by: nobody (leaf or entry point)

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

main wav_parse wav_tag_is wav_read_u32 wav_read_u16

structs

47struct WavHeader {

consts

38const WAV_ERR_FORMAT: i64 = -1
39const WAV_ERR_SHORT: i64 = -2
41const WAV_FMT_PCM: i64 = 1
42const WAV_FMT_IEEE_FLOAT: i64 = 3
43const WAV_FMT_ALAW: i64 = 6
44const WAV_FMT_MULAW: i64 = 7
45const WAV_FMT_EXTENSIBLE: i64 = 65534

functions

59func wav_read_u16(buf: *u8, off: i64) -> i64 {
called by 1: wav_parse
63func wav_read_u32(buf: *u8, off: i64) -> i64 {
called by 1: wav_parse
72func wav_tag_is(buf: *u8, off: i64,
called by 1: wav_parse
83func wav_parse(buf: *u8, n: i64, h: *WavHeader) -> i64 {
132func main() -> i64 {
calls 1: wav_parse