forge
Explore
Log in

Don't you dare go Hollow

Fades reach exported and played-back audio

Browse files at this commit

9ec26f6815c53de3a6b554f3beb4289b8b84daf7Ahmet Kaan GümüşParent: 77c6364
  • fix
    • fades reach exported and played-back audio
Show full message
🐛 fix(engine): fades reach exported and played-back audio

Two bugs: `forces_encode` never checked a clip's own fade, so the
default Web MP4 copy path silently dropped fades from the exported
AAC track. Worse, `Fade`'s frame counts are timeline (fps) frames but
`Fade::apply` multiplies audio-rate sample blocks; unconverted, a
fade's threshold was crossed a few milliseconds into any clip, so a
fade-out muted the rest of the segment outright and a fade-in finished
before an ear (or a 100ms RMS window) could catch it. `Fade::scaled`
now re-counts a fade at the mix's own sample rate the moment the audio
session learns it, which also fixes the same bug in live preview.
crates/engine/src/audio.rsmodified+27 -8
@@ -393,20 +393,25 @@ impl AudioSession {
393 speeds: &[Option<crate::project::Stretch>],393 speeds: &[Option<crate::project::Stretch>],
394 sample_rate: Option<u32>,394 sample_rate: Option<u32>,
395 ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> {395 ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> {
396- Self::open_multi_streams_speed_at_fade(sources, segs, eqs, speeds, &[], sample_rate)396+ // No fades on this path, so the fps a `Fade` would be rescaled by is
397+ // never read; any finite value does.
398+ Self::open_multi_streams_speed_at_fade(sources, segs, eqs, speeds, &[], 1.0, sample_rate)
397 }399 }
398 400
399 /// [`open_multi_streams_speed_at`](Self::open_multi_streams_speed_at) with a401 /// [`open_multi_streams_speed_at`](Self::open_multi_streams_speed_at) with a
400 /// fade envelope per segment: `fades[i]` is what segment `i` plays through402 /// fade envelope per segment: `fades[i]` is what segment `i` plays through
401 /// ([`emit`]'s last effect, after the rate and the equalizer), built the403 /// ([`emit`]'s last effect, after the rate and the equalizer), built the
402 /// same way `eqs` and `speeds` are -- one entry per `segs`, a short list404 /// same way `eqs` and `speeds` are -- one entry per `segs`, a short list
403- /// meaning flat from there on.405+ /// meaning flat from there on. `fps` is the timeline rate each `Fade` was
406+ /// built at ([`crate::Project::audio_fades_from`]) -- this is the one
407+ /// place that rate meets the audio one ([`crate::project::Fade::scaled`]).
404 pub fn open_multi_streams_speed_at_fade(408 pub fn open_multi_streams_speed_at_fade(
405 sources: &[(PathBuf, usize)],409 sources: &[(PathBuf, usize)],
406 segs: &[(Option<usize>, f64, f64)],410 segs: &[(Option<usize>, f64, f64)],
407 eqs: &[Option<EqParams>],411 eqs: &[Option<EqParams>],
408 speeds: &[Option<crate::project::Stretch>],412 speeds: &[Option<crate::project::Stretch>],
409 fades: &[Option<crate::project::Fade>],413 fades: &[Option<crate::project::Fade>],
414+ fps: f64,
410 sample_rate: Option<u32>,415 sample_rate: Option<u32>,
411 ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> {416 ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> {
412 // The first source that could have a track, which is not always index 0:417 // The first source that could have a track, which is not always index 0:
@@ -591,11 +596,15 @@ impl AudioSession {
591 // lists' rule: a short `fades` (the empty one every plain caller596 // lists' rule: a short `fades` (the empty one every plain caller
592 // passes) means the rest play flat, and it is cloned rather than597 // passes) means the rest play flat, and it is cloned rather than
593 // built here because [`Project::audio_fades_from`] already resolved598 // built here because [`Project::audio_fades_from`] already resolved
594- // each clip's own frame count against where this segment lands.599+ // each clip's own frame count against where this segment lands --
600+ // in timeline frames, though, which is `fps`-relative and not yet
601+ // the rate `Fade::apply` will count samples at; `.scaled` re-counts
602+ // it in frames of `meta.sample_rate` now that this is known.
603+ let fade_ratio = f64::from(meta.sample_rate) / fps;
595 let fades: Vec<Option<crate::project::Fade>> = segments604 let fades: Vec<Option<crate::project::Fade>> = segments
596 .iter()605 .iter()
597 .enumerate()606 .enumerate()
598- .map(|(i, _)| fades.get(i).copied().flatten())607+ .map(|(i, _)| fades.get(i).copied().flatten().map(|f| f.scaled(fade_ratio)))
599 .collect();608 .collect();
600 609
601 let (tx, rx) = sync_channel(32);610 let (tx, rx) = sync_channel(32);
@@ -718,26 +727,30 @@ impl AudioSession {
718 limiter: Limiter,727 limiter: Limiter,
719 sample_rate: Option<u32>,728 sample_rate: Option<u32>,
720 ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> {729 ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> {
730+ // No fades on this path -- see `open_multi_streams_speed_at`'s same
731+ // placeholder.
721 Self::open_mixed_streams_master_at_fade(732 Self::open_mixed_streams_master_at_fade(
722- sources, lanes, eqs, speeds, &[], gains, limiter, sample_rate,733+ sources, lanes, eqs, speeds, &[], 1.0, gains, limiter, sample_rate,
723 )734 )
724 }735 }
725 736
726 /// [`open_mixed_streams_master_at`](Self::open_mixed_streams_master_at)737 /// [`open_mixed_streams_master_at`](Self::open_mixed_streams_master_at)
727 /// with a fade envelope per segment; see738 /// with a fade envelope per segment; see
728 /// [`open_mixed_streams_live_fade`](Self::open_mixed_streams_live_fade).739 /// [`open_mixed_streams_live_fade`](Self::open_mixed_streams_live_fade).
740+ /// `fps` is [`open_multi_streams_speed_at_fade`](Self::open_multi_streams_speed_at_fade)'s.
729 pub fn open_mixed_streams_master_at_fade(741 pub fn open_mixed_streams_master_at_fade(
730 sources: &[(PathBuf, usize)],742 sources: &[(PathBuf, usize)],
731 lanes: &[Vec<(Option<usize>, f64, f64)>],743 lanes: &[Vec<(Option<usize>, f64, f64)>],
732 eqs: &[Vec<Option<EqParams>>],744 eqs: &[Vec<Option<EqParams>>],
733 speeds: &[Vec<Option<crate::project::Stretch>>],745 speeds: &[Vec<Option<crate::project::Stretch>>],
734 fades: &[Vec<Option<crate::project::Fade>>],746 fades: &[Vec<Option<crate::project::Fade>>],
747+ fps: f64,
735 gains: &[f32],748 gains: &[f32],
736 limiter: Limiter,749 limiter: Limiter,
737 sample_rate: Option<u32>,750 sample_rate: Option<u32>,
738 ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> {751 ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> {
739 Self::open_mixed_streams_live_fade(752 Self::open_mixed_streams_live_fade(
740- sources, lanes, eqs, speeds, fades, gains, limiter, None, sample_rate,753+ sources, lanes, eqs, speeds, fades, fps, gains, limiter, None, sample_rate,
741 )754 )
742 }755 }
743 756
@@ -759,8 +772,10 @@ impl AudioSession {
759 live: Option<&Arc<MixControls>>,772 live: Option<&Arc<MixControls>>,
760 sample_rate: Option<u32>,773 sample_rate: Option<u32>,
761 ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> {774 ) -> crate::Result<Option<(AudioMeta, Receiver<AudioChunk>)>> {
775+ // No fades on this path -- see `open_multi_streams_speed_at`'s same
776+ // placeholder.
762 Self::open_mixed_streams_live_fade(777 Self::open_mixed_streams_live_fade(
763- sources, lanes, eqs, speeds, &[], gains, limiter, live, sample_rate,778+ sources, lanes, eqs, speeds, &[], 1.0, gains, limiter, live, sample_rate,
764 )779 )
765 }780 }
766 781
@@ -768,13 +783,15 @@ impl AudioSession {
768 /// envelope per segment as well: `fades[i]` is what segment `i` plays783 /// envelope per segment as well: `fades[i]` is what segment `i` plays
769 /// through -- [`crate::Project::audio_fades_from`] is what builds it, off784 /// through -- [`crate::Project::audio_fades_from`] is what builds it, off
770 /// the same walk the segments come from. A short or missing list means785 /// the same walk the segments come from. A short or missing list means
771- /// the rest play flat, the eq list's rule.786+ /// the rest play flat, the eq list's rule. `fps` is the timeline rate
787+ /// those fades were built at ([`crate::project::Fade::scaled`]).
772 pub fn open_mixed_streams_live_fade(788 pub fn open_mixed_streams_live_fade(
773 sources: &[(PathBuf, usize)],789 sources: &[(PathBuf, usize)],
774 lanes: &[Vec<(Option<usize>, f64, f64)>],790 lanes: &[Vec<(Option<usize>, f64, f64)>],
775 eqs: &[Vec<Option<EqParams>>],791 eqs: &[Vec<Option<EqParams>>],
776 speeds: &[Vec<Option<crate::project::Stretch>>],792 speeds: &[Vec<Option<crate::project::Stretch>>],
777 fades: &[Vec<Option<crate::project::Fade>>],793 fades: &[Vec<Option<crate::project::Fade>>],
794+ fps: f64,
778 gains: &[f32],795 gains: &[f32],
779 limiter: Limiter,796 limiter: Limiter,
780 live: Option<&Arc<MixControls>>,797 live: Option<&Arc<MixControls>>,
@@ -793,6 +810,7 @@ impl AudioSession {
793 eqs.first().unwrap_or(&flat),810 eqs.first().unwrap_or(&flat),
794 speeds.first().unwrap_or(&plain),811 speeds.first().unwrap_or(&plain),
795 fades.first().unwrap_or(&flat_fade),812 fades.first().unwrap_or(&flat_fade),
813+ fps,
796 sample_rate,814 sample_rate,
797 );815 );
798 }816 }
@@ -811,6 +829,7 @@ impl AudioSession {
811 eqs.get(i).unwrap_or(&flat),829 eqs.get(i).unwrap_or(&flat),
812 speeds.get(i).unwrap_or(&plain),830 speeds.get(i).unwrap_or(&plain),
813 fades.get(i).unwrap_or(&flat_fade),831 fades.get(i).unwrap_or(&flat_fade),
832+ fps,
814 sample_rate,833 sample_rate,
815 )?834 )?
816 else {835 else {
crates/engine/src/export.rsmodified+32 -0
@@ -592,6 +592,17 @@ fn mastered(project: &Project) -> bool {
592 project.limiter().is_active() || project.audio_gains().iter().any(|&g| g != 1.0)592 project.limiter().is_active() || project.audio_gains().iter().any(|&g| g != 1.0)
593 }593 }
594 594
595+/// Whether any audio clip has a fade -- [`equalized`]'s pair again: a fade is
596+/// gain math on decoded samples ([`crate::project::Fade::apply`]), and a
597+/// packet copy carries neither an equalizer nor a fade. An mp4 whose timeline
598+/// has one is decoded and re-encoded so the fade actually reaches the file.
599+fn faded(project: &Project) -> bool {
600+ project
601+ .audio_lanes()
602+ .into_iter()
603+ .any(|lane| project.lane(lane).iter().any(|c| c.fade_in > 0 || c.fade_out > 0))
604+}
605+
595 /// The bitrate an export codes at: the caller's number clamped into what an606 /// The bitrate an export codes at: the caller's number clamped into what an
596 /// asked-for rate may be ([`MAX_EXPLICIT_BITRATE`]), the derived one where there607 /// asked-for rate may be ([`MAX_EXPLICIT_BITRATE`]), the derived one where there
597 /// was none. Clamped rather than refused, for the reason [`Enc::open`] states.608 /// was none. Clamped rather than refused, for the reason [`Enc::open`] states.
@@ -736,6 +747,7 @@ fn forces_encode(project: &Project, ranged: bool) -> bool {
736 .any(|&lane| project.lane(lane).iter().any(|c| !c.speed.is_normal()))747 .any(|&lane| project.lane(lane).iter().any(|c| !c.speed.is_normal()))
737 || equalized(project)748 || equalized(project)
738 || mastered(project)749 || mastered(project)
750+ || faded(project)
739 }751 }
740 752
741 /// What the sound is written by. Every audio encoder here is software -- there753 /// What the sound is written by. Every audio encoder here is software -- there
@@ -1825,6 +1837,7 @@ fn encode_audio(
1825 &eqs,1837 &eqs,
1826 &speeds,1838 &speeds,
1827 &fades,1839 &fades,
1840+ meta.frame_rate,
1828 &project.audio_gains(),1841 &project.audio_gains(),
1829 project.limiter(),1842 project.limiter(),
1830 sample_rate,1843 sample_rate,
@@ -2996,6 +3009,7 @@ fn run_audio(
2996 &eqs,3009 &eqs,
2997 &speeds,3010 &speeds,
2998 &fades,3011 &fades,
3012+ meta.frame_rate,
2999 &project.audio_gains(),3013 &project.audio_gains(),
3000 project.limiter(),3014 project.limiter(),
3001 sample_rate,3015 sample_rate,
@@ -4897,6 +4911,24 @@ mod tests {
4897 assert_eq!(asked(1), MIN_BITRATE, "and floored");4911 assert_eq!(asked(1), MIN_BITRATE, "and floored");
4898 }4912 }
4899 4913
4914+ /// A clip's fade takes the copy path away, exactly as an equalizer does:
4915+ /// a copied AAC packet cannot carry gain math nobody put in the file. The
4916+ /// bug this guards is [`forces_encode`] gating on `equalized`/`mastered`
4917+ /// but never checking a clip's own `fade_in`/`fade_out` at all -- the
4918+ /// default Web MP4 export then labelled and took the "AAC copy" path for
4919+ /// a project whose picture showed a fade, and the fade never reached the
4920+ /// file.
4921+ #[test]
4922+ fn a_fade_forces_the_audio_to_be_re_encoded() {
4923+ let mut project = Project::single("/nonexistent/film.mp4", 90);
4924+ assert!(!forces_encode(&project, false), "flat, so a copy is fine");
4925+ assert!(project.set_fade_in(crate::project::Lane::new(crate::project::LaneKind::Audio, 0), 0, 15));
4926+ assert!(
4927+ forces_encode(&project, false),
4928+ "a fade-in on the only clip must force a re-encode"
4929+ );
4930+ }
4931+
4900 fn meta(width: u32, height: u32) -> VideoMeta {4932 fn meta(width: u32, height: u32) -> VideoMeta {
4901 VideoMeta {4933 VideoMeta {
4902 width,4934 width,
crates/engine/src/playback.rsmodified+1 -0
@@ -3347,6 +3347,7 @@ impl PlaybackSession {
3347 &eqs,3347 &eqs,
3348 &speeds,3348 &speeds,
3349 &fades,3349 &fades,
3350+ fps,
3350 &gains,3351 &gains,
3351 limiter,3352 limiter,
3352 Some(&worker_controls),3353 Some(&worker_controls),
crates/engine/src/project.rsmodified+23 -0
@@ -822,6 +822,29 @@ impl Fade {
822 }822 }
823 }823 }
824 }824 }
825+
826+ /// Every field re-counted at `ratio` frames-out per frame-in, rounded to
827+ /// the nearest whole frame. [`Project::lane_fades_from`] builds a `Fade`
828+ /// in *timeline* frames ([`Clip::fade_in`]'s own unit, the fps every clip
829+ /// position is in) but [`Self::apply`] multiplies *audio* frames --
830+ /// `channels`-wide sample blocks at whatever rate the mix is running at,
831+ /// which is almost never the video's fps. Left unconverted, `elapsed` (an
832+ /// audio-frame count) raced past `total`/`fade_out` (fps-frame counts) a
833+ /// few milliseconds into any clip, so a fade-out silenced the rest of the
834+ /// clip outright and a fade-in finished before a listener's ear caught up
835+ /// -- audible on nothing shorter than a clip a few fps-frames long, which
836+ /// is why 338 green tests never once ran the two curves out of step.
837+ /// `ratio` is `sample_rate / fps`, applied once where the audio session
838+ /// first learns its own rate ([`crate::AudioSession::open_multi_streams_speed_at_fade`]).
839+ pub fn scaled(self, ratio: f64) -> Fade {
840+ let conv = |f: u32| (f64::from(f) * ratio).round() as u32;
841+ Fade {
842+ elapsed: conv(self.elapsed),
843+ fade_in: conv(self.fade_in),
844+ fade_out: conv(self.fade_out),
845+ total: conv(self.total),
846+ }
847+ }
825 }848 }
826 849
827 /// What a save writes and a load takes back: the sources, every lane in850 /// What a save writes and a load takes back: the sources, every lane in
crates/engine/tests/audio_export.rsmodified+189 -0
@@ -901,6 +901,195 @@ fn exports_the_timeline_as_an_ogg_vorbis() {
901 std::fs::remove_file(&out).unwrap();901 std::fs::remove_file(&out).unwrap();
902 }902 }
903 903
904+/// A synthetic 44.1 kHz stereo WAV of a constant-amplitude 440 Hz tone,
905+/// `secs` long, as plain a RIFF header as `a_mono_timeline_exports_as_dual_mono_ogg`
906+/// writes -- no fixture needed, since a fade's shape is a claim about level
907+/// over time and a flat tone is the cleanest body to shape.
908+fn tone_wav(path: &Path, secs: f64) {
909+ let frames = (secs * f64::from(RATE)) as usize;
910+ let data = (frames * 4) as u32; // stereo, 16-bit
911+ let mut wav = Vec::with_capacity(44 + frames * 4);
912+ wav.extend_from_slice(b"RIFF");
913+ wav.extend_from_slice(&(36 + data).to_le_bytes());
914+ wav.extend_from_slice(b"WAVEfmt ");
915+ wav.extend_from_slice(&16u32.to_le_bytes());
916+ wav.extend_from_slice(&1u16.to_le_bytes()); // PCM
917+ wav.extend_from_slice(&2u16.to_le_bytes()); // stereo
918+ wav.extend_from_slice(&RATE.to_le_bytes());
919+ wav.extend_from_slice(&(RATE * 4).to_le_bytes()); // byte rate
920+ wav.extend_from_slice(&4u16.to_le_bytes()); // block align
921+ wav.extend_from_slice(&16u16.to_le_bytes());
922+ wav.extend_from_slice(b"data");
923+ wav.extend_from_slice(&data.to_le_bytes());
924+ for i in 0..frames {
925+ let t = i as f64 / f64::from(RATE);
926+ let s = (0.8 * (2.0 * std::f64::consts::PI * 440.0 * t).sin() * 32767.0) as i16;
927+ wav.extend_from_slice(&s.to_le_bytes());
928+ wav.extend_from_slice(&s.to_le_bytes());
929+ }
930+ std::fs::write(path, &wav).expect("write the tone fixture");
931+}
932+
933+/// Regression for the export that drew a fade in the UI and stored it on the
934+/// clip but never carried it into the written file: a single clip with a
935+/// 1.5 s fade-in, exported as a WAV, must actually be quiet at the start and
936+/// rise across the ramp -- not the source's own flat level from sample zero.
937+#[test]
938+fn a_fade_in_reaches_the_exported_audio() {
939+ let src = out_path("fadein_src", "wav");
940+ tone_wav(&src, 3.0);
941+ let fps = 30.0;
942+ let clip = Clip {
943+ fade_in: 45, // 1.5 s at 30 fps
944+ fade_out: 0,
945+ transition_out: 0,
946+ start: 0,
947+ in_frame: 0,
948+ out_frame: 90, // 3.0 s at 30 fps
949+ source: 0,
950+ link: None,
951+ eq: None,
952+ color: None,
953+ fit: FitPolicy::default(),
954+ speed: Speed::NORMAL,
955+ };
956+ let project = Project::from_parts(
957+ vec![Source::new(src.to_path_buf(), 0)],
958+ vec![(LaneKind::Audio, vec![clip])],
959+ Vec::new(),
960+ Vec::new(),
961+ )
962+ .expect("a one-clip fade-in project");
963+ let meta = engine::VideoMeta {
964+ width: 1,
965+ height: 1,
966+ frame_rate: fps,
967+ frame_count: 90,
968+ codec: engine::Codec::H264,
969+ color: Default::default(),
970+ };
971+ let out = out_path("fadein", "wav");
972+ let handle = engine::export::start(
973+ project,
974+ meta,
975+ &out,
976+ &ExportSettings {
977+ format: Format::Wav,
978+ ..Default::default()
979+ },
980+ None,
981+ );
982+ wait(&handle, Duration::from_secs(60)).expect("wav export of a faded clip");
983+
984+ let (audio, samples) = decode(&out);
985+ let channels = usize::from(audio.channels);
986+ let body = rms(&samples, channels, 2.0, 2.9);
987+ let start = rms(&samples, channels, 0.0, 0.1);
988+ let quarter = rms(&samples, channels, 0.3, 0.4);
989+ let half = rms(&samples, channels, 0.7, 0.8);
990+ let near_end = rms(&samples, channels, 1.35, 1.45);
991+ println!(
992+ "fade-in rms: start {start:.4} quarter {quarter:.4} half {half:.4} \
993+ near-end {near_end:.4} body {body:.4}"
994+ );
995+ assert!(body > 0.3, "the tone's own body is audible: {body:.4}");
996+ assert!(
997+ start < body * 0.1,
998+ "the very start is quiet: {start:.4} vs body {body:.4}"
999+ );
1000+ assert!(quarter < half, "the envelope rises: {quarter:.4} -> {half:.4}");
1001+ assert!(
1002+ half < near_end,
1003+ "the envelope keeps rising into the ramp's end: {half:.4} -> {near_end:.4}"
1004+ );
1005+ assert!(
1006+ (near_end - body).abs() < body * 0.15,
1007+ "past the ramp the level settles at the body's own: {near_end:.4} vs {body:.4}"
1008+ );
1009+ std::fs::remove_file(&out).unwrap();
1010+ std::fs::remove_file(&src).unwrap();
1011+}
1012+
1013+/// Regression for the worse of the two bugs: a clip split in two and
1014+/// cross-faded at the join used to go silent for its *entire* remaining
1015+/// length once the fade's frame count (a handful of fps-frames) was read as
1016+/// a sample count (a mixed-rate quantity thousands of times larger) -- the
1017+/// gain curve's tail condition was true from a few milliseconds in to the
1018+/// end of the segment. The first half's own interior, well clear of either
1019+/// edge, must still be at the tone's own level.
1020+#[test]
1021+fn a_split_and_crossfaded_clip_has_no_muted_interior() {
1022+ let src = out_path("crossfade_src", "wav");
1023+ tone_wav(&src, 3.0);
1024+ let fps = 30.0;
1025+ let clip = |start, in_frame, out_frame| Clip {
1026+ fade_in: 0,
1027+ fade_out: 0,
1028+ transition_out: 0,
1029+ start,
1030+ in_frame,
1031+ out_frame,
1032+ source: 0,
1033+ link: None,
1034+ eq: None,
1035+ color: None,
1036+ fit: FitPolicy::default(),
1037+ speed: Speed::NORMAL,
1038+ };
1039+ // The clip split at 1.5 s (45 frames @ 30 fps) into two adjacent halves,
1040+ // exactly what `Project::split` leaves behind.
1041+ let mut project = Project::from_parts(
1042+ vec![Source::new(src.to_path_buf(), 0)],
1043+ vec![(
1044+ LaneKind::Audio,
1045+ vec![clip(0, 0, 45), clip(45, 45, 90)],
1046+ )],
1047+ Vec::new(),
1048+ Vec::new(),
1049+ )
1050+ .expect("a split clip on one audio lane");
1051+ assert!(
1052+ project.crossfade(Lane::new(LaneKind::Audio, 0), 0, 15),
1053+ "adjacent halves cross-fade at their join"
1054+ );
1055+ let meta = engine::VideoMeta {
1056+ width: 1,
1057+ height: 1,
1058+ frame_rate: fps,
1059+ frame_count: 90,
1060+ codec: engine::Codec::H264,
1061+ color: Default::default(),
1062+ };
1063+ let out = out_path("crossfade", "wav");
1064+ let handle = engine::export::start(
1065+ project,
1066+ meta,
1067+ &out,
1068+ &ExportSettings {
1069+ format: Format::Wav,
1070+ ..Default::default()
1071+ },
1072+ None,
1073+ );
1074+ wait(&handle, Duration::from_secs(60)).expect("wav export of a cross-faded split");
1075+
1076+ let (audio, samples) = decode(&out);
1077+ let channels = usize::from(audio.channels);
1078+ // The source's own flat level, read off a stretch with no fade anywhere
1079+ // near it (the second half's own interior, past its fade-in).
1080+ let reference = rms(&samples, channels, 2.0, 2.9);
1081+ // The first half's interior: from just past 0 to well before its own
1082+ // fade-out starts at 1.0 s (45 - 15 frames = 30 frames @ 30 fps).
1083+ let interior = rms(&samples, channels, 0.1, 0.9);
1084+ println!("crossfade rms: interior {interior:.4} reference {reference:.4}");
1085+ assert!(
1086+ interior > reference * 0.7,
1087+ "the first half's interior is not muted: {interior:.4} vs reference {reference:.4}"
1088+ );
1089+ std::fs::remove_file(&out).unwrap();
1090+ std::fs::remove_file(&src).unwrap();
1091+}
1092+
904 /// A **mono** timeline through the same door. `rusty_vorbis` ships one embedded1093 /// A **mono** timeline through the same door. `rusty_vorbis` ships one embedded
905 /// setup header and it is a stereo profile -- a mono push is refused outright1094 /// setup header and it is a stereo profile -- a mono push is refused outright
906 /// ("bad coupling channels") -- so `export::write_ogg` writes the mix as dual1095 /// ("bad coupling channels") -- so `export::write_ogg` writes the mix as dual