U10: ec-aac sbr_qmf delete dead 64-band analysis structs (QmfAnalysis64, HfAnalysis) and the test-only dominant_freq helper with its stale allow
Browse files at this commitf4b503fde8f4e27a27197fc8c0bedb3108169f7bParent: 2fb2a9c2 changed files +0 -126
- crates/ec-aac/src/sbr_qmf.rs +0 -126
- crates/ec-aac/tests/oracle.rs → crates/ec-aac/tests/it/oracle.rs +0 -0
crates/ec-aac/src/sbr_qmf.rsmodified+0 -126
| @@ -31,67 +31,6 @@ pub const ANALYSIS_BANDS: usize = 32; | ||
| 31 | 31 | /// Synthesis channel count (twice the core's, spanning the doubled band). |
| 32 | 32 | pub const SYNTHESIS_BANDS: usize = 64; |
| 33 | 33 | |
| 34 | -/// The shared ISO/IEC 14496-3 4.6.18.4 64-band analysis core: `PROTO_LEN` | |
| 35 | -/// real history samples in (newest inserted last, matching PCM order), | |
| 36 | -/// `SYNTHESIS_BANDS` complex subbands out per slot of `SYNTHESIS_BANDS` new | |
| 37 | -/// samples. | |
| 38 | -struct QmfAnalysis64 { | |
| 39 | - hist: [f64; PROTO_LEN], | |
| 40 | - cos_tab: Vec<f64>, | |
| 41 | - sin_tab: Vec<f64>, | |
| 42 | -} | |
| 43 | - | |
| 44 | -impl QmfAnalysis64 { | |
| 45 | - fn new() -> QmfAnalysis64 { | |
| 46 | - let mut cos_tab = vec![0.0f64; SYNTHESIS_BANDS * 128]; | |
| 47 | - let mut sin_tab = vec![0.0f64; SYNTHESIS_BANDS * 128]; | |
| 48 | - for k in 0..SYNTHESIS_BANDS { | |
| 49 | - for n in 0..128 { | |
| 50 | - // X[k] = sum_n u[n] * exp(j*pi/128*(k+0.5)*(2n-1)) | |
| 51 | - let theta = std::f64::consts::PI / 128.0 | |
| 52 | - * (k as f64 + 0.5) | |
| 53 | - * (2.0 * n as f64 - 1.0); | |
| 54 | - cos_tab[k * 128 + n] = theta.cos(); | |
| 55 | - sin_tab[k * 128 + n] = theta.sin(); | |
| 56 | - } | |
| 57 | - } | |
| 58 | - QmfAnalysis64 { | |
| 59 | - hist: [0.0; PROTO_LEN], | |
| 60 | - cos_tab, | |
| 61 | - sin_tab, | |
| 62 | - } | |
| 63 | - } | |
| 64 | - | |
| 65 | - fn process_slot(&mut self, samples64: &[f64; SYNTHESIS_BANDS]) -> [Complex<f64>; SYNTHESIS_BANDS] { | |
| 66 | - for &s in samples64 { | |
| 67 | - self.hist.copy_within(0..PROTO_LEN - 1, 1); | |
| 68 | - self.hist[0] = s; | |
| 69 | - } | |
| 70 | - // Z[n] = x[n]*c[n], n=0..639; u[n] = sum_{j=0}^{4} Z[n+128j], n=0..127 | |
| 71 | - let mut u = [0.0f64; 128]; | |
| 72 | - for (n, uu) in u.iter_mut().enumerate() { | |
| 73 | - let mut acc = 0.0; | |
| 74 | - for j in 0..5 { | |
| 75 | - let idx = n + 128 * j; | |
| 76 | - acc += self.hist[idx] * QMF_WINDOW[idx]; | |
| 77 | - } | |
| 78 | - *uu = acc; | |
| 79 | - } | |
| 80 | - let mut out = [Complex::new(0.0, 0.0); SYNTHESIS_BANDS]; | |
| 81 | - for (k, slot) in out.iter_mut().enumerate() { | |
| 82 | - let row = k * 128; | |
| 83 | - let mut re = 0.0f64; | |
| 84 | - let mut im = 0.0f64; | |
| 85 | - for (n, &u_n) in u.iter().enumerate() { | |
| 86 | - re += u_n * self.cos_tab[row + n]; | |
| 87 | - im += u_n * self.sin_tab[row + n]; | |
| 88 | - } | |
| 89 | - *slot = Complex::new(re, im); | |
| 90 | - } | |
| 91 | - out | |
| 92 | - } | |
| 93 | -} | |
| 94 | - | |
| 95 | 34 | /// ISO/IEC 14496-3 4.6.18.4.1 32-band analysis: core PCM in (32 |
| 96 | 35 | /// samples/slot), 32 complex subbands out, the decimated prototype `c[2n]` |
| 97 | 36 | /// over a 320-sample history and carrier `exp(j*pi/64*(k+0.5)*(2n-0.5))` |
| @@ -176,48 +115,6 @@ impl Default for Analysis { | ||
| 176 | 115 | } |
| 177 | 116 | } |
| 178 | 117 | |
| 179 | -/// The same [`QmfAnalysis64`] core run directly on already-doubled-rate | |
| 180 | -/// samples: doubled-rate PCM in, complex subband slots out, one slot per | |
| 181 | -/// [`SYNTHESIS_BANDS`] input samples. The decoder itself never runs this -- | |
| 182 | -/// it only ever synthesizes at this band count, from HF-generated subbands, | |
| 183 | -/// never analyzes a full-rate PCM signal back into them -- so this exists | |
| 184 | -/// for exact QMF-domain measurement only (round-46's third-witness | |
| 185 | -/// instrument): it lets a test read the reference decoder's and our own | |
| 186 | -/// already-decoded 44100Hz output straight into the same 64-band grid the | |
| 187 | -/// patch map's band indices are defined in, with no STFT-bin-width | |
| 188 | -/// approximation. | |
| 189 | -pub struct HfAnalysis { | |
| 190 | - core: QmfAnalysis64, | |
| 191 | -} | |
| 192 | - | |
| 193 | -impl HfAnalysis { | |
| 194 | - pub fn new() -> HfAnalysis { | |
| 195 | - HfAnalysis { | |
| 196 | - core: QmfAnalysis64::new(), | |
| 197 | - } | |
| 198 | - } | |
| 199 | - | |
| 200 | - /// Feeds exactly [`SYNTHESIS_BANDS`] new samples (oldest first, matching | |
| 201 | - /// PCM order) and returns the [`SYNTHESIS_BANDS`] complex subband | |
| 202 | - /// samples for this slot. | |
| 203 | - pub fn process_slot( | |
| 204 | - &mut self, | |
| 205 | - samples: &[f32; SYNTHESIS_BANDS], | |
| 206 | - ) -> [Complex<f64>; SYNTHESIS_BANDS] { | |
| 207 | - let mut x64 = [0.0f64; SYNTHESIS_BANDS]; | |
| 208 | - for (d, &s) in x64.iter_mut().zip(samples.iter()) { | |
| 209 | - *d = s as f64; | |
| 210 | - } | |
| 211 | - self.core.process_slot(&x64) | |
| 212 | - } | |
| 213 | -} | |
| 214 | - | |
| 215 | -impl Default for HfAnalysis { | |
| 216 | - fn default() -> HfAnalysis { | |
| 217 | - HfAnalysis::new() | |
| 218 | - } | |
| 219 | -} | |
| 220 | - | |
| 221 | 118 | pub struct Synthesis { |
| 222 | 119 | bands: usize, |
| 223 | 120 | v: Vec<f64>, |
| @@ -474,29 +371,6 @@ mod tests { | ||
| 474 | 371 | |
| 475 | 372 | |
| 476 | 373 | |
| 477 | - #[allow(dead_code)] | |
| 478 | - /// Peak-bin frequency (cycles/sample, in `0.0..0.5`) of a real signal's | |
| 479 | - /// dominant spectral line: FFT magnitude over the whole window, biggest | |
| 480 | - /// positive-frequency bin. `signal.len()` must be a power of two. | |
| 481 | - fn dominant_freq(signal: &[f64]) -> f64 { | |
| 482 | - let n = signal.len(); | |
| 483 | - let mut fft = Fft::<f64>::new(n); | |
| 484 | - let mut spectrum: Vec<Complex<f64>> = | |
| 485 | - signal.iter().map(|&v| Complex::new(v, 0.0)).collect(); | |
| 486 | - fft.forward(&mut spectrum); | |
| 487 | - let mut best_bin = 1usize; | |
| 488 | - let mut best_mag = -1.0f64; | |
| 489 | - for (k, c) in spectrum.iter().enumerate().take(n / 2).skip(1) { | |
| 490 | - let mag = c.norm_sqr(); | |
| 491 | - if mag > best_mag { | |
| 492 | - best_mag = mag; | |
| 493 | - best_bin = k; | |
| 494 | - } | |
| 495 | - } | |
| 496 | - best_bin as f64 / n as f64 | |
| 497 | - } | |
| 498 | - | |
| 499 | - | |
| 500 | 374 | /// TASK 1(b) (round-35 SBR-HF-patch conviction): the actual patch |
| 501 | 375 | /// operation -- analyze a real tone at a known offset from source band |
| 502 | 376 | /// `p`'s own centre via [`Analysis`], copy that complex series straight |
crates/ec-aac/tests/oracle.rs → crates/ec-aac/tests/it/oracle.rsrenamed+0 -0