1

I trying to develop a simple guitar tuner based on harmonic detection using the web audio API and js. https://github.com/lontafara/El-audio-en-la-web

I have always worked with a sample rate of 48000 Hz. Allowing me some resolution in the frequency domain. But whenever a working draft of the Web Audio API is published, this value automatically changes to 44100 for a while.

I realized for the first time in the version of 13 December, and now on April 25.

The .samplerate attribute is a readonly constant and i cant change it.

my question is, Can I continue working with a sample rate of 48000, or i've got to change to 44100? Is this change temporary, because last week the default sampling rate was still 48000?

Thank you!!!

2 Answers2

2

The Web Audio API runs at whatever the default output device's sampling rate is. That is frequently 44.1kHz, but it is system-dependent. You shouldn't hardcode a sampling rate into your code.

cwilso
  • 13,610
  • 1
  • 30
  • 35
  • Ok, Chris thanks for your reply, But what do you mean by "default output"? I work in the same computer, browser... and the value of .sampleRate param changes automatically anyway, just when an update of the webaudioapi is made... – user3575793 May 12 '14 at 17:15
  • I'm using the integrated mic of an imac to getUserMedia, and i work with that input (at 44100) . But now I got a 48000Herz value of default sampleRate – user3575793 May 12 '14 at 17:24
  • That's because your default output device must be running at 48kHz, and Web Audio resamples the input to the output device's rate. – cwilso May 12 '14 at 17:44
  • Watch out as the sample rate might also change in runtime if the user switches e.g. from sound out from his PC running at 48000 kHz to e.g. headphones over bluetooth playing at 44100 kHz. I spent ages wondering why the rate kept changing as I was coding only to realize it happened whenever I turned on my Bose headsets. – Johncl Feb 15 '23 at 11:23
0

Ok, as cwilso says the web audio API runs at the default device sample rate. In my case, I had to adjust the value of 44100 to get my application working properly. In Mac OS the output is set on Utilities -> Audio MIDI Setup.

There are no relation between the Web Audio API updates.

Thanks again cwilso