Decompress sample in memory

Synth objects only play uncompressed audio samples. If I wanted to make a procedural track or play a midi with samples, I would have to use uncompressed PCM.

It would be cool if I could supply my game with compressed audio samples, then uncompress them in memory and use the uncompressed audio for the synths. Something like

compressedSample = playdate.sound.sample.new(path_to_compressed_sample) 
uncompressedSample = compressedSample:decompress()
synth = playdate.sound.synth.new(uncompressedSample)

My first thought was the synth could automatically decompress to a new sample under the hood if you pass it ADPCM audio, but the drawback there is if you do that a bunch with the same ADPCM sample you'll get a separate copy each time and it won't be obvious at all. Yeah, your way is better. :slight_smile:

decompress() does sound like it's doing it in-place, so maybe copyDecompressed() instead? decompressedCopy()? Is just decompressed() enough? ..or should it decompress in place? You probably don't need the original after you've decompressed it.

I'll take a stab at this and have it decompress in place but it'll be easy to change that behavior later

1 Like

I added an in-place sample:decompress() function and ran it on a 2.7 MB ADPCM file, which decompresses to 10.8 MB--i.e., it's about as big as it's possible to deal with in our 16 MB of memory. It takes just over a second to decompress. :tada:

I'll schedule this for the 2.4 update. Thanks for the great idea!

1 Like

Oh amazing, thank you Dave!! That's totally great performance too!