nx_flac_frame.nx
buildroot/runtime/nx_flac_frame.nx
about
nx_flac_frame.nx -- FLAC frame and subframe decoding.
Completes the FLAC decode path. nx_flac.nx holds the maths (Rice, fixed and
LPC predictors, stereo decorrelation, CRC-8, the header tables); this reads
an actual frame off a bitstream and turns it into samples.
THE HEADER LENGTH IS NOT FIXED. A frame header is 4 bytes of flags, then a
UTF-8-style extended number of 1-7 bytes, then optionally an 8- or 16-bit
block size, then optionally an 8- or 16-bit sample rate, then the CRC-8.
The CRC covers exactly those bytes and no more, so the parser has to know
where it stopped. Hard-coding a length is the classic FLAC bug: it works on
every small file (frame number < 128, standard block size and rate) and
fails the moment a stream runs past frame 127.
THE PARTITION SPLIT IS UNEVEN. Residuals are Rice-coded in 2^order
partitions, and the FIRST partition is short by the predictor order because
those samples are warm-up, already carried literally. Every later partition
is full width. Splitting evenly decodes without error and desyncs the
bitstream by exactly `order` samples.
genealogy_id: flac_format_spec_frame
lineage_id: nx_flac_frame_v1
license_tier: ORIGINAL
dependencies 3 imports · 1 importers
imports: nx_syscalls.nxnx_bitstream.nxnx_flac.nx
imported by: nx_flac_frame_gate.nx
structs
| none |
consts
| 29 | const NX_FLACF_SYNC: i64 = 0x3ffe |
| 30 | const NX_FLACF_ESC4: i64 = 15 |
| 31 | const NX_FLACF_ESC5: i64 = 31 |
| 34 | const NX_FLACF_FLD_BLOCKSIZE: i64 = 0 |
| 35 | const NX_FLACF_FLD_RATE: i64 = 1 |
| 36 | const NX_FLACF_FLD_CHANNELS: i64 = 2 |
| 37 | const NX_FLACF_FLD_CHANASSIGN:i64 = 3 |
| 38 | const NX_FLACF_FLD_BPS: i64 = 4 |
| 39 | const NX_FLACF_FLD_NUMBER: i64 = 5 |
| 40 | const NX_FLACF_FLD_HDRLEN: i64 = 6 |
functions
| 47 | func nx_flac_utf8_len(first: i64) -> i64 |
| 59 | func nx_flac_utf8_read(data: *u8, n: i64, off: i64, out_len: *i64) -> i64 |
| 85 | func nx_flac_frame_parse(data: *u8, n: i64, off: i64, fld: *i64) -> i64 |
| 163 | func nx_flac_read_signed(bs: *NxBitStream, bits: i64) -> i64 |
| 175 | func nx_flac_read_residual(bs: *NxBitStream, buf: *i64, blocksize: i64, order: i64) -> i64 |
| 220 | func nx_flac_subframe(bs: *NxBitStream, buf: *i64, blocksize: i64, bps: i64) -> i64 |
| 294 | func nx_flac_crc16(data: *u8, n: i64) -> i64 called by 1: main |