nx_flac.nx
buildroot/runtime/nx_flac.nx
about
nx_flac.nx -- FLAC lossless audio decoder core.
The audio quadrant of this tree held PCM and nothing else. FLAC is the
cheapest real codec to close that with: it is native in every browser, it
is the archival lossless standard, and its whole decode path is integer
arithmetic -- no transform, no float, no psychoacoustics.
FLAC is MSB-first (unlike DEFLATE/VP8L), so this composes onto
nx_bitstream_read_msb. Its residuals are Rice-coded, which nx_huffman.nx
already names as a sibling of its own family.
THE SIGN TRAP. Rice codes an unsigned value that must be UNFOLDED to signed
by zigzag: even -> +n/2, odd -> -(n+1)/2. Getting that backwards produces
audio that decodes without error and sounds like noise, because every
residual has the wrong sign but the right magnitude. There is no checksum
on the sample path that would catch it -- only the frame CRC, which many
decoders skip.
genealogy_id: flac_format_spec
lineage_id: nx_flac_v1
license_tier: ORIGINAL
dependencies 2 imports · 3 importers
imports: nx_syscalls.nxnx_bitstream.nx
imported by: nx_flac_frame.nxnx_flac_frame_gate.nxnx_flac_gate.nx
structs
| none |
consts
| 25 | const NX_MAGIC_1000000: i64 = 1000000 |
| 26 | const NX_MAGIC_88200: i64 = 88200 |
| 27 | const NX_MAGIC_176400: i64 = 176400 |
| 28 | const NX_MAGIC_192000: i64 = 192000 |
| 29 | const NX_MAGIC_8000: i64 = 8000 |
| 30 | const NX_MAGIC_16000: i64 = 16000 |
| 31 | const NX_MAGIC_22050: i64 = 22050 |
| 32 | const NX_MAGIC_24000: i64 = 24000 |
| 33 | const NX_MAGIC_32000: i64 = 32000 |
| 34 | const NX_MAGIC_44100: i64 = 44100 |
| 35 | const NX_MAGIC_48000: i64 = 48000 |
| 36 | const NX_MAGIC_96000: i64 = 96000 |
| 38 | const NX_FLAC_MAX_FIXED_ORDER: i64 = 4 |
| 39 | const NX_FLAC_SUB_CONSTANT: i64 = 0 |
| 40 | const NX_FLAC_SUB_VERBATIM: i64 = 1 |
| 41 | const NX_FLAC_SUB_FIXED: i64 = 2 |
| 42 | const NX_FLAC_SUB_LPC: i64 = 3 |
| 44 | const NX_FLAC_CH_INDEPENDENT: i64 = 0 |
| 45 | const NX_FLAC_CH_LEFT_SIDE: i64 = 1 |
| 46 | const NX_FLAC_CH_RIGHT_SIDE: i64 = 2 |
| 47 | const NX_FLAC_CH_MID_SIDE: i64 = 3 |
functions
| 54 | func nx_flac_unfold(v: i64) -> i64 |
| 59 | func nx_flac_fold(v: i64) -> i64 called by 1: main |
| 71 | func nx_flac_read_rice(bs: *NxBitStream, param: i64) -> i64 |
| 95 | func nx_flac_fixed_predict(order: i64, p1: i64, p2: i64, p3: i64, p4: i64) -> i64 |
| 106 | func nx_flac_restore_fixed(buf: *i64, n: i64, order: i64) -> i64 |
| 132 | func nx_flac_restore_lpc(buf: *i64, n: i64, order: i64, coef: *i64, shift: i64) -> i64 |
| 157 | func nx_flac_undo_stereo(a: *i64, b: *i64, n: i64, mode: i64) -> i64 called by 1: main |
| 185 | func nx_flac_block_size(code: i64) -> i64 |
| 194 | func nx_flac_sample_rate(code: i64) -> i64 |
| 211 | func nx_flac_bit_depth(code: i64) -> i64 |
| 228 | func nx_flac_crc8(data: *u8, n: i64) -> i64 |
| 249 | func nx_flac_is_stream(b: *u8, n: i64) -> i64 called by 1: main |