0

I want to control the audio volume of an incoming webRTC audio stream. The code looks like this:

...
audioContext=new AudioContext;
gainFilter=audioContext.createGain(),
jsnode=audioContext.createScriptProcessor(512,1,1); // used for VU-Meter

source=audioContext.createMediaStreamSource(stream);
source.connect(gainFilter); 
gainFilter.connect(jsnode);
jsnode.connect(audioContext.destination);

...

// when volume slider is moved
gainFilter.gain.value=volume;
...

The basic idea is working: I hear the audio, I can see in my VU meter that the signal's volume is affected by the fader that determines the gainFilters's setting. But the output I hear through the speakers never changes in volume.

I do not understand what is wrong: The audio data seen by the script processor is affected. When I move the fader to lowest volume, the vu meter correctly shows no peak. Still, I can hear the audio.

Armin Hierstetter
  • 1,078
  • 2
  • 12
  • 27
  • Probably a wrong routing? I met a lot of strange behaviors while playing with the web audio api... I couldnt tell right now if you are doing it all right or not but I suggest you to do some tests with your routing ! It usually comes from here. Your visualization may be routed correctly which means when you turn the volume off you have no sign of signal, but there would still be the audio going on through another node that is linked to your main output? just some hints... – DevMoutarde Mar 14 '17 at 10:32
  • But I can't see where the routing is wrong. It is like in the example above: Source->GainFilter->AnalyserNode->Destination. Not very complex. Also, I can HEAR the audio and the analyzer gets the volume modified audio. – Armin Hierstetter Mar 14 '17 at 11:10
  • I may take a look later, if you can provide me the full code :) – DevMoutarde Mar 14 '17 at 13:57
  • why are you using the jsnode? I think removing that would heal the problem. – Kilian Hertel May 31 '17 at 12:10

0 Answers0