hedgewars/uSound.pas
changeset 2745 11fce231f24a
parent 2744 803d0142594e
child 2832 8cb73c0e77a1
equal deleted inserted replaced
2744:803d0142594e 2745:11fce231f24a
    34 procedure free_uSound;
    34 procedure free_uSound;
    35 
    35 
    36 procedure InitSound;
    36 procedure InitSound;
    37 procedure ReleaseSound;
    37 procedure ReleaseSound;
    38 procedure SoundLoad;
    38 procedure SoundLoad;
    39 procedure PlaySound(snd: TSound; infinite: boolean; voicepack: PVoicepack);
    39 procedure PlaySound(snd: TSound);
    40 procedure LoopSound(snd: TSound; voicepack: PVoicepack);
    40 procedure PlaySound(snd: TSound; voicepack: PVoicepack);
       
    41 function LoopSound(snd: TSound): LongInt;
       
    42 function LoopSound(snd: TSound; voicepack: PVoicepack): LongInt;
    41 procedure PlayMusic;
    43 procedure PlayMusic;
    42 procedure PauseMusic;
    44 procedure PauseMusic;
    43 procedure ResumeMusic;
    45 procedure ResumeMusic;
    44 procedure StopSound(snd: TSound);
    46 procedure StopSound(snd: TSound);
       
    47 procedure StopSound(chn: LongInt);
    45 function  ChangeVolume(voldelta: LongInt): LongInt;
    48 function  ChangeVolume(voldelta: LongInt): LongInt;
    46 function  AskForVoicepack(name: shortstring): Pointer;
    49 function  AskForVoicepack(name: shortstring): Pointer;
    47 
    50 
    48 
    51 
    49 implementation
    52 implementation
   150 {$IFDEF SDL_MIXER_NEWER}
   153 {$IFDEF SDL_MIXER_NEWER}
   151 	Mix_Quit();
   154 	Mix_Quit();
   152 {$ENDIF}	
   155 {$ENDIF}	
   153 end;
   156 end;
   154 
   157 
   155 procedure PlaySound(snd: TSound; infinite: boolean; voicepack: PVoicepack);
   158 procedure PlaySound(snd: TSound);
   156 var loops: LongInt;
   159 begin
       
   160 	PlaySound(snd, nil);
       
   161 end;
       
   162 
       
   163 procedure PlaySound(snd: TSound; voicepack: PVoicepack);
   157 begin
   164 begin
   158 if (not isSoundEnabled) or fastUntilLag then exit;
   165 if (not isSoundEnabled) or fastUntilLag then exit;
   159 if infinite and (lastChan[snd] <> -1) then exit;
       
   160 if infinite then loops:= -1 else loops:= 0;
       
   161 
   166 
   162 if (voicepack <> nil) and (voicepack^.chunks[snd] <> nil) then
   167 if (voicepack <> nil) and (voicepack^.chunks[snd] <> nil) then
   163 	lastChan[snd]:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], loops, -1)
   168 	lastChan[snd]:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], 0, -1)
   164 else
   169 else
   165 	lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], loops, -1)
   170 	lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], 0, -1)
   166 end;
   171 end;
   167 
   172 
   168 procedure LoopSound(snd: TSound; voicepack: PVoicepack);
   173 function LoopSound(snd: TSound): LongInt;
       
   174 begin
       
   175 	LoopSound:= LoopSound(snd, nil)
       
   176 end;
       
   177 
       
   178 function LoopSound(snd: TSound; voicepack: PVoicepack): LongInt;
   169 begin
   179 begin
   170 if (not isSoundEnabled) or fastUntilLag then exit;
   180 if (not isSoundEnabled) or fastUntilLag then exit;
   171 if lastChan[snd] <> -1 then exit;
       
   172 
   181 
   173 if (voicepack <> nil) and (voicepack^.chunks[snd] <> nil) then
   182 if (voicepack <> nil) and (voicepack^.chunks[snd] <> nil) then
   174 	lastChan[snd]:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], -1, -1)
   183 	LoopSound:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], -1, -1)
   175 else
   184 else
   176 	lastChan[snd]:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], -1, -1)
   185 	LoopSound:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], -1, -1)
   177 end;
   186 end;
   178 
   187 
   179 procedure StopSound(snd: TSound);
   188 procedure StopSound(snd: TSound);
   180 begin
   189 begin
   181 if not isSoundEnabled then exit;
   190 if not isSoundEnabled then exit;
   184 	Mix_HaltChannel(lastChan[snd]);
   193 	Mix_HaltChannel(lastChan[snd]);
   185 	lastChan[snd]:= -1;
   194 	lastChan[snd]:= -1;
   186 	end;
   195 	end;
   187 end;
   196 end;
   188 
   197 
       
   198 procedure StopSound(chn: LongInt);
       
   199 begin
       
   200 	if (chn <> -1) and (Mix_Playing(chn) <> 0) then Mix_HaltChannel(chn);
       
   201 end;
       
   202 
   189 procedure PlayMusic;
   203 procedure PlayMusic;
   190 var s: string;
   204 var s: string;
   191 begin
   205 begin
   192 if (not isSoundEnabled)
   206 if (not isSoundEnabled)
   193 	or (MusicFN = '')
   207 	or (MusicFN = '')