Search code examples
html5-audioweb-audio-api

Why the default sample rate is 48000 in Web Audio Context rather that no one could even hear?


The default sample rate of web audio context is 48000. However, most people can only hear 20-20000Hz and almost no one can hear over 30000Hz, why it is set to 48000?

var a = new AudioContext();
var samplerate = a.sampleRate;
alert(samplerate); // 48000


Solution

  • The fact that 20kHz is approximately the highest frequency humans can hear is exactly the reason why values above 40kHz are so commonly used by audio hardware.

    To represent a signal digitally you have to sample it with at least twice the frequency. https://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem

    By default an AudioContext uses the sampleRate of the audio hardware which is commonly 44.1kHz (thanks to the CD format) or 48kHz these days.