Re: Changing the sample rate of the audio device

On Wed, Mar 6, 2013 at 1:32 AM, Jan Deinhard <jan.deinhard@gmail.com> wrote:

> Hello,
>
> when I run the following code and then change the audio output device to a
> device with a different sample rate the sound is distorted.
>
> var context = new webkitAudioContext();
> var gain = context.createGainNode();
> gain.gain.value = 0.05;
> var osc = context.createOscillator();
> osc.type = 0;
> osc.frequency.value = 440;
> osc.connect(gain);
> gain.connect(context.destination);
> osc.noteOn(0);
>
> http://jsfiddle.net/cQswX/1/
>
> Even if I create a new context in the same tab after I changed the output
> device the sound is still distorted. Only after I opened a new tab (in
> Chrome) Web Audio API seems to adapt to the new settings.
>
> I noticed this behavior when I plugged in head phones to my notebook which
> is connected to a Cinema Display. The display audio device has a sample
> rate of 48 kHz. The internal device has 44.1 kHz. The display was the
> initial output device. When I plugged in the head phone the output switched
> to the internal audio device. When I started playback the audio was
> distorted.
>
> Is there anything I can do about this in an application using Web Audio
> API? Is there a way to detect the changed settings? Or is it just
> a deficiency in WebKit?
>
> Best regards
>
> Jan
>

This is really something to be handled at the user-agent level.  For
example, if an <audio> element is playing under the same circumstances then
it would be expected to adapt to the new hardware sample-rate.  So ideally
we'd like to have the AudioContext continue playing, adapting to the new
hardware internally.  I think it would be best in these types of cases for
the AudioContext to continue to operate at the sample-rate it was created
with, and that the user-agent simply does the appropriate sample-rate
conversion.

Chrome doesn't do anything fancy yet to adapt as I describe, so that's
probably why you were experiencing problems...

Chris

Received on Wednesday, 6 March 2013 21:23:24 UTC