Sound in Mad Tea Lab

Sound can be rendered by clicking the “Play” symbol in the header of the function box.


Here is a basic example.
Here is an example generating the melody and bass from “The Great Giana Sisters” theme

How is the function transformed to sound?

It is just interpreted as a waveform, the default length is 3 seconds, so it will play the range from x=0 to x=3. If several functions are enabled they will first be added. To avoid clipping and loud noises, the final sound is peak normalized to 0.4 before played). By the way, note that the play options panel is expanded when you first press any of the play buttons:



Sound can also be rendered from js code using the function
which takes an array with values that are assumed to
be in the range -1 to 1. (values outside will be clipped to that range)

By default, it renders at 44100 hz 16bit, but this can be changed.


Playing Realtime Generated Loop


Loop Playing uses the same play options (sample length, rate etc) as the normal play function, but instead of rendering all at once and generating a wav file, it renders audio on the fly so changes can be heard within a few milliseconds.


Implementation details

For non-looping playing, the file is encoded to WAV binary, and then converted to base64 text, and via innerHTML played using the HTML 5 audio tag. If this should not work, you can try setting useAudioTag=0, then it will try to play using an iframe instead of the HTML 5 audio tag.

For continous playing, it uses the Web Audio API
(Initially, it was using the now deprecated Mozilla Audio Data API)

Comments are closed.