-
-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Environment
- Firefox (all versions)
- WebGL platform
Bug
In UnityMicrophoneLibrary.jslib, Microphone_StartRecording creates an AudioContext with a forced sample rate:
const audioContext = new AudioContext({ sampleRate: frequency });
const source = audioContext.createMediaStreamSource(stream);Firefox does not support connecting a MediaStreamSource (which runs at the device's native sample rate, e.g. 48000) to an AudioContext with a different sample rate (e.g. 24000). This throws:
DOMException: AudioContext.createMediaStreamSource: Connecting AudioNodes from AudioContexts with different sample-rate is currently not supported.
A secondary issue: the .catch() handler calls this.Microphone_StopRecording(deviceName), but this doesn't refer to the library object in Emscripten merged functions, resulting in:
TypeError: this.Microphone_StopRecording is not a function
Suggested fix
- Don't force sampleRate on the AudioContext — let the browser pick the native rate:
const audioContext = new AudioContext(); - The C# RecordingManager already handles resampling via ClipData.InputSampleRate / OutputSampleRate.
- Use the Emscripten global _Microphone_StopRecording(deviceName) instead of this.Microphone_StopRecording(deviceName) in the catch handler.
Additional note
GetDeviceCaps on WebGL (line 332-333 of Microphone.cs) is hardcoded to 44100 and ignores the actual maxFrequency/minFrequency values that the .jspre already reads from device.getCapabilities().sampleRate. Now that Firefox supports MediaStreamTrack.getCapabilities(), these values could be surfaced to C# instead of being hardcoded.