I\'ve been struggling with an elusive audio distortion bug using webkitAudioContext in HTML5 under iOS 6. It can happen in other circumstances, but the only way I can get 1
I have been having similar problems, even on iOS 9.2.
Even without a tag, playback is distorted when first playing audio on the page after cold boot. After a reload, it works fine.
The initial AudioContext
seems to default to 48 kHz, which is where distortion is happening (even with our audio at 48 kHz sample rate). When playback is working properly, the AudioContext
has a sample rate of 44.1 kHz.
I did find a workaround: it is possible to re-create the AudioContext
after playing an initial sound. The newly-created AudioContext
seems to have the correct sample rate. To do this:
// inside the click/touch handler
var playInitSound = function playInitSound() {
var source = context.createBufferSource();
source.buffer = context.createBuffer(1, 1, 48000);
source.connect(context.destination);
if (source.start) {
source.start(0);
} else {
source.noteOn(0);
}
};
playInit();
if (context.sampleRate === 48000) {
context = new AudioContext();
playInit();
}