Avoid non-alpha characters in _qdgdfv_alnum in win32.
[qdgdf.git] / qdgdf_audio_esd.c
blobb3d04f0975f972e6d636f6be2b969c296224abda
1 /*
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
25 #include "config.h"
26 #include <stdio.h>
27 #include "qdgdf_audio.h"
29 #ifdef CONFOPT_ESD
31 #include <unistd.h>
33 #include "esd.h"
36 /** data **/
38 /* esd socket */
39 int _esd_fd;
41 /* sound sample ids */
42 #define MAX_SAMPLES 512
44 int _sample_ids[MAX_SAMPLES];
45 int _sample_idx = 0;
48 /** code **/
50 static int _qdgdfa_load_sound(char *wavfile)
52 int snd;
54 snd = esd_file_cache(_esd_fd, "qdgdfa", wavfile);
56 /* fill the pool */
57 _sample_ids[_sample_idx++] = snd;
59 return snd;
63 static int _qdgdfa_dup_sound(int snd)
65 /* sounds cannot be duplicated with esound,
66 but seems not necessary as sounds can
67 be directly played many times; so, return
68 the same sample id. Does esound allows
69 a sample to be freed many times without crashing? */
71 return snd;
75 static void _qdgdfa_play_sound(int snd, int loop)
77 esd_sample_stop(_esd_fd, snd);
79 /* Esd is crap. I just can't force it to stop
80 big files played in loops, nor unload them,
81 nor kill them; looped sounds are played
82 forever. So, looped sounds are disabled
83 by now. */
84 if (!loop)
85 esd_sample_play(_esd_fd, snd);
89 static void _qdgdfa_respawn_sound(int snd)
91 esd_sample_play(_esd_fd, snd);
95 static void _qdgdfa_stop_sound(int snd)
97 esd_sample_stop(_esd_fd, snd);
101 static void _qdgdfa_set_pan(int snd, int pan)
103 int left = 256, right = 256;
105 if (pan == -1)
106 right = 0;
107 if (pan == 1)
108 left = 0;
110 esd_set_default_sample_pan(_esd_fd, snd, left, right);
114 static void _qdgdfa_set_attenuation(int snd, int att)
116 /* unimplemented */
120 static void _qdgdfa_reset(void)
122 int n;
124 for (n = 0; n < _sample_idx; n++) {
125 qdgdfa_stop_sound(_sample_ids[n]);
127 esd_sample_free(_esd_fd, _sample_ids[n]);
129 _sample_ids[n] = -1;
132 _sample_idx = 0;
136 static void _qdgdfa_pause(int p)
138 if (p)
139 esd_standby(_esd_fd);
140 else
141 esd_resume(_esd_fd);
145 static int _qdgdfa_startup(void)
147 _esd_fd = esd_open_sound(NULL);
149 if (_esd_fd < 0)
150 return 0;
152 _sample_idx = 0;
153 return 1;
157 static void _qdgdfa_shutdown(void)
159 qdgdfa_reset();
161 esd_close(_esd_fd);
165 /* driver information */
167 static struct _qdgdfa_driver drv = {
168 "esd",
170 _qdgdfa_load_sound,
171 _qdgdfa_dup_sound,
172 _qdgdfa_play_sound,
173 _qdgdfa_respawn_sound,
174 _qdgdfa_stop_sound,
176 _qdgdfa_set_pan,
177 _qdgdfa_set_attenuation,
178 _qdgdfa_reset,
179 _qdgdfa_pause,
180 _qdgdfa_startup,
181 _qdgdfa_shutdown
185 struct _qdgdfa_driver *esd_drv_detect(void)
186 /* detection function */
188 if (_qdgdfa_startup())
189 return &drv;
191 return NULL;
194 #endif /* CONFOPT_ESD */