Fix iOS stereo microphone capture
Build and test / test (macos-latest) (push) Canceled after 0s
Build and test / test (ubuntu-24.04) (push) Canceled after 0s
Build and test / test (windows-latest) (push) Canceled after 0s
Build and test / apple-client (push) Canceled after 0s

This commit is contained in:
2026-09-21 18:04:00 +02:00
parent 0372baf589
commit 4aa0aa4fbd
4 changed files with 75 additions and 14 deletions
+13 -2
View File
@@ -55,7 +55,7 @@ internal sealed class IosAudioEngine
internal void StartMicrophone(uint streamId, int channels)
{
Volatile.Write(ref microphone, new(streamId, Math.Clamp(channels, 1, 2))); Rebuild();
Volatile.Write(ref microphone, CreateMicrophoneRoute(streamId, channels)); Rebuild();
}
internal void StopMicrophone() { Volatile.Write(ref microphone, null); Rebuild(); }
@@ -70,10 +70,21 @@ internal sealed class IosAudioEngine
// an in-flight callback could interpret its old converter buffer using the new width.
DestroyGraph();
if (current.Channels != channels) client!.Audio.SetCaptureChannels(current.StreamId, channels);
Volatile.Write(ref microphone, new(current.StreamId, channels));
Volatile.Write(ref microphone, CreateMicrophoneRoute(current.StreamId, channels));
}
Rebuild();
}
private static MicrophoneRoute CreateMicrophoneRoute(uint streamId, int channels)
{
var route = new MicrophoneRoute(streamId, Math.Clamp(channels, 1, 2));
// Physical RemoteIO capture is commonly delivered in 100 ms bursts. Starting its 20 ms
// pacer with only the VPIO-oriented 60 ms cushion guarantees several underruns after every
// mono/stereo rebuild before the adaptive path catches up. Prime one full burst plus one
// frame for non-VPIO routes; VPIO remains at the proven low-latency three-frame cushion.
route.TargetFrames = IosAudioRouter.Shared.UsesVoiceProcessing ? 3 : 6;
return route;
}
internal bool EnsureRunning()
{
if (!IsConnected || engine?.Running == true) return true;