1

I've been playing with a few different Web Audio API libraries, and I've been having mixed results. My favourite so far is Timbre.js. I'm generally getting a 'buzz' coming out of the speaker on iOS (even when using AudioContextMonkeyPatch). This sometimes does not happen. For example, reboot the phone, start the app, click the 'go' button, and the sound is identical (to my ears) as per my desktop browser. Make a change (eg. change tempo), and buzz buzz buzz. Generally though, the audio output is buzz buzz buzz.

Example code:

var freqs = T(function(count) {
  return [220, 440, 660, 880][count % 4];
});

var osc = T("sin", {freq:freqs, mul:0.5});
var env = T("perc", {a:50, r:500}, osc).bang();

var interval = T("param", {value:500}).linTo(50, "30sec");

T("interval", {interval:interval}, freqs, env).start();

env.play();
Rob Welan
  • 2,070
  • 1
  • 11
  • 20

1 Answers1

1

I asked a similar question a little while after you (Distortion in WebAudio API in iOS9?) and believe I found an answer: WebKit Audio distorts on iOS 6 (iPhone 5) first time after power cycling

Summary: play an audio sample at the desired bitrate and then create a new context.

// 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();
}

Editing to note that it's possible you'd have to do some hacking of Timbre.js to get this to work, but it at least worked for me in using Web Audio on its own.

Community
  • 1
  • 1
  • Using a different audio library to timbre.js now (timbre.js no longer under development). In between noise creation / silence, I reset the audiocontext. Similar solution to the one above. I do the "context = new AudioContext();' as a command within the 'stop sound' button press. – Rob Welan Jan 16 '16 at 23:01