edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB24666c0Tahinli6 days ago3938 commits
| 1 | #!/usr/bin/env python3 |
| 2 | """Black-box probing rig for the SBR (HE-AAC v1) tool. WORK IN PROGRESS. |
| 3 | |
| 4 | Same method as the AAC tables: the vehicle is an ADTS access unit whose core is |
| 5 | an AAC-LC frame of exactly known bit length -- so the FIL element carrying the |
| 6 | SBR payload starts at a position we control -- followed by a FIL element holding |
| 7 | an sbr_extension_data built field by field. A reference decoder is the only |
| 8 | oracle. |
| 9 | |
| 10 | State, so a successor does not repeat the ground already covered: |
| 11 | |
| 12 | * The core writer is correct: `sce_core` frames decode clean at every max_sfb, |
| 13 | and the FIL length accounting is right (the reference decoder reads the |
| 14 | element without complaint about its framing). |
| 15 | * `sbr_header` is parsed by the reference decoder -- `start_freq=14` comes back |
| 16 | as "Invalid n_master: 0", which is a semantic complaint about a field it read, |
| 17 | not a framing one. |
| 18 | * `sbr_data` is NOT yet accepted: the decoder consumes 16 bits more than this |
| 19 | writer emits ("Expected to read 7 SBR bytes actually read 9"), constant across |
| 20 | start_freq, stop_freq and freq_res. The gap is most likely the envelope |
| 21 | Huffman reads for bands beyond the first, whose codebooks are still unknown -- |
| 22 | which is the bootstrap problem: only the first envelope value of a |
| 23 | frequency-delta frame is raw (6 or 7 bits), every later one is coded. |
| 24 | * The decoder reports the exact byte count its parser consumed, which is a |
| 25 | precise, cheap observable: that is the instrument to bootstrap the ten SBR |
| 26 | codebooks by the same prefix walk the AAC tables came from. |
| 27 | """ |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | = |
| 37 | = |
| 38 | |
| 39 | |
| 40 | |
| 41 | = |
| 42 | = |
| 43 | return |
| 44 | |
| 45 | |
| 46 | |
| 47 | = |
| 48 | = |
| 49 | return |
| 50 | |
| 51 | |
| 52 | = |
| 53 | = |
| 54 | = |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | = |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | return |
| 65 | |
| 66 | |
| 67 | |
| 68 | return |
| 69 | |
| 70 | |
| 71 | return |
| 72 | |
| 73 | |
| 74 | |
| 75 | = // 8 |
| 76 | = |
| 77 | = |
| 78 | |
| 79 | = 0 |
| 80 | |
| 81 | = | |
| 82 | |
| 83 | return |
| 84 | |
| 85 | |
| 86 | |
| 87 | = |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | return + |
| 93 | |
| 94 | |
| 95 | |
| 96 | = + 1 |
| 97 | = 0 |
| 98 | |
| 99 | = * + |
| 100 | return |
| 101 | |
| 102 | |
| 103 | |
| 104 | """A single_channel_element of exactly known length: codebook 3 throughout, |
| 105 | the same tuple in every position, so the bit cost is arithmetic.""" |
| 106 | = |
| 107 | = |
| 108 | # SCE, instance tag |
| 109 | |
| 110 | # ONLY_LONG, sine |
| 111 | # one section, codebook 3 |
| 112 | = |
| 113 | |
| 114 | |
| 115 | -= 31 |
| 116 | |
| 117 | |
| 118 | # delta 0 |
| 119 | # pulse / tns / gain-control absent |
| 120 | , = |
| 121 | = |
| 122 | |
| 123 | |
| 124 | |
| 125 | # positive |
| 126 | return |
| 127 | |
| 128 | |
| 129 | |
| 130 | """sbr_extension_data for one single channel element, from `cfg`.""" |
| 131 | = |
| 132 | # bs_header_flag |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | # bs_reserved |
| 138 | # bs_header_extra_1 |
| 139 | # bs_header_extra_2 |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | # sbr_single_channel_element |
| 148 | # bs_data_extra |
| 149 | # sbr_grid: FIXFIX with one envelope |
| 150 | # bs_frame_class = FIXFIX |
| 151 | # bs_num_env_raw -> num_env = 1 |
| 152 | |
| 153 | # sbr_dtdf |
| 154 | # bs_df_env[0] = frequency direction |
| 155 | # bs_df_noise[0] |
| 156 | # sbr_invf: one mode per noise band |
| 157 | |
| 158 | |
| 159 | # sbr_envelope: first value raw, the rest would need Huffman |
| 160 | |
| 161 | |
| 162 | |
| 163 | # sbr_noise: first value raw, the rest Huffman |
| 164 | |
| 165 | |
| 166 | |
| 167 | # bs_add_harmonic_flag |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | # bs_extended_data |
| 175 | return |
| 176 | |
| 177 | |
| 178 | |
| 179 | = |
| 180 | |
| 181 | = |
| 182 | # extension_type nibble plus the payload, padded to whole bytes |
| 183 | = 4 + |
| 184 | = // 8 |
| 185 | # FIL |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | = |
| 192 | # EXT_SBR_DATA |
| 193 | |
| 194 | |
| 195 | |
| 196 | # END |
| 197 | return |
| 198 | |
| 199 | |
| 200 | |
| 201 | = |
| 202 | |
| 203 | |
| 204 | |
| 205 | return |
| 206 | |
| 207 | |
| 208 | |
| 209 | """(samples, stderr) from ffmpeg for a stream of frames.""" |
| 210 | = f |
| 211 | |
| 212 | |
| 213 | = |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | return , |
| 219 | |
| 220 | |
| 221 | = |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | = |
| 229 | = + + |
| 230 | , = |
| 231 |