BlueGit

ict rusty-teams

Closed Draft

fix(calling): ruisonderdrukking Uit houdt echo-onderdrukking en microfoonversterking aan

!23 · closed 8 hours ago

hephaestus bot wants to merge 1 commit from kvt/fix-208-mic-off into master

Pipeline

#576 Canceled

Reviews

  • No reviews yet.

Overview Commits 1 Pipelines 1 Changes 5

Changes

5 files changed +51 −32
crates/calling/src/audio_io.rs +18 −7
@@ -46,6 +46,8 @@ pub struct AudioSetup {
46 46 factory: PeerConnectionFactory,
47 47 pub track: RtcAudioTrack,
48 48 pub track_with_ns: Option<RtcAudioTrack>,
49 /// Noise suppression Off: echo cancellation and gain control, no noise suppression.
50 pub track_without_ns: Option<RtcAudioTrack>,
49 51 pub listen_only: bool,
50 52 platform_acquired: bool,
51 53 pub adm_state: String,
@@ -99,10 +101,13 @@ impl AudioSetup {
99 101 let track =
100 102 factory.create_device_audio_track_with_options("microphone", !cfg!(windows));
101 103 let track_with_ns = Some(factory.create_device_audio_track("microphone-ns"));
104 let track_without_ns =
105 Some(factory.create_device_audio_track_with_options("microphone-raw", false));
102 106 return AudioSetup {
103 107 factory: factory.clone(),
104 108 track,
105 109 track_with_ns,
110 track_without_ns,
106 111 listen_only: false,
107 112 platform_acquired,
108 113 adm_state,
@@ -135,6 +140,7 @@ impl AudioSetup {
135 140 factory: factory.clone(),
136 141 track,
137 142 track_with_ns: None,
143 track_without_ns: None,
138 144 listen_only: mode == AudioMode::Platform,
139 145 platform_acquired,
140 146 adm_state,
@@ -143,17 +149,22 @@ impl AudioSetup {
143 149 }
144 150
145 151 pub fn device_track(&self, settings: MicSettings) -> &RtcAudioTrack {
146 if classical_noise_track(settings)
147 && let Some(track) = &self.track_with_ns
148 {
149 return track;
150 }
151 &self.track
152 let other = if classical_noise_track(settings) {
153 self.track_with_ns.as_ref()
154 } else if settings.noise_suppression == NoiseSuppression::Off {
155 self.track_without_ns.as_ref()
156 } else {
157 None
158 };
159 other.unwrap_or(&self.track)
152 160 }
153 161
154 162 pub fn set_device_tracks_enabled(&self, enabled: bool) {
155 163 self.track.set_enabled(enabled);
156 if let Some(track) = &self.track_with_ns {
164 for track in [&self.track_with_ns, &self.track_without_ns]
165 .into_iter()
166 .flatten()
167 {
157 168 track.set_enabled(enabled);
158 169 }
159 170 }
@@ -46,6 +46,8 @@ pub struct AudioSetup {
46 factory: PeerConnectionFactory,
46 factory: PeerConnectionFactory,
47 pub track: RtcAudioTrack,
47 pub track: RtcAudioTrack,
48 pub track_with_ns: Option<RtcAudioTrack>,
48 pub track_with_ns: Option<RtcAudioTrack>,
49 /// Noise suppression Off: echo cancellation and gain control, no noise suppression.
50 pub track_without_ns: Option<RtcAudioTrack>,
49 pub listen_only: bool,
51 pub listen_only: bool,
50 platform_acquired: bool,
52 platform_acquired: bool,
51 pub adm_state: String,
53 pub adm_state: String,
@@ -99,10 +101,13 @@ impl AudioSetup {
99 let track =
101 let track =
100 factory.create_device_audio_track_with_options("microphone", !cfg!(windows));
102 factory.create_device_audio_track_with_options("microphone", !cfg!(windows));
101 let track_with_ns = Some(factory.create_device_audio_track("microphone-ns"));
103 let track_with_ns = Some(factory.create_device_audio_track("microphone-ns"));
104 let track_without_ns =
105 Some(factory.create_device_audio_track_with_options("microphone-raw", false));
102 return AudioSetup {
106 return AudioSetup {
103 factory: factory.clone(),
107 factory: factory.clone(),
104 track,
108 track,
105 track_with_ns,
109 track_with_ns,
110 track_without_ns,
106 listen_only: false,
111 listen_only: false,
107 platform_acquired,
112 platform_acquired,
108 adm_state,
113 adm_state,
@@ -135,6 +140,7 @@ impl AudioSetup {
135 factory: factory.clone(),
140 factory: factory.clone(),
136 track,
141 track,
137 track_with_ns: None,
142 track_with_ns: None,
143 track_without_ns: None,
138 listen_only: mode == AudioMode::Platform,
144 listen_only: mode == AudioMode::Platform,
139 platform_acquired,
145 platform_acquired,
140 adm_state,
146 adm_state,
@@ -143,17 +149,22 @@ impl AudioSetup {
143 }
149 }
144
150
145 pub fn device_track(&self, settings: MicSettings) -> &RtcAudioTrack {
151 pub fn device_track(&self, settings: MicSettings) -> &RtcAudioTrack {
146 if classical_noise_track(settings)
152 let other = if classical_noise_track(settings) {
147 && let Some(track) = &self.track_with_ns
153 self.track_with_ns.as_ref()
148 {
154 } else if settings.noise_suppression == NoiseSuppression::Off {
149 return track;
155 self.track_without_ns.as_ref()
150 }
156 } else {
151 &self.track
157 None
158 };
159 other.unwrap_or(&self.track)
152 }
160 }
153
161
154 pub fn set_device_tracks_enabled(&self, enabled: bool) {
162 pub fn set_device_tracks_enabled(&self, enabled: bool) {
155 self.track.set_enabled(enabled);
163 self.track.set_enabled(enabled);
156 if let Some(track) = &self.track_with_ns {
164 for track in [&self.track_with_ns, &self.track_without_ns]
165 .into_iter()
166 .flatten()
167 {
157 track.set_enabled(enabled);
168 track.set_enabled(enabled);
158 }
169 }
159 }
170 }
crates/calling/src/call/mod.rs +3 −2
@@ -2120,8 +2120,9 @@ async fn drive(
2120 2120 }
2121 2121 }
2122 2122 Some(CallCommand::SetMicSettings(settings)) if !audio_disabled => {
2123 let device_ns_changed =
2124 mic_settings.ml_noise_suppression() != settings.ml_noise_suppression();
2123 let device_ns_changed = mic_settings.ml_noise_suppression()
2124 != settings.ml_noise_suppression()
2125 || mic_settings.noise_suppression != settings.noise_suppression;
2125 2126 mic_settings = settings;
2126 2127 if let Some(audio) = live.audio.as_ref() {
2127 2128 track = audio.device_track(mic_settings).clone();
@@ -2120,8 +2120,9 @@ async fn drive(
2120 }
2120 }
2121 }
2121 }
2122 Some(CallCommand::SetMicSettings(settings)) if !audio_disabled => {
2122 Some(CallCommand::SetMicSettings(settings)) if !audio_disabled => {
2123 let device_ns_changed =
2123 let device_ns_changed = mic_settings.ml_noise_suppression()
2124 mic_settings.ml_noise_suppression() != settings.ml_noise_suppression();
2124 != settings.ml_noise_suppression()
2125 || mic_settings.noise_suppression != settings.noise_suppression;
2125 mic_settings = settings;
2126 mic_settings = settings;
2126 if let Some(audio) = live.audio.as_ref() {
2127 if let Some(audio) = live.audio.as_ref() {
2127 track = audio.device_track(mic_settings).clone();
2128 track = audio.device_track(mic_settings).clone();
crates/calling/src/mic_chain.rs +7 −5
@@ -108,12 +108,14 @@ mod tests {
108 108 }
109 109
110 110 #[test]
111 fn off_leaves_the_frame_untouched() {
112 let off = MicSettings {
113 noise_suppression: crate::mic_processing::NoiseSuppression::Off,
114 music_mode: false,
111 fn a_passthrough_chain_leaves_the_frame_untouched() {
112 let passthrough = ApmConfig {
113 echo_canceller: false,
114 gain_controller: false,
115 high_pass_filter: false,
116 noise_suppression: false,
115 117 };
116 let mut chain = MicChain::new(off.apm_config(), off.ml_noise_suppression(), None);
118 let mut chain = MicChain::new(passthrough, false, None);
117 119 let mut generator = SineGenerator::new(300.0, 0.2);
118 120 let original = generator.next_frame();
119 121 let mut frame = original.clone();
@@ -108,12 +108,14 @@ mod tests {
108 }
108 }
109
109
110 #[test]
110 #[test]
111 fn off_leaves_the_frame_untouched() {
111 fn a_passthrough_chain_leaves_the_frame_untouched() {
112 let off = MicSettings {
112 let passthrough = ApmConfig {
113 noise_suppression: crate::mic_processing::NoiseSuppression::Off,
113 echo_canceller: false,
114 music_mode: false,
114 gain_controller: false,
115 high_pass_filter: false,
116 noise_suppression: false,
115 };
117 };
116 let mut chain = MicChain::new(off.apm_config(), off.ml_noise_suppression(), None);
118 let mut chain = MicChain::new(passthrough, false, None);
117 let mut generator = SineGenerator::new(300.0, 0.2);
119 let mut generator = SineGenerator::new(300.0, 0.2);
118 let original = generator.next_frame();
120 let original = generator.next_frame();
119 let mut frame = original.clone();
121 let mut frame = original.clone();
crates/calling/src/mic_processing.rs +19 −16
@@ -79,26 +79,21 @@ impl MicSettings {
79 79 noise_suppression: false,
80 80 };
81 81 }
82 let on = self.noise_suppression != NoiseSuppression::Off;
83 let apm_noise_suppression = self.noise_suppression == NoiseSuppression::Low;
82 // Off only turns noise suppression off: echo cancellation and gain control stay on, as in Teams.
84 83 ApmConfig {
85 echo_canceller: on,
86 gain_controller: on,
87 high_pass_filter: on,
88 noise_suppression: apm_noise_suppression,
84 echo_canceller: true,
85 gain_controller: true,
86 high_pass_filter: true,
87 noise_suppression: self.noise_suppression == NoiseSuppression::Low,
89 88 }
90 89 }
91 90
92 /// Auto and Low use the native WebRTC platform ADM device track on every desktop OS
91 /// Every noise level uses the native WebRTC platform ADM device track on every desktop OS
93 92 /// (WASAPI2/CoreAudio on Windows, Pulse/PipeWire on Linux, CoreAudio on macOS), matching
94 93 /// Web Teams and avoiding software-feeder jitter and unsynchronized AEC.
95 /// Music mode and Off run the software chain.
94 /// Only music mode runs the software chain.
96 95 pub fn uses_device_track(self) -> bool {
97 96 !self.music_mode
98 && matches!(
99 self.noise_suppression,
100 NoiseSuppression::Auto | NoiseSuppression::Low
101 )
102 97 }
103 98
104 99 pub fn ml_noise_suppression(self) -> bool {
@@ -165,14 +160,22 @@ mod tests {
165 160 }
166 161
167 162 #[test]
168 fn off_leaves_the_device_track_and_processes_nothing() {
163 fn off_keeps_echo_cancellation_and_gain_control_on_the_device_track() {
169 164 let settings = MicSettings {
170 165 noise_suppression: NoiseSuppression::Off,
171 166 music_mode: false,
172 167 };
173 assert!(!settings.uses_device_track());
174 assert!(settings.apm_config().is_passthrough());
175 assert!(settings.apm_config().front_module().is_none());
168 assert!(settings.uses_device_track());
169 assert!(!settings.ml_noise_suppression());
170 assert_eq!(
171 settings.apm_config(),
172 ApmConfig {
173 echo_canceller: true,
174 gain_controller: true,
175 high_pass_filter: true,
176 noise_suppression: false
177 }
178 );
176 179 }
177 180
178 181 #[test]
@@ -79,26 +79,21 @@ impl MicSettings {
79 noise_suppression: false,
79 noise_suppression: false,
80 };
80 };
81 }
81 }
82 let on = self.noise_suppression != NoiseSuppression::Off;
82 // Off only turns noise suppression off: echo cancellation and gain control stay on, as in Teams.
83 let apm_noise_suppression = self.noise_suppression == NoiseSuppression::Low;
84 ApmConfig {
83 ApmConfig {
85 echo_canceller: on,
84 echo_canceller: true,
86 gain_controller: on,
85 gain_controller: true,
87 high_pass_filter: on,
86 high_pass_filter: true,
88 noise_suppression: apm_noise_suppression,
87 noise_suppression: self.noise_suppression == NoiseSuppression::Low,
89 }
88 }
90 }
89 }
91
90
92 /// Auto and Low use the native WebRTC platform ADM device track on every desktop OS
91 /// Every noise level uses the native WebRTC platform ADM device track on every desktop OS
93 /// (WASAPI2/CoreAudio on Windows, Pulse/PipeWire on Linux, CoreAudio on macOS), matching
92 /// (WASAPI2/CoreAudio on Windows, Pulse/PipeWire on Linux, CoreAudio on macOS), matching
94 /// Web Teams and avoiding software-feeder jitter and unsynchronized AEC.
93 /// Web Teams and avoiding software-feeder jitter and unsynchronized AEC.
95 /// Music mode and Off run the software chain.
94 /// Only music mode runs the software chain.
96 pub fn uses_device_track(self) -> bool {
95 pub fn uses_device_track(self) -> bool {
97 !self.music_mode
96 !self.music_mode
98 && matches!(
99 self.noise_suppression,
100 NoiseSuppression::Auto | NoiseSuppression::Low
101 )
102 }
97 }
103
98
104 pub fn ml_noise_suppression(self) -> bool {
99 pub fn ml_noise_suppression(self) -> bool {
@@ -165,14 +160,22 @@ mod tests {
165 }
160 }
166
161
167 #[test]
162 #[test]
168 fn off_leaves_the_device_track_and_processes_nothing() {
163 fn off_keeps_echo_cancellation_and_gain_control_on_the_device_track() {
169 let settings = MicSettings {
164 let settings = MicSettings {
170 noise_suppression: NoiseSuppression::Off,
165 noise_suppression: NoiseSuppression::Off,
171 music_mode: false,
166 music_mode: false,
172 };
167 };
173 assert!(!settings.uses_device_track());
168 assert!(settings.uses_device_track());
174 assert!(settings.apm_config().is_passthrough());
169 assert!(!settings.ml_noise_suppression());
175 assert!(settings.apm_config().front_module().is_none());
170 assert_eq!(
171 settings.apm_config(),
172 ApmConfig {
173 echo_canceller: true,
174 gain_controller: true,
175 high_pass_filter: true,
176 noise_suppression: false
177 }
178 );
176 }
179 }
177
180
178 #[test]
181 #[test]
crates/calling/src/software_audio.rs +4 −2
@@ -362,8 +362,10 @@ mod tests {
362 362 };
363 363 assert_eq!(SoftwareAudioPlan::wanted_on(low, false, true), None);
364 364 assert_eq!(SoftwareAudioPlan::wanted_on(off, false, false), None);
365 let mic_only = SoftwareAudioPlan::wanted_on(off, false, true).unwrap();
366 assert!(!mic_only.computer_sound && mic_only.processing.is_passthrough());
365 assert_eq!(SoftwareAudioPlan::wanted_on(off, false, true), None);
366 let off_sharing = SoftwareAudioPlan::wanted_on(off, true, true).unwrap();
367 assert!(off_sharing.processing.echo_canceller && off_sharing.processing.gain_controller);
368 assert!(!off_sharing.processing.noise_suppression && !off_sharing.ml_noise);
367 369 let sharing = SoftwareAudioPlan::wanted_on(auto, true, false).unwrap();
368 370 assert!(sharing.computer_sound && sharing.processing.echo_canceller);
369 371 }
@@ -362,8 +362,10 @@ mod tests {
362 };
362 };
363 assert_eq!(SoftwareAudioPlan::wanted_on(low, false, true), None);
363 assert_eq!(SoftwareAudioPlan::wanted_on(low, false, true), None);
364 assert_eq!(SoftwareAudioPlan::wanted_on(off, false, false), None);
364 assert_eq!(SoftwareAudioPlan::wanted_on(off, false, false), None);
365 let mic_only = SoftwareAudioPlan::wanted_on(off, false, true).unwrap();
365 assert_eq!(SoftwareAudioPlan::wanted_on(off, false, true), None);
366 assert!(!mic_only.computer_sound && mic_only.processing.is_passthrough());
366 let off_sharing = SoftwareAudioPlan::wanted_on(off, true, true).unwrap();
367 assert!(off_sharing.processing.echo_canceller && off_sharing.processing.gain_controller);
368 assert!(!off_sharing.processing.noise_suppression && !off_sharing.ml_noise);
367 let sharing = SoftwareAudioPlan::wanted_on(auto, true, false).unwrap();
369 let sharing = SoftwareAudioPlan::wanted_on(auto, true, false).unwrap();
368 assert!(sharing.computer_sound && sharing.processing.echo_canceller);
370 assert!(sharing.computer_sound && sharing.processing.echo_canceller);
369 }
371 }