PDA

View Full Version : Anyone familiar with SDL_mixer?



masonwheeler
22-09-2007, 11:25 PM
I'm trying to use SDL_Mixer to create a sound/music player for a game engine. But I can't get it to load a music file. Can anyone tell me what I'm doing wrong with this example?



unit music_player;

interface
uses sdl, sdl_mixer, sdl_sound;

type
TMyMediaPlayer = class(TObject)
private
FBgm: string;
FBgmLooped: boolean;

public
constructor create;
procedure playMusic(filename: string);
end;

implementation
uses sysUtils;
{ TMyMediaPlayer }

constructor TMyMediaPlayer.create;
begin
FBgm := '';
SDL_Init(SDL_INIT_AUDIO);
assert&#40;Mix_OpenAudio&#40;44100, AUDIO_S16, 4, 8192&#41; <> 0&#41;;
end;

procedure TMyMediaPlayer.playMusic&#40;filename&#58; string&#41;;
var
music&#58; PMix_Music;
begin
********
music &#58;= Mix_LoadMUS&#40;PChar&#40;filename&#41;&#41;;
********
Mix_PlayMusic&#40;music, -1&#41;;
FBgmLooped &#58;= false;
end;

end.


I put *s around the line that's giving me trouble. After I initialize everything and call playMusic, Mix_LoadMUS returns nil. The filename I passed in exists, and it's just a WAV file. Any idea why this isn't loading?

Mason

grudzio
23-09-2007, 09:57 AM
If Mix_LoadMus fails, you may want to call Mix_GetError to see what happend.

The only thing I've noticed, is your call to Mix_OpenAudio. The third parameter indicates if the output will be mono or stereo.
So you should pass 1 for mono or 2 for stereo. Also you may try changing the second parameter form AUDIO_S16 to AUDIO_S16SYS.

savage
23-09-2007, 01:57 PM
Is the WAV file compressed in any way? I have you tried and MP3 or other format just to make sure that everything is working ok?

masonwheeler
23-09-2007, 02:23 PM
Nevermind, I managed to work around it by using SDLAudioMixer. But I did find one interesting error there.

I've tried a variety of files, and most of them work just fine. But one particular MIDI file won't load properly. It won't load under Delphi's media player either, but it plays just fine in Winamp and Windows Media Player, so I know the MIDI file isn't corrupted.

Is there some esoteric feature of the MIDI specification that just isn't supported by SDL_Sound? In case you'd like to look at the file itself, you can find it here (http://www.hotlinkfiles.com/files/406035_ey4ad/bad%20midi.mid).

EDIT: Oh, and calling Mix_GetError after this fails to load returns a blank string.

Thanks,

Mason