hoch / WAAX

NOTE: This project in not currently maintained.
MIT License
302 stars 19 forks source link

Sampler node management #10

Closed colinsullivan closed 10 years ago

colinsullivan commented 10 years ago

This implementation is not meant to be a polyphonic sampler, although it could evolve into one. I have implemented a list of active nodes instead of just keeping track of the most recent. This list is maintained so the nodes have time to finish and call onended before they are removed from the heap. Since they aren't removed immediately after calling stop, it allows stop to be called multiple times, because we wait until the sound actually finishes to remove the reference to the node.

Calling stop multiple times is specified here:

http://webaudio.github.io/web-audio-api/#widl-AudioBufferSourceNode-stop-void-double-when

Also included is the start of a unit test framework for WAAX. The tests included test the timing of the oneshot, start, and stop methods, as well as that the proper behavior occurs when calling stop more than once (most recent stop time is used).

hoch commented 10 years ago

Actually I was thinking of designing a polyphonic sampler, but I think it should be a larger scale rather than extending this super simple implementation. While we're at it, maybe we can talk about use/edge cases.

Keeping track of # of voices is required to implement conventional plug-in sampler instruments. I believe this is to make easier to constrain the resource, this design is definitely beneficial in the scenario of web-based music apps.

The real problem lies in the mechanism of Web Audio API. There is no way of getting 'onended' callback/event from a source node. It will just stop at the specified timing. This is a design choice: Chris Rogers designed the source node to be super robust. Handling callback events from hundreds of source nodes would cause a big performance hit. (e.g. granular synthesizer)

I have tested few ways of voice management in the sampler, but none of them works 100% perfectly. (e.g. dirty checking, elapsing timers...)

I totally agree with the idea of voice management, but I guess we can build a polyphonic sampler from scratch. With the more sophisticated design, such as resource management, velocity layer and key-zone, it could be easily a medium size project by itself.

By the way, thanks for checking them in!

hoch commented 10 years ago

Sorry about the fuss: I accidentally pressed the close button. :(

The request is merged and closed.