code wiki / (root) / nx_flac_frame.nx

nx_flac_frame.nx

buildroot/runtime/nx_flac_frame.nx

10488 B311 linesdepth 5pulls 5 transitivereach 1 importersview sourcekind librarytopic flac
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_bitstream.nx nx_flac.nx nx_flac_frame.nx nx_flac_frame_gate.nx

imports: nx_syscalls.nxnx_bitstream.nxnx_flac.nx

imported by: nx_flac_frame_gate.nx

structs

none

consts

29const NX_FLACF_SYNC: i64 = 0x3ffe
30const NX_FLACF_ESC4: i64 = 15
31const NX_FLACF_ESC5: i64 = 31
34const NX_FLACF_FLD_BLOCKSIZE: i64 = 0
35const NX_FLACF_FLD_RATE: i64 = 1
36const NX_FLACF_FLD_CHANNELS: i64 = 2
37const NX_FLACF_FLD_CHANASSIGN:i64 = 3
38const NX_FLACF_FLD_BPS: i64 = 4
39const NX_FLACF_FLD_NUMBER: i64 = 5
40const NX_FLACF_FLD_HDRLEN: i64 = 6

functions

47func nx_flac_utf8_len(first: i64) -> i64
59func nx_flac_utf8_read(data: *u8, n: i64, off: i64, out_len: *i64) -> i64
85func nx_flac_frame_parse(data: *u8, n: i64, off: i64, fld: *i64) -> i64
163func nx_flac_read_signed(bs: *NxBitStream, bits: i64) -> i64
175func nx_flac_read_residual(bs: *NxBitStream, buf: *i64, blocksize: i64, order: i64) -> i64
220func nx_flac_subframe(bs: *NxBitStream, buf: *i64, blocksize: i64, bps: i64) -> i64
294func nx_flac_crc16(data: *u8, n: i64) -> i64
called by 1: main