edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiBe3a8adfTahinli3 months ago144 commits
| 1 | #!/usr/bin/env python3 |
| 2 | """Round-27: measures the reference decoder's ACTUAL SBR HF patch map (which |
| 3 | low QMF source band feeds which high target band), by isolating one source |
| 4 | band at a time and reading off which target bands carry power in the output. |
| 5 | |
| 6 | Method (one-band-at-a-time, simpler than a multi-line comb and avoids any |
| 7 | ambiguity from overlapping lines): the core spectrum for a probe frame is a |
| 8 | single isolated MDCT bin -- `tone_core()` in `sbrchirp.py`, already proven to |
| 9 | place value 2 in one 4-bin group and ZERO_HCB everywhere else -- at the first |
| 10 | bin of low QMF band `p` (`k = p*16`, always a group boundary since a QMF band |
| 11 | is 16 MDCT bins wide and a group is 4). Patching copies that source band's |
| 12 | complex QMF series verbatim (mixed by LPC/chirp, which round-19 already |
| 13 | measured as a <0.1% power effect regardless of `bs_invf_mode`) into every |
| 14 | target band any patch maps it to, so an FFT of the decoded output that finds |
| 15 | elevated power in target band `q` means "patch measured: source `p` -> target |
| 16 | `q`" directly, no fractional-offset bookkeeping needed. |
| 17 | |
| 18 | Runs the same probes through our own decoder via the `adts_to_pcm` example |
| 19 | (`cargo build -p ec-aac --example adts_to_pcm`) for the sanity cross-check the |
| 20 | charter requires: our measured map must equal `build_patches`' prediction, or |
| 21 | the fingerprint method itself is the thing that's broken. |
| 22 | """ |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | = |
| 30 | |
| 31 | |
| 32 | # noqa: E402 |
| 33 | # noqa: E402 |
| 34 | # noqa: E402 |
| 35 | # noqa: E402 |
| 36 | |
| 37 | = 7 |
| 38 | = 44100 |
| 39 | = |
| 40 | |
| 41 | |
| 42 | |
| 43 | """Python port of `build_patches` (crates/ec-aac/src/sbr_hf.rs), for |
| 44 | comparing the reference's measured map against our own prediction.""" |
| 45 | = |
| 46 | |
| 47 | return |
| 48 | , = , |
| 49 | |
| 50 | , = 0, |
| 51 | |
| 52 | = |
| 53 | |
| 54 | break |
| 55 | = - |
| 56 | |
| 57 | break |
| 58 | += |
| 59 | = |
| 60 | |
| 61 | = |
| 62 | = - |
| 63 | |
| 64 | += |
| 65 | = |
| 66 | return |
| 67 | |
| 68 | |
| 69 | |
| 70 | = |
| 71 | |
| 72 | |
| 73 | |
| 74 | return |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | return , // 4 |
| 81 | return None |
| 82 | |
| 83 | |
| 84 | |
| 85 | = |
| 86 | |
| 87 | |
| 88 | = |
| 89 | return , |
| 90 | |
| 91 | |
| 92 | |
| 93 | """`n_frames` FIXFIX/2-env amp_res=1 frames (round-19's engaging shape), |
| 94 | core = one isolated tone at low QMF band `active_p`'s first bin, held |
| 95 | fixed; envelope flat/loud, noise floor minimal, invf NONE, no harmonics.""" |
| 96 | = |
| 97 | = * 16 |
| 98 | = |
| 99 | assert is not None, f |
| 100 | , = |
| 101 | = |
| 102 | = |
| 103 | |
| 104 | = |
| 105 | |
| 106 | = |
| 107 | |
| 108 | = |
| 109 | |
| 110 | = // 8 |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | = |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | return |
| 125 | |
| 126 | |
| 127 | |
| 128 | = f |
| 129 | |
| 130 | |
| 131 | = |
| 132 | = |
| 133 | |
| 134 | return , |
| 135 | |
| 136 | |
| 137 | |
| 138 | """Power in each target band `q in [kx, k2)`, from a steady-state FFT |
| 139 | window (RATE/128 Hz per band, `n_fft=8192` gives ~5.4 Hz/bin -- fine |
| 140 | enough that a single active source band's line falls cleanly in one |
| 141 | band's bin range even without knowing its exact intra-band position).""" |
| 142 | = |
| 143 | |
| 144 | = |
| 145 | = ** 2 |
| 146 | = |
| 147 | = |
| 148 | |
| 149 | , = * / 128, * / 128 |
| 150 | = & |
| 151 | = |
| 152 | return |
| 153 | |
| 154 | |
| 155 | |
| 156 | """Bands whose power is at least `rel_threshold` of the loudest band's -- |
| 157 | the loudest is always the patch that actually fired, background/leakage |
| 158 | bands sit orders of magnitude lower.""" |
| 159 | |
| 160 | return |
| 161 | = |
| 162 | |
| 163 | return |
| 164 | return |
| 165 | |
| 166 | |
| 167 | |
| 168 | , = |
| 169 | assert is not None, f |
| 170 | , = , |
| 171 | |
| 172 | |
| 173 | = |
| 174 | |
| 175 | |
| 176 | , = , |
| 177 | |
| 178 | = |
| 179 | , = |
| 180 | , = |
| 181 | = |
| 182 | = |
| 183 | = |
| 184 | = |
| 185 | = |
| 186 | = |
| 187 | = |
| 188 | = |
| 189 | = |
| 190 | |
| 191 | |
| 192 | return , , , , |
| 193 | |
| 194 | |
| 195 | |
| 196 | assert , f |
| 197 | # Header A: the real file's ACTUAL SBR header, read straight off |
| 198 | # reeln's own bitstream via `EC_AAC_SBR_DEBUG=1` on our own decoder |
| 199 | # (start_freq=5 stop_freq=8 xover_band=0 freq_scale=2 alter_scale=1 |
| 200 | # noise_bands=2 -> kx=14 k2=43 n_q=3) -- NOT the `sbr_hf.rs` unit test's |
| 201 | # `real_file_tables()`, whose stop_freq/xover_band guess (3/2) was wrong |
| 202 | # and gives a different, smaller kx=16 k2=29 header. |
| 203 | |
| 204 | |
| 205 | # Headers B and C: different start/stop/xover -> differently-shaped |
| 206 | # kx/k2, to pin the algorithm's shape rather than one lucky header. |
| 207 | |
| 208 | |
| 209 | |
| 210 |