Ovilia
Ovilia

Reputation: 7310

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?

Upvotes: 4

Views: 2163

Answers (4)

notthetup
notthetup

Reputation: 1137

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 5kHz Analyzer data at 15kHz Analyzer data at 17kHz Analyzer 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.

Upvotes: 3

hotpaw2
hotpaw2

Reputation: 70733

There is probably an anti-alias low pass filter (between the microphone and the ADC) which has a cut-off below Fs/2 in order to make sure everything is rolled off by that frequency (given a finite filter transition width).

There may also be nulls in the room's acoustics. At frequencies above 2 Khz, it might be only inches from a peak to a null location for the microphone placement.

Upvotes: 1

Scott Stensland
Scott Stensland

Reputation: 28325

Lookup the concept of Nyquist Frequency - the default sampling rate of web audio is 44.1kHz - this means the theoretical maximum frequency would be 22050 hertz given perfect hardware such as microphone and analog-to-digital converter inside your computer. @Ovilia on that same computer using same microphone record the same input sound and then examine the audio file using a utility like Audacity where you can view the output of its FFT analysis - in Audacity when you open an audio file go to menu Analyze -> Plot Spectrum ... also to see a very nice FFT view click the down arror near left side of waveform view subwindow and pick Spectrogram - another excellent FFT capable audio tool is called Sonic Visualizer - are you now seeing power at frequencies you are not seeing using FFT within web audio ?

Upvotes: 2

ederwander
ederwander

Reputation: 3478

I think that the most microphones just works well in the voice range frequency, something around 80 Hz to 1100 Hz

So probably do you have a hardware limit problem, try check with manufacturer or manual the frequency input response from your device !

Upvotes: 1

Related Questions