diff --git a/crates/ec-aac/src/sbr_qmf.rs b/crates/ec-aac/src/sbr_qmf.rs index a1c06315..0cae487f 100644 --- a/crates/ec-aac/src/sbr_qmf.rs +++ b/crates/ec-aac/src/sbr_qmf.rs @@ -31,67 +31,6 @@ pub const ANALYSIS_BANDS: usize = 32; /// Synthesis channel count (twice the core's, spanning the doubled band). pub const SYNTHESIS_BANDS: usize = 64; -/// The shared ISO/IEC 14496-3 4.6.18.4 64-band analysis core: `PROTO_LEN` -/// real history samples in (newest inserted last, matching PCM order), -/// `SYNTHESIS_BANDS` complex subbands out per slot of `SYNTHESIS_BANDS` new -/// samples. -struct QmfAnalysis64 { - hist: [f64; PROTO_LEN], - cos_tab: Vec, - sin_tab: Vec, -} - -impl QmfAnalysis64 { - fn new() -> QmfAnalysis64 { - let mut cos_tab = vec![0.0f64; SYNTHESIS_BANDS * 128]; - let mut sin_tab = vec![0.0f64; SYNTHESIS_BANDS * 128]; - for k in 0..SYNTHESIS_BANDS { - for n in 0..128 { - // X[k] = sum_n u[n] * exp(j*pi/128*(k+0.5)*(2n-1)) - let theta = std::f64::consts::PI / 128.0 - * (k as f64 + 0.5) - * (2.0 * n as f64 - 1.0); - cos_tab[k * 128 + n] = theta.cos(); - sin_tab[k * 128 + n] = theta.sin(); - } - } - QmfAnalysis64 { - hist: [0.0; PROTO_LEN], - cos_tab, - sin_tab, - } - } - - fn process_slot(&mut self, samples64: &[f64; SYNTHESIS_BANDS]) -> [Complex; SYNTHESIS_BANDS] { - for &s in samples64 { - self.hist.copy_within(0..PROTO_LEN - 1, 1); - self.hist[0] = s; - } - // Z[n] = x[n]*c[n], n=0..639; u[n] = sum_{j=0}^{4} Z[n+128j], n=0..127 - let mut u = [0.0f64; 128]; - for (n, uu) in u.iter_mut().enumerate() { - let mut acc = 0.0; - for j in 0..5 { - let idx = n + 128 * j; - acc += self.hist[idx] * QMF_WINDOW[idx]; - } - *uu = acc; - } - let mut out = [Complex::new(0.0, 0.0); SYNTHESIS_BANDS]; - for (k, slot) in out.iter_mut().enumerate() { - let row = k * 128; - let mut re = 0.0f64; - let mut im = 0.0f64; - for (n, &u_n) in u.iter().enumerate() { - re += u_n * self.cos_tab[row + n]; - im += u_n * self.sin_tab[row + n]; - } - *slot = Complex::new(re, im); - } - out - } -} - /// ISO/IEC 14496-3 4.6.18.4.1 32-band analysis: core PCM in (32 /// samples/slot), 32 complex subbands out, the decimated prototype `c[2n]` /// 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 { } } -/// The same [`QmfAnalysis64`] core run directly on already-doubled-rate -/// samples: doubled-rate PCM in, complex subband slots out, one slot per -/// [`SYNTHESIS_BANDS`] input samples. The decoder itself never runs this -- -/// it only ever synthesizes at this band count, from HF-generated subbands, -/// never analyzes a full-rate PCM signal back into them -- so this exists -/// for exact QMF-domain measurement only (round-46's third-witness -/// instrument): it lets a test read the reference decoder's and our own -/// already-decoded 44100Hz output straight into the same 64-band grid the -/// patch map's band indices are defined in, with no STFT-bin-width -/// approximation. -pub struct HfAnalysis { - core: QmfAnalysis64, -} - -impl HfAnalysis { - pub fn new() -> HfAnalysis { - HfAnalysis { - core: QmfAnalysis64::new(), - } - } - - /// Feeds exactly [`SYNTHESIS_BANDS`] new samples (oldest first, matching - /// PCM order) and returns the [`SYNTHESIS_BANDS`] complex subband - /// samples for this slot. - pub fn process_slot( - &mut self, - samples: &[f32; SYNTHESIS_BANDS], - ) -> [Complex; SYNTHESIS_BANDS] { - let mut x64 = [0.0f64; SYNTHESIS_BANDS]; - for (d, &s) in x64.iter_mut().zip(samples.iter()) { - *d = s as f64; - } - self.core.process_slot(&x64) - } -} - -impl Default for HfAnalysis { - fn default() -> HfAnalysis { - HfAnalysis::new() - } -} - pub struct Synthesis { bands: usize, v: Vec, @@ -474,29 +371,6 @@ mod tests { - #[allow(dead_code)] - /// Peak-bin frequency (cycles/sample, in `0.0..0.5`) of a real signal's - /// dominant spectral line: FFT magnitude over the whole window, biggest - /// positive-frequency bin. `signal.len()` must be a power of two. - fn dominant_freq(signal: &[f64]) -> f64 { - let n = signal.len(); - let mut fft = Fft::::new(n); - let mut spectrum: Vec> = - signal.iter().map(|&v| Complex::new(v, 0.0)).collect(); - fft.forward(&mut spectrum); - let mut best_bin = 1usize; - let mut best_mag = -1.0f64; - for (k, c) in spectrum.iter().enumerate().take(n / 2).skip(1) { - let mag = c.norm_sqr(); - if mag > best_mag { - best_mag = mag; - best_bin = k; - } - } - best_bin as f64 / n as f64 - } - - /// TASK 1(b) (round-35 SBR-HF-patch conviction): the actual patch /// operation -- analyze a real tone at a known offset from source band /// `p`'s own centre via [`Analysis`], copy that complex series straight diff --git a/crates/ec-aac/tests/oracle.rs b/crates/ec-aac/tests/it/oracle.rs similarity index 100% rename from crates/ec-aac/tests/oracle.rs rename to crates/ec-aac/tests/it/oracle.rs