lichen-community-systems / Flocking

Flocking - Creative audio synthesis for the Web
GNU General Public License v2.0
692 stars 60 forks source link

It should be possible for a user to specify the AudioContext used by Flocking #298

Open colinbdclark opened 3 years ago

colinbdclark commented 3 years ago

Currently, there's no supported API that a user can use to provide the Web Audio AudioContext object that Flocking should use instead of creating its own. This should be an option that can be provided to an flock.environ component, and via a call to flock.init() for those in the imperative mindset.

For now, luckily, there is a workaround. Flocking stores its AudioContext as a singleton in a global variable, flock.webAudio.audioSystem.audioContextSingleton. Assigning an AudioContext instance to this variable prior to initializing Flocking will cause it to use that context instead of creating its own. For example:

var ac = new AudioContext();
flock.webAudio.audioSystem.audioContextSingleton = ac;
flock.init();