diff src/audio/amigaos/SDL_ahiaudio.c @ 1996:f25d771fe6f2

Added int32 support to Amiga audio driver and cleaned up some other details in driver initialization. May need tweaking: I can't compile the amiga driver here.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 31 Aug 2006 21:43:25 +0000
parents c121d94672cb
children cbac0f77a799
line wrap: on
line diff
--- a/src/audio/amigaos/SDL_ahiaudio.c	Thu Aug 31 21:28:21 2006 +0000
+++ b/src/audio/amigaos/SDL_ahiaudio.c	Thu Aug 31 21:43:25 2006 +0000
@@ -226,47 +226,60 @@
 AHI_OpenAudio(_THIS, SDL_AudioSpec * spec)
 {
 //      int width;
+    SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format);
+    int valid_datatype = 0;
 
     D(bug("AHI opening...\n"));
 
     /* Determine the audio parameters from the AudioSpec */
-    switch (spec->format & 0xFF) {
-
-    case 8:
-        {                       /* Signed 8 bit audio data */
-            D(bug("Samples a 8 bit...\n"));
-            spec->format = AUDIO_S8;
-            this->hidden->bytespersample = 1;
-            if (spec->channels < 2)
-                this->hidden->type = AHIST_M8S;
-            else
-                this->hidden->type = AHIST_S8S;
-        }
-        break;
+    while ((!valid_datatype) && (test_format)) {
+        switch (test_format) {
+            case AUDIO_S8:
+                D(bug("AUDIO_S8...\n"));
+                valid_datatype = 1;
+                spec->format = AUDIO_S8;
+                this->hidden->bytespersample = 1;
+                if (spec->channels < 2)
+                    this->hidden->type = AHIST_M8S;
+                else
+                    this->hidden->type = AHIST_S8S;
+                break;
 
-    case 16:
-        {                       /* Signed 16 bit audio data */
-            D(bug("Samples a 16 bit...\n"));
-            spec->format = AUDIO_S16MSB;
-            this->hidden->bytespersample = 2;
-            if (spec->channels < 2)
-                this->hidden->type = AHIST_M16S;
-            else
-                this->hidden->type = AHIST_S16S;
-        }
-        break;
+            case AUDIO_S16MSB:
+                D(bug("AUDIO_S16MSB...\n"));
+                valid_datatype = 1;
+                spec->format = AUDIO_S16MSB;
+                this->hidden->bytespersample = 2;
+                if (spec->channels < 2)
+                    this->hidden->type = AHIST_M16S;
+                else
+                    this->hidden->type = AHIST_S16S;
+                break;
 
-    default:
-        {
-            SDL_SetError("Unsupported audio format");
-            return (-1);
+            case AUDIO_S32MSB:
+                D(bug("AUDIO_S32MSB...\n"));
+                valid_datatype = 1;
+                spec->format = AUDIO_S32MSB;
+                this->hidden->bytespersample = 4;
+                if (spec->channels < 2)
+                    this->hidden->type = AHIST_M32S;
+                else
+                    this->hidden->type = AHIST_S32S;
+                break;
+
+            default:
+                test_format = SDL_NextAudioFormat();
+                break;
         }
     }
 
-    if (spec->channels != 1 && spec->channels != 2) {
-        D(bug("Wrong channel number!\n"));
-        SDL_SetError("Channel number non supported");
-        return -1;
+    if (!valid_datatype) { /* shouldn't happen, but just in case... */
+        SDL_SetError("Unsupported audio format");
+        return (-1);
+    }
+
+    if (spec->channels > 2) {
+        spec->channels = 2;  /* will convert at higher level. */
     }
 
     D(bug("Before CalculateAudioSpec\n"));