forge
Explore
Log in

Don't you dare go Hollow

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 commit

b4545afdb8f6c6115e789c745c274859edf36adeAhmet Kaan GümüşParent: 09e998b71895ba
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 const RESIDUE_BOOK_DIM: [usize; CLASSES] = [0, 4, 2, 2, 1, 1, 1, 1, 1];81 const RESIDUE_BOOK_DIM: [usize; CLASSES] = [0, 4, 2, 2, 1, 1, 1, 1, 1];
82 /// The vector books save packet bits but add setup and make the rate loop spend82 /// The vector books save packet bits but add setup and make the rate loop spend
83 /// harder; this keeps the realised rate at the caller's target.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 /// Headroom in dB the widest residue book can actually state: 20 log10 12785 /// Headroom in dB the widest residue book can actually state: 20 log10 127
86 /// is 42, but a coupled angle channel is a difference of two magnitudes, so a86 /// is 42, but a coupled angle channel is a difference of two magnitudes, so a
87 /// pair's step must leave half that range — 63, 36 dB. Past this the rate loop's extra headroom lowers the absolute-threshold87 /// 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 /// three tracks at 128 kbps: 50 dB kept the accuracy win without inflating the102 /// three tracks at 128 kbps: 50 dB kept the accuracy win without inflating the
103 /// files.103 /// files.
104 const CO_MASK_RANGE: f64 = 50.0;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 /// A short block gets no co-masking cap: a bin it drops is an error spread112 /// A short block gets no co-masking cap: a bin it drops is an error spread
106 /// across its whole window, the half before an onset included, and that is113 /// across its whole window, the half before an onset included, and that is
107 /// the pre-echo the short block exists to prevent (44.1k mono, onset on the114 /// 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 const MODE_LONG: u32 = 1;139 const MODE_LONG: u32 = 1;
133 /// A tick energy jump past this multiple of its predecessor is a transient;140 /// A tick energy jump past this multiple of its predecessor is a transient;
134 /// a near-zero predecessor makes this trip on any onset above the floor.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 /// Below this per-sample mean square (-60 dBFS), a tick is not "content" at143 /// Below this per-sample mean square (-60 dBFS), a tick is not "content" at
137 /// all — the floor that keeps digital silence, dither and fade tails from144 /// all — the floor that keeps digital silence, dither and fade tails from
138 /// tripping the detector.145 /// tripping the detector.
@@ -610,15 +617,17 @@ impl VorbisEncoder {
610 // until nothing clamps, so the curve hugs the peaks the range is617 // until nothing clamps, so the curve hugs the peaks the range is
611 // measured from.618 // measured from.
612 let limit = CLASS_RANGE[CLASSES - 1];619 let limit = CLASS_RANGE[CLASSES - 1];
613- // A short block's precision is what bounds the pre-echo inside the620+ // Blocks next to short windows bound pre-echo too: the transition-out
614- // window that carries an onset, so it does not inherit whatever621+ // long block still overlaps the samples just before the onset, so high
615- // headroom the music before it left the rate loop at: at 6 ch / 96 kHz622+ // bitrate transients get extra minimum precision.
616- // the loop sat at 22 dB when the onset came and leaked -36 dB across623+ let transient_headroom = if self.config.bitrate_bps >= 128_000 {
617- // the half-window before it. A short run is 16 blocks once a second624+ 54.0
618- // or so on music, so the extra bits are noise to the loop.625+ } else {
619- let headroom = match plan.is_long {626+ HEADROOM_SHORT_MIN
627+ };
628+ let headroom = match plan.is_long && plan.prev_long && plan.next_long {
620 true => self.headroom,629 true => self.headroom,
621- false => self.headroom.max(HEADROOM_SHORT_MIN),630+ false => self.headroom.max(transient_headroom),
622 };631 };
623 let mut lift: Vec<Vec<f64>> = vec![vec![1.0; bc.floor.x_list.len()]; channels];632 let mut lift: Vec<Vec<f64>> = vec![vec![1.0; bc.floor.x_list.len()]; channels];
624 // Per X point, the span of bins whose curve it has a hand in.633 // Per X point, the span of bins whose curve it has a hand in.
@@ -645,6 +654,12 @@ impl VorbisEncoder {
645 })654 })
646 .collect();655 .collect();
647 let mut passes = 0;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 let (floor_values, quantised) = loop {663 let (floor_values, quantised) = loop {
649 let mut curves: Vec<Vec<f32>> = vec![Vec::new(); channels];664 let mut curves: Vec<Vec<f32>> = vec![Vec::new(); channels];
650 let mut floor_values: Vec<Vec<i32>> = vec![Vec::new(); channels];665 let mut floor_values: Vec<Vec<i32>> = vec![Vec::new(); channels];
@@ -657,7 +672,14 @@ impl VorbisEncoder {
657 }672 }
658 }673 }
659 let (y, step2) = fit_floor(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 let mut curve = vec![0.0f32; half];684 let mut curve = vec![0.0f32; half];
663 render_floor1(&bc.floor, &y, &step2, &mut curve);685 render_floor1(&bc.floor, &y, &step2, &mut curve);
@@ -676,37 +698,75 @@ impl VorbisEncoder {
676 fit(&[channel]);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 let mut quantised: Vec<Vec<i32>> = (0..channels)705 let mut quantised: Vec<Vec<i32>> = (0..channels)
681 .map(|channel| {706 .map(|channel| {
682 spectra[channel]707 spectra[channel]
683 .iter()708 .iter()
684 .zip(curves[channel].iter())709 .zip(curves[channel].iter())
685- .map(|(&value, &floor)| match floor > 0.0 {710+ .map(|(&value, &floor)| {
686- true => value / floor,711+ if floor <= 0.0 || value.abs() <= floor {
687- false => 0.0,712+ 0
713+ } else {
714+ (value / floor).round() as i32
715+ }
688 })716 })
689- .map(|normalised| normalised.round() as i32)
690 .collect::<Vec<i32>>()717 .collect::<Vec<i32>>()
691 })718 })
692 .collect();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 for &(magnitude, angle) in &self.coupling {744 for &(magnitude, angle) in &self.coupling {
694 let mut left = std::mem::take(&mut quantised[magnitude]);745 let mut left = std::mem::take(&mut quantised[magnitude]);
695 let mut right = std::mem::take(&mut quantised[angle]);746 let mut right = std::mem::take(&mut quantised[angle]);
696- // Only while bits are scarce: headroom at the range is the747+ let cutoff = if self.config.bitrate_bps >= 128_000 {
697- // rate loop saying the step cannot get finer, so the budget748+ 6_000.0
698- // is better spent stating the angle than left unspent.749+ } else {
750+ POINT_STEREO_HZ
751+ };
699 let point = match self.headroom < bc.range {752 let point = match self.headroom < bc.range {
700- true => {753+ true => (cutoff / (f64::from(self.config.sample_rate) * 0.5) * half as f64)
701- (POINT_STEREO_HZ / (f64::from(self.config.sample_rate) * 0.5) * half as f64)754+ as usize,
702- as usize
703- }
704 false => half,755 false => half,
705 };756 };
706 for (bin, (l, r)) in left.iter_mut().zip(right.iter_mut()).enumerate() {757 for (bin, (l, r)) in left.iter_mut().zip(right.iter_mut()).enumerate() {
707 let (m, a) = couple(*l, *r);758 let (m, a) = couple(*l, *r);
708 *l = m;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 quantised[magnitude] = left;771 quantised[magnitude] = left;
712 quantised[angle] = right;772 quantised[angle] = right;
@@ -829,6 +889,7 @@ fn fit_floor(
829 headroom: f64,889 headroom: f64,
830 range: f64,890 range: f64,
831 co_mask: f64,891 co_mask: f64,
892+ masking_offset: f64,
832 peaks: &[f64],893 peaks: &[f64],
833 ) -> (Vec<i32>, Vec<bool>) {894 ) -> (Vec<i32>, Vec<bool>) {
834 let db: Vec<f64> = peaks895 let db: Vec<f64> = peaks
@@ -865,7 +926,9 @@ fn fit_floor(
865 .zip(ath.iter())926 .zip(ath.iter())
866 .map(|(&level, &threshold)| {927 .map(|(&level, &threshold)| {
867 let threshold = threshold.max(loudest - co_mask);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 .collect();933 .collect();
871 let y: Vec<i32> = target934 let y: Vec<i32> = target
shims/symphonia/tests/vorbis_timing.rsmodified+111 -18
@@ -177,11 +177,14 @@ fn decode_from_reader(
177 out177 out
178 }178 }
179 179
180-fn packet_prefix(180+#[derive(Debug, Clone, PartialEq, Eq)]
181- reader: &mut dyn FormatReader,181+struct PacketTiming {
182- track_id: u32,182+ data: Vec<u8>,
183- n: usize,183+ ts: i64,
184-) -> Vec<(Vec<u8>, Option<i64>)> {184+ granule: Option<i64>,
185+}
186+
187+fn packet_prefix(reader: &mut dyn FormatReader, track_id: u32, n: usize) -> Vec<PacketTiming> {
185 let mut out = Vec::new();188 let mut out = Vec::new();
186 while out.len() < n {189 while out.len() < n {
187 let packet = reader190 let packet = reader
@@ -189,12 +192,49 @@ fn packet_prefix(
189 .expect("packet")192 .expect("packet")
190 .expect("enough packets");193 .expect("enough packets");
191 if packet.track_id == track_id && !packet.data.is_empty() {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 out223 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 fn seek_to_start(reader: &mut dyn FormatReader, track_id: u32) {238 fn seek_to_start(reader: &mut dyn FormatReader, track_id: u32) {
199 reader239 reader
200 .seek(240 .seek(
@@ -213,11 +253,7 @@ fn shim_decode(path: &Path) -> Vec<f32> {
213 decode_from_reader(&mut *reader, track_id, &params)253 decode_from_reader(&mut *reader, track_id, &params)
214 }254 }
215 255
216-fn gap_rms(samples: &[f32], rate: u32) -> f64 {256+fn rms(window: &[f32]) -> 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())];
221 (window257 (window
222 .iter()258 .iter()
223 .map(|&v| f64::from(v) * f64::from(v))259 .map(|&v| f64::from(v) * f64::from(v))
@@ -226,6 +262,31 @@ fn gap_rms(samples: &[f32], rate: u32) -> f64 {
226 .sqrt()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 fn max_abs_after_first_packet(a: &[f32], b: &[f32]) -> f32 {290 fn max_abs_after_first_packet(a: &[f32], b: &[f32]) -> f32 {
230 let skip = FIRST_PACKET_FRAMES * usize::from(CHANNELS);291 let skip = FIRST_PACKET_FRAMES * usize::from(CHANNELS);
231 a[skip..]292 a[skip..]
@@ -252,10 +313,17 @@ fn ogg_timing_matches_reference_decoder() {
252 let shim_gap = gap_rms(&shim, rate);313 let shim_gap = gap_rms(&shim, rate);
253 let probe_gap = gap_rms(&probe, rate);314 let probe_gap = gap_rms(&probe, rate);
254 let reference_gap = gap_rms(&reference, rate);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 let shim_max = max_abs_after_first_packet(&shim, &reference);323 let shim_max = max_abs_after_first_packet(&shim, &reference);
256 let probe_max = max_abs_after_first_packet(&probe, &reference);324 let probe_max = max_abs_after_first_packet(&probe, &reference);
257 eprintln!(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 shim.len() / usize::from(CHANNELS),327 shim.len() / usize::from(CHANNELS),
260 probe.len() / usize::from(CHANNELS),328 probe.len() / usize::from(CHANNELS),
261 reference.len() / usize::from(CHANNELS),329 reference.len() / usize::from(CHANNELS),
@@ -263,9 +331,28 @@ fn ogg_timing_matches_reference_decoder() {
263 331
264 assert_eq!(shim.len(), reference.len(), "{rate}: shim length");332 assert_eq!(shim.len(), reference.len(), "{rate}: shim length");
265 assert_eq!(probe.len(), reference.len(), "{rate}: probe length");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 assert!(shim_max <= 1e-6, "{rate}: shim differs by {shim_max}");354 assert!(shim_max <= 1e-6, "{rate}: shim differs by {shim_max}");
267 assert!(probe_max <= 1e-6, "{rate}: probe differs by {probe_max}");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 let mut fresh_reader = shim_reader(&path);365 let mut fresh_reader = shim_reader(&path);
279 let (track_id, params) = audio_track(&*fresh_reader);366 let (track_id, params) = audio_track(&*fresh_reader);
280 let fresh_packets = packet_prefix(&mut *fresh_reader, track_id, 8);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 let mut seeked_reader = shim_reader(&path);371 let mut seeked_reader = shim_reader(&path);
283 let (seeked_track, seeked_params) = audio_track(&*seeked_reader);372 let (seeked_track, seeked_params) = audio_track(&*seeked_reader);
@@ -286,15 +375,13 @@ fn seek_to_start_replays_fresh_packet_timing() {
286 let _ = packet_prefix(&mut *seeked_reader, seeked_track, 5);375 let _ = packet_prefix(&mut *seeked_reader, seeked_track, 5);
287 seek_to_start(&mut *seeked_reader, seeked_track);376 seek_to_start(&mut *seeked_reader, seeked_track);
288 let seeked_packets = packet_prefix(&mut *seeked_reader, seeked_track, 8);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 eprintln!(380 eprintln!(
291 "rate={rate} fresh_first_granule={:?} seek_first_granule={:?}",381 "rate={rate} fresh_first_granule={:?} seek_first_granule={:?}",
292- fresh_packets[0].1, seeked_packets[0].1382+ fresh_packets[0].granule, seeked_packets[0].granule
293- );
294- assert_eq!(
295- seeked_packets, fresh_packets,
296- "{rate}: packets after seek(0)"
297 );383 );
384+ assert_packet_timing(rate, "seek(0) vs fresh", &seeked_packets, &fresh_packets);
298 385
299 let fresh_pcm = shim_decode(&path);386 let fresh_pcm = shim_decode(&path);
300 let mut decode_reader = shim_reader(&path);387 let mut decode_reader = shim_reader(&path);
@@ -303,6 +390,12 @@ fn seek_to_start_replays_fresh_packet_timing() {
303 seek_to_start(&mut *decode_reader, decode_track);390 seek_to_start(&mut *decode_reader, decode_track);
304 let seeked_pcm = decode_from_reader(&mut *decode_reader, decode_track, &decode_params);391 let seeked_pcm = decode_from_reader(&mut *decode_reader, decode_track, &decode_params);
305 assert_eq!(seeked_pcm, fresh_pcm, "{rate}: decoded PCM after seek(0)");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 let mut mid_reader = shim_reader(&path);400 let mut mid_reader = shim_reader(&path);
308 let (mid_track, mid_params) = audio_track(&*mid_reader);401 let (mid_track, mid_params) = audio_track(&*mid_reader);