hedgewars/uSound.pas
changeset 2262 0dc94341bf42
parent 2258 3dd028604cfd
child 2303 f411e9f8e6d4
equal deleted inserted replaced
2261:57e99c908e7c 2262:0dc94341bf42
    53 procedure PauseMusic;
    53 procedure PauseMusic;
    54 procedure ResumeMusic;
    54 procedure ResumeMusic;
    55 procedure StopSound(snd: TSound);
    55 procedure StopSound(snd: TSound);
    56 function  ChangeVolume(voldelta: LongInt): LongInt;
    56 function  ChangeVolume(voldelta: LongInt): LongInt;
    57 function  AskForVoicepack(name: shortstring): Pointer;
    57 function  AskForVoicepack(name: shortstring): Pointer;
       
    58 function  soundFadeOut(snd: TSound; qt: LongInt; voicepack: PVoicepack): LongInt;
       
    59 
    58 
    60 
    59 {*remember: LongInt = 32bit; integer = 16bit; byte = 8bit*}
    61 {*remember: LongInt = 32bit; integer = 16bit; byte = 8bit*}
    60 function openal_init		(memsize: LongInt)                      : boolean; cdecl; external OpenALBridge;
    62 function openal_init		(memsize: LongInt)                      : boolean; cdecl; external OpenALBridge;
    61 function openal_close							: boolean; cdecl; external OpenALBridge;
    63 function openal_close							: boolean; cdecl; external OpenALBridge;
    62 function openal_loadfile	(const filename: PChar)			: LongInt; cdecl; external OpenALBridge;
    64 function openal_loadfile	(const filename: PChar)			: LongInt; cdecl; external OpenALBridge;
    63 function openal_toggleloop	(index: LongInt)			: boolean; cdecl; external OpenALBridge;
    65 function openal_toggleloop	(index: LongInt)			: boolean; cdecl; external OpenALBridge;
    64 function openal_setvolume	(index: LongInt; percentage: byte)	: boolean; cdecl; external OpenALBridge;
    66 function openal_setvolume	(index: LongInt; percentage: byte)	: boolean; cdecl; external OpenALBridge;
    65 function openal_setglobalvolume	(percentage: byte)			: boolean; cdecl; external OpenALBridge;
    67 function openal_setglobalvolume	(percentage: byte)			: boolean; cdecl; external OpenALBridge;
    66 function openal_fadeout		(index: LongInt; quantity: integer)	: boolean; cdecl; external OpenALBridge;
    68 function openal_fadeout		(index: LongInt; quantity: integer)	: boolean; cdecl; external OpenALBridge;
    67 function openal_fadein		(index: LongInt; quantity: integer)	: boolean; cdecl; external OpenALBridge;
    69 function openal_fadein		(index: LongInt; quantity: integer)	: boolean; cdecl; external OpenALBridge;
    68 function openal_fade		(index: LongInt; quantity: integer; direction: byte)	: boolean; cdecl; external OpenALBridge;
    70 function openal_fade		(index: LongInt; quantity: integer; direction: boolean)	: boolean; cdecl; external OpenALBridge;
    69 function openal_playsound	(index: LongInt)			: boolean; cdecl; external OpenALBridge;
    71 function openal_playsound	(index: LongInt)			: boolean; cdecl; external OpenALBridge;
    70 function openal_pausesound	(index: LongInt)			: boolean; cdecl; external OpenALBridge;
    72 function openal_pausesound	(index: LongInt)			: boolean; cdecl; external OpenALBridge;
    71 function openal_stopsound	(index: LongInt)			: boolean; cdecl; external OpenALBridge;
    73 function openal_stopsound	(index: LongInt)			: boolean; cdecl; external OpenALBridge;
    72 
    74 
    73 var MusicFN: shortstring = '';
    75 var MusicFN: shortstring = '';
   148 				else
   150 				else
   149 					WriteLnToConsole(msgOK)
   151 					WriteLnToConsole(msgOK)
   150 				end;
   152 				end;
   151 end;
   153 end;
   152 
   154 
       
   155 function soundFadeOut(snd: TSound; qt: LongInt; voicepack: PVoicepack): LongInt;
       
   156 begin
       
   157 if not isSoundEnabled then exit(0);
       
   158 if (voicepack <> nil) and (voicepack^.chunks[snd] >= 0) then openal_fadeout(defVoicepack^.chunks[snd], qt)
       
   159 else if (defVoicepack^.chunks[snd] >= 0) then openal_fadeout(defVoicepack^.chunks[snd], qt);
       
   160 end;
       
   161 
   153 procedure PlaySound(snd: TSound; infinite: boolean; voicepack: PVoicepack);
   162 procedure PlaySound(snd: TSound; infinite: boolean; voicepack: PVoicepack);
   154 begin
   163 begin
   155 if (not isSoundEnabled) or fastUntilLag then exit;
   164 if (not isSoundEnabled) or fastUntilLag then exit;
   156 
   165 
   157 if (voicepack <> nil) and (voicepack^.chunks[snd] >= 0) then
   166 if (voicepack <> nil) then
   158 begin
   167 begin
       
   168 if voicepack^.chunks[snd] >= 0 then
       
   169 	begin
   159 	if infinite then openal_toggleloop(voicepack^.chunks[snd]);
   170 	if infinite then openal_toggleloop(voicepack^.chunks[snd]);
   160 	openal_playsound(voicepack^.chunks[snd]);
   171 	openal_playsound(voicepack^.chunks[snd]);
   161 	lastChan[snd]:=voicepack^.chunks[snd];
   172 	lastChan[snd]:=voicepack^.chunks[snd];
       
   173 	end
   162 end
   174 end
   163 else
   175 else
   164 begin
   176 begin
       
   177 if (defVoicepack^.chunks[snd] >= 0) then
       
   178 	begin
   165 	if infinite then openal_toggleloop(defVoicepack^.chunks[snd]);
   179 	if infinite then openal_toggleloop(defVoicepack^.chunks[snd]);
   166 	openal_playsound(defVoicepack^.chunks[snd]);
   180 	openal_playsound(defVoicepack^.chunks[snd]);
   167 	lastChan[snd]:=defVoicepack^.chunks[snd];
   181 	lastChan[snd]:=defVoicepack^.chunks[snd];
       
   182 	end
   168 end
   183 end
   169 end;
   184 end;
   170 
   185 
   171 procedure StopSound(snd: TSound);
   186 procedure StopSound(snd: TSound);
   172 begin
   187 begin