Search code examples
javascriptgoogle-chromefirefoxaudioweb-audio-api

Does web audio oscillator type not work in Chrome, Firefox?


I seem to just get sine waves no matter what.

oscillator = context.createOscillator();
oscillator.type = 1;

I notice that this example I found online works on Safari, gives me just a sine wave on chrome, and doesn't work on firefox (maybe because it uses oscillator.noteOn instead of oscillator.start?):

http://middleearmedia.com/web-audio-api-oscillators/


Solution

  • You need to use start(), and .type is a string type:

    oscillator = context.createOscillator();
    oscillator.type = "sawtooth";
    oscillator.start(0);
    

    See http://updates.html5rocks.com/2014/07/Web-Audio-Changes-in-m36.