3 Quick and Dirty Game Development Framework (QDGDF)
5 Copyright (C) 2001/2005 Angel Ortega <angel@triptico.com>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 http://www.triptico.com
31 #include "qdgdf_audio.h"
34 * _qdgdfa_sound - Main sound switch.
36 * If set to 0 previous to startup, disables the whole sound system.
37 * If it has a value of 0 after startup, something wrong occurred
38 * in the initialization of the sound card.
41 int _qdgdfa_sound
= 1;
44 * _qdgdfa_16_bit - 16 bit sound card toggle.
46 * If set to 0 previous to startup, use only 8 bit sound output.
47 * If it has a value of 0 after startup, the sound card does not
48 * support 16 bit PCM audio.
51 int _qdgdfa_16_bit
= 1;
54 * _qdgdfa_window_title - title of the window.
56 * This string holds the title of the window.
59 char _qdgdfa_window_title
[150] = "";
61 char *_qdgdfa_version
= VERSION
;
64 * _qdgdfa_big_sound_threshold - Threshold for a sound to be considered big.
66 * This integer holds the minimum size a sound must have
67 * to be considered a 'big' sound (a sound that is paged
68 * in disk instead of being loaded completely in memory).
71 int _qdgdfa_big_sound_threshold
= 1024 * 1024;
75 * _qdgdfa_fopen_path - Search path for _qdgdfa_fopen().
77 * This string can contain a semicolon-separated list of paths
78 * where files to be open with _qdgdfa_fopen() will be tried.
81 char _qdgdfa_fopen_path
[250] = "";
84 static struct _qdgdfa_driver
*drv
= NULL
;
89 #include "qdgdf_path.c"
91 FILE *_qdgdfa_fopen(char *file
, char *mode
)
93 return _path_fopen(_qdgdfa_fopen_path
, file
, mode
);
98 * qdgdfa_path_find - Finds a file in _qdgdfa_fopen_path.
99 * @file: the file to be found
101 * Searches for @file in the path stored in _qdgdfa_fopen_path.
102 * If it's found in some of the directories there, a string is
103 * allocated contaning the full path, that should be freed
104 * when no longer needed. Otherwise, returns NULL.
106 char *qdgdfa_path_find(const char *file
)
108 return _path_find(_qdgdfa_fopen_path
, file
);
112 FILE *qdgdfa_load_wav(char *filename
, int *size
, int *bits
)
117 short int b_per_sec
, num_channels
, tag
;
118 char riffid
[5], waveid
[5], fmtid
[5], dataid
[5];
121 if ((f
= _qdgdfa_fopen(filename
, "rb")) == NULL
)
124 fread(riffid
, 1, 4, f
);
126 fread(&rlen
, 1, 4, f
);
127 fread(waveid
, 1, 4, f
);
130 if (strcmp(waveid
, "WAVE")) {
135 fread(fmtid
, 1, 4, f
);
138 flen
+= (fgetc(f
) * 256);
139 flen
+= (fgetc(f
) * 65536);
140 flen
+= (fgetc(f
) * 16777216);
145 fread(&tag
, 1, 2, f
);
147 num_channels
= fgetc(f
);
148 num_channels
+= (fgetc(f
) * 256);
149 _wav_frequency
= fgetc(f
);
150 _wav_frequency
+= (fgetc(f
) * 256);
151 _wav_frequency
+= (fgetc(f
) * 65536);
152 _wav_frequency
+= (fgetc(f
) * 16777216);
153 b_per_sec
= fgetc(f
);
154 b_per_sec
+= (fgetc(f
) * 256);
155 b_per_sec
+= (fgetc(f
) * 65536);
156 b_per_sec
+= (fgetc(f
) * 16777216);
159 (*bits
) += (fgetc(f
) * 256);
162 fread(dummydata
, 1, (size_t) flen
- 14, f
);
163 fread(dataid
, 1, 4, f
);
167 (*size
) += (fgetc(f
) * 256);
168 (*size
) += (fgetc(f
) * 65536);
169 (*size
) += (fgetc(f
) * 16777216);
176 * qdgdfa_load_sound - Loads a sound.
177 * @wavfile: the file containing the sound
179 * Loads a sound file (in .WAV format). A sound handle
183 int qdgdfa_load_sound(char *wavfile
)
188 return drv
->load_sound(wavfile
);
193 * qdgdfa_load_big_sound - Loads a big sound (deprecated).
194 * @wavfile: the file containing the sound
196 * In previous versions, sounds considered (by the programmer)
197 * to be big were loaded by using this function, but now the
198 * 'bigness' of a file is controlled by the value in the
199 * _qdgdfa_big_sound_threshold variable, so it's use is deprecated.
200 * Now it's exactly equivalent to qdgdfa_load_sound().
203 int qdgdfa_load_big_sound(char *wavfile
)
205 return qdgdfa_load_sound(wavfile
);
210 * qdgdfa_dup_sound - Duplicates a sound.
211 * @sound: the sound to be duplicated
213 * Duplicates a sound. The new sound will share the
214 * sound data with the old one. Returns the
215 * id for the new sound.
218 int qdgdfa_dup_sound(int snd
)
223 return drv
->dup_sound(snd
);
228 * qdgdfa_play_sound - Starts playing a sound.
229 * @snd: the sound handle
230 * @loop: neverending loop flag
232 * Starts playing a sound. If @loop is set, the sound restarts
233 * from the beginning when reaches the end. If the sound is
234 * already playing, nothing is done.
237 void qdgdfa_play_sound(int snd
, int loop
)
240 drv
->play_sound(snd
, loop
);
245 * qdgdfa_respawn_sound - Respawns a sound.
246 * @snd: the sound to be respawn
248 * Respawns a sound, playing it even if the sound is
249 * already playing. This new, duplicated sound inherits
250 * all properties (as pan, etc.) from the original one
251 * and cannot be stopped nor controlled in any way. The
252 * poll of respawned sounds is limited; if it can't hold
253 * more sounds, nothing is done. A respawned sound is
254 * automatically deleted when finished.
257 void qdgdfa_respawn_sound(int snd
)
260 drv
->respawn_sound(snd
);
265 * qdgdfa_stop_sound - Stop playing a sound.
266 * @snd: the sound handle
268 * Stops playing a sound.
271 void qdgdfa_stop_sound(int snd
)
274 drv
->stop_sound(snd
);
279 * qdgdfa_set_pan - Sets the pan of a sound.
280 * @snd: the sound handle
281 * @pan: pan of the sound
283 * Sets the pan of a sound. The @pan argument can be -1 (left channel only),
284 * 0 (both channels, center) or 1 (right channel only).
287 void qdgdfa_set_pan(int snd
, int pan
)
290 drv
->set_pan(snd
, pan
);
295 * qdgdfa_set_attenuation - Sets the attenuation of a sound.
296 * @snd: the sound handle
297 * @att: the attenuation
299 * Sets the attenuation of a sound. It ranges from 0 (no attenuation,
300 * sound is as is) to 63 (total silence).
303 void qdgdfa_set_attenuation(int snd
, int att
)
311 drv
->set_attenuation(snd
, att
);
316 * qdgdfa_reset - Resets the sound system.
318 * Resets the sound system, shuting up all sounds and unloading
322 void qdgdfa_reset(void)
330 * qdgdfa_pause - Pause the sound system.
333 * Pauses the sound system. The @p argument acts as a boolean
334 * to pause or unpause the sound system.
337 void qdgdfa_pause(int p
)
345 * qdgdfa_home_dir - Returns the home user directory.
347 * Returns a system-dependent directory where the user can write
348 * documents and create subdirectories.
351 char *qdgdfa_home_dir(void)
358 * qdgdfa_app_dir - Returns the applications directory.
360 * Returns a system-dependent directory where the applications store
361 * their private data, as components or resources.
364 char *qdgdfa_app_dir(void)
371 * qdgdfa_startup - Starts the sound system.
373 * Starts the sound system. If _qdgdfa_sound is not set,
374 * no action is done. If _qdgdfa_16_bit is set, it tries
375 * to use the 16 bit capabilities of the sound card. It
376 * also sets both previous variables accordingly to the
377 * current configuration.
380 void qdgdfa_startup(void)
385 if (!TRY_AUDIO_DRIVERS())
388 atexit(qdgdfa_shutdown
);
393 * qdgdfa_shutdown - Shuts down the sound system.
395 * Shuts down the sound system.
398 void qdgdfa_shutdown(void)