I opened my Audio Visualiser in iOS and the mic didn't work. It was connected, but it didn't give any output. I don't have a Mac now, so I was hopeless about debugging it there. Then I tried to open it in Chrome. And was I surprised! It didn't work! Code-wise, everything was fine, but the mic's output on the first load was empty. Only after I was loading an audio file, the mic could give proper output.
What the fuck?!
I came up with this stupid hack.
const oscillator = audioContext.createOscillator();
oscillator.frequency.value = 0;
oscillator.connect(gainNode);
oscillator.start();
oscillator.stop();
oscillator.disconnect();
This creates an oscillator node, connects it to the gain node, which is connected to the audio context destination. It starts generating a sound wave with frequency 0 and stops right away. This way, it kind of unplugs the audio flow and allows the mic to communicate with the analyser node with no issues.
Did I miss something? Maybe. But in Firefox it works fine without this silly hack.
