SDL_mixer performance

Howdy List.

I’m puzzled by something:

Playing a simple audio file (ogg, mp3, wav) in a barebones SDL app that uses
the Mix_OpenAudio and Mix_PlayMusic functions uses about 6% of CPU power. It
often fluctuates down to 2%, and sometimes up to 11%. I’ve tried a half
dozen different simplistic audio programs, and they all use a similar
amount, or more CPU power. In contrast, mplayer users 1-2% CPU power for the
same audio files, and sometimes drops way down the list in ‘top’ display.

Does anyone know why? Is it because of the libraries mplayer makes use of?
Is it crazy assembly optimization? The barebones app I refer to above uses
alsa as its audio driver, and so does mplayer. So I’m pretty puzzled. Not
that this is a surprise, since I only started researching audio programming
a couple of weeks ago, but if anyone has explanations for these observations
it would be greatly appreciated. Tips about other forums to hang out in
would be great too.

Thanks,

Christian

It might have to do with what sampling rate you’ve opened ALSA at, and
whether you’re going through dmix. My experience (driving ALSA
directly, not going through SDL) is that when I’m using a 44.1 KHz
sampling rate (where dmix is forced to resample to 48 KHz internally),
the CPU usage varies randomly from a few percent up to about 50% for
no apparently good reason, while opening it at 48 KHz exhibits no such
problem (unfortunately 48 KHz is the wrong rate for playing most media
files). Whether or not there’s more than one app using using audio
also seems to be a factor. Admittedly, this is using old versions of
the kernel and ALSA libraries (from Debian stable).On Fri, Jun 25, 2010 at 4:11 AM, Christian Leger <chrism.leger at gmail.com> wrote:

Howdy List.

I’m puzzled by something:

Playing a simple audio file (ogg, mp3, wav) in a barebones SDL app that uses
the Mix_OpenAudio and Mix_PlayMusic functions uses about 6% of CPU power. It
often fluctuates down to 2%, and sometimes up to 11%. I’ve tried a half
dozen different simplistic audio programs, and they all use a similar
amount, or more CPU power. In contrast, mplayer users 1-2% CPU power for the
same audio files, and sometimes drops way down the list in ‘top’ display.

Does anyone know why?

Hello

Howdy List.

I’m puzzled by something:

Playing a simple audio file (ogg, mp3, wav) in a barebones SDL app that uses
the Mix_OpenAudio and Mix_PlayMusic functions uses about 6% of CPU power. It
often fluctuates down to 2%, and sometimes up to 11%. I’ve tried a half

I see that SDL_mixer use as default 8 audiochannels.there is a command

Mix_AllocateChannels(channel);

to set the real channels you use.maybe that help ?

teh default channels are set in sdl_mixer.h and is this.

/* The default mixer has 8 simultaneous mixing channels */
#ifndef MIX_CHANNELS
#define MIX_CHANNELS 8
#endif

dozen different simplistic audio programs, and they all use a similar
amount, or more CPU power. In contrast, mplayer users 1-2% CPU power for the
same audio files, and sometimes drops way down the list in ‘top’ display.

Does anyone know why? Is it because of the libraries mplayer makes use of?
Is it crazy assembly optimization? The barebones app I refer to above uses
alsa as its audio driver, and so does mplayer. So I’m pretty puzzled. Not
that this is a surprise, since I only started researching audio programming
a couple of weeks ago, but if anyone has explanations for these observations
it would be greatly appreciated. Tips about other forums to hang out in
would be great too.

Thanks,

Christian
RegardsOn 24.06.10, you wrote:

Hi,

That suggestion gave me very interesting results. It turns out that sampling
rate has a huge impact on performance, and that the best performance is
achieved with samples playing at 48Khz. I’m guessing it’s because the card’s
hardware is optimized for this.

I have a different mystery now: when I play my application, it sometimes
plays audio properly, and sometimes doesn’t. I think it may have to do with
’channels’ in the driver being locked or something. However, I can’t locate
definitively which function, if any, would allow me to clean up properly
after my application, beyond Mix_HaltMusic and Mix_FreeMusic(int).

Ideas or suggestions?

Thanks!

ChristianOn Fri, Jun 25, 2010 at 8:25 AM, Bernd Roesch wrote:

Hello

On 24.06.10, you wrote:

Howdy List.

I’m puzzled by something:

Playing a simple audio file (ogg, mp3, wav) in a barebones SDL app that
uses
the Mix_OpenAudio and Mix_PlayMusic functions uses about 6% of CPU power.
It
often fluctuates down to 2%, and sometimes up to 11%. I’ve tried a half

I see that SDL_mixer use as default 8 audiochannels.there is a command

Mix_AllocateChannels(channel);

to set the real channels you use.maybe that help ?

teh default channels are set in sdl_mixer.h and is this.

/* The default mixer has 8 simultaneous mixing channels */
#ifndef MIX_CHANNELS
#define MIX_CHANNELS 8
#endif

dozen different simplistic audio programs, and they all use a similar
amount, or more CPU power. In contrast, mplayer users 1-2% CPU power for
the
same audio files, and sometimes drops way down the list in ‘top’ display.

Does anyone know why? Is it because of the libraries mplayer makes use
of?
Is it crazy assembly optimization? The barebones app I refer to above
uses
alsa as its audio driver, and so does mplayer. So I’m pretty puzzled. Not
that this is a surprise, since I only started researching audio
programming
a couple of weeks ago, but if anyone has explanations for these
observations
it would be greatly appreciated. Tips about other forums to hang out in
would be great too.

Thanks,

Christian
Regards


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org