Skip to content

Microphone_StartRecording: Firefox fails with "Connecting AudioNodes from AudioContexts with different sample-rate is currently not supported" #63

@Zarbuz

Description

@Zarbuz

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

  1. Don't force sampleRate on the AudioContext — let the browser pick the native rate: const audioContext = new AudioContext();
  2. The C# RecordingManager already handles resampling via ClipData.InputSampleRate / OutputSampleRate.
  3. 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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinghelp wantedExtra attention is needed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions