feat(audio): microphone-only sync delay, on by default at 175 ms
The webcam's frames reach the compositor later than the mic's samples reach the audio pipe, so the voice runs ahead of the lips. The existing lip-sync offset could not fix that: it delays the WHOLE mix, which drags desktop and alert audio — neither of which has a camera to follow — out of sync in the process. So the delay line learned channels (mono for a source, stereo for the mix, offset always in milliseconds so the frame count is what stays constant), and FillAndMix runs a second line over micChunk before the mix. Slider-side: presets off / 150 / 200 in the LIP-SYNC bay under the whole-mix control, persisted as Audio.MicSyncOffsetMs. Default 175 ms is the creator's own number for a C920 pipeline (they asked for +150..+200). It is a setting, not a constant, because the right figure belongs to the camera and the machine — a faster camera wants less, no camera wants none. Both delay lines are reconfigured every tick, so the 2026-09-12 trap still applies and is documented at both sites: a Configure that reallocates discards the buffered voice every 10 ms. 673 pass, 0 warnings. Ear check pending: this is an audio change.
This commit is contained in:
@@ -34,6 +34,9 @@ public sealed class AudioMixer : IDisposable
|
||||
private readonly TimeSpan _mixInterval;
|
||||
private readonly Func<int>? _syncOffsetMs;
|
||||
private readonly AudioSyncDelay _syncDelay;
|
||||
private readonly AudioSyncDelay _micSyncDelay;
|
||||
private readonly Func<int>? _micSyncOffsetMs;
|
||||
private float[]? _delayedMic;
|
||||
private int _advanceSamplesRemaining;
|
||||
private bool _started;
|
||||
|
||||
@@ -97,7 +100,8 @@ public sealed class AudioMixer : IDisposable
|
||||
Func<double>? micGain = null,
|
||||
Func<double>? loopbackGain = null,
|
||||
Func<int>? syncOffsetMs = null,
|
||||
TimeSpan? mixInterval = null)
|
||||
TimeSpan? mixInterval = null,
|
||||
Func<int>? micSyncOffsetMs = null)
|
||||
{
|
||||
_mic = mic;
|
||||
_loopback = loopback;
|
||||
@@ -108,6 +112,11 @@ public sealed class AudioMixer : IDisposable
|
||||
_loopbackGain = loopbackGain;
|
||||
_syncOffsetMs = syncOffsetMs;
|
||||
_syncDelay = new AudioSyncDelay(OutputSampleRate);
|
||||
// The microphone alone, mono: a camera's frames reach the compositor later than the mic's
|
||||
// samples reach the pipe, so the voice has to wait for the picture. Loopback and alert audio
|
||||
// are not tied to a camera frame and must not move with it.
|
||||
_micSyncOffsetMs = micSyncOffsetMs;
|
||||
_micSyncDelay = new AudioSyncDelay(OutputSampleRate, channels: 1);
|
||||
_mixInterval = mixInterval ?? DefaultMixInterval;
|
||||
|
||||
var seconds = _mixInterval.TotalSeconds;
|
||||
@@ -506,6 +515,20 @@ public sealed class AudioMixer : IDisposable
|
||||
Array.Clear(alertChunk, alertCount, alertChunk.Length - alertCount);
|
||||
}
|
||||
|
||||
// Mic-only delay: applied to the source, before the mix, so the desktop and alert audio keep
|
||||
// their timing. Reconfigured every tick like the mix line above (same 2026-09-12 trap: a
|
||||
// reallocating Configure would discard the buffered voice every 10 ms).
|
||||
var micDelayMs = _micSyncOffsetMs?.Invoke() ?? 0;
|
||||
if (micDelayMs > 0)
|
||||
{
|
||||
_micSyncDelay.Configure(micDelayMs);
|
||||
var delayedMic = _delayedMic;
|
||||
if (delayedMic is null || delayedMic.Length < micChunk.Length)
|
||||
delayedMic = _delayedMic = new float[micChunk.Length];
|
||||
_micSyncDelay.Process(micChunk, delayedMic);
|
||||
Array.Copy(delayedMic, micChunk, micChunk.Length);
|
||||
}
|
||||
|
||||
var duck = _ducker.Update(micRms);
|
||||
var micGain = (float)(_micGain?.Invoke() ?? 1.0);
|
||||
var loopGain = (float)(_loopbackGain?.Invoke() ?? 1.0) * duck;
|
||||
|
||||
Reference in New Issue
Block a user