SDL_mixer plays 22kHz WAV files at double speed

This:

SDL_RWops* rw = SDL_RWFromConstMem(dataBuf, size);
Mix_Chunk* chunk = Mix_LoadWAV_RW(rw, 1);

where ‘dataBuf’ contains 22kHz of “Microsoft WAV audio” data, results in
’chunk’ sounding like a chipmunk when it’s played (it’s played back at
44kHz).

Is there a way to avoid this?

What version of SDL and SDL_Mixer are you using? Can you post a
complete example to reproduce the problem (with the sound where the
buffer came from)?On Fri, Oct 1, 2010 at 8:49 AM, Nikos Chantziaras wrote:

This:

?SDL_RWops* rw = SDL_RWFromConstMem(dataBuf, size);
?Mix_Chunk* chunk = Mix_LoadWAV_RW(rw, 1);

where ‘dataBuf’ contains 22kHz of “Microsoft WAV audio” data, results in
’chunk’ sounding like a chipmunk when it’s played (it’s played back at
44kHz).

Is there a way to avoid this?


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

I’ve also noticed that SDL_Mixer ignores sample rate of .WAV files and just
plays them at the rate sound device is opened.
SDL_mixer 1.2.8On Fri, Oct 1, 2010 at 7:07 PM, Felipe <felipe.otamendi at gmail.com> wrote:

What version of SDL and SDL_Mixer are you using? Can you post a
complete example to reproduce the problem (with the sound where the
buffer came from)?

On Fri, Oct 1, 2010 at 8:49 AM, Nikos Chantziaras wrote:

This:

SDL_RWops* rw = SDL_RWFromConstMem(dataBuf, size);
Mix_Chunk* chunk = Mix_LoadWAV_RW(rw, 1);

where ‘dataBuf’ contains 22kHz of “Microsoft WAV audio” data, results in
’chunk’ sounding like a chipmunk when it’s played (it’s played back at
44kHz).

Is there a way to avoid this?


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


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

Oopsy, they’re 16kHz files, not 22kHz (those play correctly). Rates
that don’t play correctly are 96, 48, 32, 16 and 8.

The only rates that do play correctly are 44.1, 22.05 and 11.025.

I need to be able to play them all though :-/ (The app in question is
an open source Unix port of a Windows game engine that runs already
existing games, which already include any of the above rates for WAV files.)

SDL 1.2.14, SDL_mixer 1.2.11. x86-64. Gentoo Linux.

I am attaching a test program and put a sample WAV file in all the above
mentioned sample rates here:

http://foss.math.aegean.gr/~realnc/test-wavOn 10/01/2010 07:07 PM, Felipe wrote:

What version of SDL and SDL_Mixer are you using? Can you post a
complete example to reproduce the problem (with the sound where the
buffer came from)?

On Fri, Oct 1, 2010 at 8:49 AM, Nikos Chantziaras wrote:

This:

SDL_RWops* rw = SDL_RWFromConstMem(dataBuf, size);
Mix_Chunk* chunk = Mix_LoadWAV_RW(rw, 1);

where ‘dataBuf’ contains 22kHz of “Microsoft WAV audio” data, results in
’chunk’ sounding like a chipmunk when it’s played (it’s played back at
44kHz).

Is there a way to avoid this?
-------------- next part --------------
A non-text attachment was scrubbed…
Name: sdl_sound-bug.c
Type: text/x-c
Size: 875 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20101002/6ac082a2/attachment.bin

Ok, the problem is that SDL only converts samples in powers of 2. The
thing is that SDL is using the function SDL_BuildAudioCVT inside of
its main audio routine which doesn’t handle resampling, it just throws
whatever it receives from the conversion to the sound card, and if it
was allowed to convert audio with a non power of 2 ratio then it could
return a non power of 2 buffer and that doesn’t go well with some
sound cards.

SDL 1.3 fixes this and allows any kind of resampling, maybe you could try it.

However, If you want to get that possibility in SDL 1.2 then a quick
and dirty way, without changing SDL’s interface too much, could be to
create antoher function like SDL_BuildAudioCVT which has the np2
conversion depending on a parameter (there’s an #if disabling it in
SDL_audiocvt.c and a comment explaining the whole thing) and making
SDL_BuildAudioCVT call it allowing this kind of conversion. Then
change SDL_RunAudio in SDL_audio.c to call the new function without
np2 conversion. SDL_Mixer can convert in a non power of 2 ratio
because it will manage the buffering needed so it can pass SDL a
buffer of the size with which it was initialized.

If you are making a game for linux and you don’t want to ship a
modified version of SDL then just apply the conversion yourself after
loading the sound with SDL_LoadWAV_RW, again with a modified version
of SDL_BuildAudioCVT.

Hope this helps. Have in mind I haven’t tried any of what I said :).On Sat, Oct 2, 2010 at 12:08 AM, Nikos Chantziaras wrote:

Oopsy, they’re 16kHz files, not 22kHz (those play correctly). ?Rates that
don’t play correctly are 96, 48, 32, 16 and 8.

The only rates that do play correctly are 44.1, 22.05 and 11.025.

I need to be able to play them all though :-/ ?(The app in question is an
open source Unix port of a Windows game engine that runs already existing
games, which already include any of the above rates for WAV files.)

SDL 1.2.14, SDL_mixer 1.2.11. ?x86-64. ?Gentoo Linux.

I am attaching a test program and put a sample WAV file in all the above
mentioned sample rates here:

?http://foss.math.aegean.gr/~realnc/test-wav

On 10/01/2010 07:07 PM, Felipe wrote:

What version of SDL and SDL_Mixer are you using? Can you post a
complete example to reproduce the problem (with the sound where the
buffer came from)?

On Fri, Oct 1, 2010 at 8:49 AM, Nikos Chantziaras ?wrote:

This:

?SDL_RWops* rw = SDL_RWFromConstMem(dataBuf, size);
?Mix_Chunk* chunk = Mix_LoadWAV_RW(rw, 1);

where ‘dataBuf’ contains 22kHz of “Microsoft WAV audio” data, results in
’chunk’ sounding like a chipmunk when it’s played (it’s played back at
44kHz).

Is there a way to avoid this?


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

Thank you for the pointers. However, I found a cheaper way to make this
work: SDL_sound. I decode it with Sound_DecodeAll(), and then feed the
result to SDL_Mixer with Mix_QuickLoad_RAW(). And indeed it works like
a charm.On 10/05/2010 08:00 PM, Felipe wrote:

Ok, the problem is that SDL only converts samples in powers of 2. The
thing is that SDL is using the function SDL_BuildAudioCVT inside of
its main audio routine which doesn’t handle resampling, it just throws
whatever it receives from the conversion to the sound card, and if it
was allowed to convert audio with a non power of 2 ratio then it could
return a non power of 2 buffer and that doesn’t go well with some
sound cards.

SDL 1.3 fixes this and allows any kind of resampling, maybe you could try it.

However, If you want to get that possibility in SDL 1.2 then a quick
and dirty way, without changing SDL’s interface too much, could be to
create antoher function like SDL_BuildAudioCVT which has the np2
conversion depending on a parameter (there’s an #if disabling it in
SDL_audiocvt.c and a comment explaining the whole thing) and making
SDL_BuildAudioCVT call it allowing this kind of conversion. Then
change SDL_RunAudio in SDL_audio.c to call the new function without
np2 conversion. SDL_Mixer can convert in a non power of 2 ratio
because it will manage the buffering needed so it can pass SDL a
buffer of the size with which it was initialized.

If you are making a game for linux and you don’t want to ship a
modified version of SDL then just apply the conversion yourself after
loading the sound with SDL_LoadWAV_RW, again with a modified version
of SDL_BuildAudioCVT.

Hope this helps. Have in mind I haven’t tried any of what I said :).

On Sat, Oct 2, 2010 at 12:08 AM, Nikos Chantziaras wrote:

Oopsy, they’re 16kHz files, not 22kHz (those play correctly). Rates that
don’t play correctly are 96, 48, 32, 16 and 8.

The only rates that do play correctly are 44.1, 22.05 and 11.025.

I need to be able to play them all though :-/ (The app in question is an
open source Unix port of a Windows game engine that runs already existing
games, which already include any of the above rates for WAV files.)

SDL 1.2.14, SDL_mixer 1.2.11. x86-64. Gentoo Linux.

I am attaching a test program and put a sample WAV file in all the above
mentioned sample rates here:

http://foss.math.aegean.gr/~realnc/test-wav

On 10/01/2010 07:07 PM, Felipe wrote:

What version of SDL and SDL_Mixer are you using? Can you post a
complete example to reproduce the problem (with the sound where the
buffer came from)?

On Fri, Oct 1, 2010 at 8:49 AM, Nikos Chantziaras wrote:

This:

SDL_RWops* rw = SDL_RWFromConstMem(dataBuf, size);
Mix_Chunk* chunk = Mix_LoadWAV_RW(rw, 1);

where ‘dataBuf’ contains 22kHz of “Microsoft WAV audio” data, results in
’chunk’ sounding like a chipmunk when it’s played (it’s played back at
44kHz).

Is there a way to avoid this?