Configure native audio source from device config instead of hardcoded defaults#304
Open
MaxHeimbrock wants to merge 3 commits into
Open
Configure native audio source from device config instead of hardcoded defaults#304MaxHeimbrock wants to merge 3 commits into
MaxHeimbrock wants to merge 3 commits into
Conversation
af6d96b to
a775e59
Compare
This was referenced Jun 12, 2026
b9f4f5c to
266730d
Compare
The native (Rust) audio source was created with a hardcoded sample rate (48000) and channel count (2). Microphone frames flow through Unity's audio graph (AudioProbe) at the actual DSP output configuration, which often differs — e.g. with a Bluetooth headset. The Rust source does not resample; it rejects frames whose rate/channels don't match, causing the metadata-mismatch warning and capture failures. Read the source's sample rate and channel count from Unity's output configuration (AudioSettings.GetConfiguration) instead of hardcoded defaults, falling back to the defaults only when Unity can't report one. The base constructor now exposes a device-mode overload (type only) and an explicit overload (type, sampleRate, channels) for sources that generate a fixed format. MicrophoneSource and BasicAudioSource use device mode; BasicAudioSource drops its unused channels parameter. SineWaveAudioSource declares its exact format. If a frame's format still doesn't match (inconsistent Unity report or a runtime output change), drop it with a throttled warning instead of sending a mismatch the native side would error on. Also removes the redundant Microphone.Start in the Meet sample. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Remove logging changes
266730d to
2a26265
Compare
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.
Problem
When the device's audio output configuration differs from the hardcoded defaults — most commonly with a Bluetooth headset — microphone capture fails with
sample_rate and num_channels don't matchand theRtcAudioSourcemetadata-mismatch warning.Root cause:
RtcAudioSourcecreated the native (Rust) audio source with a fixedsample_rate(48000) andnum_channels(2). But captured frames flow through Unity's audio graph (AudioProbe.OnAudioFilterRead) at the actual DSP output configuration. The Rust native source does not resample —NativeAudioSource::capture_framerejects any frame whose rate/channels differ from how the source was configured.Change
RtcAudioSourcenow reads the sample rate and channel count from Unity's output configuration (AudioSettings.GetConfiguration) instead of hardcoded defaultsRtcAudioSourceTypeonly) for capture sources whose format is whatever Unity delivers, and an explicit one (type, sampleRate, channels) for sources that generate a fixed, known format, for exampleSineWaveAudioSourcein testsVerification
Before, using my Sony MDR-1000X Bluetooth headset, I often got 44100 Hz as sample rate from Unity but we configured to 48000 Hz hard coded. This solves the issue for me.
🤖 Generated with Claude Code