I spent a little more time to improve on the previous post’s demo, using Wyngine to synthesize sound.

This time I’ve added envelopes. You may notice that the sound of each instrument (I believe they’re technically called oscillators) have a softer feel now.

Controls:

1/2/3/4/5    = change oscillators
Q/A          = increase/decrease frequency
E/D          = increase/decrease volume
UP/DOWN      = increase/decrease octave

ZSXCFVGBNJMK = piano notes (A, A#, B, ... G#)

Things I noticed while working with audio (so far):

  • The audio will not play if you visit the page from another domain (last I tried was Facebook). The easiest way to fix this is to visit the page manually (e.g. navigating to another page in this domain and back to this page). I’ll probably have to tweak Wyngine to initialise the audio when players click on the screen for the first time. Even better, I could even add a loading screen to show resources being loaded before the game actually players.

  • There is a delay between the keypress and the synthesized sound actually being audible. This is inevitable because audio only gets generated when the key is held; Thus the audio buffer needs some time to actually be filled before being sent to the device. Off the top of my head, I could try generating and storing audio samples to memory (ala loading music files), and playing the sound like an audio clip.

  • The audio crackles (lags) during playback sometimes. I think this is just because my browser is slow (or starved of memory). It happens when I have several tabs open in Chrome. When I open in a single tab on IE or Firefox, the sound plays fine.

  • Trying to loop the sample index (the point of time at which the sound sample is being played) at every second will produce a noticeable click. You can’t see it in this demo because I forgot to enable this “bug”. I thought it would be trivial to loop the samples rather than increasing the sample count indefinitely, but looks like there is something I don’t understand about why this is happening yet.

  • Audio synthesis is fun! But I’m not really good at maths…