17 *) |
17 *) |
18 |
18 |
19 {$INCLUDE "options.inc"} |
19 {$INCLUDE "options.inc"} |
20 |
20 |
21 unit uSound; |
21 unit uSound; |
|
22 (* |
|
23 * This unit controls the sounds and music of the game. |
|
24 * Doesn't really do anything if isSoundEnabled = false. |
|
25 * |
|
26 * There are three basic types of sound controls: |
|
27 * Music - The background music of the game: |
|
28 * * will only be played if isMusicEnabled = true |
|
29 * * can be started, changed, paused and resumed |
|
30 * Sound - Can be started and stopped |
|
31 * Looped Sound - Subtype of sound: plays in a loop using a |
|
32 * "channel", of which the id is returned on start. |
|
33 * The channel id can be used to stop a specific sound loop. |
|
34 *) |
22 interface |
35 interface |
23 uses SDLh, uConsts, uTypes, sysutils; |
36 uses SDLh, uConsts, uTypes, sysutils; |
24 |
37 |
25 var MusicFN: shortstring; |
38 var MusicFN: shortstring; // music file name |
26 |
39 |
27 procedure initModule; |
40 procedure initModule; |
28 procedure freeModule; |
41 procedure freeModule; |
29 |
42 |
30 procedure InitSound; |
43 procedure InitSound; // Initiates sound-system if isSoundEnabled. |
31 procedure ReleaseSound; |
44 procedure ReleaseSound; // Releases sound-system and used resources. |
32 procedure SoundLoad; |
45 procedure SoundLoad; // Preloads some sounds for performance reasons. |
|
46 |
|
47 |
|
48 // MUSIC |
|
49 |
|
50 // Obvious music commands for music track specified in MusicFN. |
|
51 procedure PlayMusic; |
|
52 procedure PauseMusic; |
|
53 procedure ResumeMusic; |
|
54 procedure ChangeMusic; // Replaces music track with current MusicFN and plays it. |
|
55 |
|
56 |
|
57 // SOUNDS |
|
58 |
|
59 // Plays the sound snd [from a given voicepack], |
|
60 // if keepPlaying is given and true, |
|
61 // then the sound's playback won't be interrupted if asked to play again. |
33 procedure PlaySound(snd: TSound); |
62 procedure PlaySound(snd: TSound); |
34 procedure PlaySound(snd: TSound; keepPlaying: boolean); |
63 procedure PlaySound(snd: TSound; keepPlaying: boolean); |
35 procedure PlaySound(snd: TSound; voicepack: PVoicepack); |
64 procedure PlaySound(snd: TSound; voicepack: PVoicepack); |
36 procedure PlaySound(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean); |
65 procedure PlaySound(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean); |
|
66 |
|
67 // Plays sound snd [of voicepack] in a loop, but starts with fadems milliseconds of fade-in. |
|
68 // Returns sound channel of the looped sound. |
37 function LoopSound(snd: TSound): LongInt; |
69 function LoopSound(snd: TSound): LongInt; |
38 function LoopSound(snd: TSound; fadems: LongInt): LongInt; |
70 function LoopSound(snd: TSound; fadems: LongInt): LongInt; |
39 function LoopSound(snd: TSound; voicepack: PVoicepack): LongInt; |
71 function LoopSound(snd: TSound; voicepack: PVoicepack): LongInt; // WTF? |
40 function LoopSound(snd: TSound; voicepack: PVoicepack; fadems: LongInt): LongInt; |
72 function LoopSound(snd: TSound; voicepack: PVoicepack; fadems: LongInt): LongInt; |
41 procedure PlayMusic; |
73 |
42 procedure PauseMusic; |
74 // Stops the normal/looped sound of the given type/in the given channel |
43 procedure ResumeMusic; |
75 // [with a fade-out effect for fadems milliseconds]. |
44 procedure ChangeMusic; |
|
45 procedure StopSound(snd: TSound); |
76 procedure StopSound(snd: TSound); |
46 procedure StopSound(chn: LongInt); |
77 procedure StopSound(chn: LongInt); |
47 procedure StopSound(chn, fadems: LongInt); |
78 procedure StopSound(chn, fadems: LongInt); |
|
79 |
|
80 |
|
81 // MISC |
|
82 |
|
83 // Modifies the sound volume of the game by voldelta and returns the new volume level. |
48 function ChangeVolume(voldelta: LongInt): LongInt; |
84 function ChangeVolume(voldelta: LongInt): LongInt; |
|
85 |
|
86 // Returns a pointer to the voicepack with the given name. |
49 function AskForVoicepack(name: shortstring): Pointer; |
87 function AskForVoicepack(name: shortstring): Pointer; |
50 |
88 |
51 |
89 |
52 implementation |
90 implementation |
53 uses uVariables, uConsole, uUtils, uCommands, uDebug; |
91 uses uVariables, uConsole, uUtils, uCommands, uDebug; |