Crash when using bitcrusher effect

I screwed up. Sorry y'all. :frowning:

I was really excited to fix something that had been bugging me for a long time: the bad parameterization of the bitcrusher effect. As I had it mapped the amount and undersampling knobs didn't do anything audible for most of the range and then suddenly it was full distortion. So I added new depth and downsampling parameters with gamma curves to expand the usable range, and fixed the goof that the modulators were multiplying the static parameters instead of adding to them. And then I blew it by forgetting to initialize the new values/modulators, leaving possible garbage values in the modulator slots which then get dereferenced -> crash!

We'll have a fix in 3.1.1 (obvs) but in the mean time a workaround is to initialize the values yourself before using the bitcrusher:

crush = playdate.sound.bitcrusher.new()
crush:setDepth(0)
crush:setDepthMod(nil)
crush:setDownsampling(0)
crush:setDownsamplingMod(nil)

(C version left as an exercise for the reader)

So for existing games, if we’re using BitCrusher but don’t build a new 3.1.0 version, it should be OK? But if we do a new build, either wait for 3.1.1 or apply the fix above?

And are there any changes to how existing code will sound when built on 3.x?

(OUTSIDE PARTIES bitcrushes a lot.)

TIA!

My game (RollerBlade) makes use of the bitcrusher, so early that it affects playing the game at all and it crashes for everyone on OS 3.1.0.

So, to answer your question @AdamsImmersive, games built with a previous version WILL crash on players.
As for how it would affect the sound, I've been thinking about this and my guess is that since depth and downsampling are new parameters superseding amount and undersampling, and that the proposed workaround is to initialize those new parameters to 0/nil, the code behind amount and undersampling has not changed and they will continue sounding the same (and from what I've tested it's the case).
However, since those parameters are now marked as deprecated it is to be expected that they will be removed somewhere in the future. It will thus be necessary to adopt the new parameters, which will most certainly sound differently when using the original values.
@dave, could you tell us what exponent you used for your gamma curve so it's easier for us to convert amount to depth and undersampling to downsampling without having to do it by ear?

I wanted to do the fix right so that ideally I could publish a fixed version that would continue to work for players that have not updated their OS yet, and that would be fixed for players on 3.1.0.
Here are my findings:

  • the fix compiled with 3.1.0 won't run on < 3.1.0 (os_incompatible)
  • the fix compiled with 3.0.6 running on 3.0.6 can't call bitcrusher:setDepth/…
  • the fix compiled with 3.0.6 running on 3.1.0 can't call bitcrusher:setDepth/… either!

I tried protecting the function calls with a playdate.apiVersion() check and pcall but to no avail:

  • a game compiled with pdc 3.1.0 won't run on OS < 3.1.0
  • a game compiled with pdc < 3.1.0 can't find bitcrusher:setDepth even if running on OS 3.1.0 (which makes it a bit weird that the crash happens at all for a game compiled with pdc < 3.1.0…)

So it seems like it's not possible to fix for 3.1.0 without breaking for < 3.1.0 :thinking:

But maybe I'm overthinking it and people just won't be presented with a game update compiled with a pdxversion greater than their OS's?
Can I just go and push the fix without having to worry?

EDIT: just tested this with web sideloading and my playdate on 3.0.6 does tell me a system update is required to update the game to a version compiled with 3.1.0 so it's all good!

Now onto finding out if the 3.1.0 fixes for push/popContext() and sequence:getCurrentStep() are breaking the way I worked around those quirks :smiley:

Thanks!

Soooo, in making a fix for 3.1.0 I decided that I might as well switch already to the new interface so that I wouldn't get caught later when the deprecation goes into actual effect.

I removed all bitcrusher:setAmount(value) and changed them to bitcrusher:setDepth(value), took the opportunity to set some light downsampling now that it's possible to have finer control, and set both set{Depth|Downsampling}Mod(nil).

Worked like a charm on 3.1.0, but on 3.1.1 the sounds using the bitcrusher are now barely audible, if at all.

I put together a quick test but didn't see/hear anything unexpected. Can you provide a small demo showing what you're doing?