hedgewars/uSound.pas
changeset 3182 f75d546414c4
parent 3038 4e48c276a468
child 3201 400c98815100
equal deleted inserted replaced
3181:5c350b6c38f4 3182:f75d546414c4
    81     isSoundEnabled:= SDL_InitSubSystem(SDL_INIT_AUDIO) >= 0;
    81     isSoundEnabled:= SDL_InitSubSystem(SDL_INIT_AUDIO) >= 0;
    82 
    82 
    83     if isSoundEnabled then
    83     if isSoundEnabled then
    84         isSoundEnabled:= Mix_OpenAudio(44100, $8010, 2, 1024) = 0;
    84         isSoundEnabled:= Mix_OpenAudio(44100, $8010, 2, 1024) = 0;
    85 
    85 
       
    86 {$IFDEF SDL_MIXER_NEWER}
       
    87     WriteToConsole('Init SDL_mixer... ');
       
    88     SDLTry(Mix_Init(MIX_INIT_OGG) <> 0, true);
       
    89     WriteLnToConsole(msgOK);
       
    90 {$ENDIF}
       
    91 
    86     if isSoundEnabled then
    92     if isSoundEnabled then
    87         WriteLnToConsole(msgOK)
    93         WriteLnToConsole(msgOK)
    88     else
    94     else
    89         WriteLnToConsole(msgFailed);
    95         WriteLnToConsole(msgFailed);
    90 
    96 
   106     if voicepacks[t].name <> '' then
   112     if voicepacks[t].name <> '' then
   107         for i:= Low(TSound) to High(TSound) do
   113         for i:= Low(TSound) to High(TSound) do
   108             if voicepacks[t].chunks[i] <> nil then
   114             if voicepacks[t].chunks[i] <> nil then
   109                 Mix_FreeChunk(voicepacks[t].chunks[i]);
   115                 Mix_FreeChunk(voicepacks[t].chunks[i]);
   110 
   116 
   111 Mix_FreeMusic(Mus);
   117 if Mus <> nil then
       
   118     Mix_FreeMusic(Mus);
       
   119 
       
   120 {$IFDEF SDL_MIXER_NEWER}
       
   121 // make sure all instances of sdl_mixer are unloaded before continuing
       
   122 while Mix_Init(0) <> 0 do
       
   123     Mix_Quit();
       
   124 {$ENDIF}    
       
   125 
   112 Mix_CloseAudio();
   126 Mix_CloseAudio();
   113 end;
   127 end;
   114 
   128 
   115 procedure SoundLoad;
   129 procedure SoundLoad;
   116 var i: TSound;
   130 var i: TSound;
   117     s: shortstring;
   131     s: shortstring;
   118     t: Longword;
   132     t: Longword;
   119 begin
   133 begin
   120     if not isSoundEnabled then exit;
   134     if not isSoundEnabled then exit;
   121 
       
   122 {$IFDEF SDL_MIXER_NEWER}
       
   123     WriteToConsole('Init SDL_mixer... ');
       
   124     SDLTry(Mix_Init(MIX_INIT_OGG) <> 0, true);
       
   125     WriteLnToConsole(msgOK);
       
   126 {$ENDIF}
       
   127 
   135 
   128     defVoicepack:= AskForVoicepack('Default');
   136     defVoicepack:= AskForVoicepack('Default');
   129 
   137 
   130 for i:= Low(TSound) to High(TSound) do
   138 for i:= Low(TSound) to High(TSound) do
   131     if (Soundz[i].Path <> ptVoices) and (Soundz[i].FileName <> '') then
   139     if (Soundz[i].Path <> ptVoices) and (Soundz[i].FileName <> '') then
   148                 if voicepacks[t].chunks[i] = nil then
   156                 if voicepacks[t].chunks[i] = nil then
   149                     WriteLnToConsole(msgFailed)
   157                     WriteLnToConsole(msgFailed)
   150                 else
   158                 else
   151                     WriteLnToConsole(msgOK)
   159                     WriteLnToConsole(msgOK)
   152                 end;
   160                 end;
   153 {$IFDEF SDL_MIXER_NEWER}
       
   154     Mix_Quit();
       
   155 {$ENDIF}    
       
   156 end;
   161 end;
   157 
   162 
   158 procedure PlaySound(snd: TSound);
   163 procedure PlaySound(snd: TSound);
   159 begin
   164 begin
   160     PlaySound(snd, nil);
   165     PlaySound(snd, nil);