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