[flocking] Difference between synth and environments.

Colin Clark colin at colinclark.org
Tue Aug 4 13:27:27 EDT 2015

Hi Derek,

Good question. This distinction has been a source of confusion for a lot of users, to the point where I've considered the possibility of removing the Synth.play/pause methods before Flocking 1.0. I'm still not sure, since they're very convenient.

Here's a brief summary:

The environment manages the sample generation and output process for all synths. It maintains a list of all active synths, and is responsible for triggering them to generate their output. So you must start the environment before any sound will be generated. Stopping it will cause all synths to stop generating samples entirely, and for Flocking to unregister its various Web Audio API hooks, ensuring that it no longer takes up any CPU time.

A synth must be added to the environment before it will start making sound, and it must be removed from the environment in order to stop it from sounding. By default, each new Synth is automatically added to the Flocking global environment when it is instantiated. This behaviour can be controlled using the addToEnvironment option.

The play() and pause() methods provide, as a convenience, a quick way to add and remove a synth from the environment. If the environment hasn't already been started, Synth.play will also start it. The side effect of this behaviour is that all synths that have been added to the environment will start to play. Synth.pause, however, will not stop the environment; it only removes the synth from its environment.

In general, the approach that Flocking users should take is this:

1. Initialize Flocking and start the environment when you first set up your application
2. Create synths freely, using the addToEnvironment option to control whether they should start playing immediately
3. Use Synth.play and Synth.pause to easily start and stop synths from sounding

I wasn't able to reproduce the issue you mentioned with Environment.stop working. I tried this quick test in the Flocking Playground and it seemed to work.

// Simple sine wave oscillator
var synth = flock.synth({
    synthDef: {
        ugen: "flock.ugen.sinOsc",
        freq: 440,
        mul: 0.25

// Five seconds from now, stop the whole environment.
// Everything should immediately become silent.
flock.enviro.shared.asyncScheduler.once(5, function () {

Can you post an example or test case that shows the issue you're seeing, and I'll try to fix any issues that it reveals?



> On Aug 3, 2015, at 10:31 PM, derekriemer <Derek.Riemer at Colorado.EDU> wrote:
> Hi,
> If I do something like \
> enviro = flock.init();
> and create a synth with flock.synth, what is the difference between synth.play/pause and enviro.play/stop? When I call enviro.stop() it doesn't do anything, while when I call synth.pause it pauses the synth. Why doesn't calling the stop method on the environment work?
> Thanks,
> Derek
> _______________________________________________
> flocking mailing list
> flocking at lists.idrc.ocad.ca
> http://lists.idrc.ocad.ca/cgi-bin/mailman/listinfo/flocking

More information about the flocking mailing list