Add note to docs regarding limitations of IMA ADPCM (WAV) format for seamless audio looping

I noticed a few people (myself included) were running into issues trying to create seamless audio loops when exporting to the recommended IMA ADPCM (WAV) format.

"Because ADPCM uses sample blocks that are aligned one after the other, a wave compressed with ADPCM may have an unfinished, partial block at its end. The ADPCM decoder generates silence for the remainder of this partial block, which keeps the wave from looping seamlessly.”

I was noticing an unexpected pop when my audio track looped and had mistakenly assumed it was a hardware limitation of the Playdate, but it turns out it's part of the ADPCM spec.

I noticed this with both Audacity (3.1.3) and ffmpeg exports on Windows. Apparently this doesn't happen using WavePad to export but I didn't confirm.

An ugly workaround is something like this:

local music = playdate.sound.fileplayer.new("some_music_track")
music:setLoopRange(0, music:getLength() - 0.05) -- adjust offset per track

But I think the docs would benefit from a short note about this in the section where Audacity and ffmpeg are mentioned.

2 Likes

Interested if you have different results with the adpcm-xq encoder.

Related:

Interesting, I'll give this a shot. So far I've noticed the results to be different per audio file I'm encoding (which makes sense but just makes troubleshooting slightly trickier).

Alright, I gave ADPCM-XQ a quick test and it does fare better, but I still notice some silence at the end compared to the source file.

The top row is the original (mp3 in this case), middle row is what Audacity exports using IMA ADPCM, and the bottom row is the XQ conversion from Github (with default flags).

It does seem to vary heavily based on the input audio file though, so perhaps most people won't run into this issue.

XQ probably does provide the best quality though, at least from the readme it sounds like a great conversion tool.

Yeah, they will be totally different. This does an optimised encoding by looking ahead.

We've used it for music in Sparrow Solitaire, and even when we loop we don't notice the small silence.

Thanks for doing this comparison.

I use Fission audio editor on macOS and one of the great things about that is that it edits by block. But, it's still not possible to remove all silence as it's unlikely the music/loop will align exactly on block boundaries. Would love to find out a way to do this!

1 Like

Also, I wonder if the audio engine on Playdate removes the silence on looping/playback?

That could be the best way to negate all this.

It might be tricky to remove at the SDK level, eg if someone intentionally wanted silence at the end of a track (I guess could pass a flag?), but at least raising awareness that ADPCM works on a block-based system and can lead to unexpected silence would be nice. Even though it's not Panic's responsibility since it's not like they invented ADPCM, but still. :slight_smile:

1 Like