Results 1 to 4 of 4

Thread: Anyone familiar with SDL_mixer?

  1. #1

    Anyone familiar with SDL_mixer?

    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?

    Code:
    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

  2. #2

    Anyone familiar with SDL_mixer?

    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.

  3. #3

    Anyone familiar with SDL_mixer?

    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?
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  4. #4

    Anyone familiar with SDL_mixer?

    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.

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

    Thanks,

    Mason

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Comodo SSL