Sonic Pi is built on top of the SuperCollider synthesis engine. Whereas the default SuperCollider language gives you full control of the synthesis engine, Sonic Pi opts to present a much simpler interface. This is a classic trade off between simplicity and complexity. One of the biggest compromises is that Sonic Pi doesn't give you any access to the synthesiser design and composition elements of SuperCollider. Instead, it ships with a number of pre-designed synths for you to use without needing any sophisticated synth knowledge. This is with stark contrast to SuperCollider language which actually requires you to design and compile a synth before you can even make a sound!
One of the unifying design decisions behind the Sonic Pi suite of synths is that they all have a finite ASR envelope - see http://en.wikiaudio.org/ADSR_envelope. This envelope allows you to alter the duration of the sounds whereas the play
/sleep
commands control the onset of the sounds through time. Each synth has its own default values for its ASR envelope which can be seen in the help system under the synths tab. The ASR phases are represented as attack:
, sustain:
and release:
parameters. The attack is the time to go from quiet to full volume, the sustain is the time to keep at full volume and release is the time to go back to being silent. The full duration of the sound will be the attack, sustain and release times added together. Typically the defaults for these parameters are very small times for a short quick sound.
This means that technically it's impossible to play a tone which continues forever with any of the pre-built Sonic Pi synths. However, you can set the sustain value to be really long, i.e. minutes or hours which will probably achieve the desired result:
# play note C4 for 2 hours:
play :C4, sustain: 60 * 60 * 2
In the case that you wish to stop these very long sounding notes, it's essential to store a reference to the running synth:
my_note = play :C4, sustain: 60 * 60 * 2
You may then pause
or run
the node:
my_note.pause
sleep 1
my_note.run
You may control any of the synth's params:
my_note.control note: :E4
And finally you may kill it:
my_note.kill
I hope that this helps. Also, this post assumes you're using Sonic Pi v2.0
loop do play 50 end
?