Indie dev efficiency3 min read

Check Web Audio FFT Frequency Labels with One Known Tone

Use a 750 Hz tone at 48 kHz to check your analyser's peak bin and frequency labels.

Check Web Audio FFT Frequency Labels with One Known Tone
A single amber spectral spike stands above cyan frequency bins
Concept illustration

Your game debug spectrum has a distinct peak but labels it with the wrong frequency. A known sine tone can separate an axis conversion bug from what is actually in the sound.

Predict the bin before measuring

With an actual context sample rate of 48,000 Hz and an fftSize of 2048, the bin spacing is 23.4375 Hz. A 750 Hz tone is centered on zero-based bin 32. Allocate the output array using frequencyBinCount, which is 1024 for this setup. Divide by fftSize when calculating bin spacing; bin zero is DC.

Read after the signal has filled the window

Resume the context through a user action. Connect a 750 Hz sine oscillator to the analyser. For a silent test, route its output through a gain set to zero before the destination. Set smoothingTimeConstant to zero, allow a full analysis window of steady tone, then find the largest value returned by getFloatFrequencyData. If the device uses a different sample rate, choose the corresponding frequency for bin 32 using the real sample rate.

Switch to a representative game effect

Pick a short sample from the game sound effects generator and capture the same settings. Windowing and tones between bin centers can put energy in neighboring bins. A correct single-tone bin with an incorrect displayed label points to the axis. If only the effect is hard to interpret, check playback rate and the section of audio being analysed.

Recommended tools

Ready to try "Check Web Audio FFT Frequency Labels with One Known Tone"?

Use our online tools to apply this tutorial to your indie game project right away.