If anyone is interested, I'll add some documentation to get you started with MIDI Master + Master Player. My approach could still work for less demanding, puzzle style games. The performance gains were immediate, but I felt sad for all the work I put in and authentic sound of synthesized music I was throwing out. Just a few clicks in Garageband and it was done. I was time to kill my darling midi project and convert the midi files I had selected. Could I really load chunks while playing the game without performance impact? I don't think so.Īdd to all this that it might be easy to find midi-conversions of popular hit songs online, but very hard to find free-to-use original work. This idea was crazy and not going to work. But this was also the moment where I finally stopped to think about what it was that I was getting myself into. At this point I contemplated using a midi-parser written in lua such as this one, so that I could load it in chunks somehow. That's a no-go, considering players are expecting to see a single loading screen when starting the game. To add insult to injury, that midi file that was just a few kilobytes in size took a full second to load by the sdk. And that was supposed to be too cpu intensive for in-game use, according to the Inside Playdate documentation. But that's still a big, noticeable difference from the 3% cpu usage I got from playing the same song converted to 64 kbps mono mp3. By limiting the number of instruments, I could get the audio cpu usage down to 15%.
Sure, my music contained more than 15 tracks, and playing multiple samples at the same time would naturally be taxing. Somewhat surprising because midi playback is used on lower-powered hardware as well as the 90Mhz Pentium windows PC I used to play Crazy Gravity. Turns out 30% of cpu cycles were being eaten by the audio engine at times. But when navigating more taxing parts of a level, fps would drop from the target 30 to lows of 24. Initially, things were looking good on device as well. I got some great results in the simulator, that I posted before. Master Player includes 2 sampled instruments: an electronic drumkit to underpin the action and a choir (AAAAAH padum padum AAAHHH) for added drama.
The configuration would be saved as json that could in turn be loaded and played in the game by a library called Master Player. I ended up creating an entire playdate app called MIDI Master for the purpose of tuning instruments for any given midi file. The midi player sample project is helpful here, containing both synthesis (sine, sawtooth. Makes sense, considering no instruments are loaded by default.
Right off the bat I discovered that simply loading a midi file as a Sequence resulted in no audio being played at all. The SDK has quite a bit to offer for playing MIDI, so I decided to dive into it. Typical midi file size is in the order of tens of kilobytes. An additional advantage is that it helps to keep your game size low, as midi just comtains the score / sheet music, with several separate instruments that can be shared among all songs. We've seen some pretty cool audio games already on playdate, and the FM-synthesis / chiptune / oldskool sound of MIDI-music fits the playdate very well, I would say.