GP2X Thoughts About Music Playback Support In Sdl


Guyfawkes

Certified Idiot :)
Joined
Jan 11, 2004
Messages
795
Age
48
Location
London, UK
Website
www.emuholic.com
Since I started coding on the GP2X I have noticed that the main SDL development area is the graphics side of things such as the Hardware SDL support by Payern. This is great, but now we have a bottleneck (in my opinion) with the audio side with music playback.

I have been testing MP3, OGG and MOD playback in my game to see which is the fastest and surprisingly MP3 works the best. The following is from a menu screen in my game:

No music playing = ~100 FPS
MP3 music playing (44100Hz Stereo) = ~60 FPS
OGG music playing (44100Hz Stereo) = ~53 FPS
MOD music playing (4 Channel) = ~49 FPS

As you can see its taking anything from over a third to half the FPS depending on the format, which is quite bad. I know the music could encoded to say 22,000Hz which may speed things up (I haven't checked) but why should quality be sacrificed?

I am aware that some work has been going on for OGG playback using the second CPU, but this is not for SDL and it is out of my depth to try and add it. So, and I bet you all knew this was coming :) is there anyone interested in trying to add support for it? I really think music playback being optimised or offloaded to the second CPU would improve things a great deal for both developers and the players.

Feel free to reply back with your thoughts on this and if you have you own results let me know. And more importantly if you would like to be involved with improving music playback reply here.

Thanks for your time!
 
Since Dzz ported tremor to the 940, I don't see why you couldn't apply the tremor patch to SDL_mixer and just plug this version of tremor in (though you'd need a few modifications to load the 940 binary).

I would recommend you try it at 22kHz just to see how much of a difference it makes (I used to get crashes on the GP2X with anything above 22kHz for some reason).
 
For MOD music SDL_mixer is definitely the worst option, because it can't handle large files. Use libmikmod directly for that, it's very fast and works fairly well. However, I hit a small bottleneck there as well, because in order to play a large mod file (many channels), you need to allocate a large buffer, which in turn delays the playing of small .wav sound effects.

At a point I used SDL_mixer for OGG playback. I tested it with MP3s as well, and it ran significantly slower:

No music playing = ~111 FPS
MP3 music playing (11025Hz Stereo) = ~83 FPS
OGG music playing (11025Hz Stereo) = ~96 FPS

Of course, you'll notice the low Hz.
 
Lowering the Hz is an option but I don't see why we should, take for example the music player in Squares which played music found on the GP2X, I would bet most music on your SD Card is 44,000Hz.

Alex - I will look into SDL_mixer for playback. 111 vs 83 and 96 FPS is a massive improvement (ignoring the Hz) over my results, what libs are you using?

UPDATE- I tried lowering the Hz for MP3 playback

44,100Hz MP3 at 96kps = ~60 FPS
22,050Hz MP3 at 80kps = ~60 FPS
22,050Hz MP3 at 40kps = ~60 FPS
11,000Hz MP3 at 32kps = ~77 FPS

What is interesting is 22,050Hz is the same FPS as playing a 44,000Hz MP3. I changed the Mix_OpenAudio to 22,050 and 44,000 (the buffer is 128 if that is any help) for each test but still get the same FPS, is something set elsewhere?
 
MOD shoudl be next to no CPU hit; I mean, mixxing 4 channels is just a few adds. MP3's shoudl be some serious heavy lefting by comparison, so you must be doign somethign really wrong or using a heavy fat bloated MOD player.

(guessing; my MOD player is very very limited, but it takes almost no CPU time too.)

But I am _amazed_ you can play mp3s without killing things; I mean, losing 10% of your frames for mp3 support.. thats damned incredible. Like.. shit, we shoudl asll stop using MODs at all if we can get mp3s playing.

Is there a background mp3 player? That'd be the test; run your game, and run your game with another app playing an mp3 in background, and theres your performance test.

Maybe I should try it :p

I'm finding it impossible to locate a MOD musician to make music; though I do have a friend working on a MIDI renderer that might be fast enough :p

jeff

Buffer too small? 128b buffer means your CPU is being pgged generating audio; make a slightly larger one? 512b? 1k? A larger buffer for a larger Hz.

jeff
 
Guyfawkes said:
Alex - I will look into SDL_mixer for playback. 111 vs 83 and 96 FPS is a massive improvement (ignoring the Hz) over my results, what libs are you using?
When I got those particular results I used Paeryn's HW accelerated SDL. I still use it now, only with SW surfaces to avoid occasional artifacts. I would imagine the performance would be lower with SW surfaces. I do however use a 512 buffer, which isn't very good for also playing sound effects in addition to just music. I wish sound wasn't invented, what a pain ;)
 
Last edited by a moderator:
It would be great if the integer only mp3 lib and the ogg lib were used on the second cpu by default by sdl_mixer.
 
libmad can't be used by default at all as it's GPL and by doing so, anybody who linked to SDL_mixer would then be forced to release their program under the GPL too.
 
Orkie said:
libmad can't be used by default at all as it's GPL and by doing so, anybody who linked to SDL_mixer would then be forced to release their program under the GPL too.
Which is what makes GPL such a kickass license.
 
Last edited by a moderator:
Orkie said:
libmad can't be used by default at all as it's GPL and by doing so, anybody who linked to SDL_mixer would then be forced to release their program under the GPL too.
That's a massive shame, that code is pretty much rendered useless :(
Ogg is probably better anyway.
 
Last edited by a moderator:
rooster said:
As far as I was aware, OGGs and MP3s etc are decompressed by SDL at load time so why should there be different framerates!?
They are streamed from the disk.
 
Last edited by a moderator:
Back
Top