edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB6828b15Tahinli3 months ago393 commits
| 1 | #!/usr/bin/env python3 |
| 2 | """Black-box measurement of the reference decoder's HF-generator chirp |
| 3 | (bandwidth-expansion) factor per `bs_invf_mode`, and its frame-to-frame |
| 4 | smoothing rule. |
| 5 | |
| 6 | Method: a pure single-bin AAC-LC core spectrum (one isolated MDCT line, all |
| 7 | other lines silent via ZERO_HCB) puts an exact, noiseless sinusoid into one |
| 8 | low QMF subband. A single-tone AR(2) source has *exact* LPC coefficients |
| 9 | `a1 = 2*cos(w0), a2 = -1` (unit-radius poles) independent of estimation |
| 10 | method, so the SBR "inverse filter" recursion `y = residual + g*a1*y[-1] - |
| 11 | g^2*y[-2]` (residual ~= 0 once the source is a pure tone the predictor |
| 12 | already explains) collapses to an undriven damped oscillator whose envelope |
| 13 | decays geometrically as `g^n` per QMF slot -- `g` *is* the chirp factor |
| 14 | (pole radius), directly recoverable from the decay rate with no analysis of |
| 15 | our own decoder involved. |
| 16 | |
| 17 | STATUS (round-19): the round-18 non-engagement was `stream()`'s own recipe |
| 18 | shape, not a framing bug -- bisected field-by-field against a known-working |
| 19 | CPE probe (see project ledger) and isolated to TWO independent culprits, |
| 20 | either one sufficient alone to make the reference decoder's SBR gain stage |
| 21 | not engage (envelope amplitude and `bs_invf_mode` both become powerless, |
| 22 | `"No quantized data read for sbr_dequant."` fires either way -- that |
| 23 | message is a red herring, printed on this SCE probe shape regardless of |
| 24 | engagement, not diagnostic of it): |
| 25 | |
| 26 | 1. `bs_amp_res=0` (coarse, 7-bit raw envelope resolution). Sweeping the |
| 27 | full raw range (0..127) still gives <0.03% output-power change; fine |
| 28 | resolution (`bs_amp_res=1`, 6-bit raw) with the same header gives |
| 29 | three-to-four-orders-of-magnitude power swings for a mid-range raw |
| 30 | sweep (3 -> 60). Pure probe-construction quirk, not implicating our |
| 31 | parser/writer: real encoders emit both resolutions routinely and nothing |
| 32 | here says our AAC parser mishandles coarse-resolution streams -- it is |
| 33 | specifically *this reference build's* dequant path refusing these raw |
| 34 | values under `amp_res=0`, for a reason not chased further (plausibly an |
| 35 | offset/table-range mismatch in how this probe's raw codewords map, |
| 36 | unrelated to any of our own code). |
| 37 | 2. `bs_num_env=1` (FIXFIX single envelope). Independent of amp_res: even |
| 38 | requesting `amp_res=1` explicitly, a single-envelope frame still fails |
| 39 | to engage here. |
| 40 | |
| 41 | `stream()` below now uses the repaired shape: SCE, FIXFIX with `num_env=2`, |
| 42 | `amp_res=1`, envelope held constant across `bs_invf_mode` sweeps. Task 2 (a |
| 43 | four-level `bs_invf_mode` sweep plus a HIGH->NONE transition, `n_q=1` |
| 44 | narrow HF target) on this repaired instrument found only a ~0.1% output |
| 45 | power drift across all four levels and no resolvable flatness difference, |
| 46 | against a `BW_TABLE` that nominally spans `bw=0.0..0.98` -- STOP RULE |
| 47 | applies: fingerprints are indistinguishable on the working instrument, so |
| 48 | the bw-per-level hypothesis is refuted for this measurement and `sbr_hf.rs` |
| 49 | was left unchanged. (The HIGH->NONE transition run showed a >200x power |
| 50 | spike two frames from the stream's end; that coincides with the trailing |
| 51 | silence frame and reads as a decoder-side reset artifact of this probe's |
| 52 | framing, not a chirp-smoothing signal -- not chased further.) |
| 53 | """ |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | = |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | = 7 |
| 67 | = 44100 |
| 68 | |
| 69 | |
| 70 | |
| 71 | """SCE with one isolated MDCT line: `sfb_idx`'s `group_active`'th 4-tuple |
| 72 | group carries value 2 in its first line, everything else (all other |
| 73 | sfbs, and the other groups of `sfb_idx`) silent.""" |
| 74 | = |
| 75 | = + 1 |
| 76 | # SCE, instance tag |
| 77 | |
| 78 | |
| 79 | # section 1: ZERO_HCB over the leading silent sfbs |
| 80 | |
| 81 | = |
| 82 | |
| 83 | |
| 84 | -= 31 |
| 85 | |
| 86 | # section 2: codebook 3 over the one active sfb |
| 87 | |
| 88 | |
| 89 | # scalefactor delta 0 |
| 90 | # pulse/tns/gain-control absent -- MUST precede spectral_data() |
| 91 | # (round-28 fix: this write sat AFTER the spectral loop below, shifting |
| 92 | # every bit that followed and desyncing the reference decoder on every |
| 93 | # probed band -- byte-accounted against sce_core's proven field order.) |
| 94 | = // 4 |
| 95 | |
| 96 | = |
| 97 | , = |
| 98 | = |
| 99 | |
| 100 | |
| 101 | |
| 102 | return |
| 103 | |
| 104 | |
| 105 | = 29 # SWB_LONG[7][29:31] = [240, 260]: bins 240..260, QMF band 15 |
| 106 | = 0 # bin 240, QMF band [15*344.5, 16*344.5) Hz |
| 107 | = 30 # bins 0..260: covers source QMF band 15 (bins 240..256) broadband |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | """The already-verified codebook-3 comb pattern (`sce_core`, proven clean |
| 116 | at `max_sfb=30` above) -- strongly, stationarily correlated but not a |
| 117 | literal single MDCT bin, used as the resonant-content probe once the |
| 118 | isolated-tone encoding above turned out not to round-trip (HCB3 table |
| 119 | entries away from the exact tuple that earlier probes exercised are |
| 120 | unverified; not chased further here, broadband suffices for a fingerprint |
| 121 | test).""" |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | """`n_frames` FIXFIX/2-env, `amp_res=1` frames (the repaired, engaging |
| 127 | shape -- see module docstring), header on the first, `bs_invf_mode` |
| 128 | taken from `invf_seq[i]` (repeats last if shorter), envelope held fixed |
| 129 | across the sweep.""" |
| 130 | = |
| 131 | = |
| 132 | |
| 133 | = |
| 134 | = |
| 135 | |
| 136 | = |
| 137 | |
| 138 | = |
| 139 | |
| 140 | = // 8 |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | = |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | return |
| 155 | |
| 156 | |
| 157 | |
| 158 | return |
| 159 | |
| 160 | |
| 161 | |
| 162 | """Per-QMF-slot (32 samples at full SBR rate here since no dual-rate) |
| 163 | envelope of the isolated band via a Goertzel-style single-bin DFT swept |
| 164 | along the signal -- narrowband enough that only the target tone |
| 165 | contributes, since nothing else in the stream carries energy there.""" |
| 166 | = |
| 167 | = 32 |
| 168 | = / 2 |
| 169 | = 2 * * / |
| 170 | = |
| 171 | = |
| 172 | = |
| 173 | = |
| 174 | |
| 175 | = |
| 176 | = |
| 177 | = |
| 178 | |
| 179 | return |
| 180 | |
| 181 | |
| 182 | |
| 183 | """Geometric/arithmetic mean ratio of the power spectrum inside |
| 184 | `[lo_hz,hi_hz)`, in a steady-state window (`skip` frames of 1024 samples |
| 185 | dropped for transient). Near 1 = white/flat (bw~0, whitened residual); |
| 186 | near 0 = tonal/peaky (bw~1, resonance preserved).""" |
| 187 | = * 1024 |
| 188 | = |
| 189 | |
| 190 | = |
| 191 | = |
| 192 | = |
| 193 | = & |
| 194 | = ** 2 + 1e-24 |
| 195 | = |
| 196 | = |
| 197 | return / , |
| 198 | |
| 199 | |
| 200 | |
| 201 | , = |
| 202 | |
| 203 | |
| 204 | # kx=19, k2=23: target HF region is QMF bands [19,23) = [6546, 7924) Hz. |
| 205 | , = 19 * / 128, 23 * / 128 |
| 206 | , = 15 * / 128, 16 * / 128 |
| 207 | |
| 208 | |
| 209 | = |
| 210 | |
| 211 | = |
| 212 | |
| 213 | = |
| 214 | , = |
| 215 | |
| 216 | |
| 217 | , = |
| 218 | |
| 219 | = |
| 220 | |
| 221 | |
| 222 | = |
| 223 | , = |
| 224 | |
| 225 | , = |
| 226 | |
| 227 | |
| 228 |