Fix triangle release by switching period by tick #714
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes the bug with the 1ms triangle release not happening after #711.
As you can see, it's not as clean as one could hope.
This is kind of a compromise between having tone be sample-based and having it tick-based. I believe this is the best kind of compromise when perfect 60 Hz ticks aren't possible though. Basically, we respect samples when it comes to envelopes A->D->S but respect ticks for starting the Release.
In practice this means that if ticks were to drift (which they almost always do), they only do so during the Sustain period. If we were to make all parts of ADSR tick based, the drift could happen at any parts.
Still, this is a bit unfortunate for the case of frequency slides where we can't know how many samples long a tone will be until we have already detected the drift, meaning we either have to end the slide short (because of tick-sample drift), or we have to adjust it as it happens (leading to pitch skips).
I chose here to go with having the slide end short which would be the least audible of the two. This required introducing a new
releaseTime
for what is estimated when the tone starts playing to be able to have a target time forgetCurrentFrequency
.I am thinking even more about rewriting the WASM-4
update
to be based on the audio routine to both fix the tick-sample drift and issue #678 for good, but for now this is what we can do.Since this is a bit more code, I would appreciate someone else checking the logic so I don't introduce any new bugs!