Skip to repository content58 lines · 2.1 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T06:49:55.837Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
echo_canceller.rs
1#[cfg(not(any(all(target_os = "windows", target_env = "gnu"), target_os = "freebsd")))]
2mod real_implementation {
3 use anyhow::Context;
4 use libwebrtc::native::apm;
5 use parking_lot::Mutex;
6 use std::sync::Arc;
7
8 use crate::{CHANNEL_COUNT, SAMPLE_RATE};
9
10 #[derive(Clone)]
11 pub struct EchoCanceller(Arc<Mutex<apm::AudioProcessingModule>>);
12
13 impl Default for EchoCanceller {
14 fn default() -> Self {
15 // Sound-effect playback only feeds this APM through `process_reverse_stream`
16 // for AEC reference; gain/HPF/NS would be no-ops here, so we keep the
17 // original (echo only) configuration via the legacy flag form.
18 Self(Arc::new(Mutex::new(
19 apm::AudioProcessingModule::from_flags(true, false, false, false),
20 )))
21 }
22 }
23
24 impl EchoCanceller {
25 pub fn process_reverse_stream(&mut self, buf: &mut [i16]) {
26 self.0
27 .lock()
28 .process_reverse_stream(buf, SAMPLE_RATE.get() as i32, CHANNEL_COUNT.get().into())
29 .expect("Audio input and output threads should not panic");
30 }
31
32 pub fn process_stream(&mut self, buf: &mut [i16]) -> anyhow::Result<()> {
33 self.0
34 .lock()
35 .process_stream(buf, SAMPLE_RATE.get() as i32, CHANNEL_COUNT.get() as i32)
36 .context("livekit audio processor error")
37 }
38 }
39}
40
41#[cfg(any(all(target_os = "windows", target_env = "gnu"), target_os = "freebsd"))]
42mod fake_implementation {
43 #[derive(Clone, Default)]
44 pub struct EchoCanceller;
45
46 impl EchoCanceller {
47 pub fn process_reverse_stream(&mut self, _buf: &mut [i16]) {}
48 pub fn process_stream(&mut self, _buf: &mut [i16]) -> anyhow::Result<()> {
49 Ok(())
50 }
51 }
52}
53
54#[cfg(any(all(target_os = "windows", target_env = "gnu"), target_os = "freebsd"))]
55pub use fake_implementation::EchoCanceller;
56#[cfg(not(any(all(target_os = "windows", target_env = "gnu"), target_os = "freebsd")))]
57pub use real_implementation::EchoCanceller;
58