Page 3 of 3 FirstFirst 123
Results 21 to 30 of 30

Thread: JEDI-SDL Audio

  1. #21

    JEDI-SDL Audio

    The open_audio doesn't work with his method though... Open audio uses obtained.blah and and desired.blah which does not work in non-oop, while I was under the impression his example was non-oop.

    EDIT: nevermind. I was thinking sdl_openaudio Now it works, sort of.

    And, .mp3 files don't work The original SDL supported MP3's too... Is there anything specific I need to change to make it work with MP3's?
    --MagicRPG--

  2. #22

    JEDI-SDL Audio

    It supports MP3s through smpeg.dll and only certain MP3 types. Which types exactly I have not worked out yet as I have not had the need.
    <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 =-

  3. #23

    JEDI-SDL Audio

    Well, I have smpeg.dll in there (obviously, or else it wouldn't work ) and I tried taking a plain music file, didn't work. I tried using another music file, again, didn't work. They don't have protection on them. Is it possible for me to 'add' support for them, hopefully easily?
    --MagicRPG--

  4. #24

    JEDI-SDL Audio

    Quote Originally Posted by DarknessX
    The open_audio doesn't work with his method though... Open audio uses obtained.blah and and desired.blah which does not work in non-oop, while I was under the impression his example was non-oop.

    EDIT: nevermind. I was thinking sdl_openaudio Now it works, sort of.

    And, .mp3 files don't work The original SDL supported MP3's too... Is there anything specific I need to change to make it work with MP3's?
    it only supports mp3 (and ogg format) if you use smpeg and Mixer_LoadMUS(), etc. instead of Mixer_LoadWAV().

    like this:

    Code:
    Var
        bAudioOpen &#58; Boolean;
        music      &#58; PMix_Music;
    Initialization
    Code:
        bAudioOpen &#58;= False;
        Log&#40;'Initializing...'&#41;;
        If SDL_Init&#40;SDL_INIT_AUDIO Or SDL_INIT_VIDEO Or SDL_INIT_JOYSTICK&#41; < 0 Then
        Begin
            Log&#40;'Could not initialize SDL'&#41;;
            Exit;
        End
    I open the audio
    Code:
            audio_rate     &#58;= 22050;//MIX_DEFAULT_FREQUENCY;
            audio_format   &#58;= AUDIO_S16SYS;
            audio_channels &#58;= MIX_DEFAULT_CHANNELS;
            audio_buffers  &#58;= 4096;
            // Open the audio device
            Log&#40;'Opening audio...'&#41;;
            If Mix_OpenAudio&#40;audio_rate, audio_format, audio_channels, audio_buffers&#41; < 0 Then
            Begin
                Log&#40;Format&#40;'Could not open audio&#58; %s', &#91;SDL_GetError&#93;&#41;&#41;;
                Exit;
            End

    I then play the music if that went ok:
    Code:
    Procedure PlayMusic&#40;AFileName&#58; AnsiString; loops&#58; Integer&#41;;
    Begin
        Log&#40;'Loading music...'&#41;;
        music &#58;= Mix_LoadMUS&#40;PChar&#40;AFileName&#41;&#41;;
        If &#40;music = Nil&#41; Then
        Begin
            Log&#40;Format&#40;'Could not load "%s"&#58; %s', &#91;AFileName, SDL_GetError&#40;&#41;&#93;&#41;&#41;;
            Exit;
        End;
        Log&#40;'Music loaded'&#41;;
        If loops <> -1 Then
        Begin
            Log&#40;Format&#40;'Playing&#58; "%s"&#40; looping &#41;',&#91;AFileName&#93;&#41;&#41;;
        End
        Else
            Log&#40;Format&#40;'Playing&#58; "%s"&#40; not looping &#41; ',&#91;AFileName&#93;&#41;&#41;;
        Mix_PlayMusic&#40;music, loops&#41;;
        Log&#40;'Playing'&#41;;
    End;

    After everything is finished I cleanup
    Code:
    Procedure Cleanup;
    Begin
        If music <> Nil Then
        Begin
            Log&#40;'Freeing music...'&#41;;
            Mix_FreeMusic&#40;music&#41;;
            Log&#40;'Music freed'&#41;;
            music &#58;= Nil;
        End;
        If bAudioOpen Then
        Begin
            bAudioOpen &#58;= False;
            Log&#40;'Closing audio...'&#41;;
            Mix_CloseAudio;
            Log&#40;'Audio closed'&#41;;
        End;
        SDL_Quit;
    End;
    My complete example program (ignore gp2x bits) that works on windows.

    Code:
    Program gp2x_sdl_mixer;
    &#123;$IFDEF fpc&#125;
    &#123;$MODE Delphi&#125; &#123;$H+&#125;
    &#123;$ENDIF&#125;
    
    Uses
        sdl_mixer,
        sdl,
        SysUtils;
    
    Var
        bAudioOpen &#58; Boolean;
        music      &#58; PMix_Music;
        screen     &#58; PSDL_Surface;
    
    &#123;..............................................................................&#125;
    
    &#123;..............................................................................&#125;
    Procedure Log&#40;AString&#58; AnsiString&#41;;
    Var
        FileName &#58; AnsiString;
        LogFile  &#58; Text;
    Begin
        FileName &#58;= ExtractFilePath&#40;ParamStr&#40;0&#41;&#41; + 'LogFile.txt';
        AssignFile&#40;LogFile,FileName&#41;;
        If FileExists&#40;FileName&#41; Then
            Append&#40;LogFile&#41;
        Else
            Rewrite&#40;LogFile&#41;;
        WriteLn&#40;LogFile,AString&#41;;
        Flush&#40;LogFile&#41;;
        CloseFile&#40;LogFile&#41;;
    End;
    &#123;..............................................................................&#125;
    
    &#123;..............................................................................&#125;
    Function  Initialize&#58; Boolean;
    Var
        audio_rate     &#58; integer;
        audio_format   &#58; Uint16;
        audio_channels &#58; integer;
        audio_buffers  &#58; integer;
    Begin
        Result &#58;= False;
        bAudioOpen &#58;= False;
        Log&#40;'Initializing...'&#41;;
        If SDL_Init&#40;SDL_INIT_AUDIO Or SDL_INIT_VIDEO Or SDL_INIT_JOYSTICK&#41; < 0 Then
        Begin
            Log&#40;'Could not initialize SDL'&#41;;
            Exit;
        End
        Else
        Begin
            screen &#58;= SDL_SetVideoMode&#40;320,240,16,SDL_SWSURFACE&#41;;
            If screen = Nil Then
            Begin
                Log&#40;Format&#40;'Could not create window&#58; %s',&#91;SDL_GetError&#93;&#41;&#41;;
                Exit;
            End;
            Log&#40;'Window created'&#41;;
            SDL_ShowCursor&#40;0&#41;;
            audio_rate     &#58;= 22050;//MIX_DEFAULT_FREQUENCY;
            audio_format   &#58;= AUDIO_S16SYS;
            audio_channels &#58;= MIX_DEFAULT_CHANNELS;
    &#123;$IFDEF gp2x&#125;
            audio_buffers  &#58;= 512;
    &#123;$ELSE&#125;
            audio_buffers  &#58;= 4096;
    &#123;$ENDIF&#125;
            // Open the audio device
            Log&#40;'Opening audio...'&#41;;
            If Mix_OpenAudio&#40;audio_rate, audio_format, audio_channels, audio_buffers&#41; <0> 1&#41; Then
                    Log&#40;Format&#40;'Opened audio at %d Hz %d bit %s', &#91;audio_rate,
                            &#40;audio_format and $FF&#41;, 'stereo'&#93;&#41;&#41;
                Else
                    Log&#40;Format&#40;'Opened audio at %d Hz %d bit %s', &#91;audio_rate,
                            &#40;audio_format and $FF&#41;, 'mono'&#93;&#41;&#41;;
            End;
        End;
        Result &#58;= True;
        bAudioOpen &#58;= True;
        Log&#40;'Initialized'&#41;;
    End;
    &#123;..............................................................................&#125;
    
    &#123;..............................................................................&#125;
    Procedure PlayMusic&#40;AFileName&#58; AnsiString; loops&#58; Integer&#41;;
    Begin
        Log&#40;'Loading music...'&#41;;
        music &#58;= Mix_LoadMUS&#40;PChar&#40;AFileName&#41;&#41;;
        If &#40;music = Nil&#41; Then
        Begin
            Log&#40;Format&#40;'Could not load "%s"&#58; %s', &#91;AFileName, SDL_GetError&#40;&#41;&#93;&#41;&#41;;
            Exit;
        End;
        Log&#40;'Music loaded'&#41;;
        If loops <> -1 Then
        Begin
            Log&#40;Format&#40;'Playing&#58; "%s"&#40; looping &#41;',&#91;AFileName&#93;&#41;&#41;;
        End
        Else
            Log&#40;Format&#40;'Playing&#58; "%s"&#40; not looping &#41; ',&#91;AFileName&#93;&#41;&#41;;
        Mix_PlayMusic&#40;music, loops&#41;;
        Log&#40;'Playing'&#41;;
    End;
    &#123;..............................................................................&#125;
    
    &#123;..............................................................................&#125;
    Procedure Cleanup;
    Begin
        If music <> Nil Then
        Begin
            Log&#40;'Freeing music...'&#41;;
            Mix_FreeMusic&#40;music&#41;;
            Log&#40;'Music freed'&#41;;
            music &#58;= Nil;
        End;
        If bAudioOpen Then
        Begin
            bAudioOpen &#58;= False;
            Log&#40;'Closing audio...'&#41;;
            Mix_CloseAudio;
            Log&#40;'Audio closed'&#41;;
        End;
    &#123;$IFNDEF gp2x&#125;
        SDL_Quit;
    &#123;$ELSE&#125;
        chdir         &#40;'/usr/gp2x'&#41;;
        ExecuteProcess&#40;'/usr/gp2x/gp2xmenu',&#91;'/usr/gp2x/gp2xmenu'&#93;&#41;;
    &#123;$ENDIF&#125;
    End;
    &#123;..............................................................................&#125;
    
    &#123;..............................................................................&#125;
    Procedure WaitForKeyUp&#40;AKey&#58; Uint32&#41;;
    Var
        event &#58; TSDL_Event;
        done  &#58; Boolean;
    Begin
        done &#58;= False;
    
        While Not done Do
        Begin
            SDL_Delay&#40;1&#41;;
            While SDL_PollEvent&#40;@event&#41; = 1 Do
            Begin
                If event.type_ = SDL_KEYUP Then
                    If event.key.keysym.sym = AKey Then done &#58;= True;
            End;
        End;
    End;
    &#123;..............................................................................&#125;
    
    &#123;..............................................................................&#125;
    Procedure WaitForJoystickButtonUp&#40;AButton&#58; Uint32&#41;;
    Var
        event &#58; TSDL_Event;
        done  &#58; Boolean;
    Begin
        done &#58;= False;
    
        While Not done Do
        Begin
            SDL_Delay&#40;1&#41;;
            While SDL_PollEvent&#40;@event&#41; = 1 Do
            Begin
                If event.type_ = SDL_JOYBUTTONUP Then
                    If event.jbutton.button = AButton Then done &#58;= True;
            End;
        End;
    End;
    &#123;..............................................................................&#125;
    
    &#123;..............................................................................&#125;
    Begin
        Try
            DeleteFile&#40;ExtractFilePath&#40;ParamStr&#40;0&#41;&#41; + 'LogFile.txt'&#41;;
            If Initialize Then
            Begin
                PlayMusic&#40;ExtractFilePath&#40;ParamStr&#40;0&#41;&#41; + 'Pet Shop Boys - 02 - West End Girls.mp3',0&#41;;
    &#123;$IFNDEF gp2x&#125;
                WaitForKeyUp&#40;SDLK_Escape&#41;;
    &#123;$ELSE&#125;
                WaitForJoystickButtonUp&#40;SDLK_GP2X_START&#41;;
    &#123;$ENDIF&#125;
            End
            Else
                Log&#40;'Initializing failed.'&#41;;
        Except
            On E&#58;Exception Do Log&#40;E.Message&#41;;
        End;
        Log&#40;'closing...'&#41;;
        Cleanup;
    End.
    I hope this helps
    cheers,
    Paul.
    Games:
    Seafox


    Pages:
    Syntax Error Software itch.io page

    Online Chess
    http://gameknot.com/#paul_nicholls

  5. #25

    JEDI-SDL Audio

    Thanks Paul, I totally forgot to mention that you need to use Mixer_LoadMUS and not Mixer_LoadWav for other music formats.
    <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 =-

  6. #26
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    JEDI-SDL Audio

    Mixer_LoadMUS can also load MOD, S3M, XM and IT modules as well. If you know what a tracker is then you'll know all about these.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  7. #27

    JEDI-SDL Audio

    [pascal]
    begin
    SDL_INIT(SDL_INIT_AUDIO);
    if baudioopen = true then begin
    writeln('Error! SDL Audio could not be initialized.');
    sdl_quit;
    readln;
    exit;
    end
    else
    begin
    writeln('stage 1- initialization');
    baudioopen := false;
    audio_rate := 22050;
    audio_format := AUDIO_S16SYS;
    audio_channels := MIX_DEFAULT_CHANNELS;
    song := 'testx.mp3';
    //song := 'test.wav';
    wave := mix_loadmus(song);
    error := mix_geterror;
    writeln(error);
    if wave = nil then begin
    writeln('Couldn''t load ',song,'.');
    sdl_quit;
    readln;
    exit;
    end;
    mix_playmusic(wave,loops);
    if wave <> nil then begin
    mix_freemusic(wave);
    wave := nil;
    end;
    if baudioopen then begin
    baudioopen := false;
    mix_closeAudio;
    end;
    sdl_quit;
    end;
    end.
    [/pascal]

    Ok, thats my code. The result, depending on the audio file being run, is:
    WAV File:
    [pascal]
    Couldn't Load WAV File.
    [/pascal]

    MP3 File:
    [pascal]
    Module Format not Recognized.
    [/pascal]

    Anyone have a clue where my problem is?
    --MagicRPG--

  8. #28

    JEDI-SDL Audio

    You could try downloading the zip file from here (http://www.pygame.org/ftp/win32-dependencies.zip).

    This contains a smpeg.dll that you could use instead of whatever you are currently using...I had problems till I used that one.

    cheers,
    Paul.
    Games:
    Seafox


    Pages:
    Syntax Error Software itch.io page

    Online Chess
    http://gameknot.com/#paul_nicholls

  9. #29

    JEDI-SDL Audio

    DarkNess, in the code you posted where is the call to Mix_OpenAudio?

    Also you are using mix_playmusic to play WAV files. I don't think that will work.
    <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 =-

  10. #30

    JEDI-SDL Audio

    [pascal]
    begin
    SDL_INIT(SDL_INIT_AUDIO);
    if baudioopen = true then begin
    writeln('Error! SDL Audio could not be initialized.');
    sdl_quit;
    readln;
    exit;
    end
    else
    begin
    writeln('stage 1- initialization');
    writeln(mix_geterror);
    readln;
    baudioopen := false;
    audio_rate := 22050;
    audio_format := AUDIO_S16SYS;
    audio_channels := MIX_DEFAULT_CHANNELS;
    audio_buffers := 4096;
    mix_openaudio(audio_rate,audio_format,audio_channe ls, audio_buffers);
    writeln('stage 2- set song file');
    song := 'testb.mp3';
    wave := mix_loadmus('testb.mp3' {normally var song} );
    error := mix_geterror;
    writeln(error);
    if wave = nil then begin
    writeln('Couldn''t load ',song,'.');
    sdl_quit;
    readln;
    exit;
    end;
    writeln('stage 3- play song');
    writeln(mix_geterror);
    repeat
    loops := 1;
    mix_playmusic(wave,loops);
    until bool = true;
    if wave <> nil then begin
    mix_freemusic(wave);
    wave := nil;
    end;
    if baudioopen then begin
    baudioopen := false;
    mix_closeAudio;
    end;
    writeln('stage 4- quit');
    sdl_quit;
    end;
    end.
    [/pascal]

    Ok. This is my new code. My problem being, instead of playing the file, I hear a bunch of ticks. It's running testb.mp3, and it works, except instead of the song, I hear ticks. Now, if I try .wav, I get an error stating:
    "You can't pass a FILE pointer to a DLL (?)"
    with that exact caps, including the (?). I have no clue what this means.
    --MagicRPG--

Page 3 of 3 FirstFirst 123

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
  •