branch | flibqtfrontend |
changeset 8251 | 81789b027dd7 |
parent 8191 | 3f03f0b6a385 |
child 8330 | aaefa587e277 |
child 8370 | 0c79946e96f8 |
8248:34d1aceb31aa | 8251:81789b027dd7 |
---|---|
19 {$INCLUDE "options.inc"} |
19 {$INCLUDE "options.inc"} |
20 |
20 |
21 unit uSound; |
21 unit uSound; |
22 (* |
22 (* |
23 * This unit controls the sounds and music of the game. |
23 * This unit controls the sounds and music of the game. |
24 * Doesn't really do anything if isSoundEnabled = false. |
24 * Doesn't really do anything if isSoundEnabled = false and isMusicEnabled = false |
25 * |
25 * |
26 * There are three basic types of sound controls: |
26 * There are three basic types of sound controls: |
27 * Music - The background music of the game: |
27 * Music - The background music of the game: |
28 * * will only be played if isMusicEnabled = true |
28 * * will only be played if isMusicEnabled = true |
29 * * can be started, changed, paused and resumed |
29 * * can be started, changed, paused and resumed |
285 AskForVoicepack:= @voicepacks[i] |
285 AskForVoicepack:= @voicepacks[i] |
286 end; |
286 end; |
287 |
287 |
288 procedure InitSound; |
288 procedure InitSound; |
289 const channels: LongInt = {$IFDEF MOBILE}1{$ELSE}2{$ENDIF}; |
289 const channels: LongInt = {$IFDEF MOBILE}1{$ELSE}2{$ENDIF}; |
290 begin |
290 var success: boolean; |
291 if not isSoundEnabled then |
291 begin |
292 if not (isSoundEnabled or isMusicEnabled) then |
|
292 exit; |
293 exit; |
293 WriteToConsole('Init sound...'); |
294 WriteToConsole('Init sound...'); |
294 isSoundEnabled:= SDL_InitSubSystem(SDL_INIT_AUDIO) >= 0; |
295 success:= SDL_InitSubSystem(SDL_INIT_AUDIO) >= 0; |
295 |
296 |
296 if isSoundEnabled then |
297 if success then |
297 isSoundEnabled:= Mix_OpenAudio(44100, $8010, channels, 1024) = 0; |
298 success:= Mix_OpenAudio(44100, $8010, channels, 1024) = 0; |
298 |
299 |
299 if isSoundEnabled then |
300 if success then |
300 WriteLnToConsole(msgOK) |
301 WriteLnToConsole(msgOK) |
301 else |
302 else |
303 begin |
|
302 WriteLnToConsole(msgFailed); |
304 WriteLnToConsole(msgFailed); |
305 isSoundEnabled:= false; |
|
306 isMusicEnabled:= false; |
|
307 end; |
|
303 |
308 |
304 WriteToConsole('Init SDL_mixer... '); |
309 WriteToConsole('Init SDL_mixer... '); |
305 SDLTry(Mix_Init(MIX_INIT_OGG) <> 0, true); |
310 SDLTry(Mix_Init(MIX_INIT_OGG) <> 0, true); |
306 WriteLnToConsole(msgOK); |
311 WriteLnToConsole(msgOK); |
307 |
312 |
541 end; |
546 end; |
542 |
547 |
543 procedure PlayMusic; |
548 procedure PlayMusic; |
544 var s: shortstring; |
549 var s: shortstring; |
545 begin |
550 begin |
546 if (not isSoundEnabled) or (MusicFN = '') or (not isMusicEnabled) then |
551 if (MusicFN = '') or (not isMusicEnabled) then |
547 exit; |
552 exit; |
548 |
553 |
549 s:= '/Music/' + MusicFN; |
554 s:= '/Music/' + MusicFN; |
550 WriteToConsole(msgLoading + s + ' '); |
555 WriteToConsole(msgLoading + s + ' '); |
551 |
556 |
562 end; |
567 end; |
563 |
568 |
564 function ChangeVolume(voldelta: LongInt): LongInt; |
569 function ChangeVolume(voldelta: LongInt): LongInt; |
565 begin |
570 begin |
566 ChangeVolume:= 0; |
571 ChangeVolume:= 0; |
567 if (not isSoundEnabled) or ((voldelta = 0) and (not (cInitVolume = 0))) then |
572 if not (isSoundEnabled or isMusicEnabled) or ((voldelta = 0) and (not (cInitVolume = 0))) then |
568 exit; |
573 exit; |
569 |
574 |
570 inc(Volume, voldelta); |
575 inc(Volume, voldelta); |
571 if Volume < 0 then |
576 if Volume < 0 then |
572 Volume:= 0; |
577 Volume:= 0; |
602 ChangeVolume(previousVolume - Volume); |
607 ChangeVolume(previousVolume - Volume); |
603 end; |
608 end; |
604 |
609 |
605 procedure MuteAudio; |
610 procedure MuteAudio; |
606 begin |
611 begin |
607 if not isSoundEnabled then |
612 if not (isSoundEnabled or isMusicEnabled) then |
608 exit; |
613 exit; |
609 |
614 |
610 if (isAudioMuted) then |
615 if (isAudioMuted) then |
611 begin |
616 begin |
612 ResumeMusic; |
617 ResumeMusic; |
725 |
730 |
726 end; |
731 end; |
727 |
732 |
728 procedure freeModule; |
733 procedure freeModule; |
729 begin |
734 begin |
730 if isSoundEnabled then |
735 if isSoundEnabled or isMusicEnabled then |
731 ReleaseSound(true); |
736 ReleaseSound(true); |
732 end; |
737 end; |
733 |
738 |
734 end. |
739 end. |
735 |
740 |