Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit f7c30d8

Browse files
committed
Add advanced audio settings
autoGainControl, echoCancellation, and noiseSuppression are audio processing options that are usually enabled by default on WebRTC input tracks. This commit adds the possibility to enable/disable them, as they can be undesirable in some cases (audiophile use cases). For example, one might want to stream electronic dance music, which is basically noise, so it should not be suppressed in that specific case. Signed-off-by: László Várady <[email protected]>
1 parent 2e6ceeb commit f7c30d8

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed

src/MediaDeviceHandler.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ export default class MediaDeviceHandler extends EventEmitter {
7878

7979
await MatrixClientPeg.get().getMediaHandler().setAudioInput(audioDeviceId);
8080
await MatrixClientPeg.get().getMediaHandler().setVideoInput(videoDeviceId);
81+
82+
await MediaDeviceHandler.updateAudioSettings();
83+
}
84+
85+
private static async updateAudioSettings(): Promise<void> {
86+
await MatrixClientPeg.get().getMediaHandler().setAudioSettings({
87+
autoGainControl: MediaDeviceHandler.getAudioAutoGainControl(),
88+
echoCancellation: MediaDeviceHandler.getAudioEchoCancellation(),
89+
noiseSuppression: MediaDeviceHandler.getAudioNoiseSuppression(),
90+
});
8191
}
8292

8393
public setAudioOutput(deviceId: string): void {
@@ -113,6 +123,21 @@ export default class MediaDeviceHandler extends EventEmitter {
113123
}
114124
}
115125

126+
public static async setAudioAutoGainControl(value: boolean): Promise<void> {
127+
await SettingsStore.setValue("webrtc_audio_autoGainControl", null, SettingLevel.DEVICE, value);
128+
await MediaDeviceHandler.updateAudioSettings();
129+
}
130+
131+
public static async setAudioEchoCancellation(value: boolean): Promise<void> {
132+
await SettingsStore.setValue("webrtc_audio_echoCancellation", null, SettingLevel.DEVICE, value);
133+
await MediaDeviceHandler.updateAudioSettings();
134+
}
135+
136+
public static async setAudioNoiseSuppression(value: boolean): Promise<void> {
137+
await SettingsStore.setValue("webrtc_audio_noiseSuppression", null, SettingLevel.DEVICE, value);
138+
await MediaDeviceHandler.updateAudioSettings();
139+
}
140+
116141
public static getAudioOutput(): string {
117142
return SettingsStore.getValueAt(SettingLevel.DEVICE, "webrtc_audiooutput");
118143
}
@@ -125,6 +150,18 @@ export default class MediaDeviceHandler extends EventEmitter {
125150
return SettingsStore.getValueAt(SettingLevel.DEVICE, "webrtc_videoinput");
126151
}
127152

153+
public static getAudioAutoGainControl(): boolean {
154+
return SettingsStore.getValue("webrtc_audio_autoGainControl");
155+
}
156+
157+
public static getAudioEchoCancellation(): boolean {
158+
return SettingsStore.getValue("webrtc_audio_echoCancellation");
159+
}
160+
161+
public static getAudioNoiseSuppression(): boolean {
162+
return SettingsStore.getValue("webrtc_audio_noiseSuppression");
163+
}
164+
128165
/**
129166
* Returns the current set deviceId for a device kind
130167
* @param {MediaDeviceKindEnum} kind of the device that will be returned

src/components/views/settings/tabs/user/VoiceUserSettingsTab.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { MatrixClientPeg } from "../../../../../MatrixClientPeg";
2727
import Modal from "../../../../../Modal";
2828
import { SettingLevel } from "../../../../../settings/SettingLevel";
2929
import SettingsFlag from '../../../elements/SettingsFlag';
30+
import LabelledToggleSwitch from "../../../elements/LabelledToggleSwitch";
3031
import ErrorDialog from '../../../dialogs/ErrorDialog';
3132

3233
const getDefaultDevice = (devices: Array<Partial<MediaDeviceInfo>>) => {
@@ -43,6 +44,9 @@ const getDefaultDevice = (devices: Array<Partial<MediaDeviceInfo>>) => {
4344

4445
interface IState extends Record<MediaDeviceKindEnum, string> {
4546
mediaDevices: IMediaDevices;
47+
audioAutoGainControl: boolean;
48+
audioEchoCancellation: boolean;
49+
audioNoiseSuppression: boolean;
4650
}
4751

4852
export default class VoiceUserSettingsTab extends React.Component<{}, IState> {
@@ -54,6 +58,9 @@ export default class VoiceUserSettingsTab extends React.Component<{}, IState> {
5458
[MediaDeviceKindEnum.AudioOutput]: null,
5559
[MediaDeviceKindEnum.AudioInput]: null,
5660
[MediaDeviceKindEnum.VideoInput]: null,
61+
audioAutoGainControl: MediaDeviceHandler.getAudioAutoGainControl(),
62+
audioEchoCancellation: MediaDeviceHandler.getAudioEchoCancellation(),
63+
audioNoiseSuppression: MediaDeviceHandler.getAudioNoiseSuppression(),
5764
};
5865
}
5966

@@ -197,6 +204,33 @@ export default class VoiceUserSettingsTab extends React.Component<{}, IState> {
197204

198205
<div className="mx_SettingsTab_heading">{ _t("Advanced") }</div>
199206
<div className="mx_SettingsTab_section">
207+
<span className="mx_SettingsTab_subheading">{ _t("Voice processing") }</span>
208+
<div className="mx_SettingsTab_section">
209+
<LabelledToggleSwitch
210+
value={this.state.audioAutoGainControl}
211+
onChange={async (v) => {
212+
await MediaDeviceHandler.setAudioAutoGainControl(v);
213+
this.setState({ audioAutoGainControl: MediaDeviceHandler.getAudioAutoGainControl() });
214+
}}
215+
label={_t("Automatic gain control")}
216+
/>
217+
<LabelledToggleSwitch
218+
value={this.state.audioEchoCancellation}
219+
onChange={async (v) => {
220+
await MediaDeviceHandler.setAudioEchoCancellation(v);
221+
this.setState({ audioEchoCancellation: MediaDeviceHandler.getAudioEchoCancellation() });
222+
}}
223+
label={_t("Echo cancellation")}
224+
/>
225+
<LabelledToggleSwitch
226+
value={this.state.audioNoiseSuppression}
227+
onChange={async (v) => {
228+
await MediaDeviceHandler.setAudioNoiseSuppression(v);
229+
this.setState({ audioNoiseSuppression: MediaDeviceHandler.getAudioNoiseSuppression() });
230+
}}
231+
label={_t("Noise suppression")}
232+
/>
233+
</div>
200234
<div className="mx_SettingsTab_section">
201235
<span className="mx_SettingsTab_subheading">{ _t("Connection") }</span>
202236
<SettingsFlag

src/i18n/strings/en_EN.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,9 @@
944944
"Use a system font": "Use a system font",
945945
"System font name": "System font name",
946946
"Allow Peer-to-Peer for 1:1 calls (if you enable this, the other party might be able to see your IP address)": "Allow Peer-to-Peer for 1:1 calls (if you enable this, the other party might be able to see your IP address)",
947+
"Automatic gain control": "Automatic gain control",
948+
"Echo cancellation": "Echo cancellation",
949+
"Noise suppression": "Noise suppression",
947950
"Send analytics data": "Send analytics data",
948951
"Never send encrypted messages to unverified sessions from this session": "Never send encrypted messages to unverified sessions from this session",
949952
"Never send encrypted messages to unverified sessions in this room from this session": "Never send encrypted messages to unverified sessions in this room from this session",
@@ -1552,6 +1555,7 @@
15521555
"Voice & Video": "Voice & Video",
15531556
"Voice settings": "Voice settings",
15541557
"Video settings": "Video settings",
1558+
"Voice processing": "Voice processing",
15551559
"Connection": "Connection",
15561560
"This room is not accessible by remote Matrix servers": "This room is not accessible by remote Matrix servers",
15571561
"<b>Warning</b>: Upgrading a room will <i>not automatically migrate room members to the new version of the room.</i> We'll post a link to the new room in the old version of the room - room members will have to click this link to join the new room.": "<b>Warning</b>: Upgrading a room will <i>not automatically migrate room members to the new version of the room.</i> We'll post a link to the new room in the old version of the room - room members will have to click this link to join the new room.",

src/settings/Settings.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,21 @@ export const SETTINGS: {[setting: string]: ISetting} = {
645645
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS,
646646
default: "default",
647647
},
648+
"webrtc_audio_autoGainControl": {
649+
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS,
650+
displayName: _td("Automatic gain control"),
651+
default: true,
652+
},
653+
"webrtc_audio_echoCancellation": {
654+
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS,
655+
displayName: _td("Echo cancellation"),
656+
default: true,
657+
},
658+
"webrtc_audio_noiseSuppression": {
659+
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS,
660+
displayName: _td("Noise suppression"),
661+
default: true,
662+
},
648663
"language": {
649664
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
650665
default: "en",

0 commit comments

Comments
 (0)