feat(clients): wire RNNoise mic noise reduction into Windows, macOS, and iOS
Expose the existing send-side vc_set_input_noise_reduction C ABI (MIC-only, mono, LOCAL — denoises captured mic PCM before input gain and VAD/PTT gate) as a persisted global toggle in each client's audio settings, applied live and re-applied on Join Voice. Mirrors the existing mic-gain wiring pattern. - Shared Swift (VoiceCatCore): add setInputNoiseReduction(_:) wrapper - Windows: P/Invoke + SetInputNoiseReduction wrapper, MicNoiseReduction in VoiceSettings, new checkbox in AudioSettingsForm (layout shifted +28px), apply on Join Voice; also fix stale 'planned - currently passthrough' label on the receive-side per-user NR checkbox (RNNoise now backs it) - macOS: inputNoiseReduction state + UserDefaults in MainWindowController, NR checkbox + nrChanged action in SettingsWindowController - iOS: inputNoiseReduction in VoiceState + setter + restore in SessionState, NR Toggle in SettingsView Voice section Aux/screen are out of scope by design (core's NR guards kind == MIC). Apple builds require a rebuilt VoiceCatCore.xcframework with VOICECAT_HAS_NS.
This commit is contained in:
@@ -27,6 +27,7 @@ public sealed class AudioSettingsForm : Form
|
||||
private readonly VcInputMode _origMode;
|
||||
private readonly int _origVadSlider;
|
||||
private readonly int _origMicGain;
|
||||
private readonly bool _origMicNoiseReduction;
|
||||
private readonly Keys _origPttKey;
|
||||
private readonly bool _origAuxEnabled;
|
||||
private readonly string? _origAuxDeviceId;
|
||||
@@ -42,6 +43,7 @@ public sealed class AudioSettingsForm : Form
|
||||
private readonly Label _lblSensitivity;
|
||||
private readonly TrackBar _trkVad;
|
||||
private readonly TrackBar _trkGain;
|
||||
private readonly CheckBox _chkNoiseReduction;
|
||||
private readonly CheckBox _chkAux;
|
||||
private readonly Label _lblAuxDevice;
|
||||
private readonly ComboBox _cboAuxDevice;
|
||||
@@ -67,6 +69,7 @@ public sealed class AudioSettingsForm : Form
|
||||
_origMode = (VcInputMode)settings.InputMode;
|
||||
_origVadSlider = settings.VadThresholdSlider;
|
||||
_origMicGain = settings.MicGain;
|
||||
_origMicNoiseReduction = settings.MicNoiseReduction;
|
||||
_origPttKey = _pttKey;
|
||||
_origAuxEnabled = settings.AuxEnabled;
|
||||
_origAuxDeviceId = settings.AuxDeviceId;
|
||||
@@ -78,7 +81,7 @@ public sealed class AudioSettingsForm : Form
|
||||
MinimizeBox = false;
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(420, 555);
|
||||
ClientSize = new Size(420, 583);
|
||||
|
||||
// ── Device row ────────────────────────────────────────────────────────
|
||||
var lblDevice = new Label
|
||||
@@ -199,6 +202,21 @@ public sealed class AudioSettingsForm : Form
|
||||
"Boost a quiet microphone. 100 is unity gain; range 0–300 percent.";
|
||||
_trkGain.Scroll += TrkGain_Scroll;
|
||||
|
||||
// ── Mic noise reduction ───────────────────────────────────────────────
|
||||
// Send-side RNNoise denoise of the mic stream. MIC-only (the core's NR runs before
|
||||
// the input gain and VAD/PTT gate; aux/screen are excluded). One pass for all listeners.
|
||||
_chkNoiseReduction = new CheckBox
|
||||
{
|
||||
Text = "Noise &reduction (RNNoise)",
|
||||
Location = new Point(12, 340),
|
||||
AutoSize = true,
|
||||
Checked = settings.MicNoiseReduction,
|
||||
AccessibleName = "Microphone noise reduction",
|
||||
AccessibleDescription =
|
||||
"RNNoise denoising of your microphone. Cleans your signal for everyone listening.",
|
||||
};
|
||||
_chkNoiseReduction.CheckedChanged += ChkNoiseReduction_CheckedChanged;
|
||||
|
||||
// ── Aux input stream ──────────────────────────────────────────────────
|
||||
// A second outgoing stream from another hardware input device (e.g. line-in / aux),
|
||||
// captured client-side and fed to the core. Device + volume only — aux is always-on
|
||||
@@ -206,7 +224,7 @@ public sealed class AudioSettingsForm : Form
|
||||
_chkAux = new CheckBox
|
||||
{
|
||||
Text = "&Aux stream (second input device)",
|
||||
Location = new Point(12, 348),
|
||||
Location = new Point(12, 376),
|
||||
AutoSize = true,
|
||||
Checked = settings.AuxEnabled,
|
||||
AccessibleName = "Enable aux input stream",
|
||||
@@ -218,12 +236,12 @@ public sealed class AudioSettingsForm : Form
|
||||
_lblAuxDevice = new Label
|
||||
{
|
||||
Text = "Aux d&evice:",
|
||||
Location = new Point(12, 378),
|
||||
Location = new Point(12, 406),
|
||||
AutoSize = true,
|
||||
};
|
||||
_cboAuxDevice = new ComboBox
|
||||
{
|
||||
Location = new Point(12, 398),
|
||||
Location = new Point(12, 426),
|
||||
Width = 300,
|
||||
DropDownStyle = ComboBoxStyle.DropDownList,
|
||||
DisplayMember = "Name",
|
||||
@@ -236,7 +254,7 @@ public sealed class AudioSettingsForm : Form
|
||||
_btnAuxRefresh = new Button
|
||||
{
|
||||
Text = "Re&fresh",
|
||||
Location = new Point(320, 396),
|
||||
Location = new Point(320, 424),
|
||||
Size = new Size(80, 26),
|
||||
};
|
||||
_btnAuxRefresh.Click += (_, _) => LoadAuxDevices();
|
||||
@@ -244,12 +262,12 @@ public sealed class AudioSettingsForm : Form
|
||||
_lblAuxGain = new Label
|
||||
{
|
||||
Text = "Aux vo&lume:",
|
||||
Location = new Point(12, 434),
|
||||
Location = new Point(12, 462),
|
||||
AutoSize = true,
|
||||
};
|
||||
_trkAuxGain = new TrackBar
|
||||
{
|
||||
Location = new Point(12, 454),
|
||||
Location = new Point(12, 482),
|
||||
Size = new Size(200, 45),
|
||||
Minimum = 0,
|
||||
Maximum = 300,
|
||||
@@ -268,14 +286,14 @@ public sealed class AudioSettingsForm : Form
|
||||
{
|
||||
Text = "&OK",
|
||||
DialogResult = DialogResult.OK,
|
||||
Location = new Point(228, 516),
|
||||
Location = new Point(228, 544),
|
||||
Size = new Size(80, 27),
|
||||
};
|
||||
var btnCancel = new Button
|
||||
{
|
||||
Text = "&Cancel",
|
||||
DialogResult = DialogResult.Cancel,
|
||||
Location = new Point(316, 516),
|
||||
Location = new Point(316, 544),
|
||||
Size = new Size(80, 27),
|
||||
};
|
||||
|
||||
@@ -292,7 +310,7 @@ public sealed class AudioSettingsForm : Form
|
||||
lblDevice, _cboDevice, _btnRefresh,
|
||||
lblMode, _radioVad, _lblSensitivity, _trkVad,
|
||||
_radioPtt, _lblPttKey, _btnChangePtt, _radioAlwaysOn,
|
||||
lblGain, _trkGain,
|
||||
lblGain, _trkGain, _chkNoiseReduction,
|
||||
_chkAux, _lblAuxDevice, _cboAuxDevice, _btnAuxRefresh, _lblAuxGain, _trkAuxGain,
|
||||
btnOk, btnCancel,
|
||||
]);
|
||||
@@ -430,6 +448,13 @@ public sealed class AudioSettingsForm : Form
|
||||
_client.SetInputGain(_trkGain.Value / 100f);
|
||||
}
|
||||
|
||||
private void ChkNoiseReduction_CheckedChanged(object? sender, EventArgs e)
|
||||
{
|
||||
_settings.MicNoiseReduction = _chkNoiseReduction.Checked;
|
||||
if (_micStreamId != 0)
|
||||
_client.SetInputNoiseReduction(_chkNoiseReduction.Checked);
|
||||
}
|
||||
|
||||
private void BtnChangePtt_Click(object? sender, EventArgs e)
|
||||
{
|
||||
using var dlg = new PttKeyCaptureDialog(_pttKey);
|
||||
@@ -450,6 +475,7 @@ public sealed class AudioSettingsForm : Form
|
||||
_settings.InputMode = (int)_origMode;
|
||||
_settings.VadThresholdSlider = _origVadSlider;
|
||||
_settings.MicGain = _origMicGain;
|
||||
_settings.MicNoiseReduction = _origMicNoiseReduction;
|
||||
_settings.PttKey = (int)_origPttKey;
|
||||
|
||||
if (_micStreamId != 0)
|
||||
@@ -459,6 +485,7 @@ public sealed class AudioSettingsForm : Form
|
||||
if (_origMode == VcInputMode.VoiceActivation)
|
||||
_client.SetVadThreshold(0.1f * (1f - (_origVadSlider - 1f) / 99f));
|
||||
_client.SetInputGain(_origMicGain / 100f);
|
||||
_client.SetInputNoiseReduction(_origMicNoiseReduction);
|
||||
}
|
||||
|
||||
// Aux: restore originals to settings and re-apply live (order: device + gain first so a
|
||||
|
||||
@@ -650,6 +650,7 @@ public partial class MainForm : Form
|
||||
if (mode == VcInputMode.VoiceActivation)
|
||||
_client.SetVadThreshold(VadThresholdFromSettings());
|
||||
_client.SetInputGain(_voiceSettings.MicGain / 100f);
|
||||
_client.SetInputNoiseReduction(_voiceSettings.MicNoiseReduction);
|
||||
SetVoiceJoinedState(true);
|
||||
AddActivity("Joined voice — microphone active");
|
||||
_feedback.PlaySound(SoundEvent.VoiceOn);
|
||||
|
||||
@@ -150,7 +150,7 @@ public sealed class PerUserTuningDialog : Form
|
||||
|
||||
var chkNr = new CheckBox
|
||||
{
|
||||
Text = "&Noise reduction (planned — currently passthrough)",
|
||||
Text = "&Noise reduction",
|
||||
AutoSize = true,
|
||||
Location = new Point(96, y + 48),
|
||||
Checked = nr0,
|
||||
|
||||
@@ -21,6 +21,11 @@ public sealed class VoiceSettings
|
||||
/// <summary>Microphone input gain slider position, 0–300 percent (100 = unity).</summary>
|
||||
public int MicGain { get; set; } = 100;
|
||||
|
||||
/// <summary>Send-side mic noise reduction (RNNoise) toggle. MIC stream only, mono only;
|
||||
/// denoises captured mic PCM before input gain and VAD/PTT gate so everyone hears the
|
||||
/// cleaned signal. Independent of the per-listener receive-side NR.</summary>
|
||||
public bool MicNoiseReduction { get; set; } = false;
|
||||
|
||||
/// <summary>Push-to-talk key, stored as the integer value of System.Windows.Forms.Keys.</summary>
|
||||
public int PttKey { get; set; } = (int)Keys.F8;
|
||||
|
||||
|
||||
@@ -83,6 +83,9 @@ internal static partial class NativeMethods
|
||||
[LibraryImport(LibName)]
|
||||
internal static partial VcResult vc_set_input_gain(nint c, float gain);
|
||||
|
||||
[LibraryImport(LibName)]
|
||||
internal static partial VcResult vc_set_input_noise_reduction(nint c, int enable);
|
||||
|
||||
[LibraryImport(LibName)]
|
||||
internal static partial VcResult vc_set_remote_stream(nint c, uint userId, uint streamId,
|
||||
float gain, int muted, int noiseReduction);
|
||||
|
||||
@@ -232,6 +232,13 @@ public sealed class VoiceCatClient : IDisposable
|
||||
public VcResult SetInputGain(float gain) =>
|
||||
NativeMethods.vc_set_input_gain(_handle.DangerousGetHandle(), gain < 0f ? 0f : gain);
|
||||
|
||||
/// <summary>Send-side microphone noise suppression (RNNoise). Denoises captured MIC PCM before
|
||||
/// the input gain and VAD/PTT gate, so everyone hears the cleaned signal. MIC stream only,
|
||||
/// mono only; always LOCAL — no protocol traffic. Independent of per-listener receive-side
|
||||
/// NR in <see cref="SetRemoteStream"/>.</summary>
|
||||
public VcResult SetInputNoiseReduction(bool enable) =>
|
||||
NativeMethods.vc_set_input_noise_reduction(_handle.DangerousGetHandle(), enable ? 1 : 0);
|
||||
|
||||
public VcResult SetRemoteStream(uint userId, uint streamId, float gain, bool muted, bool noiseReduction) =>
|
||||
NativeMethods.vc_set_remote_stream(_handle.DangerousGetHandle(), userId, streamId, gain,
|
||||
muted ? 1 : 0, noiseReduction ? 1 : 0);
|
||||
|
||||
Reference in New Issue
Block a user