mirror of
https://github.com/zed-industries/zed.git
synced 2026-06-01 03:14:56 +07:00
This updates our WebRTC configuration to enable gain normalization in the recording flow, which should help normalize the effective volume of participants in calls. Release Notes: - Added volume equalizations to participants in collab calls
57 lines
2 KiB
Rust
57 lines
2 KiB
Rust
#[cfg(not(any(all(target_os = "windows", target_env = "gnu"), target_os = "freebsd")))]
|
|
mod real_implementation {
|
|
use anyhow::Context;
|
|
use libwebrtc::native::apm;
|
|
use parking_lot::Mutex;
|
|
use std::sync::Arc;
|
|
|
|
use crate::{CHANNEL_COUNT, SAMPLE_RATE};
|
|
|
|
#[derive(Clone)]
|
|
pub struct EchoCanceller(Arc<Mutex<apm::AudioProcessingModule>>);
|
|
|
|
impl Default for EchoCanceller {
|
|
fn default() -> Self {
|
|
// Sound-effect playback only feeds this APM through `process_reverse_stream`
|
|
// for AEC reference; gain/HPF/NS would be no-ops here, so we keep the
|
|
// original (echo only) configuration via the legacy flag form.
|
|
Self(Arc::new(Mutex::new(
|
|
apm::AudioProcessingModule::from_flags(true, false, false, false),
|
|
)))
|
|
}
|
|
}
|
|
|
|
impl EchoCanceller {
|
|
pub fn process_reverse_stream(&mut self, buf: &mut [i16]) {
|
|
self.0
|
|
.lock()
|
|
.process_reverse_stream(buf, SAMPLE_RATE.get() as i32, CHANNEL_COUNT.get().into())
|
|
.expect("Audio input and output threads should not panic");
|
|
}
|
|
|
|
pub fn process_stream(&mut self, buf: &mut [i16]) -> anyhow::Result<()> {
|
|
self.0
|
|
.lock()
|
|
.process_stream(buf, SAMPLE_RATE.get() as i32, CHANNEL_COUNT.get() as i32)
|
|
.context("livekit audio processor error")
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(any(all(target_os = "windows", target_env = "gnu"), target_os = "freebsd"))]
|
|
mod fake_implementation {
|
|
#[derive(Clone, Default)]
|
|
pub struct EchoCanceller;
|
|
|
|
impl EchoCanceller {
|
|
pub fn process_reverse_stream(&mut self, _buf: &mut [i16]) {}
|
|
pub fn process_stream(&mut self, _buf: &mut [i16]) -> anyhow::Result<()> {
|
|
Ok(())
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(any(all(target_os = "windows", target_env = "gnu"), target_os = "freebsd"))]
|
|
pub use fake_implementation::EchoCanceller;
|
|
#[cfg(not(any(all(target_os = "windows", target_env = "gnu"), target_os = "freebsd")))]
|
|
pub use real_implementation::EchoCanceller;
|