Gravity Express

Errata: Music cpu demands

Earlier, I wrote a long post about how mp3 would only use 3% of cpu power. Well, I was wrong and it's high time to correct the misinformation.

You see, when you have your playdate connected to your computer and press cmd+D in the simulator, you get a device info dialog like this:

In the example above, an MP3 song is playing. Note how the audio part of the chart shows 2.4% cpu usage.

Let's compare that to a screenshot from the same situation without music playing:


Audio usage dropped significantly from 2.4% to 0.6%.
However, the game portion of this graph dropped much more severely, from 57% to 35%. The total impact of this MP3 song then comes to 1.8% music + 21.6% game = 23.4%

At the time I wrote my original post, I was so focused on comparing the audio parameter that I completely glossed over this huge difference. Sorry! (this can be explained because I looked at the MIDI situation first. MIDI is handled by the audio engine and would have an impact of 5-30% on the audio part of the chart with neglible impact on the game part).

From my MP3 testing, an interesting performance factor became apparant: sample rate. This is bizarre, because the whole thing about MP3 compression is that it stores frequencies, rather than samples. This is the core concept behind MP3 that makes it's files so much smaller than WAV.
However, sample rate is still a thing when decoding MP3: the sound chip needs samples to send to the speaker, so the sample rate is the frequency at which the audio samples are reconstructed. Higher frequency = higer cpu usage. The 22khz and 44khz files, however, are exactly the same size.

This can be adjusted easily in Audacity:

Updated cpu cost comparision
Song: Smooth and Cool by Nico Staf from Youtube Audio Library, 3:58 duration.

ADPCM 2.6MB: 1% game + 3% audio = 4%
MP3 32 kbit mono* 22khz 0.95MB: 16% game + 3% audio = 19%
MP3 48 kbit mono* 22khz 1.4MB: 17% game + 3% audio = 20%
MP3 48 kbit mono* 44khz 1.4MB : 21% game + 3% audio = 24%
MIDI playback: 5-30% audio

Conclusion
The Inside Playdate documentation was right all-along: ADPCM is the cpu-friendliest music format.
What's best for your project depends on your situation. You might even go with MP3 for the least complex levels in your game and use adpcm for the demanding levels. I was pleasantly surprised by the quality of 32kbps MP3 and decided to go with the 22khz mono variant.

* technically saved as joint stereo, meaning a single channel is played on both left and right speakers. Mono would be interpreted as playing on the left channel while the right channel is silent

8 Likes