7

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.

beaver
  • 109
  • 5
RPiAwesomeness
  • 3,021
  • 4
  • 31
  • 52

1 Answers1

9

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

Sam Aaron
  • 251
  • 1
  • 3