jussi-kalliokoski / audiolib.js

audiolib.js is a powerful audio tools library for javascript.
http://audiolibjs.org/
672 stars 58 forks source link

Where should nodes' parameters live? #92

Open sebpiq opened 10 years ago

sebpiq commented 10 years ago

At the moment params can live in two places for the same node :

var sine = new Sine()
sine.parameters.frequency = 220  // place 1
sine.process(dst, frequencies)      // place 2

I suggest to clean this. Several possibilities :

  1. All parameters passed in process . This is simple, clear, coherent with ArrayMath, but if lots of parameters, could be annoying
  2. we leave it like this
  3. ?
jussi-kalliokoski commented 10 years ago

This is indeed something I've been pondering as well. 1) is coherent, and I like it in simple cases, but then if something has a lot of different parameters, or state, that may or may not be relevant to modify, it gets tricky. Not cool to have to specify all the stuff for example for BandLimitedOscillator. We should probably sit down to think the architecture a bit more. Maybe we shouldn't have classes but just functions (since if we have no state, instances make no sense)? I don't have a solution yet. This stuff is hard. x)

sebpiq commented 10 years ago

I think it makes sense to have classes + instances, cause we do have states. For example in the case of an oscillator we have the phase.

We could also go for an hybrid solution : parameters are either passed to process or to the constructor but not both.