Mercurial > sdl-ios-xcode
comparison src/audio/mint/SDL_mintaudio_gsxb.c @ 2005:45af7d69f8eb
MiNT audio driver cleanups for clamping types and channels to supported
values. int32 support now available in one instance.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Fri, 01 Sep 2006 06:32:54 +0000 |
parents | c121d94672cb |
children | d48ead2d2ba5 |
comparison
equal
deleted
inserted
replaced
2004:c27292a690b7 | 2005:45af7d69f8eb |
---|---|
206 static int | 206 static int |
207 Mint_CheckAudio(_THIS, SDL_AudioSpec * spec) | 207 Mint_CheckAudio(_THIS, SDL_AudioSpec * spec) |
208 { | 208 { |
209 long snd_format; | 209 long snd_format; |
210 int i, resolution, format_signed, format_bigendian; | 210 int i, resolution, format_signed, format_bigendian; |
211 | 211 SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format); |
212 resolution = spec->format & 0x00ff; | 212 int valid_datatype = 0; |
213 format_signed = ((spec->format & 0x8000) != 0); | 213 |
214 format_bigendian = ((spec->format & 0x1000) != 0); | 214 resolution = SDL_AUDIO_BITSIZE(spec->format); |
215 | 215 format_signed = SDL_AUDIO_ISSIGNED(spec->format); |
216 DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ", spec->format & 0x00ff)); | 216 format_bigendian = SDL_AUDIO_ISBIGENDIAN(spec->format); |
217 DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000) != 0))); | 217 |
218 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000) != 0))); | 218 DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ", resolution)); |
219 DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format))); | |
220 DEBUG_PRINT(("signed=%d, ", format_signed)); | |
221 DEBUG_PRINT(("big endian=%d, ", format_bigendian)); | |
219 DEBUG_PRINT(("channels=%d, ", spec->channels)); | 222 DEBUG_PRINT(("channels=%d, ", spec->channels)); |
220 DEBUG_PRINT(("freq=%d\n", spec->freq)); | 223 DEBUG_PRINT(("freq=%d\n", spec->freq)); |
221 | 224 |
222 /* Check formats available */ | 225 if (spec->channels > 2) { |
223 snd_format = Sndstatus(SND_QUERYFORMATS); | 226 spec->channels = 2; /* no more than stereo! */ |
224 switch (resolution) { | 227 } |
225 case 8: | 228 |
226 if ((snd_format & SND_FORMAT8) == 0) { | 229 while ((!valid_datatype) && (test_format)) { |
227 SDL_SetError("Mint_CheckAudio: 8 bits samples not supported"); | 230 spec->format = test_format; |
228 return -1; | 231 switch (test_format) { |
229 } | 232 case AUDIO_U8: |
230 snd_format = Sndstatus(SND_QUERY8BIT); | 233 case AUDIO_S8: |
231 break; | 234 case AUDIO_U16LSB: |
232 case 16: | 235 case AUDIO_S16LSB: |
233 if ((snd_format & SND_FORMAT16) == 0) { | 236 case AUDIO_U16MSB: |
234 SDL_SetError("Mint_CheckAudio: 16 bits samples not supported"); | 237 case AUDIO_S16MSB: |
235 return -1; | 238 case AUDIO_S32LSB: |
236 } | 239 case AUDIO_S32MSB: |
237 snd_format = Sndstatus(SND_QUERY16BIT); | 240 /* no float support... */ |
238 break; | 241 resolution = SDL_AUDIO_BITSIZE(spec->format); |
239 default: | 242 format_signed = SDL_AUDIO_ISSIGNED(spec->format); |
240 SDL_SetError("Mint_CheckAudio: Unsupported sample resolution"); | 243 format_bigendian = SDL_AUDIO_ISBIGENDIAN(spec->format); |
241 return -1; | 244 |
242 break; | 245 /* Check formats available */ |
246 snd_format = Sndstatus(SND_QUERYFORMATS); | |
247 switch (resolution) { | |
248 case 8: | |
249 if (snd_format & SND_FORMAT8) { | |
250 valid_datatype = 1; | |
251 snd_format = Sndstatus(SND_QUERY8BIT); | |
252 } | |
253 break; | |
254 case 16: | |
255 if (snd_format & SND_FORMAT16) { | |
256 valid_datatype = 1; | |
257 snd_format = Sndstatus(SND_QUERY16BIT); | |
258 } | |
259 break; | |
260 case 32: | |
261 if (snd_format & SND_FORMAT32) { | |
262 valid_datatype = 1; | |
263 snd_format = Sndstatus(SND_QUERY32BIT); | |
264 } | |
265 break; | |
266 } | |
267 | |
268 break; | |
269 } | |
270 } | |
271 | |
272 if (!valid_datatype) { | |
273 SDL_SetError("Unsupported audio format"); | |
274 return (-1); | |
243 } | 275 } |
244 | 276 |
245 /* Check signed/unsigned format */ | 277 /* Check signed/unsigned format */ |
246 if (format_signed) { | 278 if (format_signed) { |
247 if (snd_format & SND_FORMATSIGNED) { | 279 if (snd_format & SND_FORMATSIGNED) { |
248 /* Ok */ | 280 /* Ok */ |
249 } else if (snd_format & SND_FORMATUNSIGNED) { | 281 } else if (snd_format & SND_FORMATUNSIGNED) { |
250 /* Give unsigned format */ | 282 /* Give unsigned format */ |
251 spec->format = spec->format & (~0x8000); | 283 spec->format = spec->format & (~SDL_AUDIO_MASK_SIGNED); |
252 } | 284 } |
253 } else { | 285 } else { |
254 if (snd_format & SND_FORMATUNSIGNED) { | 286 if (snd_format & SND_FORMATUNSIGNED) { |
255 /* Ok */ | 287 /* Ok */ |
256 } else if (snd_format & SND_FORMATSIGNED) { | 288 } else if (snd_format & SND_FORMATSIGNED) { |
257 /* Give signed format */ | 289 /* Give signed format */ |
258 spec->format |= 0x8000; | 290 spec->format |= SDL_AUDIO_MASK_SIGNED; |
259 } | 291 } |
260 } | 292 } |
261 | 293 |
262 if (format_bigendian) { | 294 if (format_bigendian) { |
263 if (snd_format & SND_FORMATBIGENDIAN) { | 295 if (snd_format & SND_FORMATBIGENDIAN) { |
264 /* Ok */ | 296 /* Ok */ |
265 } else if (snd_format & SND_FORMATLITTLEENDIAN) { | 297 } else if (snd_format & SND_FORMATLITTLEENDIAN) { |
266 /* Give little endian format */ | 298 /* Give little endian format */ |
267 spec->format = spec->format & (~0x1000); | 299 spec->format = spec->format & (~SDL_AUDIO_MASK_ENDIAN); |
268 } | 300 } |
269 } else { | 301 } else { |
270 if (snd_format & SND_FORMATLITTLEENDIAN) { | 302 if (snd_format & SND_FORMATLITTLEENDIAN) { |
271 /* Ok */ | 303 /* Ok */ |
272 } else if (snd_format & SND_FORMATBIGENDIAN) { | 304 } else if (snd_format & SND_FORMATBIGENDIAN) { |
273 /* Give big endian format */ | 305 /* Give big endian format */ |
274 spec->format |= 0x1000; | 306 spec->format |= SDL_AUDIO_MASK_ENDIAN; |
275 } | 307 } |
276 } | 308 } |
277 | 309 |
278 /* Calculate and select the closest frequency */ | 310 /* Calculate and select the closest frequency */ |
279 MINTAUDIO_freqcount = 0; | 311 MINTAUDIO_freqcount = 0; |
294 #endif | 326 #endif |
295 | 327 |
296 MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, spec->freq); | 328 MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, spec->freq); |
297 spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; | 329 spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; |
298 | 330 |
299 DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ", spec->format & 0x00ff)); | 331 DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ", SDL_AUDIO_BITSIZE(spec->format))); |
300 DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000) != 0))); | 332 DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format))); |
301 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000) != 0))); | 333 DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format))); |
334 DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format))); | |
302 DEBUG_PRINT(("channels=%d, ", spec->channels)); | 335 DEBUG_PRINT(("channels=%d, ", spec->channels)); |
303 DEBUG_PRINT(("freq=%d\n", spec->freq)); | 336 DEBUG_PRINT(("freq=%d\n", spec->freq)); |
304 | 337 |
305 return 0; | 338 return 0; |
306 } | 339 } |
317 /* Set replay tracks */ | 350 /* Set replay tracks */ |
318 Settracks(0, 0); | 351 Settracks(0, 0); |
319 Setmontracks(0); | 352 Setmontracks(0); |
320 | 353 |
321 /* Select replay format */ | 354 /* Select replay format */ |
322 switch (spec->format & 0xff) { | 355 switch (SDL_AUDIO_BITSIZE(spec->format)) { |
323 case 8: | 356 case 8: |
324 if (spec->channels == 2) { | 357 if (spec->channels == 2) { |
325 channels_mode = STEREO8; | 358 channels_mode = STEREO8; |
326 } else { | 359 } else { |
327 channels_mode = MONO8; | 360 channels_mode = MONO8; |
332 channels_mode = STEREO16; | 365 channels_mode = STEREO16; |
333 } else { | 366 } else { |
334 channels_mode = MONO16; | 367 channels_mode = MONO16; |
335 } | 368 } |
336 break; | 369 break; |
370 case 32: | |
371 if (spec->channels == 2) { | |
372 channels_mode = STEREO32; | |
373 } else { | |
374 channels_mode = MONO32; | |
375 } | |
376 break; | |
337 default: | 377 default: |
338 channels_mode = STEREO16; | 378 channels_mode = STEREO16; |
339 break; | 379 break; |
340 } | 380 } |
341 if (Setmode(channels_mode) < 0) { | 381 if (Setmode(channels_mode) < 0) { |