Learn creative coding writing simple programs

135. Sounds that end

By using Env and EnvGen we can produce synths that disappear after they are done playing. Compared to other programming languages, there is something very different in SuperCollider: you write one source code, but it actually produces two programs. One runs in the client side, known as the language, the other runs in the sound server. This is probably a strange concept :) Env is used in the language side to generate an envelope (like a curve that changes over time which can be used to control sound parameters). EnvGen is used in the sound server to produce changing values in real time, based on an Env. Env.linen() is a simple type of Env, good enough to get started. There are many other types of envelopes with different shapes and complexities.
In this episode we use envelopes to produce sounds that have a limited duration. By adding the option doneAction:2 to the EnvGen we tell SuperCollider that the synth should be removed once it's done playing. This is important to avoid having hundreds or thousands of zombie synths lying around. That would be scary :)

Tags: supercollider, env, envgen, rand, rrand

Code editor

You can make changes to the code below. Then
Reference

Questions and comments

Try to stay close to the topic of this episode. Use the Processing forums for help with unrelated Processing projects (or hire me for help ;-)

To indicate that a word in your comment is code, use the `backtick`. Example
Do `float` and `int` smell similar?
To highlight code blocks, surround it with ``` code-fences ``` like this:
``` void setup() { size(600, 600); } ```