diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index fe55c35..83889a5 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -410,14 +410,21 @@ impl Import { } } +/// What a scan is *of*: the source, which of its audio streams, and the clip's +/// own `[in, out)` source frames. The range is part of the name because it is +/// part of the read -- a clip cut in half is a different, shorter decode than +/// the whole take was, and levels read for one are not the other's. +type ScanKey = (PathBuf, usize, u32, u32); + /// The silence scan a worker is running, as the card shows it. Same two clocks /// as an [`Import`] and for the same reason -- one proves the window answers, /// one says the read has stopped moving -- over a progress that *can* move: /// a decode knows how far into the sound it has come, so the card says so. struct SilenceScan { - /// Source and stream being scanned, which is the cache key the levels land - /// under and what tells a second open of the same clip from a new one. - key: (PathBuf, usize), + /// Source, stream and source range being scanned, which is the cache key + /// the levels land under and what tells a second open of the same clip from + /// a new one. + key: ScanKey, /// When the worker started, for the elapsed clock. started: Instant, /// Written by the worker, read here every repaint. The cancel flag in it is @@ -1490,12 +1497,12 @@ struct Player { /// over and what an apply acts on -- *exactly* the previewed set, never a /// second scan at the moment of the press. silence_marks: Vec<(u32, u32)>, - /// The levels of every source scanned this session, kept so moving a - /// threshold is arithmetic rather than another decode. Keyed by source and - /// stream, and not one entry: two films on one timeline would otherwise - /// evict each other, and the decode being paid twice is the fifty seconds - /// this card exists to not spend. - silence_levels: HashMap<(PathBuf, usize), Arc>>, + /// The levels of every stretch scanned this session, kept so moving a + /// threshold is arithmetic rather than another decode. Keyed by + /// [`ScanKey`], and not one entry: two films on one timeline would + /// otherwise evict each other, and the decode being paid twice is the fifty + /// seconds this card exists to not spend. + silence_levels: HashMap>>, /// The scan a worker is running for the card, if one is. `None` means the /// card is drawing numbers it already has. silence_scan: Option, @@ -2560,8 +2567,9 @@ impl Player { /// Opens the silence card on the clip to be scanned: the selected one, or /// -- with nothing selected -- the clip the picture is coming from, which is /// the rule the speed card follows and what a person means by "this shot". - /// Either half of a take will do: the scan reads the *source*, and both - /// halves of an A/V take name the same file. + /// Either half of a take will do: both halves of an A/V take name the same + /// file and play the same source frames, which is the whole of what a scan + /// is of ([`ScanKey`]). /// /// The card is up on the next frame whatever the file is: a still is /// refused by name here, where the answer costs a look at the path, and @@ -2584,16 +2592,16 @@ impl Player { .map(|clip| audio_half(session, clip)) { Some((lane, idx)) => { - let source = self.session.as_ref().and_then(|session| { - let clip = session.lane_clips(lane).get(idx)?; - session.sources().get(clip.source).cloned() + let found = self.session.as_ref().and_then(|session| { + let clip = *session.lane_clips(lane).get(idx)?; + Some((session.sources().get(clip.source)?.clone(), clip)) }); // A still is asked *before* the decoder is: handing a png to the // mp4 demuxer answers "a box with a larger size than it", which // is a true sentence about a container and nothing a person can // act on. A picture has no sound for the same reason a silent // video has none, so it is refused in the same words. - let Some(source) = source else { + let Some((source, clip)) = found else { cx.notify(); return; }; @@ -2611,7 +2619,15 @@ impl Player { self.color_open = None; self.speed_open = None; self.context_menu = None; - let key = (source.path.clone(), source.audio_stream); + // The clip's own range, not the file's: the scan reads what this + // clip plays and nothing else, so a take cut in half costs half + // the decode and finds only what is still on the timeline. + let key = ( + source.path.clone(), + source.audio_stream, + clip.in_frame, + clip.out_frame, + ); match scan_plan( self.silence_levels.contains_key(&key), self.silence_scan.as_ref().map(|scan| &scan.key), @@ -2733,13 +2749,18 @@ impl Player { /// /// Whatever was scanning is cancelled first: one card, one scan, and the /// clip that has just been asked about is the one worth the disk. - fn start_silence_scan(&mut self, key: (PathBuf, usize), cx: &mut Context) { + /// + /// Only the clip's own `[in, out)` is read -- source frames over the + /// project's rate, the same seconds [`engine::Project`] hands the decoder + /// for playback -- so half a take is half a wait. + fn start_silence_scan(&mut self, key: ScanKey, cx: &mut Context) { self.cancel_silence_scan(); self.silence_marks.clear(); let progress = Arc::new(engine::silence::Progress::default()); + let range = source_secs(&key, self.fps); let scan = cx.background_executor().spawn({ let (key, progress) = (key.clone(), Arc::clone(&progress)); - async move { engine::silence::levels_with_progress(&key.0, key.1, &progress) } + async move { engine::silence::levels_with_progress(&key.0, key.1, range, &progress) } }); let now = Instant::now(); self.silence_scan = Some(SilenceScan { @@ -2819,7 +2840,12 @@ impl Player { // line. The marks arrive with the levels. let Some(levels) = self .silence_levels - .get(&(source.path.clone(), source.audio_stream)) + .get(&( + source.path.clone(), + source.audio_stream, + clip.in_frame, + clip.out_frame, + )) .cloned() else { return; @@ -9948,7 +9974,7 @@ enum ScanPlan { /// Which of the three [`ScanPlan`]s opening the card on `key` means. The whole /// of the cache policy, and the reason a second film does not cost the first /// one its levels: what is cached is asked per source, never "the last one". -fn scan_plan(cached: bool, running: Option<&(PathBuf, usize)>, key: &(PathBuf, usize)) -> ScanPlan { +fn scan_plan(cached: bool, running: Option<&ScanKey>, key: &ScanKey) -> ScanPlan { match (cached, running) { (true, _) => ScanPlan::Marks, (false, Some(at)) if at == key => ScanPlan::Wait, @@ -9956,6 +9982,18 @@ fn scan_plan(cached: bool, running: Option<&(PathBuf, usize)>, key: &(PathBuf, u } } +/// The half-open source seconds a [`ScanKey`]'s frames name, at the project's +/// rate -- what [`engine::silence::levels`] is asked to read, and the same +/// arithmetic playback puts a clip's `in_frame` through. A rate that is not a +/// rate reads the whole file rather than an empty window: a scan of nothing is +/// worse than a scan of too much. +fn source_secs(key: &ScanKey, fps: f64) -> (f64, f64) { + match fps.is_finite() && fps > 0. { + true => (f64::from(key.2) / fps, f64::from(key.3) / fps), + false => (0., f64::INFINITY), + } +} + /// What the silence card says while its worker reads. Unlike an import this /// one *has* a fraction -- a decode knows how far into the sound it has come -- /// so the line is where it is up to, out of what the header claims the track is @@ -10059,9 +10097,9 @@ mod tests { ZOOM_MIN_FRAMES, ZOOM_OUT_MARGIN, ZOOM_STEP, audio_rate_choices, clock, eta_secs, file_name, file_uri, fit_choices, landing, lane_refuses, library_rows, live_idx, next_fit, next_resolution, note_progress, px_along, - IMPORT_STALL, Import, ImportStage, SEEK_STALL, ScanPlan, SilenceScan, import_line, + IMPORT_STALL, Import, ImportStage, SEEK_STALL, ScanKey, ScanPlan, SilenceScan, import_line, Landing, arrival, launch_queue, - read_ahead, scan_plan, seek_line, silence_line, stash_or_write, + read_ahead, scan_plan, seek_line, silence_line, source_secs, stash_or_write, repeats, resolution_choices, resolution_ladder, span_label, tone_choices, tone_label, clip_width, trimmed_clip, trims, unscannable, unusable, visible_slice, @@ -14043,7 +14081,7 @@ mod tests { progress.total.store(7680, Relaxed); let started = Instant::now() - Duration::from_secs(9); let mut scan = SilenceScan { - key: (PathBuf::from("/films/A Film.mkv"), 0), + key: (PathBuf::from("/films/A Film.mkv"), 0, 0, 192_000), started, progress: Arc::clone(&progress), seen: 0, @@ -14082,18 +14120,20 @@ mod tests { assert_eq!(scan.since, held, "an unchanged mark must not reset it"); } - /// The cache is per source, which is what stops two films thrashing each - /// other's fifty seconds: A, then B, then A again is *one* decode of A. - /// And a source already being read is waited for rather than read twice -- - /// both halves of an A/V take name the same file. + /// The cache is per scanned stretch, which is what stops two films + /// thrashing each other's fifty seconds: A, then B, then A again is *one* + /// decode of A. And a stretch already being read is waited for rather than + /// read twice -- both halves of an A/V take name the same file and the same + /// frames. A *trimmed* A is not A: it is a shorter read of its own, which + /// is the whole point of scanning the clip instead of the file. #[test] fn a_second_film_does_not_cost_the_first_one_its_levels() { let (a, b) = ( - (PathBuf::from("/films/a.mkv"), 0), - (PathBuf::from("/films/b.mkv"), 0), + (PathBuf::from("/films/a.mkv"), 0, 0, 3000), + (PathBuf::from("/films/b.mkv"), 0, 0, 3000), ); - let mut cache: std::collections::HashMap<(PathBuf, usize), ()> = - std::collections::HashMap::new(); + let half = (PathBuf::from("/films/a.mkv"), 0, 0, 1500); + let mut cache: std::collections::HashMap = std::collections::HashMap::new(); let mut started = Vec::new(); // What a card open does, three times over, with the worker landing // between each: plan, and start what the plan says to start. @@ -14117,6 +14157,18 @@ mod tests { assert_eq!(scan_plan(false, Some(&b), &a), ScanPlan::Start); // Levels in hand beat a worker either way: the marks are arithmetic. assert_eq!(scan_plan(true, Some(&a), &a), ScanPlan::Marks); + // The same file cut in half is a read of its own: neither A's levels + // nor A's worker answers for it. + assert_eq!( + scan_plan(cache.contains_key(&half), None, &half), + ScanPlan::Start + ); + assert_eq!(scan_plan(false, Some(&a), &half), ScanPlan::Start); + // ...and the seconds asked for are the clip's, at the project's rate. + assert_eq!(source_secs(&half, 30.), (0., 50.)); + assert_eq!(source_secs(&(half.0.clone(), 0, 900, 1500), 30.), (30., 50.)); + // A rate that is not one reads the file rather than nothing. + assert_eq!(source_secs(&half, 0.), (0., f64::INFINITY)); } /// The two halves a worker hands back for an import, unwrapped: every import diff --git a/crates/engine/src/silence.rs b/crates/engine/src/silence.rs index 9944f8b..0b8e6cd 100644 --- a/crates/engine/src/silence.rs +++ b/crates/engine/src/silence.rs @@ -2,11 +2,15 @@ //! waveform takes, and the stretches of them nobody wants to watch. //! //! Three steps, kept apart so only the first one costs a decode: [`levels`] -//! turns a file into one loudness number per 20 ms window, [`regions`] turns -//! those numbers plus a [`Settings`] into silent stretches of *source* seconds, -//! and [`timeline_regions`] puts those on the timeline through one clip's own -//! range and rate. A card tweaking a threshold re-runs the last two and decodes -//! nothing. +//! turns a *stretch* of a file into one loudness number per 20 ms window, +//! [`regions`] turns those numbers plus a [`Settings`] into silent stretches of +//! seconds from where that read began, and [`timeline_regions`] puts those on +//! the timeline through one clip's own range and rate. A card tweaking a +//! threshold re-runs the last two and decodes nothing. +//! +//! The stretch is the *clip's*, not the file's: a take cut in half is half a +//! decode, and the half nobody is looking at is never read (which is what a +//! person means by "scan this clip"). //! //! Loudness in **dBFS**, which is the unit every tool that does this speaks //! (ffmpeg's `silencedetect` noise floor, auto-editor's threshold) -- and RMS @@ -31,7 +35,7 @@ pub const WINDOWS_PER_SEC: u32 = 50; pub const SILENT_DB: f32 = -120.; /// What counts as a silence worth cutting. Seconds, not frames: detection runs -/// on the *source*, whose sample rate is its own business, and the frame grid +/// on the *sound*, whose sample rate is its own business, and the frame grid /// is applied once at the end ([`timeline_regions`]). #[derive(Clone, Copy, PartialEq, Debug)] pub struct Settings { @@ -64,17 +68,26 @@ impl Default for Settings { } /// One RMS level in dBFS per [`WINDOWS_PER_SEC`]th of a second of `stream` of -/// `path`, from media time 0 -- the same decode [`crate::waveform::peaks`] runs -/// and with the same contract: channels folded together, `Ok(None)` for a file -/// with **no audio track at all**, which is a source to refuse by name rather -/// than one long silence to cut. +/// `path`, over the half-open `range` of **source seconds** -- the same decode +/// [`crate::waveform::peaks`] runs and with the same contract: channels folded +/// together, `Ok(None)` for a file with **no audio track at all**, which is a +/// source to refuse by name rather than one long silence to cut. +/// +/// `levels[0]` is the window at `range.0`, never the window at media time 0: +/// what is read is what is asked for, so a clip that plays a minute of a film +/// costs a minute of decode and the rest of the file is never touched. Whole +/// file is `(0., f64::INFINITY)`. /// -/// Linear in source length at ~1700x realtime, so a ten-minute take scans in -/// well under a second; a caller caches it per source and stream, because the -/// settings above are all applied to the result and none of them needs a second -/// decode. -pub fn levels(path: impl AsRef, stream: usize) -> crate::Result>> { - levels_with_progress(path, stream, &Progress::default()) +/// Linear in the range's length at ~1700x realtime, so a ten-minute take scans +/// in well under a second; a caller caches it per source, stream and range, +/// because the settings above are all applied to the result and none of them +/// needs a second decode. +pub fn levels( + path: impl AsRef, + stream: usize, + range: (f64, f64), +) -> crate::Result>> { + levels_with_progress(path, stream, range, &Progress::default()) } /// What a running [`levels_with_progress`] says about itself while it runs, and @@ -106,22 +119,32 @@ pub struct Progress { pub fn levels_with_progress( path: impl AsRef, stream: usize, + range: (f64, f64), progress: &Progress, ) -> crate::Result>> { + let from = range.0.max(0.); let sources = [(path.as_ref().to_path_buf(), stream)]; - let Some((meta, rx)) = - AudioSession::open_multi_streams(&sources, &[(Some(0), 0.0, f64::INFINITY)])? + let Some((meta, rx)) = AudioSession::open_multi_streams(&sources, &[(Some(0), from, range.1)])? else { return Ok(None); }; let rate = f64::from(meta.sample_rate).max(1.); if let Some(total) = meta.total_samples { - progress.total.store((total as f64 / rate * 10.) as u64, Relaxed); + // What is left to read, not what the file is: the line has to count out + // of the stretch the scan actually decodes or it stalls at a third. + let secs = (total as f64 / rate).min(range.1) - from; + progress.total.store((secs.max(0.) * 10.) as u64, Relaxed); } // Fractional for `peaks`'s reason: 44100 / 50 is whole, 44100 / 30 is not, // and a rounded window drifts a bucket every few seconds over a long take. let per_window = f64::from(meta.sample_rate) / f64::from(WINDOWS_PER_SEC); let channels = (meta.channels as usize).max(1); + // Chunks are stamped in the source's own samples, counted from where the + // segment starts reading -- so a scan of a clip an hour in would otherwise + // build an hour of empty windows in front of it, and every one of those + // reads as digital silence and would fuse with the first real quiet of the + // clip. The window the range begins at is window zero here instead. + let base = (from * f64::from(WINDOWS_PER_SEC)) as usize; // Sum of squares and how many samples went into it -- the two halves of a // mean square, kept in f64 because a loud minute is millions of terms. let mut sums: Vec<(f64, u64)> = Vec::new(); @@ -131,11 +154,13 @@ pub fn levels_with_progress( if progress.cancel.load(Relaxed) { break; } - progress - .scanned - .store((chunk.start_sample as f64 / rate * 10.) as u64, Relaxed); + progress.scanned.store( + ((chunk.start_sample as f64 / rate - from).max(0.) * 10.) as u64, + Relaxed, + ); for (frame, values) in chunk.samples.chunks(channels).enumerate() { - let window = ((chunk.start_sample + frame as u64) as f64 / per_window) as usize; + let at = ((chunk.start_sample + frame as u64) as f64 / per_window) as usize; + let window = at.saturating_sub(base); if window >= sums.len() { sums.resize(window + 1, (0., 0)); } @@ -162,8 +187,8 @@ fn dbfs(square_sum: f64, samples: u64) -> f32 { (20. * rms.log10()).max(f64::from(SILENT_DB)) as f32 } -/// The silent stretches of a `levels` track, as half-open `(from, to)` *source* -/// seconds, in order and never overlapping. +/// The silent stretches of a `levels` track, as half-open `(from, to)` seconds +/// **from where the read began**, in order and never overlapping. /// /// Pure arithmetic: this is what a card re-runs on every keystroke. The three /// settings are applied in the order a person means them -- quiet runs first, @@ -208,9 +233,12 @@ pub fn regions(levels: &[f32], cfg: Settings) -> Vec<(f64, f64)> { /// pairs of the lane `clip` is on -- what a preview marks and what /// [`crate::Project::cut_regions`] cuts. /// -/// Only the part of each region the clip actually plays: the scan reads the -/// whole file and the clip is a range of it, so a silence outside `[in, out)` -/// is not on the timeline at all. Positions go through the clip's **own rate** +/// `regions` are seconds from the clip's **in point**, which is where +/// [`levels`] was asked to start reading; they land at `in_frame` plus that. +/// Only the part of each region the clip actually plays survives -- a region +/// running past `out_frame` is trimmed to it and one starting beyond it is +/// dropped, so a short read or a rounding at the tail cannot mark a frame the +/// clip does not have. Positions go through the clip's **own rate** /// ([`Speed::timeline_at`]), so a silence in a 2x clip marks the frames it is /// really on. /// @@ -228,8 +256,11 @@ pub fn timeline_regions(clip: &Clip, fps: f64, regions: &[(f64, f64)]) -> Vec<(u regions .iter() .filter_map(|&(from, to)| { - let first = frame(from, f64::ceil).max(clip.in_frame); - let last = frame(to, f64::floor).min(clip.out_frame); + let first = clip.in_frame.saturating_add(frame(from, f64::ceil)); + let last = clip + .in_frame + .saturating_add(frame(to, f64::floor)) + .min(clip.out_frame); if last <= first { return None; } @@ -304,7 +335,7 @@ mod tests { /// peaks instead of RMS, would not line up second after second. #[test] fn the_dips_of_the_1hz_pulse_are_where_the_silences_are() { - let levels = levels(asset("test_av.mp4"), 0) + let levels = levels(asset("test_av.mp4"), 0, (0., f64::INFINITY)) .expect("open") .expect("test_av.mp4 has an audio track"); // A short forgiveness, because each dip of a sine is brief. @@ -346,10 +377,12 @@ mod tests { use super::{Progress, levels_with_progress}; use std::sync::atomic::Ordering::Relaxed; let progress = Progress::default(); - let watched = levels_with_progress(asset("test_av.mp4"), 0, &progress) + let watched = levels_with_progress(asset("test_av.mp4"), 0, (0., f64::INFINITY), &progress) .expect("open") .expect("test_av.mp4 has an audio track"); - let plain = levels(asset("test_av.mp4"), 0).expect("open").expect("audio"); + let plain = levels(asset("test_av.mp4"), 0, (0., f64::INFINITY)) + .expect("open") + .expect("audio"); assert_eq!(watched, plain, "a watched scan must find the same levels"); // Five seconds of fixture, in tenths, from the header and from the last // chunk the loop saw. @@ -360,12 +393,63 @@ mod tests { // receiver is dropped and the decoder behind it stops with it. let stopped = Progress::default(); stopped.cancel.store(true, Relaxed); - let partial = levels_with_progress(asset("test_av.mp4"), 0, &stopped) + let partial = levels_with_progress(asset("test_av.mp4"), 0, (0., f64::INFINITY), &stopped) .expect("open") .expect("audio"); assert!(partial.len() < plain.len(), "{} windows", partial.len()); } + /// A clip cut in half costs half a decode, and the half it reads is its + /// own: asked for `[2, 4)` seconds the scan hands back two seconds of + /// windows, starting at the *second* second -- the fixture's dips at 2.75 + /// and 3.75 land at 0.75 and 1.75 of what comes back, and the three dips + /// outside the range are not in it at all. + #[test] + fn a_range_is_read_from_its_own_start_and_nothing_outside_it_is() { + let cfg = Settings { + threshold_db: -40., + min_silence: 0.08, + padding: 0., + min_keep: 0., + }; + let whole = levels(asset("test_av.mp4"), 0, (0., f64::INFINITY)) + .expect("open") + .expect("audio"); + let half = levels(asset("test_av.mp4"), 0, (2., 4.)) + .expect("open") + .expect("audio"); + // Two seconds of windows for two seconds asked, give or take the one a + // packet boundary rounds -- not the five the file is. + assert!( + (half.len() as i64 - 100).abs() <= 2 && half.len() < whole.len(), + "{} windows for [2, 4) of {} for the file", + half.len(), + whole.len() + ); + let found = regions(&half, cfg); + assert_eq!(found.len(), 2, "{found:?}"); + for (nth, &(from, to)) in found.iter().enumerate() { + let dip = nth as f64 + 0.75; + assert!( + (from..to).contains(&dip), + "dip {nth}: {from}..{to} does not cover {dip}" + ); + } + // ...and on the timeline they are where the clip plays them: a clip + // reading from source frame 60 at 30 fps, laid at frame 500. + let placed = clip(500, 60, 120, Speed::NORMAL); + let marks = timeline_regions(&placed, 30., &found); + assert_eq!(marks.len(), 2, "{marks:?}"); + for (nth, &(start, len)) in marks.iter().enumerate() { + let dip = 500. + (nth as f64 + 0.75) * 30.; + assert!( + (f64::from(start)..f64::from(start + len)).contains(&dip), + "dip {nth}: [{start}, {}) is not the dip at {dip}", + start + len + ); + } + } + /// The three settings, each one visible on its own: a quiet run shorter /// than `min_silence` is forgiven, `padding` shrinks what is left at both /// ends, and a kept sliver shorter than `min_keep` joins the silences @@ -409,33 +493,37 @@ mod tests { near(&merged, &[(2., 5.)]); } - /// Where a region lands on the timeline is the clip's business: its range - /// clips what was scanned, its placement offsets it, and its rate divides - /// it. A 2x clip's silences mark half as many frames, at the right place. + /// Where a region lands on the timeline is the clip's business: seconds + /// counted from its in point, its placement offsets them, its end trims + /// them and its rate divides them. A 2x clip's silences mark half as many + /// frames, at the right place. #[test] fn regions_map_through_the_clips_range_and_rate() { let secs = [(1., 2.), (3., 3.5)]; - // Whole file, real time, placed at the start: source seconds are - // timeline frames at 30 fps. + // Whole file, real time, placed at the start: seconds read are timeline + // frames at 30 fps. let whole = clip(0, 0, 300, Speed::NORMAL); assert_eq!( timeline_regions(&whole, 30., &secs), vec![(30, 30), (90, 15)] ); // The same clip placed at frame 100 and reading from source frame 45: - // the first region is only the half of it the clip still plays, and it - // lands at the clip's own start. + // the scan began at 45, so a region a second in is source frame 75 -- + // and it lands 30 frames after the clip's own start. let placed = clip(100, 45, 300, Speed::NORMAL); assert_eq!( timeline_regions(&placed, 30., &secs), - vec![(100, 15), (145, 15)] + vec![(130, 30), (190, 15)] ); // At 2x every timeline frame is two source frames, so both regions are // half as wide and sit half as far along. let fast = clip(0, 0, 300, Speed::from_permille(2000)); assert_eq!(timeline_regions(&fast, 30., &secs), vec![(15, 15), (45, 7)]); - // A region entirely outside what the clip plays is not on the timeline. - assert!(timeline_regions(&clip(0, 200, 300, Speed::NORMAL), 30., &[(1., 2.)]).is_empty()); + // A read that ran past the clip's end is trimmed to it, and a region + // wholly past it is not on the timeline at all. + let short = clip(0, 0, 45, Speed::NORMAL); + assert_eq!(timeline_regions(&short, 30., &[(1., 2.)]), vec![(30, 15)]); + assert!(timeline_regions(&short, 30., &[(2., 3.)]).is_empty()); } /// Rounded inward at both ends: a region whose seconds fall between frames diff --git a/crates/engine/tests/silence.rs b/crates/engine/tests/silence.rs index 6c67bf6..9134bbf 100644 --- a/crates/engine/tests/silence.rs +++ b/crates/engine/tests/silence.rs @@ -323,7 +323,14 @@ fn scanning_a_clip_and_cutting_what_it_finds() { // is not an edit. assert!(!p.undo()); - let levels = silence::levels(asset("test_av.mp4"), 0) + let audio = Lane::new(LaneKind::Audio, 0); + let clip = p.lane(audio)[0]; + // The clip's own stretch of the file, which is what the card asks for. + let range = ( + f64::from(clip.in_frame) / FPS, + f64::from(clip.out_frame) / FPS, + ); + let levels = silence::levels(asset("test_av.mp4"), 0, range) .expect("scan") .expect("the fixture has audio"); let cfg = Settings { @@ -332,8 +339,6 @@ fn scanning_a_clip_and_cutting_what_it_finds() { padding: 0.02, min_keep: 0., }; - let audio = Lane::new(LaneKind::Audio, 0); - let clip = p.lane(audio)[0]; let regions = silence::timeline_regions(&clip, FPS, &silence::regions(&levels, cfg)); assert_eq!(regions.len(), 5, "{regions:?}"); for (second, &(start, len)) in regions.iter().enumerate() {