feat(audio): stereo mic capture on Windows & macOS desktop clients
Both desktop mics were hard-mono: the core defaults capture_channels=1 and neither client ever called vc_set_capture_channels (only iOS did). Add a persisted "Stereo microphone" toggle to each client's Audio settings, applied when the mic stream starts and live via vc_set_capture_channels + vc_audio_restart. Expose both ABI calls in the Windows interop; the macOS wrapper already had them. Core fix: encode_and_send_frame now folds a stereo mic frame to mono on a mono channel - previously the channels==2 branch encoded interleaved L/R directly even on a mono channel, feeding a mono opus_encode 2x its samples (wrong pitch/garbage). Real stereo still only reaches the wire on a stereo channel; on a mono channel the mic is cleanly downmixed. Test: test_stereo_mic_mono_channel. ctest --preset dev green (28/28). Docs: voice.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -63,6 +63,12 @@ final class SettingsWindowController: NSWindowController, NSWindowDelegate {
|
||||
private let nrCheckbox = NSButton(checkboxWithTitle: "Noise reduction (RNNoise)",
|
||||
target: nil, action: nil)
|
||||
|
||||
// Capture the mic in stereo (interleaved L/R) instead of mono. Real stereo only reaches the
|
||||
// wire on a stereo channel; the core folds a stereo mic to mono on a mono channel. Persisted
|
||||
// via MainWindowController.stereoMic.
|
||||
private let stereoMicCheckbox = NSButton(checkboxWithTitle: "Stereo microphone",
|
||||
target: nil, action: nil)
|
||||
|
||||
// Aux input stream: a second outgoing stream from another hardware input device (e.g. line-in
|
||||
// / aux), captured client-side. Device + volume only — aux is always-on. Persisted via
|
||||
// MainWindowController.auxEnabled / auxDeviceUID / auxGain.
|
||||
@@ -178,6 +184,11 @@ final class SettingsWindowController: NSWindowController, NSWindowDelegate {
|
||||
nrCheckbox.setAccessibilityLabel("Microphone noise reduction")
|
||||
nrCheckbox.setAccessibilityHelp("RNNoise denoising of your microphone. Cleans your signal for everyone.")
|
||||
|
||||
stereoMicCheckbox.target = self
|
||||
stereoMicCheckbox.action = #selector(stereoMicChanged)
|
||||
stereoMicCheckbox.setAccessibilityLabel("Stereo microphone")
|
||||
stereoMicCheckbox.setAccessibilityHelp("Capture your microphone in stereo. Only transmitted in stereo on a stereo channel.")
|
||||
|
||||
let inputModeRow = NSStackView(views: [inputModeLabel, inputModeControl])
|
||||
inputModeRow.orientation = .horizontal
|
||||
inputModeRow.spacing = 8
|
||||
@@ -259,7 +270,7 @@ final class SettingsWindowController: NSWindowController, NSWindowDelegate {
|
||||
volumeRow.orientation = .horizontal
|
||||
volumeRow.spacing = 8
|
||||
|
||||
let stack = NSStackView(views: [inputModeRow, vadRow, inputGainRow, nrCheckbox, pttRow, deviceRow,
|
||||
let stack = NSStackView(views: [inputModeRow, vadRow, inputGainRow, nrCheckbox, stereoMicCheckbox, pttRow, deviceRow,
|
||||
levelRow, auxHeader, auxCheckbox, auxDeviceRow, auxGainRow,
|
||||
notificationsHeader, soundsCheckbox, volumeRow,
|
||||
speechCheckbox, selfTalkCheckbox, pttSoundCheckbox])
|
||||
@@ -330,6 +341,7 @@ final class SettingsWindowController: NSWindowController, NSWindowDelegate {
|
||||
inputGainSlider.doubleValue = Double(mc.inputGain * 100)
|
||||
updateInputGainLabel()
|
||||
nrCheckbox.state = mc.inputNoiseReduction ? .on : .off
|
||||
stereoMicCheckbox.state = mc.stereoMic ? .on : .off
|
||||
|
||||
auxCheckbox.state = mc.auxEnabled ? .on : .off
|
||||
auxGainSlider.doubleValue = Double(mc.auxGain * 100)
|
||||
@@ -390,6 +402,16 @@ final class SettingsWindowController: NSWindowController, NSWindowDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func stereoMicChanged() {
|
||||
let on = stereoMicCheckbox.state == .on
|
||||
mainController?.stereoMic = on
|
||||
// Channel count only takes effect when the capture device (re)starts, so restart it live.
|
||||
if let mc = mainController, mc.micStreamId != 0 {
|
||||
client.setCaptureChannels(streamId: mc.micStreamId, channels: on ? 2 : 1)
|
||||
client.audioRestart()
|
||||
}
|
||||
}
|
||||
|
||||
private func updateInputGainLabel() {
|
||||
let pct = Int(inputGainSlider.doubleValue.rounded())
|
||||
inputGainValueLabel.stringValue = "\(pct)%"
|
||||
|
||||
Reference in New Issue
Block a user