wav_header.nx
buildroot/runtime/wav_header.nx
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
imports: syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 47 | struct WavHeader { |
consts
| 38 | const WAV_ERR_FORMAT: i64 = -1 |
| 39 | const WAV_ERR_SHORT: i64 = -2 |
| 41 | const WAV_FMT_PCM: i64 = 1 |
| 42 | const WAV_FMT_IEEE_FLOAT: i64 = 3 |
| 43 | const WAV_FMT_ALAW: i64 = 6 |
| 44 | const WAV_FMT_MULAW: i64 = 7 |
| 45 | const WAV_FMT_EXTENSIBLE: i64 = 65534 |
functions
| 59 | func wav_read_u16(buf: *u8, off: i64) -> i64 {
called by 1: wav_parse |
| 63 | func wav_read_u32(buf: *u8, off: i64) -> i64 {
called by 1: wav_parse |
| 72 | func wav_tag_is(buf: *u8, off: i64,
called by 1: wav_parse |
| 83 | func wav_parse(buf: *u8, n: i64, h: *WavHeader) -> i64 { |
| 132 | func main() -> i64 {
calls 1: wav_parse |