Open espadrine opened 8 years ago
Seems I missed this issue when I filed #188. As I wrote there, it seems as if timing in WebAudio is sometimes absolute sometimes relative, as you pointed out here. Compared to that, AudioTag is always relative, and WebMIDI appears to be always absolute. What a mess! The longer I think about it, the more I believe that the correct fix would be to
In a sense this is talking the solution opposite to #150, by making things absolute by default instead of relative. The main point is that otherwise it's impossible to perfectly time notes, since while you are computing the method invocations you need, the ctx.currentTime
will continue to increase so you don't have a common basis for all the notes you enqueue. If backwards compatibility is an issue, this could be made configurable. I guess I'll write yet another pull request.
Even for something as simple as the basic example which plays a single note, we can notice the following by playing around in the JS console:
The WebAudioContext's currentTime is perpetually increasing, starting from a value of zero. So far so good.
However, the following line of code, present since the very beginning, will negatively impact the
delay
parameter of thenoteOn()
method:Consider the case where we play two notes, one with a delay of 2, the other with a delay of 4, with two calls to
noteOn()
at the same moment, when currentTime is 3. The first note will be played in 5 seconds (because ofdelay += ctx.currentTime
), while the second will be played in 4 seconds (before the first)!What is the point of modifying the delay? It is unclear to me what the difference between the relative delay and the absolute delay is, but the end result is that the following code gives results that are highly different from what I would assume it to do:
Could you help me understand and hopefully fix this issue in MIDI.js, be it a matter of documentation or a bug in the code?