I've been messing around with Sonic-Pi lately, trying to figure out various things. One thing I'm finding I want to be able to do is play a continuous MIDI tone/note. However, the closest thing I can figure out how to do is play the note repeating very quickly, which leads to a wave affect. While it doesn't sound bad, I still want to be able to create background tones that just play continuously.

It would make sense that you can do this, but I can't find out how, especially seeing as Sonic-Pi is so new. I'd love to do more with it, but this is kind of blocking my path.

I'm planning on researching the language/software/engine behind Sonic-Pi (can't remember what it's called - SuperCollider and/or Clojure I believe) and seeing if I can't figure this out via learning at a lower level. However, until then I figured I would ask and see if anyone knows how to do this, or have done it themselves.

  • You need to use (or create) a synth that does not decay.
    – CL.
    Jun 23, 2014 at 7:09
  • Such as a loop do play 50 end? Jun 23, 2014 at 13:28

1 Answer 1


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:

sleep 1

You may control any of the synth's params:

my_note.control note: :E4

And finally you may kill it:


I hope that this helps. Also, this post assumes you're using Sonic Pi v2.0

  • So the sustain keyword is used for creating continuous notes without constantly re-playing the note. Thanks! And yes, I am using Sonic Pi v2.0 Jun 24, 2014 at 14:00
  • Yes, the sustain: parameter is for modifying the duration of the sound. I've edited my original post to reflect this and add more detail w.r.t. the ASR envelope parameters.
    – Sam Aaron
    Jun 24, 2014 at 19:19
  • I knew about the attack parameter (essentially fade-in time) and the release parameter just make sense. Again, thanks for the explanation! I hope to continue using Sonic Pi and SuperCollider! Great job I must add :) Jun 24, 2014 at 20:00
  • 2
    Using last version (currently 2.9) of Sonic Pi, my_note.control note: :E4 returns a runtime error: undefined method to_f for :E4:Symbol. Use control my_note, note: :E4 instead. Mar 4, 2016 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.