Merge branch 'lane-vorbisvq2': Vorbis floor at the masking threshold, masked residue zeroing, transient and stereo-angle masking; shim timing test pins packet granules and PCM onset
Browse files at this commit2 changed files +199 -43
- crates/ec-vorbis/src/encode.rs +88 -25
- shims/symphonia/tests/vorbis_timing.rs +111 -18
crates/ec-vorbis/src/encode.rsmodified+88 -25
| @@ -81,7 +81,7 @@ const CLASS_RANGE: [i32; CLASSES] = [0, 1, 2, 4, 8, 16, 32, 64, 127]; | ||
| 81 | 81 | const RESIDUE_BOOK_DIM: [usize; CLASSES] = [0, 4, 2, 2, 1, 1, 1, 1, 1]; |
| 82 | 82 | /// The vector books save packet bits but add setup and make the rate loop spend |
| 83 | 83 | /// harder; this keeps the realised rate at the caller's target. |
| 84 | -const RATE_TARGET_SCALE: f64 = 0.99; | |
| 84 | +const RATE_TARGET_SCALE: f64 = 0.97; | |
| 85 | 85 | /// Headroom in dB the widest residue book can actually state: 20 log10 127 |
| 86 | 86 | /// is 42, but a coupled angle channel is a difference of two magnitudes, so a |
| 87 | 87 | /// pair's step must leave half that range — 63, 36 dB. Past this the rate loop's extra headroom lowers the absolute-threshold |
| @@ -102,6 +102,13 @@ const HEADROOM_RANGE_SHORT: f64 = 42.0; | ||
| 102 | 102 | /// three tracks at 128 kbps: 50 dB kept the accuracy win without inflating the |
| 103 | 103 | /// files. |
| 104 | 104 | const CO_MASK_RANGE: f64 = 50.0; |
| 105 | +/// Extra dB above the spread threshold. This is the single long-block | |
| 106 | +/// rate/quality knob: raising the curve zeroes masked coefficients earlier, | |
| 107 | +/// while peaks still ride as residue above it. | |
| 108 | +const MASKING_OFFSET_DB: f64 = 9.0; | |
| 109 | +/// All-zero partition guard: if the masked band still has a bin within this | |
| 110 | +/// fraction of the floor, keep that bin as one sign-only residue sample. | |
| 111 | +const NOISE_NORMALISE_MIN_RATIO: f32 = 0.5; | |
| 105 | 112 | /// A short block gets no co-masking cap: a bin it drops is an error spread |
| 106 | 113 | /// across its whole window, the half before an onset included, and that is |
| 107 | 114 | /// the pre-echo the short block exists to prevent (44.1k mono, onset on the |
| @@ -132,7 +139,7 @@ const MODE_SHORT: u32 = 0; | ||
| 132 | 139 | const MODE_LONG: u32 = 1; |
| 133 | 140 | /// A tick energy jump past this multiple of its predecessor is a transient; |
| 134 | 141 | /// a near-zero predecessor makes this trip on any onset above the floor. |
| 135 | -const TRANSIENT_RATIO: f64 = 16.0; | |
| 142 | +const TRANSIENT_RATIO: f64 = 14.0; | |
| 136 | 143 | /// Below this per-sample mean square (-60 dBFS), a tick is not "content" at |
| 137 | 144 | /// all — the floor that keeps digital silence, dither and fade tails from |
| 138 | 145 | /// tripping the detector. |
| @@ -610,15 +617,17 @@ impl VorbisEncoder { | ||
| 610 | 617 | // until nothing clamps, so the curve hugs the peaks the range is |
| 611 | 618 | // measured from. |
| 612 | 619 | let limit = CLASS_RANGE[CLASSES - 1]; |
| 613 | - // A short block's precision is what bounds the pre-echo inside the | |
| 614 | - // window that carries an onset, so it does not inherit whatever | |
| 615 | - // headroom the music before it left the rate loop at: at 6 ch / 96 kHz | |
| 616 | - // the loop sat at 22 dB when the onset came and leaked -36 dB across | |
| 617 | - // the half-window before it. A short run is 16 blocks once a second | |
| 618 | - // or so on music, so the extra bits are noise to the loop. | |
| 619 | - let headroom = match plan.is_long { | |
| 620 | + // Blocks next to short windows bound pre-echo too: the transition-out | |
| 621 | + // long block still overlaps the samples just before the onset, so high | |
| 622 | + // bitrate transients get extra minimum precision. | |
| 623 | + let transient_headroom = if self.config.bitrate_bps >= 128_000 { | |
| 624 | + 54.0 | |
| 625 | + } else { | |
| 626 | + HEADROOM_SHORT_MIN | |
| 627 | + }; | |
| 628 | + let headroom = match plan.is_long && plan.prev_long && plan.next_long { | |
| 620 | 629 | true => self.headroom, |
| 621 | - false => self.headroom.max(HEADROOM_SHORT_MIN), | |
| 630 | + false => self.headroom.max(transient_headroom), | |
| 622 | 631 | }; |
| 623 | 632 | let mut lift: Vec<Vec<f64>> = vec![vec![1.0; bc.floor.x_list.len()]; channels]; |
| 624 | 633 | // Per X point, the span of bins whose curve it has a hand in. |
| @@ -645,6 +654,12 @@ impl VorbisEncoder { | ||
| 645 | 654 | }) |
| 646 | 655 | .collect(); |
| 647 | 656 | let mut passes = 0; |
| 657 | + let steady = plan.is_long && plan.prev_long && plan.next_long; | |
| 658 | + let masking_offset = if !steady && self.config.bitrate_bps >= 128_000 { | |
| 659 | + 0.0 | |
| 660 | + } else { | |
| 661 | + MASKING_OFFSET_DB | |
| 662 | + }; | |
| 648 | 663 | let (floor_values, quantised) = loop { |
| 649 | 664 | let mut curves: Vec<Vec<f32>> = vec![Vec::new(); channels]; |
| 650 | 665 | let mut floor_values: Vec<Vec<i32>> = vec![Vec::new(); channels]; |
| @@ -657,7 +672,14 @@ impl VorbisEncoder { | ||
| 657 | 672 | } |
| 658 | 673 | } |
| 659 | 674 | let (y, step2) = fit_floor( |
| 660 | - &bc.floor, &bc.ath, &bc.bark, headroom, bc.range, bc.co_mask, &peaks, | |
| 675 | + &bc.floor, | |
| 676 | + &bc.ath, | |
| 677 | + &bc.bark, | |
| 678 | + headroom, | |
| 679 | + bc.range, | |
| 680 | + bc.co_mask, | |
| 681 | + masking_offset, | |
| 682 | + &peaks, | |
| 661 | 683 | ); |
| 662 | 684 | let mut curve = vec![0.0f32; half]; |
| 663 | 685 | render_floor1(&bc.floor, &y, &step2, &mut curve); |
| @@ -676,37 +698,75 @@ impl VorbisEncoder { | ||
| 676 | 698 | fit(&[channel]); |
| 677 | 699 | } |
| 678 | 700 | |
| 679 | - // Normalise, couple, quantise. | |
| 701 | + // Normalise, couple, quantise. The floor is the masking threshold: | |
| 702 | + // bins that do not clear it are inaudible here and code as zero; | |
| 703 | + // bins that do clear it keep their full rounded residue, producing | |
| 704 | + // sparse small classes and larger tonal residues. | |
| 680 | 705 | let mut quantised: Vec<Vec<i32>> = (0..channels) |
| 681 | 706 | .map(|channel| { |
| 682 | 707 | spectra[channel] |
| 683 | 708 | .iter() |
| 684 | 709 | .zip(curves[channel].iter()) |
| 685 | - .map(|(&value, &floor)| match floor > 0.0 { | |
| 686 | - true => value / floor, | |
| 687 | - false => 0.0, | |
| 710 | + .map(|(&value, &floor)| { | |
| 711 | + if floor <= 0.0 || value.abs() <= floor { | |
| 712 | + 0 | |
| 713 | + } else { | |
| 714 | + (value / floor).round() as i32 | |
| 715 | + } | |
| 688 | 716 | }) |
| 689 | - .map(|normalised| normalised.round() as i32) | |
| 690 | 717 | .collect::<Vec<i32>>() |
| 691 | 718 | }) |
| 692 | 719 | .collect(); |
| 720 | + for channel in 0..channels { | |
| 721 | + for (band, values) in quantised[channel].chunks_mut(partition).enumerate() { | |
| 722 | + if values.iter().any(|&value| value != 0) { | |
| 723 | + continue; | |
| 724 | + } | |
| 725 | + let start = band * partition; | |
| 726 | + let end = (start + values.len()).min(half); | |
| 727 | + let mut peak = (NOISE_NORMALISE_MIN_RATIO, 0usize, 0i32); | |
| 728 | + for bin in start..end { | |
| 729 | + let floor = curves[channel][bin]; | |
| 730 | + if floor <= 0.0 { | |
| 731 | + continue; | |
| 732 | + } | |
| 733 | + let value = spectra[channel][bin]; | |
| 734 | + let ratio = value.abs() / floor; | |
| 735 | + if ratio > peak.0 { | |
| 736 | + peak = (ratio, bin - start, value.signum() as i32); | |
| 737 | + } | |
| 738 | + } | |
| 739 | + if peak.2 != 0 { | |
| 740 | + values[peak.1] = peak.2; | |
| 741 | + } | |
| 742 | + } | |
| 743 | + } | |
| 693 | 744 | for &(magnitude, angle) in &self.coupling { |
| 694 | 745 | let mut left = std::mem::take(&mut quantised[magnitude]); |
| 695 | 746 | let mut right = std::mem::take(&mut quantised[angle]); |
| 696 | - // Only while bits are scarce: headroom at the range is the | |
| 697 | - // rate loop saying the step cannot get finer, so the budget | |
| 698 | - // is better spent stating the angle than left unspent. | |
| 747 | + let cutoff = if self.config.bitrate_bps >= 128_000 { | |
| 748 | + 6_000.0 | |
| 749 | + } else { | |
| 750 | + POINT_STEREO_HZ | |
| 751 | + }; | |
| 699 | 752 | let point = match self.headroom < bc.range { |
| 700 | - true => { | |
| 701 | - (POINT_STEREO_HZ / (f64::from(self.config.sample_rate) * 0.5) * half as f64) | |
| 702 | - as usize | |
| 703 | - } | |
| 753 | + true => (cutoff / (f64::from(self.config.sample_rate) * 0.5) * half as f64) | |
| 754 | + as usize, | |
| 704 | 755 | false => half, |
| 705 | 756 | }; |
| 706 | 757 | for (bin, (l, r)) in left.iter_mut().zip(right.iter_mut()).enumerate() { |
| 707 | 758 | let (m, a) = couple(*l, *r); |
| 708 | 759 | *l = m; |
| 709 | - *r = if bin >= point { 0 } else { a }; | |
| 760 | + *r = if bin < point { | |
| 761 | + a | |
| 762 | + } else { | |
| 763 | + let delta = (spectra[magnitude][bin] - spectra[angle][bin]).abs(); | |
| 764 | + if delta > curves[magnitude][bin].max(curves[angle][bin]) { | |
| 765 | + a.signum() | |
| 766 | + } else { | |
| 767 | + 0 | |
| 768 | + } | |
| 769 | + }; | |
| 710 | 770 | } |
| 711 | 771 | quantised[magnitude] = left; |
| 712 | 772 | quantised[angle] = right; |
| @@ -829,6 +889,7 @@ fn fit_floor( | ||
| 829 | 889 | headroom: f64, |
| 830 | 890 | range: f64, |
| 831 | 891 | co_mask: f64, |
| 892 | + masking_offset: f64, | |
| 832 | 893 | peaks: &[f64], |
| 833 | 894 | ) -> (Vec<i32>, Vec<bool>) { |
| 834 | 895 | let db: Vec<f64> = peaks |
| @@ -865,7 +926,9 @@ fn fit_floor( | ||
| 865 | 926 | .zip(ath.iter()) |
| 866 | 927 | .map(|(&level, &threshold)| { |
| 867 | 928 | let threshold = threshold.max(loudest - co_mask); |
| 868 | - (level - headroom.min(range)).max(threshold - (headroom - range).max(0.0)) | |
| 929 | + let offset = (masking_offset - (headroom - range).max(0.0)).max(0.0); | |
| 930 | + (level - headroom.min(range) + offset) | |
| 931 | + .max(threshold - (headroom - range).max(0.0)) | |
| 869 | 932 | }) |
| 870 | 933 | .collect(); |
| 871 | 934 | let y: Vec<i32> = target |
shims/symphonia/tests/vorbis_timing.rsmodified+111 -18
| @@ -177,11 +177,14 @@ fn decode_from_reader( | ||
| 177 | 177 | out |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | -fn packet_prefix( | |
| 181 | - reader: &mut dyn FormatReader, | |
| 182 | - track_id: u32, | |
| 183 | - n: usize, | |
| 184 | -) -> Vec<(Vec<u8>, Option<i64>)> { | |
| 180 | +#[derive(Debug, Clone, PartialEq, Eq)] | |
| 181 | +struct PacketTiming { | |
| 182 | + data: Vec<u8>, | |
| 183 | + ts: i64, | |
| 184 | + granule: Option<i64>, | |
| 185 | +} | |
| 186 | + | |
| 187 | +fn packet_prefix(reader: &mut dyn FormatReader, track_id: u32, n: usize) -> Vec<PacketTiming> { | |
| 185 | 188 | let mut out = Vec::new(); |
| 186 | 189 | while out.len() < n { |
| 187 | 190 | let packet = reader |
| @@ -189,12 +192,49 @@ fn packet_prefix( | ||
| 189 | 192 | .expect("packet") |
| 190 | 193 | .expect("enough packets"); |
| 191 | 194 | if packet.track_id == track_id && !packet.data.is_empty() { |
| 192 | - out.push((packet.data.as_ref().to_vec(), packet.granule)); | |
| 195 | + out.push(PacketTiming { | |
| 196 | + data: packet.data.as_ref().to_vec(), | |
| 197 | + ts: packet.pts.value() as i64, | |
| 198 | + granule: packet.granule, | |
| 199 | + }); | |
| 200 | + } | |
| 201 | + } | |
| 202 | + out | |
| 203 | +} | |
| 204 | + | |
| 205 | +fn probe_packet_prefix(path: &Path, n: usize) -> Vec<PacketTiming> { | |
| 206 | + let mut demuxer = ec_ogg::OggDemuxer::open(File::open(path).expect("open")).expect("demux"); | |
| 207 | + let mut out = Vec::new(); | |
| 208 | + while out.len() < n { | |
| 209 | + match demuxer.next_packet() { | |
| 210 | + Ok(packet) => { | |
| 211 | + if packet.stream == 0 { | |
| 212 | + out.push(PacketTiming { | |
| 213 | + data: packet.data.as_ref().to_vec(), | |
| 214 | + ts: packet.pts.unwrap_or(0), | |
| 215 | + granule: ec_ogg::granule_of(&packet), | |
| 216 | + }); | |
| 217 | + } | |
| 218 | + } | |
| 219 | + Err(e) if e.is_eof() => panic!("enough packets"), | |
| 220 | + Err(e) => panic!("demux: {e}"), | |
| 193 | 221 | } |
| 194 | 222 | } |
| 195 | 223 | out |
| 196 | 224 | } |
| 197 | 225 | |
| 226 | +fn assert_packet_timing(rate: u32, label: &str, left: &[PacketTiming], right: &[PacketTiming]) { | |
| 227 | + assert_eq!(left.len(), right.len(), "{rate}: {label} packet count"); | |
| 228 | + for (i, (left, right)) in left.iter().zip(right).enumerate() { | |
| 229 | + assert_eq!(left.ts, right.ts, "{rate}: {label} packet {i} ts"); | |
| 230 | + assert_eq!( | |
| 231 | + left.granule, right.granule, | |
| 232 | + "{rate}: {label} packet {i} granule" | |
| 233 | + ); | |
| 234 | + assert_eq!(left.data, right.data, "{rate}: {label} packet {i} payload"); | |
| 235 | + } | |
| 236 | +} | |
| 237 | + | |
| 198 | 238 | fn seek_to_start(reader: &mut dyn FormatReader, track_id: u32) { |
| 199 | 239 | reader |
| 200 | 240 | .seek( |
| @@ -213,11 +253,7 @@ fn shim_decode(path: &Path) -> Vec<f32> { | ||
| 213 | 253 | decode_from_reader(&mut *reader, track_id, ¶ms) |
| 214 | 254 | } |
| 215 | 255 | |
| 216 | -fn gap_rms(samples: &[f32], rate: u32) -> f64 { | |
| 217 | - let channels = usize::from(CHANNELS); | |
| 218 | - let onset = ((rate / 2 + rate) as usize) * channels; | |
| 219 | - let start = onset - ((rate / 20) as usize) * channels; | |
| 220 | - let window = &samples[start..onset.min(samples.len())]; | |
| 256 | +fn rms(window: &[f32]) -> f64 { | |
| 221 | 257 | (window |
| 222 | 258 | .iter() |
| 223 | 259 | .map(|&v| f64::from(v) * f64::from(v)) |
| @@ -226,6 +262,31 @@ fn gap_rms(samples: &[f32], rate: u32) -> f64 { | ||
| 226 | 262 | .sqrt() |
| 227 | 263 | } |
| 228 | 264 | |
| 265 | +fn tone_rms(samples: &[f32], rate: u32) -> f64 { | |
| 266 | + let channels = usize::from(CHANNELS); | |
| 267 | + let start = FIRST_PACKET_FRAMES * channels; | |
| 268 | + let end = (rate / 2) as usize * channels; | |
| 269 | + rms(&samples[start..end.min(samples.len())]) | |
| 270 | +} | |
| 271 | + | |
| 272 | +fn gap_rms(samples: &[f32], rate: u32) -> f64 { | |
| 273 | + let channels = usize::from(CHANNELS); | |
| 274 | + let onset = ((rate / 2 + rate) as usize) * channels; | |
| 275 | + let start = onset - ((rate / 20) as usize) * channels; | |
| 276 | + rms(&samples[start..onset.min(samples.len())]) | |
| 277 | +} | |
| 278 | + | |
| 279 | +fn first_tone_onset(samples: &[f32], rate: u32) -> usize { | |
| 280 | + let channels = usize::from(CHANNELS); | |
| 281 | + let threshold = (tone_rms(samples, rate) * 0.25) as f32; | |
| 282 | + let search = rate as usize * channels; | |
| 283 | + samples[search..] | |
| 284 | + .chunks_exact(channels) | |
| 285 | + .position(|frame| frame.iter().any(|v| v.abs() >= threshold)) | |
| 286 | + .map(|frame| frame + search / channels) | |
| 287 | + .expect("tone onset") | |
| 288 | +} | |
| 289 | + | |
| 229 | 290 | fn max_abs_after_first_packet(a: &[f32], b: &[f32]) -> f32 { |
| 230 | 291 | let skip = FIRST_PACKET_FRAMES * usize::from(CHANNELS); |
| 231 | 292 | a[skip..] |
| @@ -252,10 +313,17 @@ fn ogg_timing_matches_reference_decoder() { | ||
| 252 | 313 | let shim_gap = gap_rms(&shim, rate); |
| 253 | 314 | let probe_gap = gap_rms(&probe, rate); |
| 254 | 315 | let reference_gap = gap_rms(&reference, rate); |
| 316 | + let shim_tone = tone_rms(&shim, rate); | |
| 317 | + let probe_tone = tone_rms(&probe, rate); | |
| 318 | + let reference_tone = tone_rms(&reference, rate); | |
| 319 | + let gap_bound = reference_tone * 0.001; | |
| 320 | + let shim_onset = first_tone_onset(&shim, rate); | |
| 321 | + let probe_onset = first_tone_onset(&probe, rate); | |
| 322 | + let reference_onset = first_tone_onset(&reference, rate); | |
| 255 | 323 | let shim_max = max_abs_after_first_packet(&shim, &reference); |
| 256 | 324 | let probe_max = max_abs_after_first_packet(&probe, &reference); |
| 257 | 325 | eprintln!( |
| 258 | - "rate={rate} frames shim={} probe={} ref={} gap shim={shim_gap:.8} probe={probe_gap:.8} ref={reference_gap:.8} max shim={shim_max:.8} probe={probe_max:.8}", | |
| 326 | + "rate={rate} frames shim={} probe={} ref={} tone shim={shim_tone:.8} probe={probe_tone:.8} ref={reference_tone:.8} gap_bound={gap_bound:.8} gap shim={shim_gap:.8} probe={probe_gap:.8} ref={reference_gap:.8} onset shim={shim_onset} probe={probe_onset} ref={reference_onset} max shim={shim_max:.8} probe={probe_max:.8}", | |
| 259 | 327 | shim.len() / usize::from(CHANNELS), |
| 260 | 328 | probe.len() / usize::from(CHANNELS), |
| 261 | 329 | reference.len() / usize::from(CHANNELS), |
| @@ -263,9 +331,28 @@ fn ogg_timing_matches_reference_decoder() { | ||
| 263 | 331 | |
| 264 | 332 | assert_eq!(shim.len(), reference.len(), "{rate}: shim length"); |
| 265 | 333 | assert_eq!(probe.len(), reference.len(), "{rate}: probe length"); |
| 334 | + assert!( | |
| 335 | + shim_gap <= gap_bound, | |
| 336 | + "{rate}: shim gap RMS {shim_gap:.8} exceeds 60 dB-down absolute bound {gap_bound:.8}; tone RMS {shim_tone:.8}" | |
| 337 | + ); | |
| 338 | + assert!( | |
| 339 | + probe_gap <= gap_bound, | |
| 340 | + "{rate}: probe gap RMS {probe_gap:.8} exceeds 60 dB-down absolute bound {gap_bound:.8}; tone RMS {probe_tone:.8}" | |
| 341 | + ); | |
| 342 | + assert!( | |
| 343 | + reference_gap <= gap_bound, | |
| 344 | + "{rate}: reference gap RMS {reference_gap:.8} exceeds 60 dB-down absolute bound {gap_bound:.8}; tone RMS {reference_tone:.8}" | |
| 345 | + ); | |
| 346 | + assert!( | |
| 347 | + shim_onset.abs_diff(probe_onset) <= 1, | |
| 348 | + "{rate}: shim onset {shim_onset} vs probe onset {probe_onset}" | |
| 349 | + ); | |
| 350 | + assert!( | |
| 351 | + shim_onset.abs_diff(reference_onset) <= 1, | |
| 352 | + "{rate}: shim onset {shim_onset} vs reference onset {reference_onset}" | |
| 353 | + ); | |
| 266 | 354 | assert!(shim_max <= 1e-6, "{rate}: shim differs by {shim_max}"); |
| 267 | 355 | assert!(probe_max <= 1e-6, "{rate}: probe differs by {probe_max}"); |
| 268 | - assert!(shim_gap < 1e-4, "{rate}: shim gap rms {shim_gap}"); | |
| 269 | 356 | } |
| 270 | 357 | } |
| 271 | 358 | |
| @@ -278,6 +365,8 @@ fn seek_to_start_replays_fresh_packet_timing() { | ||
| 278 | 365 | let mut fresh_reader = shim_reader(&path); |
| 279 | 366 | let (track_id, params) = audio_track(&*fresh_reader); |
| 280 | 367 | let fresh_packets = packet_prefix(&mut *fresh_reader, track_id, 8); |
| 368 | + let probe_packets = probe_packet_prefix(&path, 8); | |
| 369 | + assert_packet_timing(rate, "shim vs probe", &fresh_packets, &probe_packets); | |
| 281 | 370 | |
| 282 | 371 | let mut seeked_reader = shim_reader(&path); |
| 283 | 372 | let (seeked_track, seeked_params) = audio_track(&*seeked_reader); |
| @@ -286,15 +375,13 @@ fn seek_to_start_replays_fresh_packet_timing() { | ||
| 286 | 375 | let _ = packet_prefix(&mut *seeked_reader, seeked_track, 5); |
| 287 | 376 | seek_to_start(&mut *seeked_reader, seeked_track); |
| 288 | 377 | let seeked_packets = packet_prefix(&mut *seeked_reader, seeked_track, 8); |
| 378 | + assert_packet_timing(rate, "seek(0) vs probe", &seeked_packets, &probe_packets); | |
| 289 | 379 | |
| 290 | 380 | eprintln!( |
| 291 | 381 | "rate={rate} fresh_first_granule={:?} seek_first_granule={:?}", |
| 292 | - fresh_packets[0].1, seeked_packets[0].1 | |
| 293 | - ); | |
| 294 | - assert_eq!( | |
| 295 | - seeked_packets, fresh_packets, | |
| 296 | - "{rate}: packets after seek(0)" | |
| 382 | + fresh_packets[0].granule, seeked_packets[0].granule | |
| 297 | 383 | ); |
| 384 | + assert_packet_timing(rate, "seek(0) vs fresh", &seeked_packets, &fresh_packets); | |
| 298 | 385 | |
| 299 | 386 | let fresh_pcm = shim_decode(&path); |
| 300 | 387 | let mut decode_reader = shim_reader(&path); |
| @@ -303,6 +390,12 @@ fn seek_to_start_replays_fresh_packet_timing() { | ||
| 303 | 390 | seek_to_start(&mut *decode_reader, decode_track); |
| 304 | 391 | let seeked_pcm = decode_from_reader(&mut *decode_reader, decode_track, &decode_params); |
| 305 | 392 | assert_eq!(seeked_pcm, fresh_pcm, "{rate}: decoded PCM after seek(0)"); |
| 393 | + let fresh_onset = first_tone_onset(&fresh_pcm, rate); | |
| 394 | + let seeked_onset = first_tone_onset(&seeked_pcm, rate); | |
| 395 | + assert!( | |
| 396 | + seeked_onset.abs_diff(fresh_onset) <= 1, | |
| 397 | + "{rate}: seek(0) onset {seeked_onset} vs fresh onset {fresh_onset}" | |
| 398 | + ); | |
| 306 | 399 | |
| 307 | 400 | let mut mid_reader = shim_reader(&path); |
| 308 | 401 | let (mid_track, mid_params) = audio_track(&*mid_reader); |