Quiet Frame Decompress
EditDate | 2025-03-16 |
---|
Related Threads: FLAC Agent Build
Page created to understand how fLaC decompresses the 0 Quiet Frame so it can be incorporated into analAI
Key differences:
- Mid-side compression
Could well be the key
lossless transformation mid = (left + right)/2 and side = left − right.Web References https://www.reddit.com/r/audioengineering/comments/u2t2o4/questions about the way flac works relatively/
Issues:
- Warmup does not appear in wave or raw file which I don't understand as I get the same warmup values in analAI as FLaC seems to produce.
Seems I may have to include additional step for mid side channel de-correlation. lossless transformation mid = (left + right)/2 and side = left − right. [1]. One sure issue with this is the side channel requires an extra bit (25 vs 24) which might explain the missed warmup values but right now I don’t think so. Either way it needs to be fixed.
Instruction trace flac for analQuiet.flac
Skip metadata not pertinent [2]
Sync Frame
Line Number | Code Package | Module | Value | Opertion Description |
---|---|---|---|---|
1047 | SDC | Find Metadata | 0xFFF8 | FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC FFF8 |
1071 | SDC | stream decoder process | 0xFFF8 | FLAC__stream_decoder_process_until_end_of_stream |
2041 | SDC | read_frame | Unk | read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode) |
350 | BRC | FLAC__bitreader_reset_read_crc16 | Unk | (FLAC__BitReader *br, FLAC__uint16 seed) |
2277 | SDC | read_frame_header_ | Unk | read_frame_header_(FLAC__StreamDecoder *decoder)byte. |
381 | BDC | FLAC__bitreader_is_consumed_byte_aligned | 0 | (const FLAC__BitReader *br) |
2319 | SDC | read in the raw header as bytes so we can CRC it, and parse it on the way | if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) | |
418 | BDC | FLAC__bitreader_read_raw_uint32 | variables below | (FLAC__BitReader *br, FLAC__uint32 *val, uint32_t bits) |
Read Frame Sync Fixed Header Channel Side
Starting at 0x_1192 FFF8 C38C
& value 007F
- 0b_1111 1111 1111 10 Frame Header sync'. 14 bits
- 0b_0 mandatory 0 value Validation Bit 15
- 0b_0 0 = fixed blocking strategy Fixed Blocks or Not Bit 16
- 0b_1100 0x_C 12-8 = 4 so 2 to the 4th power = 16 time 256 = 4096 samples. ( 2358 SDC read frame header) frame blocksize
- 0b_0011 0x3 3 sample rate 192,000 ( 2379 SDC read frame header) samplerate'
- 0b1010 & 0b0111 = Case 2 FLAC__CHANNEL_ASSIGNMENT_MID_SIDE Channel Handling
- 0b110 = C 24 bits per sample bps
- 0b_0 Mandatory 0. Validation
32 bits consumed.
Variable | Decimal | Hex | Location Flac File |
---|---|---|---|
Bits | 8 | 8 | |
br->word | 0xfff8c3ac005e | 1192 | |
br->consumed_bits | 32 | 0x20 |
Read Frame Header
Line Number | Code Package | Module | Value | Opertion Description |
---|---|---|---|---|
2319 | SDC | read_frame_header_ | Variables Above | (FLAC__StreamDecoder *decoder) read in the raw header as bytes so we can CRC it, and parse it on the way |
420 | BDC | FLAC__bitreader_read_raw_uint32 | 0xC3 0xAC |
(FLAC__BitReader *br, FLAC__uint32 *val, uint32_t bits) |
2358 | SDC | read_frame_header_ | 0xC3 | frame.header.blocksize = 256 << (x-8) = 4098 =0x1000 (x = 0xC3 >> 4 = C = 12) |
2379 | SDC | read_frame_header_ | 0xC3 | case 3 x &0x0F (x=0xC3) frame.header.sample_rate = 192,000 |
2429 | SDC | read_frame_header_ | 0xAC | case 2 frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE; [3] |
2467 | SDC | read_frame_header_ | 0xAC | case 6 (x = (uint32_t)(raw_header[3] & 0x0e) >> 1) frame.header.bits_per_sample = 32; |
Read Subframe
Channel 0 Warmup
2082 | SDC | read_frame | NA | Allocate channels +1 bit for channel 1 in MID_SIDE |
2093 | SDC | read_frame | channel 0 then 1 bps 24 then 25 |
if(!read_subframe_(decoder, channel, bps, do_full_decode)) |
2600 | SDC | read_subframe_ | channel 0 then 1 bps 24 then 25 |
(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, FLAC__bool do_full_decode) |
2606 | SDC | read_subframe_ | x = 78 = 0x4E then x = 76 = 0x4c (returned values) |
FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8) |
2625 | SDC | read_subframe_ | channel 0 then 1 bps 24 then 25 |
decoder->private_->frame.subframes[channel].wasted_bits = 0; |
2666 | SDC | read_subframe_ | predictor_order = 8(chan 0) then 7(chan 1) | uint32_t predictor_order = ((x>>1)&31)+1 |
2672 | SDC | read_subframe_ | channel 0 then 1 bps 24 then 25 predictor_order = 8 |
if(!read_subframe_lpc_(decoder, channel, bps, predictor_order, do_full_decode)) |
2806 | SDC | read_subframe_lpc | channel 0 then 1 bps 24 then 25 order = 8 |
(FLAC__StreamDecoder *decoder, uint32_t channel, uint32_t bps, const uint32_t order, FLAC__bool do_full_decode) |
2821 | SDC | read_subframe_lpc | see warmup values below | FLAC__bitreader_read_raw_int64(decoder->private_->input, &i64, bps) |
Variable | Decimal | Hex | Location Flac File |
---|---|---|---|
Bits | 8 | 8 | |
br->word | 0x4e000000fffff200 | 1192 | |
br->consumed_bits | 0 | 0x20 |
Channel 0 Warmup Values
Below warmup channel 0 bps 24 order 8
Warmup Channel 0 bps 24
0 i64 FLAC__int64 0 0x0 1 i64 FLAC__int64 -14 0xfffffffffffffff2 2 i64 FLAC__int64 28 0x1c 3 i64 FLAC__int64 -2 0xfffffffffffffffe 4 i64 FLAC__int64 12 0xc 5 i64 FLAC__int64 37 0x25 6 i64 FLAC__int64 -12 0xfffffffffffffff4 7 i64 FLAC__int64 32 0x20 Little Endian Memory Dump 0000000000000000 F2FFFFFFFFFFFFFF 1C00000000000000 FEFFFFFFFFFFFFFF 0C00000000000000 2500000000000000 F4FFFFFFFFFFFFFF 2000000000000000
Memory Dump as Dump
From fLaC
00000000 00000000 F2FFFFFF FFFFFFFF 1C000000 00000000 FEFFFFFF FFFFFFFF 0C000000 00000000 25000000 00000000 F4FFFFFF FFFFFFFF 20000000 00000000
From analAI
00000000 00000000 F2FFFFFF FFFFFFFF 1C000000 00000000 FEFFFFFF FFFFFFFF 0C000000 00000000 25000000 00000000 F4FFFFFF FFFFFFFF 20000000 00000000
Channel 0 Coefficients
Entry
word 0x4e000000fffff200 at consumed bits 8 bits 24
2821 | SDC | read_subframe_lpc | See Warmup values above | FLAC__bitreader_read_raw_int64(decoder->private_->input, &i64, bps) |
2827 | SDC | read_subframe_lpc | u32 = 14 = 0xE | FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN=4 bits) |
2834 | SDC | read_subframe_lpc | qlp_coeff_precision = 15 = 0xF | subframe->qlp_coeff_precision = u32(14)+1; |
2837 | SDC | read_subframe_lpc | i32 = 13 =0xD | FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5 bits |
2844 | SDC | read_subframe_lpc | subframe->quantization_level = i32 = 13 = 0xD | subframe->quantization_level = i32; |
2850 | SDC | read_subframe_lpc | coefficient values below | FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision = 15 bits) |
Channel 0 Coefficient Values
Below coefficients channel 0 bps 15 order 8
Channel 0 Coefficients
0 i64 FLAC__int64 -5075 0xffffec2d 1 i64 FLAC__int64 9697 0x25e1 2 i64 FLAC__int64 11427 0x2ca3 3 i64 FLAC__int64 -2752 0xfffff540 4 i64 FLAC__int64 -10443 0xffffd735 5 i64 FLAC__int64 -3453 0xfffff283 6 i64 FLAC__int64 3865 0xf19 7 i64 FLAC__int64 2880 0xb40
Warmup Channel 1 bps 25 predictor_order 7
0 i64 FLAC__int64 0 0x0 1 i64 FLAC__int64 13 0xd 2 i64 FLAC__int64 4 0x4 3 i64 FLAC__int64 -13 0xfffffffffffffff3 4 i64 FLAC__int64 48 0x30 5 i64 FLAC__int64 -40 0xffffffffffffffd8 6 i64 FLAC__int64 48 0x30
After All Coefficients
Entry
word 0x5a8790c0df96e247 at 2440 flac file consumed bits 28 bits 4
2850 | SDC | read_subframe_lpc | coefficient values below | FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision = 15 bits) |
2854 | SDC | read_subframe_lpc | u32 = 0 | FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 4 ) |
2856 | SDC | read_subframe_lpc | u32 = 0 | subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32; |
2860 | SDC | read_subframe_lpc | u32 = 3 | FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4)) |
2868 | SDC | read_subframe_lpc | u32 = 3 | subframe->entropy_coding_method.data.partitioned_rice.order = u32; |
2869 | SDC | read_subframe_lpc | channel[1] | subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel]; |
2850 | SDC | read_subframe_lpc | coefficient values below | FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision = 15 bits) |
Edit To Here
2893 key where output for mid and side determine. need to find logic for converting mid and side to Left Right
M = (L + R)/2 S = L - R
FFFFFFF2 -14 and 0x0D 13 give us FFFFFFF9 -7 FFFFFFEC -20
R = M - S/2 | L = M + S/2 |
---|---|
S = L - R | M = (L + R)/2 |
S + R = L | M = L/2 + R/2 |
R = L - S | M - R/2 = L/2 |
L/2 = M - R/2 | |
L = 2M - R | |
Replace R on L Side | |
L = 2M - (L - S) | |
2L = 2M + S | |
L = M + S/2 | |
Replace L | |
R = M + S/2 -S | |
R = M - S/2 |
L = M + S/2 -7 = -14 + (13%2) 7 R = M - S/2 -20 = -14 - (13%2) 6
References
- ↑ https://www.reddit.com/r/audioengineering/comments/u2t2o4/questions_about_the_way_flac_works_relatively/
- ↑ (see FLAC Agent Build for metadata. Assuming equivalent in pertinent details.
- ↑ reddit link