Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Audio frequency limitation?

My goal is to generate an audio at a certain frequency and then check at what frequency it is using the result of FFT.

function speak() {
  gb.src = gb.ctx.createOscillator();
  gb.src.connect(gb.ctx.destination);
  gb.src.start(gb.ctx.currentTime);
  gb.src.frequency.value = 1000;
}

function listen() {
    navigator.getUserMedia = (navigator.getUserMedia
            || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);

    navigator.getUserMedia({
        audio : true,
        video : false
    }, function(stream) {
        gb.stream = stream;
        var input = gb.ctx.createMediaStreamSource(stream);
        gb.analyser = gb.ctx.createAnalyser();
        gb.analyser.fftSize = gb.FFT_SIZE;
        input.connect(gb.analyser);

        gb.freqs = new Uint8Array(gb.analyser.frequencyBinCount);
        setInterval(detect, gb.BIT_RATE / 2);
    }, function(err) {
        console.log('The following gUM error occured: ' + err);
    });
}

See working example at http://codepen.io/Ovilia/full/hFtrA/ . You may need to put your microphone near the speaker to see the effect.

The problem is, when the frequency is somewhere larger than 15000 (e.g. 16000), there seems not to be any response at high frequency area any more.

Is there any limit of frequency with Web Audio, or is it the limit of my device?

What is the unit of each element when I get from getByteFrequencyData?

like image 514
Ovilia Avatar asked Mar 19 '23 12:03

Ovilia


1 Answers

Is there any limit of frequency with Web Audio, or is it the limit of my device?

I don't think the WebAudio framework itself limits this. Like the other answers have mentioned here. The limit is probably from microphone's and loudspeaker's physical limits.

I tried to use the my current bookshelf loudspeaker (Kurzweil KS40A) I have along with a decent microphone (Zoom H4). The microphone was about 1 cm from the tweeter.

Analyzer data at 5kHzAnalyzer data at 15kHzAnalyzer data at 17kHzAnalyzer data at 19kHz

As you see, with these loudspeakers and microphones aren't able to effeciently generate/capture sounds at those frequencies.

This is more obvious when you look at the Zoom H4's frequency response. Unfortunately I couldn't find a frequency respose for the KS40a.

You can also do something similar using non browser tools to check if you see similar results.

What is the unit of each element when I get from getByteFrequencyData?

The unit of each element from getByteFrequencyData is a normalized magnitude data of from the FFT scaled to fit the dBFS range of the maxDecibles and minDecibles attributes on the AnalyserNode. So a byte value 0 would imply minDecibles (default is -100dBFS) or lower and a byte value of 255 would imply maxDecibles (default is -30dBFS) or higher.

like image 169
notthetup Avatar answered Mar 25 '23 11:03

notthetup