audiojs / audio-oscillator

Generate periodic oscillation into an array/audiobuffer
MIT License
27 stars 2 forks source link

Remove constructor #29

Closed dy closed 5 years ago

dy commented 6 years ago

Constructing a function is unreasonable:

let sine = generate.sine({frequency: 1000})
sine(1024)
sine(1024, {frequency: 2000})

More natural is to have instant signature as generate.<what>(<how much>, <how?>):

let result = generate.sine(1024, {frequency: 1000})
generate.sine(1024, {frequency: 2000, phase: result.phase })

That also allows for reducing difficult audio-through dependency.

dy commented 5 years ago

Another optimizations:

dy commented 5 years ago

Ways to persist state?

  1. Provide properties on the output array. That forbids deepEqual and not well established pattern, although pretty handy. Does not allow to generate a sequence of linked arrays.
  2. Keep internal weakmap cache of per-instance states. Does not allow to generate a sequence of linked arrays.
  3. Use global state - generates a sequence of arrays.
dy commented 5 years ago

Done in 3.0.1. Explicitly persisted state is better than implicit.