U9: ec-vorbis drop residue/bit-split capture, BlockLog rate-loop log, bark_hz and decouple (test-only diagnostics, no callers in edith/yumush)
Browse files at this commit5d133f9fa75a906de0503c5a70dfea31cdb7f293Parent: 41510f03 changed files +2 -166
- crates/ec-vorbis/src/decode.rs +0 -43
- crates/ec-vorbis/src/encode.rs +1 -122
- crates/ec-vorbis/src/lib.rs +1 -1
crates/ec-vorbis/src/decode.rsmodified+0 -43
| @@ -50,14 +50,6 @@ pub struct VorbisDecoder { | |||
| 50 | drained: bool, | 50 | drained: bool, |
| 51 | /// Holds decoded samples until the page granules say which are the stream's. | 51 | /// Holds decoded samples until the page granules say which are the stream's. |
| 52 | trim: GranuleTrim, | 52 | trim: GranuleTrim, |
| 53 | - /// Per-block captured decoded residue: (half, per-channel integer residue). | ||
| 54 | - /// Populated only when `enable_residue_capture` is set. | ||
| 55 | - residue_capture: Vec<(usize, Vec<Vec<i32>>)>, | ||
| 56 | - /// Per-block bit split captured alongside: (floor bits, residue bits, packet bits). | ||
| 57 | - bit_split: Vec<(u64, u64, u64)>, | ||
| 58 | - /// When true, `decode_audio` copies each block's residue (after inverse | ||
| 59 | - /// coupling, before floor multiply) into `residue_capture`. | ||
| 60 | - enable_residue_capture: bool, | ||
| 61 | } | 53 | } |
| 62 | 54 | ||
| 63 | impl VorbisDecoder { | 55 | impl VorbisDecoder { |
| @@ -97,9 +89,6 @@ impl VorbisDecoder { | |||
| 97 | frames: VecDeque::new(), | 89 | frames: VecDeque::new(), |
| 98 | drained: false, | 90 | drained: false, |
| 99 | trim: GranuleTrim::new(channels), | 91 | trim: GranuleTrim::new(channels), |
| 100 | - residue_capture: Vec::new(), | ||
| 101 | - bit_split: Vec::new(), | ||
| 102 | - enable_residue_capture: false, | ||
| 103 | ident, | 92 | ident, |
| 104 | comments, | 93 | comments, |
| 105 | setup, | 94 | setup, |
| @@ -185,8 +174,6 @@ impl VorbisDecoder { | |||
| 185 | } | 174 | } |
| 186 | 175 | ||
| 187 | let mapping = &self.setup.mappings[mode.mapping]; | 176 | let mapping = &self.setup.mappings[mode.mapping]; |
| 188 | - let packet_bits = data.len() as u64 * 8; | ||
| 189 | - let before_floors = bits.remaining(); | ||
| 190 | let mut floors = Vec::with_capacity(channels); | 177 | let mut floors = Vec::with_capacity(channels); |
| 191 | let mut no_residue = Vec::with_capacity(channels); | 178 | let mut no_residue = Vec::with_capacity(channels); |
| 192 | for &submap in mapping.mux.iter().take(channels) { | 179 | for &submap in mapping.mux.iter().take(channels) { |
| @@ -201,7 +188,6 @@ impl VorbisDecoder { | |||
| 201 | no_residue.push(state.is_unused()); | 188 | no_residue.push(state.is_unused()); |
| 202 | floors.push(state); | 189 | floors.push(state); |
| 203 | } | 190 | } |
| 204 | - let after_floors = bits.remaining(); | ||
| 205 | // A coupled pair shares its residue, so one live channel keeps both. | 191 | // A coupled pair shares its residue, so one live channel keeps both. |
| 206 | for &(magnitude, angle) in &mapping.coupling { | 192 | for &(magnitude, angle) in &mapping.coupling { |
| 207 | if !no_residue[magnitude] || !no_residue[angle] { | 193 | if !no_residue[magnitude] || !no_residue[angle] { |
| @@ -266,20 +252,6 @@ impl VorbisDecoder { | |||
| 266 | spectra[angle] = angles; | 252 | spectra[angle] = angles; |
| 267 | } | 253 | } |
| 268 | 254 | ||
| 269 | - if self.enable_residue_capture { | ||
| 270 | - let after_residues = bits.remaining(); | ||
| 271 | - self.bit_split.push(( | ||
| 272 | - before_floors - after_floors, | ||
| 273 | - after_floors - after_residues, | ||
| 274 | - packet_bits, | ||
| 275 | - )); | ||
| 276 | - let captured: Vec<Vec<i32>> = spectra | ||
| 277 | - .iter() | ||
| 278 | - .map(|ch| ch.iter().map(|&v| v.round() as i32).collect()) | ||
| 279 | - .collect(); | ||
| 280 | - self.residue_capture.push((half, captured)); | ||
| 281 | - } | ||
| 282 | - | ||
| 283 | // Floor times residue, then out of the frequency domain. | 255 | // Floor times residue, then out of the frequency domain. |
| 284 | let window = self.windows.get(mode.block_flag, previous_long, next_long); | 256 | let window = self.windows.get(mode.block_flag, previous_long, next_long); |
| 285 | let mdct = match mode.block_flag { | 257 | let mdct = match mode.block_flag { |
| @@ -378,21 +350,6 @@ impl VorbisDecoder { | |||
| 378 | self.trim.reset(); | 350 | self.trim.reset(); |
| 379 | } | 351 | } |
| 380 | 352 | ||
| 381 | - /// Enable per-block residue capture for offline histogram analysis. | ||
| 382 | - pub fn enable_residue_capture(&mut self) { | ||
| 383 | - self.enable_residue_capture = true; | ||
| 384 | - } | ||
| 385 | - | ||
| 386 | - /// Take the captured per-block residue: each entry is `(half, per-channel integer residue)`. | ||
| 387 | - pub fn take_residue_capture(&mut self) -> Vec<(usize, Vec<Vec<i32>>)> { | ||
| 388 | - std::mem::take(&mut self.residue_capture) | ||
| 389 | - } | ||
| 390 | - | ||
| 391 | - /// Take the per-block (floor bits, residue bits, packet bits) captured with the residue. | ||
| 392 | - pub fn take_bit_split(&mut self) -> Vec<(u64, u64, u64)> { | ||
| 393 | - std::mem::take(&mut self.bit_split) | ||
| 394 | - } | ||
| 395 | - | ||
| 396 | } | 353 | } |
| 397 | /// Vorbis channel order (§4.3.9) mapped onto [`ChannelLayout`]'s order. | 354 | /// Vorbis channel order (§4.3.9) mapped onto [`ChannelLayout`]'s order. |
| 398 | /// | 355 | /// |
crates/ec-vorbis/src/encode.rsmodified+1 -122
| @@ -246,30 +246,6 @@ struct BlockPlan { | |||
| 246 | next_long: bool, | 246 | next_long: bool, |
| 247 | } | 247 | } |
| 248 | 248 | ||
| 249 | -/// Per-block rate-loop snapshot, captured when `enable_block_log` is set. | ||
| 250 | -/// Used by the sweep to localise dropout seconds to their reservoir state. | ||
| 251 | -#[derive(Debug, Clone, Copy)] | ||
| 252 | -pub struct BlockLog { | ||
| 253 | - /// Centre sample of the block (maps to seconds via `centre / sample_rate`). | ||
| 254 | - pub centre: i64, | ||
| 255 | - /// Block size in samples (2048 long, 256 short). | ||
| 256 | - pub n: usize, | ||
| 257 | - /// Whether this is a long (2048) block. | ||
| 258 | - pub is_long: bool, | ||
| 259 | - /// Whether this block is steady (long, surrounded by long blocks). | ||
| 260 | - pub steady: bool, | ||
| 261 | - /// Coded size of this block's packet in bits. | ||
| 262 | - pub bits: u64, | ||
| 263 | - /// Headroom (dB) actually applied to this block's floor fit. | ||
| 264 | - pub headroom: f64, | ||
| 265 | - /// `self.headroom` after `update_rate` adjusted it. | ||
| 266 | - pub rate_headroom: f64, | ||
| 267 | - /// `reservoir_debt` after `update_rate`. | ||
| 268 | - pub reservoir: f64, | ||
| 269 | - /// Bit target this block was judged against. | ||
| 270 | - pub target: f64, | ||
| 271 | -} | ||
| 272 | - | ||
| 273 | /// The block-switch scheduler's state between calls. | 249 | /// The block-switch scheduler's state between calls. |
| 274 | #[derive(Debug, Clone, Copy)] | 250 | #[derive(Debug, Clone, Copy)] |
| 275 | enum Sched { | 251 | enum Sched { |
| @@ -335,16 +311,6 @@ pub struct VorbisEncoder { | |||
| 335 | reservoir_debt: f64, | 311 | reservoir_debt: f64, |
| 336 | finished: bool, | 312 | finished: bool, |
| 337 | packets: std::collections::VecDeque<EncodedPacket>, | 313 | packets: std::collections::VecDeque<EncodedPacket>, |
| 338 | - /// Per-block captured quantised residue: (half, per-channel quantised). | ||
| 339 | - /// Populated only when `enable_residue_capture` is set. | ||
| 340 | - residue_capture: Vec<(usize, Vec<Vec<i32>>)>, | ||
| 341 | - /// Per-block rate-loop snapshots; populated only when `enable_block_log`. | ||
| 342 | - block_log: Vec<BlockLog>, | ||
| 343 | - /// When true, `encode_block` records a [`BlockLog`] entry per block. | ||
| 344 | - enable_block_log: bool, | ||
| 345 | - /// When true, `encode_block` copies each block's quantised residue into | ||
| 346 | - /// `residue_capture` for offline histogram analysis. | ||
| 347 | - enable_residue_capture: bool, | ||
| 348 | } | 314 | } |
| 349 | 315 | ||
| 350 | impl VorbisEncoder { | 316 | impl VorbisEncoder { |
| @@ -444,10 +410,6 @@ impl VorbisEncoder { | |||
| 444 | class_book, | 410 | class_book, |
| 445 | residue_books, | 411 | residue_books, |
| 446 | coupling, | 412 | coupling, |
| 447 | - residue_capture: Vec::new(), | ||
| 448 | - enable_residue_capture: false, | ||
| 449 | - block_log: Vec::new(), | ||
| 450 | - enable_block_log: false, | ||
| 451 | }) | 413 | }) |
| 452 | } | 414 | } |
| 453 | 415 | ||
| @@ -466,31 +428,6 @@ impl VorbisEncoder { | |||
| 466 | &self.params | 428 | &self.params |
| 467 | } | 429 | } |
| 468 | 430 | ||
| 469 | - /// Enable per-block quantised-residue capture for offline histogram analysis. | ||
| 470 | - pub fn enable_residue_capture(&mut self) { | ||
| 471 | - self.enable_residue_capture = true; | ||
| 472 | - } | ||
| 473 | - | ||
| 474 | - /// Take the captured per-block quantised residue: each entry is `(half, per-channel quantised)`. | ||
| 475 | - pub fn take_residue_capture(&mut self) -> Vec<(usize, Vec<Vec<i32>>)> { | ||
| 476 | - std::mem::take(&mut self.residue_capture) | ||
| 477 | - } | ||
| 478 | - | ||
| 479 | - /// Enable per-block rate-loop capture for dropout diagnosis. | ||
| 480 | - pub fn enable_block_log(&mut self) { | ||
| 481 | - self.enable_block_log = true; | ||
| 482 | - } | ||
| 483 | - | ||
| 484 | - /// Take the captured per-block rate-loop snapshots. | ||
| 485 | - pub fn take_block_log(&mut self) -> Vec<BlockLog> { | ||
| 486 | - std::mem::take(&mut self.block_log) | ||
| 487 | - } | ||
| 488 | - | ||
| 489 | - /// Frequency in Barks for a given Hz — public so tests can bin by band. | ||
| 490 | - pub fn bark_hz(hz: f64) -> f64 { | ||
| 491 | - bark(hz) | ||
| 492 | - } | ||
| 493 | - | ||
| 494 | /// Push planar samples, one slice per channel in [`ec_core::ChannelLayout`] order. | 431 | /// Push planar samples, one slice per channel in [`ec_core::ChannelLayout`] order. |
| 495 | pub fn push_planar(&mut self, channels: &[&[f32]]) -> Result<()> { | 432 | pub fn push_planar(&mut self, channels: &[&[f32]]) -> Result<()> { |
| 496 | if channels.len() != usize::from(self.config.channels) { | 433 | if channels.len() != usize::from(self.config.channels) { |
| @@ -944,38 +881,6 @@ impl VorbisEncoder { | |||
| 944 | break (floor_values, quantised); | 881 | break (floor_values, quantised); |
| 945 | } | 882 | } |
| 946 | }; | 883 | }; |
| 947 | - if self.enable_residue_capture { | ||
| 948 | - // The bitstream stores the coupled magnitude/angle form; the | ||
| 949 | - // decoder inverse-couples before floor multiply. Capture in that | ||
| 950 | - // same per-channel domain so the histogram matches the decoder- | ||
| 951 | - // side reference capture exactly (sanity: decoding our own .ogg | ||
| 952 | - // reproduces these vectors). | ||
| 953 | - // Main codes the full `half * channels` interleaved region (no | ||
| 954 | - // HF truncation), so every bin below `half` is coded and the | ||
| 955 | - // capture keeps the whole per-channel vector. | ||
| 956 | - let coded = half; | ||
| 957 | - let mut per_channel: Vec<Vec<i32>> = quantised | ||
| 958 | - .iter() | ||
| 959 | - .map(|ch| { | ||
| 960 | - let mut v = ch[..coded].to_vec(); | ||
| 961 | - v.resize(half, 0); | ||
| 962 | - v | ||
| 963 | - }) | ||
| 964 | - .collect(); | ||
| 965 | - for &(magnitude, angle) in &self.coupling { | ||
| 966 | - let mut mags = std::mem::take(&mut per_channel[magnitude]); | ||
| 967 | - let mut angs = std::mem::take(&mut per_channel[angle]); | ||
| 968 | - for (m, a) in mags.iter_mut().zip(angs.iter_mut()) { | ||
| 969 | - let (l, r) = decouple(*m, *a); | ||
| 970 | - *m = l; | ||
| 971 | - *a = r; | ||
| 972 | - } | ||
| 973 | - per_channel[magnitude] = mags; | ||
| 974 | - per_channel[angle] = angs; | ||
| 975 | - } | ||
| 976 | - self.residue_capture.push((half, per_channel)); | ||
| 977 | - } | ||
| 978 | - | ||
| 979 | let mut out = BitsOut::new(); | 884 | let mut out = BitsOut::new(); |
| 980 | out.bit(false); | 885 | out.bit(false); |
| 981 | let mode = if plan.is_long { MODE_LONG } else { MODE_SHORT }; | 886 | let mode = if plan.is_long { MODE_LONG } else { MODE_SHORT }; |
| @@ -998,21 +903,7 @@ impl VorbisEncoder { | |||
| 998 | let bits = out.len(); | 903 | let bits = out.len(); |
| 999 | let delta = (self.centre + (self.prev_n + n) as i64 / 4) - self.centre; | 904 | let delta = (self.centre + (self.prev_n + n) as i64 / 4) - self.centre; |
| 1000 | let steady = plan.is_long && plan.prev_long && plan.next_long; | 905 | let steady = plan.is_long && plan.prev_long && plan.next_long; |
| 1001 | - let target = self.update_rate(bits, half, channels, delta, steady); | 906 | + self.update_rate(bits, half, channels, delta, steady); |
| 1002 | - if self.enable_block_log { | ||
| 1003 | - let centre = self.centre + (self.prev_n + n) as i64 / 4; | ||
| 1004 | - self.block_log.push(BlockLog { | ||
| 1005 | - centre, | ||
| 1006 | - n, | ||
| 1007 | - is_long: plan.is_long, | ||
| 1008 | - steady, | ||
| 1009 | - bits, | ||
| 1010 | - headroom, | ||
| 1011 | - rate_headroom: self.headroom, | ||
| 1012 | - reservoir: self.reservoir_debt, | ||
| 1013 | - target, | ||
| 1014 | - }); | ||
| 1015 | - } | ||
| 1016 | out.finish() | 907 | out.finish() |
| 1017 | } | 908 | } |
| 1018 | 909 | ||
| @@ -1305,18 +1196,6 @@ fn couple(left: i32, right: i32) -> (i32, i32) { | |||
| 1305 | }, | 1196 | }, |
| 1306 | } | 1197 | } |
| 1307 | } | 1198 | } |
| 1308 | -/// Inverse square-polar coupling on integer residue — the exact inverse of | ||
| 1309 | -/// [`couple`] and the integer form of the decoder's §9.4.2 step. Used only to | ||
| 1310 | -/// bring the residue capture back to per-channel (magnitude/angle undone) so it | ||
| 1311 | -/// matches the decoder-side capture domain. | ||
| 1312 | -fn decouple(m: i32, a: i32) -> (i32, i32) { | ||
| 1313 | - match (m > 0, a > 0) { | ||
| 1314 | - (true, true) => (m, m - a), | ||
| 1315 | - (true, false) => (m + a, m), | ||
| 1316 | - (false, true) => (m, m + a), | ||
| 1317 | - (false, false) => (m - a, m), | ||
| 1318 | - } | ||
| 1319 | -} | ||
| 1320 | 1199 | ||
| 1321 | /// §7.2.2 `render_point`, which both sides of the floor coding need. | 1200 | /// §7.2.2 `render_point`, which both sides of the floor coding need. |
| 1322 | fn predict(x0: u32, y0: i32, x1: u32, y1: i32, x: u32) -> i32 { | 1201 | fn predict(x0: u32, y0: i32, x1: u32, y1: i32, x: u32) -> i32 { |
crates/ec-vorbis/src/lib.rsmodified+1 -1
| @@ -42,5 +42,5 @@ mod trim; | |||
| 42 | mod window; | 42 | mod window; |
| 43 | 43 | ||
| 44 | pub use decode::{VorbisDecoder, channel_map}; | 44 | pub use decode::{VorbisDecoder, channel_map}; |
| 45 | -pub use encode::{BlockLog, EncoderConfig, VorbisEncoder}; | 45 | +pub use encode::{EncoderConfig, VorbisEncoder}; |
| 46 | pub use setup::{Comments, Identification}; | 46 | pub use setup::{Comments, Identification}; |