1 // Emacs style mode select   -*- C++ -*-
2 //-----------------------------------------------------------------------------
3 //
4 // $Id: soundst.h 1286 2016-12-19 03:09:56Z wesleyjohnson $
5 //
6 // Copyright (C) 1993-1996 by id Software, Inc.
7 // Portions Copyright (C) 1998-2000 by DooM Legacy Team.
8 //
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License
11 // as published by the Free Software Foundation; either version 2
12 // of the License, or (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 //
20 // $Log: soundst.h,v $
21 // Revision 1.2  2000/02/27 00:42:12  hurdler
22 // fix CR+LF problem
23 //
24 // Revision 1.1.1.1  2000/02/22 20:32:33  hurdler
25 // Initial import into CVS (v1.29 pr3)
26 //
27 //
28 // DESCRIPTION:
29 //      Sound (utility) related. Hang on.
30 //      See gensounds.h and gensounds.c for what soundst.h is made of.
31 //
32 //-----------------------------------------------------------------------------
33 
34 #ifndef SNDSRV_SOUNDST_H
35 #define SNDSRV_SOUNDST_H
36 
37 #define S_MAX_VOLUME            127
38 
39 // when to clip out sounds
40 // Doesn't fit the large outdoor areas.
41 #define S_CLIPPING_DIST         (1200*0x10000)
42 
43 // when sounds should be max'd out
44 #define S_CLOSE_DIST            (200*0x10000)
45 
46 
47 #define S_ATTENUATOR            ((S_CLIPPING_DIST-S_CLOSE_DIST)>>FRACBITS)
48 
49 #define NORM_PITCH              128
50 #define NORM_PRIORITY           64
51 #define NORM_VOLUME             snd_MaxVolume
52 
53 #define S_PITCH_PERTURB         1
54 #define NORM_SEP                        128
55 #define S_STEREO_SWING          (96*0x10000)
56 
57 // % attenuation from front to back
58 #define S_IFRACVOL                      30
59 
60 #define NA                              0
61 #define S_NUMCHANNELS           2
62 
63 
64 
65 
66 //
67 // MusicInfo struct.
68 //
69 typedef struct
70 {
71     // up to 6-character name
72     char*       name;
73 
74     // lump number of music
75     int         lumpnum;
76 
77     // music data
78     void*       data;
79 
80     // music handle once registered
81     int handle;
82 
83 } musicinfo_t;
84 
85 
86 
87 //
88 // SoundFX struct.
89 //
90 typedef struct sfxinfo_struct   sfxinfo_t;
91 
92 struct sfxinfo_struct
93 {
94     // up to 6-character name
95     char*       name;
96 
97     // Sfx singularity (only one at a time)
98     int         singularity;
99 
100     // Sfx priority
101     int         priority;
102 
103     // referenced sound if a link
104     sfxinfo_t*  link;
105 
106     // pitch if a link
107     int         pitch;
108 
109     // volume if a link
110     int         volume;
111 
112     // sound data
113     void*       data;
114 
115     // this is checked every second to see if sound
116     // can be thrown out (if 0, then decrement, if -1,
117     // then throw out, if > 0, then it's in use)
118     int         usefulness;
119 
120     // lump number of sfx
121     int         lumpnum;
122 };
123 
124 
125 
126 typedef struct
127 {
128     // sound information (if null, channel avail.)
129     sfxinfo_t*  sfxinfo;
130 
131     // origin of sound
132     void*       origin;
133 
134     // handle of the sound being played
135     int         handle;
136 
137 } channel_t;
138 
139 
140 
141 enum
142 {
143     Music,
144     Sfx,
145     SfxLink
146 };
147 
148 enum
149 {
150     PC=1,
151     Adlib=2,
152     SB=4,
153     Midi=8
154 }; // cards available
155 
156 enum
157 {
158     sfxThrowOut=-1,
159     sfxNotUsed=0
160 };
161 
162 
163 //
164 // Initialize the sound code at start of level
165 //
166 void S_Start(void);
167 
168 //
169 // Start sound for thing at <origin>
170 //  using <sound_id> from sounds.h
171 //
172 void S_StartSound( void* origin, int sound_id );
173 
174 
175 
176 // Will start a sound at a given volume.
177 void S_StartSoundAtVolume( void* origin, int sound_id, int volume );
178 
179 
180 // Stop sound for thing at <origin>
181 void S_StopSound(void* origin);
182 
183 // Start music using <music_id> from sounds.h
184 void S_StartMusic(int music_id);
185 
186 // Start music using <music_id> from sounds.h,
187 //  and set whether looping
188 void S_ChangeMusic( int music_id, int looping );
189 
190 
191 // Stops the music
192 void S_StopMusic(void);
193 
194 void S_PauseSound(void);
195 void S_ResumeSound(void);
196 
197 
198 //
199 // Updates music & sounds
200 //
201 void S_UpdateSounds(void* listener);
202 
203 void S_SetMusicVolume(int volume);
204 void S_SetSfxVolume(int volume);
205 
206 //
207 // Initializes sound stuff, including volume
208 //
209 void S_Init( int, int);
210 
211 
212 
213 //
214 // SOUND IO
215 //
216 #define FREQ_LOW                0x40
217 #define FREQ_NORM               0x80
218 #define FREQ_HIGH               0xff
219 
220 
221 void I_SetMusicVolume(int volume);
222 void I_SetSfxVolume(int volume);
223 
224 //
225 //  MUSIC I/O
226 //
227 void I_PauseSong(int handle);
228 void I_ResumeSong(int handle);
229 
230 //
231 // Called by anything that wishes to start music.
232 //  plays a song, and when the song is done,
233 //  starts playing it again in an endless loop.
234 // Horrible thing to do, considering.
235 void I_PlaySong( int handle, int looping );
236 
237 
238 // stops a song over 3 seconds.
239 void I_StopSong(int handle);
240 
241 // registers a song handle to song data
242 int I_RegisterSong(void *data);
243 
244 // see above then think backwards
245 void I_UnRegisterSong(int handle);
246 
247 // is the song playing?
248 int I_QrySongPlaying(int handle);
249 
250 
251 //
252 //  SFX I/O
253 //
254 void I_SetChannels(int channels);
255 
256 int I_GetSfxLumpNum (sfxinfo_t*);
257 
258 
259 // Starts a sound in a particular sound channel.
260 int I_StartSound( int id, void* data, int vol, int sep, int pitch, int priority );
261 
262 
263 // Updates the volume, separation,
264 //  and pitch of a sound channel.
265 void I_UpdateSoundParams( int handle, int vol, int sep, int pitch );
266 
267 
268 // Stops a sound channel.
269 void I_StopSound(int handle);
270 
271 // Called by S_*()'s to see if a channel is still playing.
272 // Returns 0 if no longer playing, 1 if playing.
273 int I_SoundIsPlaying(int handle);
274 
275 
276 // the complete set of sound effects
277 extern sfxinfo_t        S_sfx[];
278 
279 // the complete set of music
280 extern musicinfo_t      S_music[];
281 
282 #endif
283