From 5d133f9fa75a906de0503c5a70dfea31cdb7f293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Dec 2026 13:33:00 +0300 Subject: [PATCH] U9: ec-vorbis drop residue/bit-split capture, BlockLog rate-loop log, bark_hz and decouple (test-only diagnostics, no callers in edith/yumush) --- crates/ec-vorbis/src/decode.rs | 43 ------------ crates/ec-vorbis/src/encode.rs | 123 +-------------------------------- crates/ec-vorbis/src/lib.rs | 2 +- 3 files changed, 2 insertions(+), 166 deletions(-) diff --git a/crates/ec-vorbis/src/decode.rs b/crates/ec-vorbis/src/decode.rs index 95fd8952..661f88b4 100644 --- a/crates/ec-vorbis/src/decode.rs +++ b/crates/ec-vorbis/src/decode.rs @@ -50,14 +50,6 @@ pub struct VorbisDecoder { drained: bool, /// Holds decoded samples until the page granules say which are the stream's. trim: GranuleTrim, - /// Per-block captured decoded residue: (half, per-channel integer residue). - /// Populated only when `enable_residue_capture` is set. - residue_capture: Vec<(usize, Vec>)>, - /// Per-block bit split captured alongside: (floor bits, residue bits, packet bits). - bit_split: Vec<(u64, u64, u64)>, - /// When true, `decode_audio` copies each block's residue (after inverse - /// coupling, before floor multiply) into `residue_capture`. - enable_residue_capture: bool, } impl VorbisDecoder { @@ -97,9 +89,6 @@ impl VorbisDecoder { frames: VecDeque::new(), drained: false, trim: GranuleTrim::new(channels), - residue_capture: Vec::new(), - bit_split: Vec::new(), - enable_residue_capture: false, ident, comments, setup, @@ -185,8 +174,6 @@ impl VorbisDecoder { } let mapping = &self.setup.mappings[mode.mapping]; - let packet_bits = data.len() as u64 * 8; - let before_floors = bits.remaining(); let mut floors = Vec::with_capacity(channels); let mut no_residue = Vec::with_capacity(channels); for &submap in mapping.mux.iter().take(channels) { @@ -201,7 +188,6 @@ impl VorbisDecoder { no_residue.push(state.is_unused()); floors.push(state); } - let after_floors = bits.remaining(); // A coupled pair shares its residue, so one live channel keeps both. for &(magnitude, angle) in &mapping.coupling { if !no_residue[magnitude] || !no_residue[angle] { @@ -266,20 +252,6 @@ impl VorbisDecoder { spectra[angle] = angles; } - if self.enable_residue_capture { - let after_residues = bits.remaining(); - self.bit_split.push(( - before_floors - after_floors, - after_floors - after_residues, - packet_bits, - )); - let captured: Vec> = spectra - .iter() - .map(|ch| ch.iter().map(|&v| v.round() as i32).collect()) - .collect(); - self.residue_capture.push((half, captured)); - } - // Floor times residue, then out of the frequency domain. let window = self.windows.get(mode.block_flag, previous_long, next_long); let mdct = match mode.block_flag { @@ -378,21 +350,6 @@ impl VorbisDecoder { self.trim.reset(); } - /// Enable per-block residue capture for offline histogram analysis. - pub fn enable_residue_capture(&mut self) { - self.enable_residue_capture = true; - } - - /// Take the captured per-block residue: each entry is `(half, per-channel integer residue)`. - pub fn take_residue_capture(&mut self) -> Vec<(usize, Vec>)> { - std::mem::take(&mut self.residue_capture) - } - - /// Take the per-block (floor bits, residue bits, packet bits) captured with the residue. - pub fn take_bit_split(&mut self) -> Vec<(u64, u64, u64)> { - std::mem::take(&mut self.bit_split) - } - } /// Vorbis channel order (§4.3.9) mapped onto [`ChannelLayout`]'s order. /// diff --git a/crates/ec-vorbis/src/encode.rs b/crates/ec-vorbis/src/encode.rs index 307fb2c8..4dd87772 100644 --- a/crates/ec-vorbis/src/encode.rs +++ b/crates/ec-vorbis/src/encode.rs @@ -246,30 +246,6 @@ struct BlockPlan { next_long: bool, } -/// Per-block rate-loop snapshot, captured when `enable_block_log` is set. -/// Used by the sweep to localise dropout seconds to their reservoir state. -#[derive(Debug, Clone, Copy)] -pub struct BlockLog { - /// Centre sample of the block (maps to seconds via `centre / sample_rate`). - pub centre: i64, - /// Block size in samples (2048 long, 256 short). - pub n: usize, - /// Whether this is a long (2048) block. - pub is_long: bool, - /// Whether this block is steady (long, surrounded by long blocks). - pub steady: bool, - /// Coded size of this block's packet in bits. - pub bits: u64, - /// Headroom (dB) actually applied to this block's floor fit. - pub headroom: f64, - /// `self.headroom` after `update_rate` adjusted it. - pub rate_headroom: f64, - /// `reservoir_debt` after `update_rate`. - pub reservoir: f64, - /// Bit target this block was judged against. - pub target: f64, -} - /// The block-switch scheduler's state between calls. #[derive(Debug, Clone, Copy)] enum Sched { @@ -335,16 +311,6 @@ pub struct VorbisEncoder { reservoir_debt: f64, finished: bool, packets: std::collections::VecDeque, - /// Per-block captured quantised residue: (half, per-channel quantised). - /// Populated only when `enable_residue_capture` is set. - residue_capture: Vec<(usize, Vec>)>, - /// Per-block rate-loop snapshots; populated only when `enable_block_log`. - block_log: Vec, - /// When true, `encode_block` records a [`BlockLog`] entry per block. - enable_block_log: bool, - /// When true, `encode_block` copies each block's quantised residue into - /// `residue_capture` for offline histogram analysis. - enable_residue_capture: bool, } impl VorbisEncoder { @@ -444,10 +410,6 @@ impl VorbisEncoder { class_book, residue_books, coupling, - residue_capture: Vec::new(), - enable_residue_capture: false, - block_log: Vec::new(), - enable_block_log: false, }) } @@ -466,31 +428,6 @@ impl VorbisEncoder { &self.params } - /// Enable per-block quantised-residue capture for offline histogram analysis. - pub fn enable_residue_capture(&mut self) { - self.enable_residue_capture = true; - } - - /// Take the captured per-block quantised residue: each entry is `(half, per-channel quantised)`. - pub fn take_residue_capture(&mut self) -> Vec<(usize, Vec>)> { - std::mem::take(&mut self.residue_capture) - } - - /// Enable per-block rate-loop capture for dropout diagnosis. - pub fn enable_block_log(&mut self) { - self.enable_block_log = true; - } - - /// Take the captured per-block rate-loop snapshots. - pub fn take_block_log(&mut self) -> Vec { - std::mem::take(&mut self.block_log) - } - - /// Frequency in Barks for a given Hz — public so tests can bin by band. - pub fn bark_hz(hz: f64) -> f64 { - bark(hz) - } - /// Push planar samples, one slice per channel in [`ec_core::ChannelLayout`] order. pub fn push_planar(&mut self, channels: &[&[f32]]) -> Result<()> { if channels.len() != usize::from(self.config.channels) { @@ -944,38 +881,6 @@ impl VorbisEncoder { break (floor_values, quantised); } }; - if self.enable_residue_capture { - // The bitstream stores the coupled magnitude/angle form; the - // decoder inverse-couples before floor multiply. Capture in that - // same per-channel domain so the histogram matches the decoder- - // side reference capture exactly (sanity: decoding our own .ogg - // reproduces these vectors). - // Main codes the full `half * channels` interleaved region (no - // HF truncation), so every bin below `half` is coded and the - // capture keeps the whole per-channel vector. - let coded = half; - let mut per_channel: Vec> = quantised - .iter() - .map(|ch| { - let mut v = ch[..coded].to_vec(); - v.resize(half, 0); - v - }) - .collect(); - for &(magnitude, angle) in &self.coupling { - let mut mags = std::mem::take(&mut per_channel[magnitude]); - let mut angs = std::mem::take(&mut per_channel[angle]); - for (m, a) in mags.iter_mut().zip(angs.iter_mut()) { - let (l, r) = decouple(*m, *a); - *m = l; - *a = r; - } - per_channel[magnitude] = mags; - per_channel[angle] = angs; - } - self.residue_capture.push((half, per_channel)); - } - let mut out = BitsOut::new(); out.bit(false); let mode = if plan.is_long { MODE_LONG } else { MODE_SHORT }; @@ -998,21 +903,7 @@ impl VorbisEncoder { let bits = out.len(); let delta = (self.centre + (self.prev_n + n) as i64 / 4) - self.centre; let steady = plan.is_long && plan.prev_long && plan.next_long; - let target = self.update_rate(bits, half, channels, delta, steady); - if self.enable_block_log { - let centre = self.centre + (self.prev_n + n) as i64 / 4; - self.block_log.push(BlockLog { - centre, - n, - is_long: plan.is_long, - steady, - bits, - headroom, - rate_headroom: self.headroom, - reservoir: self.reservoir_debt, - target, - }); - } + self.update_rate(bits, half, channels, delta, steady); out.finish() } @@ -1305,18 +1196,6 @@ fn couple(left: i32, right: i32) -> (i32, i32) { }, } } -/// Inverse square-polar coupling on integer residue — the exact inverse of -/// [`couple`] and the integer form of the decoder's §9.4.2 step. Used only to -/// bring the residue capture back to per-channel (magnitude/angle undone) so it -/// matches the decoder-side capture domain. -fn decouple(m: i32, a: i32) -> (i32, i32) { - match (m > 0, a > 0) { - (true, true) => (m, m - a), - (true, false) => (m + a, m), - (false, true) => (m, m + a), - (false, false) => (m - a, m), - } -} /// §7.2.2 `render_point`, which both sides of the floor coding need. fn predict(x0: u32, y0: i32, x1: u32, y1: i32, x: u32) -> i32 { diff --git a/crates/ec-vorbis/src/lib.rs b/crates/ec-vorbis/src/lib.rs index bc0485f7..98fa653e 100644 --- a/crates/ec-vorbis/src/lib.rs +++ b/crates/ec-vorbis/src/lib.rs @@ -42,5 +42,5 @@ mod trim; mod window; pub use decode::{VorbisDecoder, channel_map}; -pub use encode::{BlockLog, EncoderConfig, VorbisEncoder}; +pub use encode::{EncoderConfig, VorbisEncoder}; pub use setup::{Comments, Identification};