AEC in Unity Audio - #381
Draft
MaxHeimbrock wants to merge 3 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Unity's
Microphonecapture bypasses the platform audio device module, soMicrophoneSourcehad no echo cancellation: everything the game played came back through the mic. OnlyPlatformAudioSourcehad AEC.Changes
MicrophoneSource(and anyRtcAudioSourcesubclass) acceptsAudioProcessingOptions. The capture then runs through libwebrtc'sAudioProcessingModule(AEC3, NS, AGC, HPF) beforeCaptureAudioFrame. If the module cannot be created, the source warns and publishes unprocessed.PlayoutReferencecomponent: attached by the SDK to the activeAudioListener, taps the final mix inOnAudioFilterReadand feeds it to the APM reverse stream. Re-attaches after scene loads andAudioSettings.OnAudioConfigurationChanged.AudioProcessorre-chunks capture and reference into 10 ms int16 frames on the Unity audio thread (the Rust side asserts on any other size). Output rates that are not a multiple of 100 Hz bypass processing with a warning.AVAudioSessionlatencies via three new exported functions inLiveKitAudioSession.mm.NewApm,ApmProcessStream,ApmProcessReverseStream,ApmSetStreamDelay(protos already present).Runtime/Scripts/Audio/Processing/.remoteAudioGain(0.7) on remoteAudioSources; periodicAudioProcessingStatslog. Custom editor updated.PcmRingBuffer,PcmConvert, rate/frame helpers, delay hint; PlayMode for 10 ms chunking end to end and for cancelling a delayed echo of the playout.API surface
AudioProcessingOptionsbool HighPassFilterDefaultsetstrue. Unity-audio sources only;PlatformAudioSourceignores it.AudioProcessingOptionsbool PreferHardwarePlatformAudioSourceonly.MicrophoneSourceMicrophoneSource(string, GameObject, AudioProcessingOptions)RtcAudioSourceprotected RtcAudioSource(RtcAudioSourceType, AudioProcessingOptions)RtcAudioSourceprotected RtcAudioSource(RtcAudioSourceType, uint, uint, AudioProcessingOptions?)RtcAudioSourcebool AudioProcessingEnabled { get; }RtcAudioSourceAudioProcessingStats AudioProcessingStats { get; }RtcAudioSourceprotected void ResetAudioProcessing()AudioProcessingModuleChunkSizeMs,Handle,IsNativeSampleRate,IsSupportedApiRate,FrameSizeFor,ProcessStream,ProcessReverseStream,SetStreamDelayMs,Dispose.AudioProcessingStatsRtcAudioSource.AudioProcessingStats.PlayoutReferenceMonoBehaviourLiveKit/Playout Reference). No public members; hand-placing it on theAudioListeneris supported.Nothing removed or changed in signature.
AudioProcessingOptionsis a struct gaining a field:default(AudioProcessingOptions)hasHighPassFilter == false,AudioProcessingOptions.Defaulthas ittrue.