Has anybody out there got working sample code that synthesizes (and plays) audio using HTML5/Javascript on Mobile Safari on the iPad? I have found some examples for javascript-based sound synthesis on the web, but they all seem to work in Firefox only.
-
The JS audio samples I'm aware of work in FF, Safari, Opera .. but they don't seem to work on the iPad version of Safari. Generally I find HMTL5 support on that browser to be either sluggish or broken - at least for the features I've tried. – brainjam Sep 02 '10 at 22:42
4 Answers
Recently I came across this js-library, I think this is what you want -> https://github.com/oampo/Audiolet

- 11
- 1
-
1This sounds like an interesting Library; however, it only works on Firefox and some Versions of Chrome. I was looking for something that works on mobile Safari for iPad. – jms Jul 17 '11 at 10:57
I'm answering a very old question... but modern webkit browsers now support the Web Audio API. I wrote a very simple fiddle that generates chords using sine waves. There are only 4 built-in wave forms, but you can build your own using Fourier coefficients (array of numbers). You have to generate a new oscillator object for each note. They are single use objects. By connecting multiple oscillators to the same destination, you get polyphonic sounds.
let audio = new(window.AudioContext || window.webkitAudioContext)();
let s1 = audio.createOscillator();
let g1 = audio.createGain();
s1.type = 'sine';
s1.frequency.value = 600;
s1.start();
g1.gain.value = 0.5;
g1.connect(audio.destination);
s1.connect(g1);

- 10,274
- 3
- 79
- 79
-
Something strange happens with more than two tones. I guess they are not summed/multiplied correctly. – agiopnl Nov 18 '22 at 23:09
-
@agiopnl I see what you mean. If you lower the GAIN the problem is fixed. But I don't know why. – John Henckel Nov 23 '22 at 18:16
Here is an example that works for me on an iPad:
www.cse.usf.edu/~turnerr/sound_demo.html
You can download the files from http://www.cse.usf.edu/~turnerr/Downloads/Sound_Demo.zip
This demo is on a Unix based server. But I have not been been able to get the same code to work on an IIS server. Hoping someone can provide some help with IIS.
-
2Sorry, but that doesn't help. Playing existing audio files is not the issue - I need to render new audio on the fly (e.g. sine waves) and then play it – jms Mar 20 '11 at 08:20
You may be able to use generated data URIs of uniform length, such as 0.1 seconds. This would give you 1/10 of a second delay and you would generate that many "frames" of audio. I'm not sure entirely what formats the iPad supports, but I read it supports uncompressed WAV. Info on this file format is pretty easy to get, I remember generating WAV files a long time ago with some primitive byte manipulation methods.
Please post back with details!

- 5,838
- 7
- 42
- 67
-
I have been thinking about a similar solution. Problem is, the iPad stubbornly refuses to auto-play audio of any kind - the user would have to tap a button 10 times a second to achieve continuous audio. – jms Dec 28 '11 at 19:37
-
@jms: Interesting. I am trying to implement a synthsizer myself but with the restriction that I want to emulate instruments. So you are saying dataUri would technically work if the user taps a button? If that's true I could just generate the anticipated sound for the future assuming no further input and then replace it with a new prediction on additional input. That works for me because I only generate sound based on user input in the first place. Have you figured anything out (this is an old topic, all I know there was no progress so far in terms of support)? – thesaint Apr 27 '14 at 12:25