0

I'm learning the WebAudio API and experimenting by building a simple audio player with a visualiser and an equaliser.

Both the visualiser and equaliser work on their own, but when I have them both connected to the AudioContext, the equaliser stops working.

Here's some of the code...

The equaliser

var sum = APP.audioContext.createGain();
APP.lGain.connect(sum);
APP.mGain.connect(sum);
APP.hGain.connect(sum);
sum.connect(APP.audioContext.destination);

And the visualiser

APP.analyser = APP.audioContext.createAnalyser();
APP.source.connect(APP.analyser);
APP.analyser.connect(APP.audioContext.destination);

If I remove the final line APP.analyser.connect(APP.audioContext.destination); then the equaliser works, but then my visualiser obviously breaks.

This works fine in Firefox, but not in Chrome (osx).

Thanks in advance for any help!

DanV
  • 3,193
  • 4
  • 29
  • 43

1 Answers1

2

1) My guess is that it's not that the equalizer "stops working" - it's that you're connecting both the output of the equalizer and the output of the analyzer (which is a pass-through of the source!) to the destination, and it's summing them - so you have an equalized copy summing with a non-equalized copy, and it's dramatically lessening the equalizer's effect. The fix is simple - don't connect the analyzer to the destination. (It doesn't need to be connected to anything to work.)

2) I suspect you're using a less-than optimal way of doing equalization. You should use shelving filters and a peak filter in SERIES (one connected to another to another), not three filters in parallel (summing to one node). If you connect them in parallel, you're going to get odd phase-offset effects. Take a look here: Web audio API equalizer.

Community
  • 1
  • 1
cwilso
  • 13,610
  • 1
  • 30
  • 35