Pulp editor/web player audio envelope bug fix

Just a heads up for anyone working on audio in Pulp: there was a bug in the ADSR envelope logic that could result in very different sounds in the editor/web player and the Playdate Simulator/hardware depending on note duration and envelope values. This was especially evident with the Noise channel usually used for percussion. The fix went up moments ago.

Give your audio a listen to make sure it still sounds correct with the fix in place. If it doesn't, in most cases you can reproduce the original sound by reducing the affected voice's decay and sustain values. Continue reading for an explanation of the bug that might help you figure out a solution for edge cases where that doesn't work. The fix just went up this morning.

So an envelope consists of four phases:

  • attack: how long it takes the volume to rise from zero to full volume (measured in seconds)
  • decay: how long it takes the volume to drop from full to sustain volume (also measured in seconds)
  • sustain: the volume to hold at after the decay phase until the note ends and the release phase begins (not measured in seconds)
  • release: how long it takes the volume to return to zero from the sustain volume after the note ends (again, measured in seconds)

This bug only revealed itself when the duration of a note caused it to end during the decay phase. What should happen in these situations is the volume drops to zero from its current value over the duraton of the release phase. The bug was a mistake in the volume calculation when a short note ended in the middle of the decay phase that resulted in the volume dropping instantly to less than the sustain volume and releasing from there.

A quick edit to clarify: the bug was on the JavaScript side, so the fix makes the sound accurate to the Simulator/hardware (and every other non-buggy ADSR envelope implementation out there :sweat_smile:).

8 Likes

Hi shaun! After the update, I have a very different balance of sounds when comparing the browser to the simulator. It's like all channels (except noise) are at half volume. I recorded this (both are at max master volume to have a reference to compare, so be careful playing the video)

sound-comparison.mp4.zip (16.6 MB)

I've noticed this also. My square-voice sound effects are much quieter than their noise-voice counterparts in the simulator (and music is affected too, of course).

Having played on a real device now ( :playdate_happy:) , I think the noise channel volume is fine β€” it’s the other channels that are too quiet, at least in comparison to system sounds and other games.