1 /* MikMod sound library
2 (c) 1998, 1999, 2000 Miodrag Vallat and others - see file AUTHORS for
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.
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.
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
21 /*==============================================================================
25 Error handling functions.
26 Register an error handler with _mm_RegisterErrorHandler() and you're all set.
28 ==============================================================================*/
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.
41 #include "mikmod_internals.h"
43 #define _mmerr_invalid "Invalid error code"
45 static const char *_mm_errmsg[MMERR_MAX+1] =
53 "Could not open requested file",
55 "Dynamic linking failed",
59 "Out of memory to load sample",
60 "Out of sample handles to load sample",
61 "Sample format not recognized",
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",
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",
86 /* AudioFile driver errors */
88 "Cannot find suitable AudioFile audio port",
93 /* AIX driver errors */
95 "Configuration (init step) of audio device failed",
96 "Configuration (control step) of audio device failed",
97 "Configuration (start step) of audio device failed",
99 _mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
102 /* Ultrasound driver errors */
104 "Ultrasound driver only works in 16 bit stereo 44 KHz",
105 "Ultrasound card could not be reset",
106 "Could not start Ultrasound timer",
108 _mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
111 /* HP driver errors */
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",
120 _mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
121 _mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
124 /* Open Sound System driver errors */
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",
131 _mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
135 /* SGI driver errors */
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",
143 _mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
144 _mmerr_invalid, _mmerr_invalid,
147 /* Sun driver errors */
149 "Sound device initialization failed",
154 /* OS/2 drivers errors */
155 #if defined(DRV_OS2) || defined(DRV_DART)
156 "Could not set mixing parameters",
161 "Could not create playback semaphores",
162 "Could not create playback timer",
163 "Could not create playback thread",
165 _mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
168 /* DirectSound driver errors */
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",
178 _mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
179 _mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
183 /* Windows Multimedia API driver errors */
185 "Invalid device handle",
186 "The resource is already allocated",
187 "Invalid device identifier",
188 "Unsupported output format",
191 _mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
192 _mmerr_invalid, _mmerr_invalid,
195 /* Macintosh driver errors */
197 "Unsupported sample rate",
198 "Could not start playback",
200 _mmerr_invalid, _mmerr_invalid,
203 /* MacOS X/Darwin driver errors */
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",
214 _mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
215 _mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
216 _mmerr_invalid, _mmerr_invalid,
219 /* DOS driver errors */
233 "This driver doesn't support 32 bit float output",
235 /* OpenAL driver errors */
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",
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,
255 /* ALSA driver errors */
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",
267 _mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
268 _mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
269 _mmerr_invalid, _mmerr_invalid, _mmerr_invalid,
274 "Could not set SNDIO output params",
275 "Unsupported SNDIO output params",
277 _mmerr_invalid, _mmerr_invalid,
285 MIKMODAPI const char *MikMod_strerror(int code)
287 if ((code<0)||(code>MMERR_MAX)) code=MMERR_MAX;
288 return _mm_errmsg[code];
291 /* User installed error callback */
292 MikMod_handler_t _mm_errorhandler = NULL;
293 MIKMODAPI int _mm_errno = 0;
294 MIKMODAPI BOOL _mm_critical = 0;
296 static MikMod_handler_t _mm_registererrorhandler(MikMod_handler_t proc)
298 MikMod_handler_t oldproc=_mm_errorhandler;
300 _mm_errorhandler = proc;
304 MIKMODAPI MikMod_handler_t MikMod_RegisterErrorHandler(MikMod_handler_t proc)
306 MikMod_handler_t result;
309 result=_mm_registererrorhandler(proc);