Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion crates/recording/src/sources/audio_mixer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,11 @@ fn construct_filter_graph(infos: &[AudioInfo]) -> Result<FilterGraphParts, ffmpe
let mut amix = filter_graph.add(
&ffmpeg::filter::find("amix").expect("Failed to find amix filter"),
"amix",
&format!("inputs={}:duration=longest", abuffers.len()),
// normalize=0: each source keeps its own level. amix's default
// divides every input by the number of inputs (the microphone at
// -6 dB beside system audio) and ramps that scale whenever an input
// drops out.
&format!("inputs={}:duration=longest:normalize=0", abuffers.len()),
)?;

let aformat_args = format!(
Expand Down Expand Up @@ -1547,6 +1551,25 @@ mod test {
assert_eq!(probe.mixer.sources[0].late_samples_dropped, 0);
}

#[test]
fn pcm_mixed_sources_keep_their_own_level() {
let mut probe = PcmProbe::new(2);
for chunk in 0..50u64 {
probe.send(0, chunk * 20, 960, (chunk % 10 == 0).then_some(0));
probe.send(1, chunk * 20, 960, (chunk % 10 == 5).then_some(0));
probe.tick(chunk * 20 + 20);
}
let peak = |channel: usize| {
probe
.pcm
.iter()
.map(|sample| sample[channel].abs())
.fold(0.0f32, f32::max)
};
assert_eq!(peak(0), 0.5);
assert_eq!(peak(1), 0.5);
}

#[test]
fn pcm_timestamp_jitter_within_tolerance_keeps_samples_contiguous() {
let mut probe = PcmProbe::new(1);
Expand Down
Loading