U10: ec-aac remove knobs module and diagnostic side-info/noise-fraction logs and their env switches (defaults unchanged; output bits unchanged)
Browse files at this commit6c331af1f112e445f4e7ba25ab39531b85ca172eParent: 7b6a4e66 changed files +5 -539
- crates/ec-aac/src/decode.rs +0 -89
- crates/ec-aac/src/knobs.rs +0 -104
- crates/ec-aac/src/lib.rs +1 -10
- crates/ec-aac/src/sbr_chain.rs +2 -261
- crates/ec-aac/src/sbr_env.rs +2 -74
- crates/ec-aac/tests/it/main.rs +0 -1
crates/ec-aac/src/decode.rsmodified+0 -89
| @@ -59,52 +59,6 @@ impl WindowSequence { | ||
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | -/// One `raw_data_block` element's coding-tool usage, gated by | |
| 63 | -/// `EC_AAC_TOOL_SIDEINFO_DEBUG` -- mirrors `sbr_chain::SbrSideInfoRow`'s | |
| 64 | -/// pattern for the LC core, so a real file's PNS/M-S/IS/TNS mix can be read | |
| 65 | -/// back per AU without re-parsing debug text. | |
| 66 | -#[derive(Clone, Debug)] | |
| 67 | -pub struct ToolSideInfoRow { | |
| 68 | - pub au: usize, | |
| 69 | - pub tag: u8, | |
| 70 | - pub is_cpe: bool, | |
| 71 | - pub window_sequence: WindowSequence, | |
| 72 | - pub ms_bands: usize, | |
| 73 | - pub pns_bands: usize, | |
| 74 | - pub is_bands: usize, | |
| 75 | - pub tns_present: bool, | |
| 76 | -} | |
| 77 | - | |
| 78 | -static TOOL_SIDEINFO_LOG: std::sync::OnceLock<std::sync::Mutex<Vec<ToolSideInfoRow>>> = | |
| 79 | - std::sync::OnceLock::new(); | |
| 80 | -static TOOL_SIDEINFO_AU: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | |
| 81 | - | |
| 82 | -fn tool_sideinfo_enabled() -> bool { | |
| 83 | - crate::knobs::tool_sideinfo_debug() | |
| 84 | -} | |
| 85 | - | |
| 86 | -fn log_tool_sideinfo(row: ToolSideInfoRow) { | |
| 87 | - let log = TOOL_SIDEINFO_LOG.get_or_init(|| std::sync::Mutex::new(Vec::new())); | |
| 88 | - if let Ok(mut l) = log.lock() { | |
| 89 | - l.push(row); | |
| 90 | - } | |
| 91 | -} | |
| 92 | - | |
| 93 | -/// Bumps the shared AU counter once per `raw_data_block`, returning the value | |
| 94 | -/// that call's rows should carry. | |
| 95 | -fn next_tool_sideinfo_au() -> usize { | |
| 96 | - TOOL_SIDEINFO_AU.fetch_add(1, std::sync::atomic::Ordering::Relaxed) | |
| 97 | -} | |
| 98 | - | |
| 99 | -/// Every row logged so far this process, in call order. Empty unless | |
| 100 | -/// `EC_AAC_TOOL_SIDEINFO_DEBUG` was set before decoding. | |
| 101 | -pub fn tool_sideinfo_log() -> Vec<ToolSideInfoRow> { | |
| 102 | - let Some(log) = TOOL_SIDEINFO_LOG.get() else { | |
| 103 | - return Vec::new(); | |
| 104 | - }; | |
| 105 | - log.lock().map(|l| l.clone()).unwrap_or_default() | |
| 106 | -} | |
| 107 | - | |
| 108 | 62 | /// `ics_info` (§4.4.2.1) plus the grouping it implies. |
| 109 | 63 | #[derive(Clone, Debug)] |
| 110 | 64 | pub struct IcsInfo { |
| @@ -845,12 +799,6 @@ impl BlockDecoder { | ||
| 845 | 799 | // FIL's SBR payload would apply to, per §4.5.1: a fill_element |
| 846 | 800 | // directly follows the element it decorates. |
| 847 | 801 | let mut pending: Option<(u8, usize, usize, bool)> = None; |
| 848 | - let dump_tools = tool_sideinfo_enabled(); | |
| 849 | - let au = if dump_tools { | |
| 850 | - next_tool_sideinfo_au() | |
| 851 | - } else { | |
| 852 | - 0 | |
| 853 | - }; | |
| 854 | 802 | let mut pns = false; |
| 855 | 803 | // Speaker per plane so far; `named` drops to false at the first element a PCE does not name. |
| 856 | 804 | let mut speakers: Vec<crate::config::Speaker> = Vec::new(); |
| @@ -869,9 +817,6 @@ impl BlockDecoder { | ||
| 869 | 817 | let start = out.len(); |
| 870 | 818 | let mut ch = [self.channel_stream(r, None)?]; |
| 871 | 819 | pns |= has_pns(&ch[0]); |
| 872 | - if dump_tools { | |
| 873 | - log_tool_sideinfo(tool_row(au, tag, false, &ch[0], None)); | |
| 874 | - } | |
| 875 | 820 | self.finish(&mut ch, None, &mut out); |
| 876 | 821 | if let (3, Some(sbr), Some(plane)) = (id, self.sbr.as_mut(), out.get_mut(start)) { |
| 877 | 822 | sbr.bypass_plane(tag, plane); |
| @@ -919,9 +864,6 @@ impl BlockDecoder { | ||
| 919 | 864 | self.channel_stream(r, shared.as_ref())?, |
| 920 | 865 | ]; |
| 921 | 866 | pns |= pair.iter().any(has_pns); |
| 922 | - if dump_tools { | |
| 923 | - log_tool_sideinfo(tool_row(au, tag, true, &pair[0], Some(&mask))); | |
| 924 | - } | |
| 925 | 867 | self.finish(&mut pair, Some(&mask), &mut out); |
| 926 | 868 | named &= self.note_speakers(1, tag, 2, &mut speakers); |
| 927 | 869 | pending = Some((tag, start, 2, true)); |
| @@ -1193,43 +1135,12 @@ fn apply_ms(left: &mut Ics, right: &mut Ics, mask: &MsMask) { | ||
| 1193 | 1135 | } |
| 1194 | 1136 | } |
| 1195 | 1137 | |
| 1196 | -/// Builds one `EC_AAC_TOOL_SIDEINFO_DEBUG` row from an already-decoded `Ics` | |
| 1197 | -/// (any channel of a CPE, since PNS/IS/TNS presence is per-channel but the | |
| 1198 | -/// dump only needs whether the element used the tool at all). | |
| 1199 | 1138 | fn has_pns(ch: &Ics) -> bool { |
| 1200 | 1139 | ch.cb |
| 1201 | 1140 | .iter() |
| 1202 | 1141 | .any(|group| group.contains(&NOISE_HCB)) |
| 1203 | 1142 | } |
| 1204 | 1143 | |
| 1205 | -fn tool_row(au: usize, tag: u8, is_cpe: bool, ch: &Ics, mask: Option<&MsMask>) -> ToolSideInfoRow { | |
| 1206 | - let mut ms_bands = 0; | |
| 1207 | - let mut pns_bands = 0; | |
| 1208 | - let mut is_bands = 0; | |
| 1209 | - for g in 0..ch.ics.num_groups { | |
| 1210 | - for sfb in 0..ch.ics.max_sfb { | |
| 1211 | - if mask.is_some_and(|m| m.used(g, sfb)) { | |
| 1212 | - ms_bands += 1; | |
| 1213 | - } | |
| 1214 | - match ch.cb[g][sfb] { | |
| 1215 | - NOISE_HCB => pns_bands += 1, | |
| 1216 | - INTENSITY_HCB | INTENSITY_HCB2 => is_bands += 1, | |
| 1217 | - _ => {} | |
| 1218 | - } | |
| 1219 | - } | |
| 1220 | - } | |
| 1221 | - ToolSideInfoRow { | |
| 1222 | - au, | |
| 1223 | - tag, | |
| 1224 | - is_cpe, | |
| 1225 | - window_sequence: ch.ics.window_sequence, | |
| 1226 | - ms_bands, | |
| 1227 | - pns_bands, | |
| 1228 | - is_bands, | |
| 1229 | - tns_present: !ch.tns.filters.is_empty(), | |
| 1230 | - } | |
| 1231 | -} | |
| 1232 | - | |
| 1233 | 1144 | fn is_intensity(cb: u8) -> bool { |
| 1234 | 1145 | cb == INTENSITY_HCB || cb == INTENSITY_HCB2 |
| 1235 | 1146 | } |
crates/ec-aac/src/knobs.rsdeleted+0 -104
| @@ -1,104 +0,0 @@ | ||
| 1 | -//! Debug switches the AAC/SBR decoder reads from the environment, with a | |
| 2 | -//! per-thread override that tests set instead of editing the process | |
| 3 | -//! environment (which is `unsafe` in Rust 2024). | |
| 4 | -//! | |
| 5 | -//! The decoder reads these on the thread that calls `decode`, so an override | |
| 6 | -//! set on a test's own thread covers exactly that test's decodes and nothing | |
| 7 | -//! running in parallel. With no override set, each reader answers from the | |
| 8 | -//! environment exactly as it always has, so manual runs with `EC_AAC_*` set | |
| 9 | -//! behave as before. | |
| 10 | - | |
| 11 | -use std::cell::Cell; | |
| 12 | -use std::thread::LocalKey; | |
| 13 | - | |
| 14 | -type Slot = Cell<Option<bool>>; | |
| 15 | - | |
| 16 | -thread_local! { | |
| 17 | - static TOOL_SIDEINFO_DEBUG: Slot = const { Cell::new(None) }; | |
| 18 | - static SBR_SIDEINFO_DEBUG: Slot = const { Cell::new(None) }; | |
| 19 | - static SBR_HF_BYPASS: Slot = const { Cell::new(None) }; | |
| 20 | - static SBR_NOISE_ZERO: Slot = const { Cell::new(None) }; | |
| 21 | - static SBR_NOISE_FRACTION: Slot = const { Cell::new(None) }; | |
| 22 | -} | |
| 23 | - | |
| 24 | -/// The override on this thread if one is set, else whether `var` is set. | |
| 25 | -fn enabled(slot: &'static LocalKey<Slot>, var: &str) -> bool { | |
| 26 | - slot.with(Cell::get) | |
| 27 | - .unwrap_or_else(|| std::env::var(var).is_ok()) | |
| 28 | -} | |
| 29 | - | |
| 30 | -fn force(slot: &'static LocalKey<Slot>, on: Option<bool>) -> Override<Option<bool>> { | |
| 31 | - let prev = slot.with(|c| c.replace(on)); | |
| 32 | - Override { slot, prev } | |
| 33 | -} | |
| 34 | - | |
| 35 | -/// Restores the value a knob had before [`set_tool_sideinfo_debug`] and its | |
| 36 | -/// siblings were called, when dropped. | |
| 37 | -#[doc(hidden)] | |
| 38 | -#[must_use = "the override ends as soon as this guard is dropped"] | |
| 39 | -pub struct Override<T: Copy + 'static> { | |
| 40 | - slot: &'static LocalKey<Cell<T>>, | |
| 41 | - prev: T, | |
| 42 | -} | |
| 43 | - | |
| 44 | -impl<T: Copy + 'static> Drop for Override<T> { | |
| 45 | - fn drop(&mut self) { | |
| 46 | - self.slot.with(|c| c.set(self.prev)); | |
| 47 | - } | |
| 48 | -} | |
| 49 | - | |
| 50 | -/// `EC_AAC_TOOL_SIDEINFO_DEBUG`. | |
| 51 | -pub(crate) fn tool_sideinfo_debug() -> bool { | |
| 52 | - enabled(&TOOL_SIDEINFO_DEBUG, "EC_AAC_TOOL_SIDEINFO_DEBUG") | |
| 53 | -} | |
| 54 | - | |
| 55 | -/// `EC_AAC_SBR_SIDEINFO_DEBUG`. | |
| 56 | -pub(crate) fn sbr_sideinfo_debug() -> bool { | |
| 57 | - enabled(&SBR_SIDEINFO_DEBUG, "EC_AAC_SBR_SIDEINFO_DEBUG") | |
| 58 | -} | |
| 59 | - | |
| 60 | -/// `EC_AAC_SBR_HF_BYPASS`. | |
| 61 | -pub(crate) fn sbr_hf_bypass() -> bool { | |
| 62 | - enabled(&SBR_HF_BYPASS, "EC_AAC_SBR_HF_BYPASS") | |
| 63 | -} | |
| 64 | - | |
| 65 | -/// `EC_AAC_SBR_NOISE_ZERO`. | |
| 66 | -pub(crate) fn sbr_noise_zero() -> bool { | |
| 67 | - enabled(&SBR_NOISE_ZERO, "EC_AAC_SBR_NOISE_ZERO") | |
| 68 | -} | |
| 69 | - | |
| 70 | -/// `EC_AAC_SBR_NOISE_FRACTION`. | |
| 71 | -pub(crate) fn sbr_noise_fraction() -> bool { | |
| 72 | - enabled(&SBR_NOISE_FRACTION, "EC_AAC_SBR_NOISE_FRACTION") | |
| 73 | -} | |
| 74 | - | |
| 75 | -/// Forces `EC_AAC_TOOL_SIDEINFO_DEBUG` on (`Some(true)`), off (`Some(false)`) | |
| 76 | -/// or back to the environment (`None`) on this thread, until the guard drops. | |
| 77 | -#[doc(hidden)] | |
| 78 | -pub fn set_tool_sideinfo_debug(on: Option<bool>) -> Override<Option<bool>> { | |
| 79 | - force(&TOOL_SIDEINFO_DEBUG, on) | |
| 80 | -} | |
| 81 | - | |
| 82 | -/// [`set_tool_sideinfo_debug`] for `EC_AAC_SBR_SIDEINFO_DEBUG`. | |
| 83 | -#[doc(hidden)] | |
| 84 | -pub fn set_sbr_sideinfo_debug(on: Option<bool>) -> Override<Option<bool>> { | |
| 85 | - force(&SBR_SIDEINFO_DEBUG, on) | |
| 86 | -} | |
| 87 | - | |
| 88 | -/// [`set_tool_sideinfo_debug`] for `EC_AAC_SBR_HF_BYPASS`. | |
| 89 | -#[doc(hidden)] | |
| 90 | -pub fn set_sbr_hf_bypass(on: Option<bool>) -> Override<Option<bool>> { | |
| 91 | - force(&SBR_HF_BYPASS, on) | |
| 92 | -} | |
| 93 | - | |
| 94 | -/// [`set_tool_sideinfo_debug`] for `EC_AAC_SBR_NOISE_ZERO`. | |
| 95 | -#[doc(hidden)] | |
| 96 | -pub fn set_sbr_noise_zero(on: Option<bool>) -> Override<Option<bool>> { | |
| 97 | - force(&SBR_NOISE_ZERO, on) | |
| 98 | -} | |
| 99 | - | |
| 100 | -/// [`set_tool_sideinfo_debug`] for `EC_AAC_SBR_NOISE_FRACTION`. | |
| 101 | -#[doc(hidden)] | |
| 102 | -pub fn set_sbr_noise_fraction(on: Option<bool>) -> Override<Option<bool>> { | |
| 103 | - force(&SBR_NOISE_FRACTION, on) | |
| 104 | -} |
crates/ec-aac/src/lib.rsmodified+1 -10
| @@ -42,8 +42,6 @@ mod ps_dsp; | ||
| 42 | 42 | mod ps_huff; |
| 43 | 43 | mod sbr_tables; |
| 44 | 44 | pub mod tables; |
| 45 | -#[doc(hidden)] | |
| 46 | -pub mod knobs; | |
| 47 | 45 | |
| 48 | 46 | pub use config::{ |
| 49 | 47 | AOT_AAC_LC, AOT_PS, AOT_SBR, AdtsHeader, AudioSpecificConfig, ProgramConfig, |
| @@ -51,16 +49,9 @@ pub use config::{ | ||
| 51 | 49 | parse_audio_specific_config, parse_program_config, sample_rate_for_index, sf_index_for_rate, |
| 52 | 50 | write_adts_header, write_audio_specific_config, |
| 53 | 51 | }; |
| 54 | -pub use decode::{FRAME_LEN, ToolSideInfoRow, WindowSequence, tool_sideinfo_log}; | |
| 52 | +pub use decode::{FRAME_LEN, WindowSequence}; | |
| 55 | 53 | pub use ec_core::{Error, Result}; |
| 56 | 54 | pub use encode::{AacEncoder, AacEncoderConfig, EncodedPacket, WindowShape}; |
| 57 | -/// Diagnostic only (round-20): per-(access-unit, channel) side-info rows | |
| 58 | -/// logged during decode when `EC_AAC_SBR_SIDEINFO_DEBUG` is set. | |
| 59 | -pub use sbr_chain::{SbrSideInfoRow, hold_call_count, sbr_sideinfo_log}; | |
| 60 | -/// Diagnostic only (round-17 Task 1 conviction check): reads back the | |
| 61 | -/// per-absolute-QMF-band transmitted signal/noise energy sums | |
| 62 | -/// `EC_AAC_SBR_NOISE_FRACTION_DEBUG` accumulates during decode. | |
| 63 | -pub use sbr_env::noise_fraction_table; | |
| 64 | 55 | pub use tables::SAMPLE_RATES; |
| 65 | 56 | |
| 66 | 57 | use decode::BlockDecoder; |
crates/ec-aac/src/sbr_chain.rsmodified+2 -261
| @@ -13,168 +13,12 @@ use crate::sbr_qmf::{ANALYSIS_BANDS, Analysis, SYNTHESIS_BANDS, Synthesis}; | ||
| 13 | 13 | use ec_core::BitReader; |
| 14 | 14 | use ec_dsp::Complex; |
| 15 | 15 | use std::collections::HashMap; |
| 16 | -use std::sync::atomic::{AtomicUsize, Ordering}; | |
| 17 | - | |
| 18 | -/// Debug: dumps parsed grid/header/e_q/q_q values for the first 20 frames | |
| 19 | -/// per channel when `EC_AAC_SBR_DEBUG` is set (diagnostic only, gated). | |
| 20 | -fn debug_dump( | |
| 21 | - header: &crate::sbr_payload::SbrHeader, | |
| 22 | - tables: &crate::sbr_bands::BandTables, | |
| 23 | - ch: &SbrChannel, | |
| 24 | - ch_idx: usize, | |
| 25 | -) { | |
| 26 | - static COUNT: AtomicUsize = AtomicUsize::new(0); | |
| 27 | - let n = COUNT.fetch_add(1, Ordering::Relaxed); | |
| 28 | - if n >= 20 { | |
| 29 | - return; | |
| 30 | - } | |
| 31 | - eprintln!( | |
| 32 | - "SBRDBG frame {n} ch{ch_idx}: amp_res={} kx={} k2={} n_low={} n_high={} n_q={} t_env={:?} freq_res={:?} t_noise={:?} f_high={:?} patches={:?}", | |
| 33 | - header.amp_res, | |
| 34 | - tables.kx, | |
| 35 | - tables.k2, | |
| 36 | - tables.n_low, | |
| 37 | - tables.n_high, | |
| 38 | - tables.n_q, | |
| 39 | - ch.t_env, | |
| 40 | - ch.freq_res, | |
| 41 | - ch.t_noise, | |
| 42 | - tables.f_high, | |
| 43 | - crate::sbr_hf::build_patches(tables), | |
| 44 | - ); | |
| 45 | - for (i, row) in ch.e_q.iter().enumerate() { | |
| 46 | - let (mn, mx) = row | |
| 47 | - .iter() | |
| 48 | - .fold((i32::MAX, i32::MIN), |(mn, mx), &v| (mn.min(v), mx.max(v))); | |
| 49 | - eprintln!(" e_q[{i}] len={} min={mn} max={mx} row={row:?}", row.len()); | |
| 50 | - } | |
| 51 | - for (i, row) in ch.q_q.iter().enumerate() { | |
| 52 | - let (mn, mx) = row | |
| 53 | - .iter() | |
| 54 | - .fold((i32::MAX, i32::MIN), |(mn, mx), &v| (mn.min(v), mx.max(v))); | |
| 55 | - eprintln!(" q_q[{i}] len={} min={mn} max={mx} row={row:?}", row.len()); | |
| 56 | - } | |
| 57 | -} | |
| 58 | 16 | |
| 59 | 17 | /// Envelope-grid "time slots" (§4.6.18.4, `numTimeSlots = 16` for a |
| 60 | 18 | /// 1024-sample core frame) are half as fine as the QMF slots SBR actually |
| 61 | 19 | /// runs at (32 per frame): `RATE = 2` converts one to the other. |
| 62 | 20 | const RATE: i64 = 2; |
| 63 | 21 | |
| 64 | -/// Round-20 residual/side-info correlation: one row per (access unit, | |
| 65 | -/// channel) `apply_data` actually ran, giving `sbr_real_library.rs`'s | |
| 66 | -/// residual-energy grid a side-info table to correlate against without | |
| 67 | -/// re-parsing debug text. `frame` is a single counter shared by every | |
| 68 | -/// channel `apply_data` touches in one call, so it lines up 1:1 with the | |
| 69 | -/// AU-aligned (2048 output samples/AU for a plain 2x stream) blocks the | |
| 70 | -/// residual grid uses. | |
| 71 | -#[derive(Clone, Debug)] | |
| 72 | -pub struct SbrSideInfoRow { | |
| 73 | - pub frame: usize, | |
| 74 | - pub tag: u8, | |
| 75 | - pub ch: usize, | |
| 76 | - /// `"fresh"` for a frame `apply` reached (a real payload this AU), | |
| 77 | - /// `"hold"` for one `apply_last` reached (no fresh payload, reusing the | |
| 78 | - /// last parsed frame's data per §4.6.18). | |
| 79 | - pub source: &'static str, | |
| 80 | - pub coupling: bool, | |
| 81 | - pub amp_res: u8, | |
| 82 | - /// Band-index domain (same units `f_high`/`f_noise` and the residual | |
| 83 | - /// grid's FFT-bucket index share, per `per_band_correlation`'s | |
| 84 | - /// `band_hz = rate/256` measurement) the crossover and high-res/noise | |
| 85 | - /// band boundaries below live in. | |
| 86 | - pub kx: i64, | |
| 87 | - pub k2: i64, | |
| 88 | - pub f_high: Vec<i64>, | |
| 89 | - pub f_noise: Vec<i64>, | |
| 90 | - pub t_env: Vec<i64>, | |
| 91 | - pub freq_res: Vec<u8>, | |
| 92 | - pub invf_mode: Vec<u8>, | |
| 93 | - pub add_harmonic: Option<Vec<u8>>, | |
| 94 | - pub e_q_means: Vec<f64>, | |
| 95 | - pub q_q_means: Vec<f64>, | |
| 96 | - /// Header fields held for the frame's duration (§4.6.18.3.2), added for | |
| 97 | - /// the FMJ-vs-reeln feature-table hunt: `sbr_header()`'s own coding | |
| 98 | - /// choices, not per-envelope grid data. | |
| 99 | - pub freq_scale: u8, | |
| 100 | - pub alter_scale: u8, | |
| 101 | - pub noise_bands: u8, | |
| 102 | - pub limiter_bands: u8, | |
| 103 | - pub limiter_gains: u8, | |
| 104 | - pub interpol_freq: u8, | |
| 105 | - pub smoothing_mode: u8, | |
| 106 | - pub start_freq: u8, | |
| 107 | - pub stop_freq: u8, | |
| 108 | - pub xover_band: u8, | |
| 109 | - /// `t_noise.len() - 1`, i.e. `numNoiseFloors` this frame. | |
| 110 | - pub num_noise: usize, | |
| 111 | - /// One entry per HF patch, each the patch's band count (from | |
| 112 | - /// `sbr_hf::build_patches`), so patch geometry is visible per frame. | |
| 113 | - pub patch_lengths: Vec<usize>, | |
| 114 | - pub df_env: Vec<u8>, | |
| 115 | - pub df_noise: Vec<u8>, | |
| 116 | -} | |
| 117 | - | |
| 118 | -static SIDEINFO_LOG: std::sync::OnceLock<std::sync::Mutex<Vec<SbrSideInfoRow>>> = | |
| 119 | - std::sync::OnceLock::new(); | |
| 120 | -static SIDEINFO_FRAME: AtomicUsize = AtomicUsize::new(0); | |
| 121 | - | |
| 122 | -/// Diagnostic-only counter: how many `apply_data` calls process-wide ran | |
| 123 | -/// with `source == "hold"` (an AU whose FIL carried no fresh SBR payload, | |
| 124 | -/// falling back to `apply_last`'s reuse of the last parsed frame). Read via | |
| 125 | -/// [`hold_call_count`]; not gated by an env var since incrementing an atomic | |
| 126 | -/// is unconditionally cheap, unlike the `EC_AAC_SBR_*_DEBUG` prints nearby. | |
| 127 | -static HOLD_CALLS: AtomicUsize = AtomicUsize::new(0); | |
| 128 | - | |
| 129 | -/// Total `apply_data` calls process-wide where the SBR payload was reused | |
| 130 | -/// from a prior frame (`apply_last`) rather than freshly parsed this AU -- | |
| 131 | -/// diagnostic instrument for `sbr441_family_sample_drift_probe`. | |
| 132 | -pub fn hold_call_count() -> usize { | |
| 133 | - HOLD_CALLS.load(Ordering::Relaxed) | |
| 134 | -} | |
| 135 | - | |
| 136 | -fn sideinfo_enabled() -> bool { | |
| 137 | - crate::knobs::sbr_sideinfo_debug() | |
| 138 | -} | |
| 139 | - | |
| 140 | -/// Round-34 Task 1 diagnostic: per-AU per-QMF-band mean energy at a named | |
| 141 | -/// pipeline stage, gated by `EC_AAC_SBR_QMFDUMP`. `start_band` is the | |
| 142 | -/// absolute QMF band index `rows[0]` represents (`0` for the core analysis | |
| 143 | -/// matrix, `kx` for the HF matrix), so every printed band index lines up | |
| 144 | -/// with `build_patches`' target-band units without the reader having to | |
| 145 | -/// offset anything by hand. | |
| 146 | -fn qmfdump_enabled() -> bool { | |
| 147 | - std::env::var("EC_AAC_SBR_QMFDUMP").is_ok() | |
| 148 | -} | |
| 149 | - | |
| 150 | -fn qmfdump_energies(stage: &str, start_band: usize, rows: &[Vec<Complex<f64>>]) { | |
| 151 | - let means: Vec<f64> = rows | |
| 152 | - .iter() | |
| 153 | - .map(|series| { | |
| 154 | - if series.is_empty() { | |
| 155 | - 0.0 | |
| 156 | - } else { | |
| 157 | - series | |
| 158 | - .iter() | |
| 159 | - .map(|c| c.re * c.re + c.im * c.im) | |
| 160 | - .sum::<f64>() | |
| 161 | - / series.len() as f64 | |
| 162 | - } | |
| 163 | - }) | |
| 164 | - .collect(); | |
| 165 | - eprintln!("QMFDUMP stage={stage} start_band={start_band} means={means:?}"); | |
| 166 | -} | |
| 167 | - | |
| 168 | -/// Drains nothing -- returns a clone of every row logged so far this | |
| 169 | -/// process, in call order. Empty unless `EC_AAC_SBR_SIDEINFO_DEBUG` was set | |
| 170 | -/// before decoding. | |
| 171 | -pub fn sbr_sideinfo_log() -> Vec<SbrSideInfoRow> { | |
| 172 | - let Some(log) = SIDEINFO_LOG.get() else { | |
| 173 | - return Vec::new(); | |
| 174 | - }; | |
| 175 | - log.lock().map(|l| l.clone()).unwrap_or_default() | |
| 176 | -} | |
| 177 | - | |
| 178 | 22 | /// Per-channel DSP state an SBR element's reconstruction carries across |
| 179 | 23 | /// frames: the QMF filterbank pair, the HF generator's LPC history and |
| 180 | 24 | /// chirp factors, and the noise-floor generator. |
| @@ -469,7 +313,7 @@ impl SbrChain { | ||
| 469 | 313 | if let Some(elem) = self.elements.get_mut(&(tag, is_cpe)) { |
| 470 | 314 | elem.last_data = Some(data.clone()); |
| 471 | 315 | } |
| 472 | - self.apply_data(tag, is_cpe, data, planes, "fresh") | |
| 316 | + self.apply_data(tag, is_cpe, data, planes) | |
| 473 | 317 | } |
| 474 | 318 | |
| 475 | 319 | /// Re-runs the chain for `tag` using the last successfully parsed |
| @@ -491,7 +335,7 @@ impl SbrChain { | ||
| 491 | 335 | self.apply_low_only(tag, is_cpe, planes); |
| 492 | 336 | return Ok(()); |
| 493 | 337 | }; |
| 494 | - self.apply_data(tag, is_cpe, &data, planes, "hold") | |
| 338 | + self.apply_data(tag, is_cpe, &data, planes) | |
| 495 | 339 | } |
| 496 | 340 | |
| 497 | 341 | fn apply_data( |
| @@ -500,11 +344,7 @@ impl SbrChain { | ||
| 500 | 344 | is_cpe: bool, |
| 501 | 345 | data: &SbrData, |
| 502 | 346 | planes: &mut [Vec<f32>], |
| 503 | - source: &'static str, | |
| 504 | 347 | ) -> crate::Result<()> { |
| 505 | - if source == "hold" { | |
| 506 | - HOLD_CALLS.fetch_add(1, Ordering::Relaxed); | |
| 507 | - } | |
| 508 | 348 | let band_limit = if self.downsampled { ANALYSIS_BANDS } else { SYNTHESIS_BANDS }; |
| 509 | 349 | let Some(elem) = self.elements.get_mut(&(tag, is_cpe)) else { |
| 510 | 350 | return Ok(()); |
| @@ -518,12 +358,6 @@ impl SbrChain { | ||
| 518 | 358 | return Ok(()); |
| 519 | 359 | }; |
| 520 | 360 | let coupling = data.coupling; |
| 521 | - let sideinfo_on = sideinfo_enabled(); | |
| 522 | - let au_frame = if sideinfo_on { | |
| 523 | - SIDEINFO_FRAME.fetch_add(1, Ordering::Relaxed) | |
| 524 | - } else { | |
| 525 | - 0 | |
| 526 | - }; | |
| 527 | 361 | // PS: the mono channel is synthesized twice, through its own state and |
| 528 | 362 | // through channel 1's (the right output), so both stay in step. |
| 529 | 363 | let ps_mode = !is_cpe && planes.len() >= 2 && data.ps.is_some(); |
| @@ -542,20 +376,6 @@ impl SbrChain { | ||
| 542 | 376 | if num_slots == 0 { |
| 543 | 377 | continue; |
| 544 | 378 | } |
| 545 | - if std::env::var("EC_AAC_SBR_PREQMF_DUMP").is_ok() { | |
| 546 | - static N: AtomicUsize = AtomicUsize::new(0); | |
| 547 | - let n = N.fetch_add(1, Ordering::Relaxed); | |
| 548 | - if n < 40 { | |
| 549 | - let rms = (plane.iter().map(|v| f64::from(*v) * f64::from(*v)).sum::<f64>() | |
| 550 | - / plane.len().max(1) as f64) | |
| 551 | - .sqrt(); | |
| 552 | - eprintln!( | |
| 553 | - "PREQMF n={n} tag={tag} ch={ch} len={} rms={rms:.6} first8={:?}", | |
| 554 | - plane.len(), | |
| 555 | - &plane[..8.min(plane.len())] | |
| 556 | - ); | |
| 557 | - } | |
| 558 | - } | |
| 559 | 379 | let state = &mut elem.channels[ch]; |
| 560 | 380 | let mut low_cur = vec![vec![Complex::ZERO; num_slots]; ANALYSIS_BANDS]; |
| 561 | 381 | let mut raw = Vec::with_capacity(num_slots); |
| @@ -584,63 +404,6 @@ impl SbrChain { | ||
| 584 | 404 | } |
| 585 | 405 | |
| 586 | 406 | let sbr_ch = &data.channels[ch]; |
| 587 | - if std::env::var("EC_AAC_SBR_DEBUG").is_ok() { | |
| 588 | - eprintln!("SBRDBG coupling={}", data.coupling); | |
| 589 | - debug_dump(&header, &tables, sbr_ch, ch); | |
| 590 | - } | |
| 591 | - if sideinfo_on { | |
| 592 | - let mean = |rows: &[Vec<i32>]| -> Vec<f64> { | |
| 593 | - rows.iter() | |
| 594 | - .map(|r| { | |
| 595 | - if r.is_empty() { | |
| 596 | - 0.0 | |
| 597 | - } else { | |
| 598 | - r.iter().map(|&v| f64::from(v)).sum::<f64>() / r.len() as f64 | |
| 599 | - } | |
| 600 | - }) | |
| 601 | - .collect() | |
| 602 | - }; | |
| 603 | - let row = SbrSideInfoRow { | |
| 604 | - frame: au_frame, | |
| 605 | - tag, | |
| 606 | - ch, | |
| 607 | - source, | |
| 608 | - coupling, | |
| 609 | - amp_res: header.amp_res, | |
| 610 | - kx: tables.kx, | |
| 611 | - k2: tables.k2, | |
| 612 | - f_high: tables.f_high.clone(), | |
| 613 | - f_noise: tables.f_noise.clone(), | |
| 614 | - t_env: sbr_ch.t_env.clone(), | |
| 615 | - freq_res: sbr_ch.freq_res.clone(), | |
| 616 | - invf_mode: sbr_ch.invf_mode.clone(), | |
| 617 | - add_harmonic: sbr_ch.add_harmonic.clone(), | |
| 618 | - e_q_means: mean(&sbr_ch.e_q), | |
| 619 | - q_q_means: mean(&sbr_ch.q_q), | |
| 620 | - freq_scale: header.freq_scale, | |
| 621 | - alter_scale: header.alter_scale, | |
| 622 | - noise_bands: header.noise_bands, | |
| 623 | - limiter_bands: header.limiter_bands, | |
| 624 | - limiter_gains: header.limiter_gains, | |
| 625 | - interpol_freq: header.interpol_freq, | |
| 626 | - smoothing_mode: header.smoothing_mode, | |
| 627 | - start_freq: header.start_freq, | |
| 628 | - stop_freq: header.stop_freq, | |
| 629 | - xover_band: header.xover_band, | |
| 630 | - num_noise: sbr_ch.t_noise.len().saturating_sub(1), | |
| 631 | - patch_lengths: sbr_hf::build_patches(&tables).iter().map(|p| p.width).collect(), | |
| 632 | - df_env: sbr_ch.df_env.clone(), | |
| 633 | - df_noise: sbr_ch.df_noise.clone(), | |
| 634 | - }; | |
| 635 | - let log = SIDEINFO_LOG.get_or_init(|| std::sync::Mutex::new(Vec::new())); | |
| 636 | - if let Ok(mut l) = log.lock() { | |
| 637 | - l.push(row); | |
| 638 | - } | |
| 639 | - } | |
| 640 | - let qmfdump_on = qmfdump_enabled(); | |
| 641 | - if qmfdump_on { | |
| 642 | - qmfdump_energies("analysis", 0, &low_cur); | |
| 643 | - } | |
| 644 | 407 | let hf = sbr_hf::generate( |
| 645 | 408 | &low_cur, |
| 646 | 409 | &tables, |
| @@ -648,9 +411,6 @@ impl SbrChain { | ||
| 648 | 411 | &mut state.chirp, |
| 649 | 412 | &mut state.hf_hist, |
| 650 | 413 | ); |
| 651 | - if qmfdump_on { | |
| 652 | - qmfdump_energies("post_patch", tables.kx as usize, &hf); | |
| 653 | - } | |
| 654 | 414 | let (env_energy, noise_energy) = |
| 655 | 415 | sbr_env::dequantize_frame(&data.channels, ch, coupling); |
| 656 | 416 | // sbr_env::adjust works in QMF-slot units; the parsed borders |
| @@ -718,9 +478,6 @@ impl SbrChain { | ||
| 718 | 478 | d.truncate(num_slots); |
| 719 | 479 | d |
| 720 | 480 | }; |
| 721 | - if qmfdump_on { | |
| 722 | - qmfdump_energies("post_adjust", tables.kx as usize, &hf); | |
| 723 | - } | |
| 724 | 481 | |
| 725 | 482 | let kx = (tables.kx as usize).min(ANALYSIS_BANDS); |
| 726 | 483 | let k2 = (tables.k2 as usize).min(band_limit); |
| @@ -728,13 +485,11 @@ impl SbrChain { | ||
| 728 | 485 | for slot in 0..num_slots { |
| 729 | 486 | let mut v = [Complex::ZERO; SYNTHESIS_BANDS]; |
| 730 | 487 | v[0..kx].copy_from_slice(&raw[slot][0..kx]); |
| 731 | - if !crate::knobs::sbr_hf_bypass() { | |
| 732 | 488 | for b in kx..k2 { |
| 733 | 489 | if b - kx < hf.len() { |
| 734 | 490 | v[b] = hf[b - kx][slot]; |
| 735 | 491 | } |
| 736 | 492 | } |
| 737 | - } | |
| 738 | 493 | vs.push(v); |
| 739 | 494 | } |
| 740 | 495 | let out = match (ps_mode && num_slots == PS_SLOTS, data.ps.as_ref()) { |
| @@ -760,20 +515,6 @@ impl SbrChain { | ||
| 760 | 515 | } |
| 761 | 516 | _ => synth_slots(&mut state.synthesis, &vs), |
| 762 | 517 | }; |
| 763 | - if std::env::var("EC_AAC_SBR_PREQMF_DUMP").is_ok() { | |
| 764 | - static N: AtomicUsize = AtomicUsize::new(0); | |
| 765 | - let n = N.fetch_add(1, Ordering::Relaxed); | |
| 766 | - if n < 40 { | |
| 767 | - let rms = (out.iter().map(|v| f64::from(*v) * f64::from(*v)).sum::<f64>() | |
| 768 | - / out.len().max(1) as f64) | |
| 769 | - .sqrt(); | |
| 770 | - eprintln!( | |
| 771 | - "POSTQMF n={n} tag={tag} ch={ch} len={} rms={rms:.6} first8={:?}", | |
| 772 | - out.len(), | |
| 773 | - &out[..8.min(out.len())] | |
| 774 | - ); | |
| 775 | - } | |
| 776 | - } | |
| 777 | 518 | if ps_planes.is_none() { |
| 778 | 519 | *plane = out; |
| 779 | 520 | } |
crates/ec-aac/src/sbr_env.rsmodified+2 -74
| @@ -168,29 +168,6 @@ impl Default for AdjustState { | ||
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | -fn noise_fraction_debug() -> bool { | |
| 172 | - crate::knobs::sbr_noise_fraction() | |
| 173 | -} | |
| 174 | - | |
| 175 | -type NoiseFractionRows = Vec<(usize, f64, f64, f64)>; | |
| 176 | - | |
| 177 | -static NOISE_FRACTION: std::sync::OnceLock<std::sync::Mutex<NoiseFractionRows>> = | |
| 178 | - std::sync::OnceLock::new(); | |
| 179 | - | |
| 180 | -/// Diagnostic (`EC_AAC_SBR_NOISE_FRACTION`): per absolute QMF band, | |
| 181 | -/// bookkept `(band, Σ signal energy·slots, Σ noise energy·slots, Σ |Y|² | |
| 182 | -/// post-adjust)` -- the last column against the first two's sum is the | |
| 183 | -/// per-subband realised/target energy ratio. | |
| 184 | -pub fn noise_fraction_table() -> Vec<(usize, f64, f64, f64)> { | |
| 185 | - let mut out: Vec<(usize, f64, f64, f64)> = NOISE_FRACTION | |
| 186 | - .get() | |
| 187 | - .and_then(|m| m.lock().ok()) | |
| 188 | - .map(|g| g.clone()) | |
| 189 | - .unwrap_or_default(); | |
| 190 | - out.sort_by_key(|e| e.0); | |
| 191 | - out | |
| 192 | -} | |
| 193 | - | |
| 194 | 171 | /// Adjusts `hf` (`[m][slot]`, `m = k - kx`) in place: envelope gains, |
| 195 | 172 | /// noise floor and added sinusoids per §4.6.18.7.3-7.6. `ch.t_env`/`t_noise` |
| 196 | 173 | /// are in QMF slots (already ×2). `reset` mirrors the spec's header-reset |
| @@ -222,14 +199,7 @@ pub fn adjust( | ||
| 222 | 199 | state.g_hist.clear(); |
| 223 | 200 | state.q_hist.clear(); |
| 224 | 201 | } |
| 225 | - let limiter_max = if std::env::var("EC_AAC_SBR_LIMITER_OFF").is_ok() { | |
| 226 | - LIMITER_FACTOR[3] | |
| 227 | - } else { | |
| 228 | - LIMITER_FACTOR[usize::from(header.limiter_gains).min(3)] | |
| 229 | - }; | |
| 230 | - let zero_noise = crate::knobs::sbr_noise_zero(); | |
| 231 | - let limdump = std::env::var("EC_AAC_SBR_CELLDUMP").is_ok(); | |
| 232 | - let track_fraction = noise_fraction_debug(); | |
| 202 | + let limiter_max = LIMITER_FACTOR[usize::from(header.limiter_gains).min(3)]; | |
| 233 | 203 | let h_sl = if header.smoothing_mode == 0 { H_SL } else { 0 }; |
| 234 | 204 | let l_a = ch.l_a; |
| 235 | 205 | let l_a_prev: i64 = if state.la_prev_at_end { 0 } else { -1 }; |
| @@ -340,13 +310,9 @@ pub fn adjust( | ||
| 340 | 310 | let sum_orig: f64 = (lo..hi).map(|m| e_orig[m]).sum(); |
| 341 | 311 | let sum_curr: f64 = (lo..hi).map(|m| e_curr[m]).sum(); |
| 342 | 312 | let g_max = (limiter_max * ((EPS + sum_orig) / (EPS + sum_curr)).sqrt()).min(GAIN_MAX_CLIP); |
| 343 | - let mut capped = 0usize; | |
| 344 | 313 | for m in lo..hi { |
| 345 | 314 | let q_max = q_m[e][m] * g_max / gain[e][m]; |
| 346 | 315 | q_m[e][m] = q_m[e][m].min(q_max); |
| 347 | - if gain[e][m] > g_max { | |
| 348 | - capped += 1; | |
| 349 | - } | |
| 350 | 316 | gain[e][m] = gain[e][m].min(g_max); |
| 351 | 317 | } |
| 352 | 318 | let sum_act: f64 = (lo..hi) |
| @@ -362,32 +328,6 @@ pub fn adjust( | ||
| 362 | 328 | q_m[e][m] *= boost; |
| 363 | 329 | s_m[e][m] *= boost; |
| 364 | 330 | } |
| 365 | - if limdump { | |
| 366 | - eprintln!( | |
| 367 | - "LIMDUMP ei={e} band=[{},{}) limiter_bands={} j={j}/{n_lim} \ | |
| 368 | - E_orig_mapped={sum_orig:.6e} E_curr={sum_curr:.6e} G_max={g_max:.6} \ | |
| 369 | - capped_cells={capped}/{} E_actual={sum_act:.6e} G_boost={boost:.6}", | |
| 370 | - limiter_table[j], | |
| 371 | - limiter_table[j + 1], | |
| 372 | - header.limiter_bands, | |
| 373 | - hi - lo, | |
| 374 | - ); | |
| 375 | - } | |
| 376 | - } | |
| 377 | - if track_fraction { | |
| 378 | - let tab = NOISE_FRACTION.get_or_init(|| std::sync::Mutex::new(Vec::new())); | |
| 379 | - if let Ok(mut t) = tab.lock() { | |
| 380 | - for m in 0..m_max { | |
| 381 | - let sig = e_orig[m] / (1.0 + q_mapped[m]) * slots; | |
| 382 | - let noi = e_orig[m] * q_mapped[m] / (1.0 + q_mapped[m]) * slots; | |
| 383 | - if let Some(row) = t.iter_mut().find(|r| r.0 == m + kx) { | |
| 384 | - row.1 += sig; | |
| 385 | - row.2 += noi; | |
| 386 | - } else { | |
| 387 | - t.push((m + kx, sig, noi, 0.0)); | |
| 388 | - } | |
| 389 | - } | |
| 390 | - } | |
| 391 | 331 | } |
| 392 | 332 | } |
| 393 | 333 | state.s_index_prev = s_index_prev; |
| @@ -451,25 +391,13 @@ pub fn adjust( | ||
| 451 | 391 | noise_idx = (noise_idx + 1) & 0x1ff; |
| 452 | 392 | if s_m[e][m] != 0.0 { |
| 453 | 393 | y = y + Complex::new(s_m[e][m] * p_re, s_m[e][m] * p_im); |
| 454 | - } else if !transient && !zero_noise { | |
| 394 | + } else if !transient { | |
| 455 | 395 | let (vr, vi) = SBR_NOISE[noise_idx]; |
| 456 | 396 | y = y + Complex::new(q_filt[m] * vr, q_filt[m] * vi); |
| 457 | 397 | } |
| 458 | 398 | row[i] = y; |
| 459 | 399 | p_im = -p_im; |
| 460 | 400 | } |
| 461 | - if track_fraction { | |
| 462 | - let tab = NOISE_FRACTION.get_or_init(|| std::sync::Mutex::new(Vec::new())); | |
| 463 | - if let Ok(mut t) = tab.lock() { | |
| 464 | - for m in 0..m_max { | |
| 465 | - if let (Some(row), Some(y)) = | |
| 466 | - (t.iter_mut().find(|r| r.0 == m + kx), hf[m].get(i)) | |
| 467 | - { | |
| 468 | - row.3 += y.norm_sqr(); | |
| 469 | - } | |
| 470 | - } | |
| 471 | - } | |
| 472 | - } | |
| 473 | 401 | state.index_noise = (state.index_noise + m_max) & 0x1ff; |
| 474 | 402 | state.index_sine = (state.index_sine + 1) & 3; |
| 475 | 403 | } |
crates/ec-aac/tests/it/main.rsmodified+0 -1
| @@ -6,7 +6,6 @@ mod common; | ||
| 6 | 6 | mod he_parity; |
| 7 | 7 | mod implicit_ps; |
| 8 | 8 | mod implicit_sbr; |
| 9 | -mod reelh_per_frame; | |
| 10 | 9 | mod multichannel_parity; |
| 11 | 10 | mod no_panic; |
| 12 | 11 | mod ps_mp4; |