diff src/audio/dc/SDL_dcaudio.c @ 2000:8c05b048c32c

Let SDL convert to valid Dreamcast audio formats instead of failing if the hardware can't be opened in a specific format. Not that you'd want to swallow the overhead on a Dreamcast, but hey, it's the SDL way.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 31 Aug 2006 23:16:23 +0000
parents c121d94672cb
children adf732f1f016
line wrap: on
line diff
--- a/src/audio/dc/SDL_dcaudio.c	Thu Aug 31 22:40:53 2006 +0000
+++ b/src/audio/dc/SDL_dcaudio.c	Thu Aug 31 23:16:23 2006 +0000
@@ -220,18 +220,31 @@
 static int
 DCAUD_OpenAudio(_THIS, SDL_AudioSpec * spec)
 {
-    switch (spec->format & 0xff) {
-    case 8:
-        spec->format = AUDIO_S8;
-        break;
-    case 16:
-        spec->format = AUDIO_S16LSB;
-        break;
-    default:
+    SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format);
+    int valid_datatype = 0;
+    while ((!valid_datatype) && (test_format)) {
+        spec->format = test_format;
+        switch (test_format) {
+            /* only formats Dreamcast accepts... */
+            case AUDIO_S8:
+            case AUDIO_S16LSB:
+                valid_datatype = 1;
+                break;
+
+            default:
+                test_format = SDL_NextAudioFormat();
+                break;
+        }
+    }
+
+    if (!valid_datatype) {  /* shouldn't happen, but just in case... */
         SDL_SetError("Unsupported audio format");
         return (-1);
     }
 
+    if (spec->channels > 2)
+        spec->channels = 2;  /* no more than stereo on the Dreamcast. */
+
     /* Update the fragment size as size in bytes */
     SDL_CalculateAudioSpec(spec);