diff src/audio/mint/SDL_mintaudio_gsxb.c @ 3851:405a192b68e7 SDL-1.2

Backport from 1.3: most of the audio drivers can now handle data conversion at a higher level when they can't open the hardware in the exact format requested.
author Ryan C. Gordon <icculus@icculus.org>
date Fri, 01 Sep 2006 22:50:24 +0000
parents a8181c4040b8
children 5b5e549382b3
line wrap: on
line diff
--- a/src/audio/mint/SDL_mintaudio_gsxb.c	Wed Aug 02 21:26:31 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_gsxb.c	Fri Sep 01 22:50:24 2006 +0000
@@ -201,6 +201,8 @@
 {
 	long snd_format;
 	int i, resolution, format_signed, format_bigendian;
+    SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format);
+    int valid_datatype = 0;
 
 	resolution = spec->format & 0x00ff;
 	format_signed = ((spec->format & 0x8000)!=0);
@@ -212,28 +214,46 @@
 	DEBUG_PRINT(("channels=%d, ", spec->channels));
 	DEBUG_PRINT(("freq=%d\n", spec->freq));
 
-	/* Check formats available */
-	snd_format = Sndstatus(SND_QUERYFORMATS);
-	switch (resolution) {
-		case 8:
-			if ((snd_format & SND_FORMAT8)==0) {
-				SDL_SetError("Mint_CheckAudio: 8 bits samples not supported");
-				return -1;
-			}
-			snd_format = Sndstatus(SND_QUERY8BIT);
-			break;
-		case 16:
-			if ((snd_format & SND_FORMAT16)==0) {
-				SDL_SetError("Mint_CheckAudio: 16 bits samples not supported");
-				return -1;
-			}
-			snd_format = Sndstatus(SND_QUERY16BIT);
-			break;
-		default:
-			SDL_SetError("Mint_CheckAudio: Unsupported sample resolution");
-			return -1;
-			break;
-	}
+    if (spec->channels > 2) {
+        spec->channels = 2;  /* no more than stereo! */
+    }
+
+    while ((!valid_datatype) && (test_format)) {
+        /* Check formats available */
+        snd_format = Sndstatus(SND_QUERYFORMATS);
+        spec->format = test_format;
+        resolution = SDL_AUDIO_BITSIZE(spec->format);
+        format_signed = SDL_AUDIO_ISSIGNED(spec->format);
+        format_bigendian = SDL_AUDIO_ISBIGENDIAN(spec->format);
+        switch (test_format) {
+            case AUDIO_U8:
+            case AUDIO_S8:
+                if (snd_format & SND_FORMAT8) {
+                    valid_datatype = 1;
+                    snd_format = Sndstatus(SND_QUERY8BIT);
+                }
+                break;
+
+            case AUDIO_U16LSB:
+            case AUDIO_S16LSB:
+            case AUDIO_U16MSB:
+            case AUDIO_S16MSB:
+                if (snd_format & SND_FORMAT16) {
+                    valid_datatype = 1;
+                    snd_format = Sndstatus(SND_QUERY16BIT);
+                }
+                break;
+
+            default:
+                test_format = SDL_NextAudioFormat();
+                break;
+        }
+    }
+
+    if (!valid_datatype) {
+        SDL_SetError("Unsupported audio format");
+        return (-1);
+    }
 
 	/* Check signed/unsigned format */
 	if (format_signed) {