Firefox 37 throwing error when trying to add microphone volume control for WebRTC audio context

274 views Asked by At

Since firefox 37 I cannot add volume control to the input(microphone), i get the error :

IndexSizeError: Index or size is negative or greater than the allowed amount

It works fine on Chrome.

Here is the code sample :

var audioContext    = new (window.AudioContext || window.webkitAudioContext)(); // define audio context
var microphone      = audioContext.createMediaStreamDestination();
var gain            = audioContext.createGain();
var speaker         = audioContext.createMediaStreamDestination(gain);
gain.gain.value = 1;
microphone.connect(gain);
gain.connect(speaker);

The error is thrown here :

microphone.connect(gain);

weirdly it works on firefox nightly.

This error is similar to this stackoverflow :link

Related link : link on StackOverflow

2

There are 2 answers

0
dors On BEST ANSWER

Shouldn't you use this for microphone?

 var microphone      = audioContext.createMediaStreamSource();

instead of this

 var microphone      = audioContext.createMediaStreamDestination();

A microphone is not a destination. It is a source.

0
Obscure Geek On

Firstly I think it should be

var microphone      = audioContext.createMediaStreamSource(stream);

Here stream is the microphone audio stream. Find more info here.

Also check out this demo with elaboration here. It is similar to what you are trying. Replace createMediaElementSource with createMediaStreamSource will work.