1 /*	MikMod sound library
2 	(c) 1998, 1999, 2000 Miodrag Vallat and others - see file AUTHORS for
3 	complete list.
4 
5 	This library is free software; you can redistribute it and/or modify
6 	it under the terms of the GNU Library General Public License as
7 	published by the Free Software Foundation; either version 2 of
8 	the License, or (at your option) any later version.
9 
10 	This program is distributed in the hope that it will be useful,
11 	but WITHOUT ANY WARRANTY; without even the implied warranty of
12 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 	GNU Library General Public License for more details.
14 
15 	You should have received a copy of the GNU Library General Public
16 	License along with this library; if not, write to the Free Software
17 	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 	02111-1307, USA.
19 */
20 
21 /*==============================================================================
22 
23   $Id$
24 
25   Error handling functions.
26   Register an error handler with _mm_RegisterErrorHandler() and you're all set.
27 
28 ==============================================================================*/
29 
30 /*
31 
32 	The global variables _mm_errno, and _mm_critical are set before the error
33 	handler in called.  See below for the values of these variables.
34 
35 */
36 
37 #ifdef HAVE_CONFIG_H
38 #include "config.h"
39 #endif
40 
41 #include "mikmod_internals.h"
42 
43 #define _mmerr_invalid "Invalid error code"
44 
45 static const char *_mm_errmsg[MMERR_MAX+1] =
46 {
47 /* No error */
48 
49 	"No error",
50 
51 /* Generic errors */
52 
53 	"Could not open requested file",
54 	"Out of memory",
55 	"Dynamic linking failed",
56 
57 /* Sample errors */
58 
59 	"Out of memory to load sample",
60 	"Out of sample handles to load sample",
61 	"Sample format not recognized",
62 
63 /* Module errors */
64 
65 	"Failure loading module pattern",
66 	"Failure loading module track",
67 	"Failure loading module header",
68 	"Failure loading sampleinfo",
69 	"Module format not recognized",
70 	"Module sample format not recognized",
71 	"Synthsounds not supported in MED files",
72 	"Compressed sample is invalid",
73 
74 /* Driver errors: */
75 
76 	"Sound device not detected",
77 	"Device number out of range",
78 	"Software mixer failure",
79 	"Could not open sound device",
80 	"This driver supports 8 bit linear output only",
81 	"This driver supports 16 bit linear output only",
82 	"This driver supports stereo output only",
83 	"This driver supports uLaw output (8 bit mono, 8 kHz) only",
84 	"Unable to set non-blocking mode for audio device",
85 
86 /* AudioFile driver errors  */
87 #ifdef DRV_AF
88 	"Cannot find suitable AudioFile audio port",
89 #else
90 	_mmerr_invalid,
91 #endif
92 
93 /* AIX driver errors */
94 #ifdef DRV_AIX
95 	"Configuration (init step) of audio device failed",
96 	"Configuration (control step) of audio device failed",
97 	"Configuration (start step) of audio device failed",
98 #else
99 	_mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
100 #endif
101 
102 /* Ultrasound driver errors */
103 #ifdef DRV_ULTRA
104 	"Ultrasound driver only works in 16 bit stereo 44 KHz",
105 	"Ultrasound card could not be reset",
106 	"Could not start Ultrasound timer",
107 #else
108 	_mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
109 #endif
110 
111 /* HP driver errors  */
112 #ifdef DRV_HP
113 	"Unable to select 16bit-linear sample format",
114 	"Could not select requested sample-rate",
115 	"Could not select requested number of channels",
116 	"Unable to select audio output",
117 	"Unable to get audio description",
118 	"Could not set transmission buffer size",
119 #else
120 	_mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
121 	_mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
122 #endif
123 
124 /* Open Sound System driver errors */
125 #ifdef DRV_OSS
126 	"Could not set fragment size",
127 	"Could not set sample size",
128 	"Could not set mono/stereo setting",
129 	"Could not set sample rate",
130 #else
131 	_mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
132 	_mmerr_invalid,
133 #endif
134 
135 /* SGI driver errors */
136 #ifdef DRV_SGI
137 	"Unsupported sample rate",
138 	"Hardware does not support 16 bit sound",
139 	"Hardware does not support 8 bit sound",
140 	"Hardware does not support stereo sound",
141 	"Hardware does not support mono sound",
142 #else
143 	_mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
144 	_mmerr_invalid, _mmerr_invalid,
145 #endif
146 
147 /* Sun driver errors */
148 #ifdef DRV_SUN
149 	"Sound device initialization failed",
150 #else
151 	_mmerr_invalid,
152 #endif
153 
154 /* OS/2 drivers errors */
155 #if defined(DRV_OS2) || defined(DRV_DART)
156 	"Could not set mixing parameters",
157 #else
158 	_mmerr_invalid,
159 #endif
160 #ifdef DRV_OS2
161 	"Could not create playback semaphores",
162 	"Could not create playback timer",
163 	"Could not create playback thread",
164 #else
165 	_mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
166 #endif
167 
168 /* DirectSound driver errors */
169 #ifdef DRV_DS
170 	"Could not set playback priority",
171 	"Could not create playback buffers",
172 	"Could not set playback format",
173 	"Could not register callback",
174 	"Could not register event",
175 	"Could not create playback thread",
176 	"Could not initialize playback thread",
177 #else
178 	_mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
179 	_mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
180 	_mmerr_invalid,
181 #endif
182 
183 /* Windows Multimedia API driver errors */
184 #ifdef DRV_WIN
185 	"Invalid device handle",
186 	"The resource is already allocated",
187 	"Invalid device identifier",
188 	"Unsupported output format",
189 	"Unknown error",
190 #else
191 	_mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
192 	_mmerr_invalid, _mmerr_invalid,
193 #endif
194 
195 /* Macintosh driver errors */
196 #ifdef DRV_MAC
197 	"Unsupported sample rate",
198 	"Could not start playback",
199 #else
200 	_mmerr_invalid, _mmerr_invalid,
201 #endif
202 
203 /* MacOS X/Darwin driver errors */
204 #ifdef DRV_OSX
205 	"Unknown device",
206 	"Bad property",
207 	"Could not set playback format",
208 	"Could not set mono/stereo setting",
209 	"Could not create playback buffers",
210 	"Could not create playback thread",
211 	"Could not start audio device",
212 	"Could not create buffer thread",
213 #else
214 	_mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
215 	_mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
216 	_mmerr_invalid, _mmerr_invalid,
217 #endif
218 
219 /* DOS driver errors */
220 #ifdef DRV_WSS
221 	"WSS_STARTDMA",
222 #else
223 	_mmerr_invalid,
224 #endif
225 #ifdef DRV_SB
226 	"SB_STARTDMA",
227 #else
228 	_mmerr_invalid,
229 #endif
230 
231 /* float32 output */
232 
233 	"This driver doesn't support 32 bit float output",
234 
235 /* OpenAL driver errors */
236 #ifdef DRV_OPENAL
237 	"Could not create context",
238 	"Could not make context current",
239 	"Could not create buffers",
240 	"Could not create sources",
241 	"Could not change source parameters",
242 	"Could not queue buffers",
243 	"Could not unqueue buffers",
244 	"Could not copy buffer data",
245 	"Could not get source parameters",
246 	"Could not play source",
247 	"Could not stop source",
248 #else
249 	_mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
250 	_mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
251 	_mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
252 	_mmerr_invalid, _mmerr_invalid,
253 #endif
254 
255 /* ALSA driver errors */
256 #ifdef DRV_ALSA
257 	"No ALSA configurations available",
258 	"Could not set ALSA output params",
259 	"Could not set playback format",
260 	"Could not set sample rate",
261 	"Could not set mono/stereo setting",
262 	"Could not get buffer size from ALSA",
263 	"ALSA PCM start error",
264 	"ALSA PCM write error",
265 	"ALSA PCM recovery failure",
266 #else
267 	_mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
268 	_mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
269 	_mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
270 #endif
271 
272 /* Sndio errors */
273 #ifdef DRV_SNDIO
274 	"Could not set SNDIO output params",
275 	"Unsupported SNDIO output params",
276 #else
277 	_mmerr_invalid, _mmerr_invalid,
278 #endif
279 
280 /* Invalid error */
281 
282 	_mmerr_invalid
283 };
284 
MikMod_strerror(int code)285 MIKMODAPI const char *MikMod_strerror(int code)
286 {
287 	if ((code<0)||(code>MMERR_MAX)) code=MMERR_MAX;
288 	return _mm_errmsg[code];
289 }
290 
291 /* User installed error callback */
292 MikMod_handler_t _mm_errorhandler = NULL;
293 MIKMODAPI int  _mm_errno = 0;
294 MIKMODAPI BOOL _mm_critical = 0;
295 
_mm_registererrorhandler(MikMod_handler_t proc)296 static MikMod_handler_t _mm_registererrorhandler(MikMod_handler_t proc)
297 {
298 	MikMod_handler_t oldproc=_mm_errorhandler;
299 
300 	_mm_errorhandler = proc;
301 	return oldproc;
302 }
303 
MikMod_RegisterErrorHandler(MikMod_handler_t proc)304 MIKMODAPI MikMod_handler_t MikMod_RegisterErrorHandler(MikMod_handler_t proc)
305 {
306 	MikMod_handler_t result;
307 
308 	MUTEX_LOCK(vars);
309 		result=_mm_registererrorhandler(proc);
310 	MUTEX_UNLOCK(vars);
311 
312 	return result;
313 }
314 
315 /* ex:set ts=4: */
316