src/audio/baudio/SDL_beaudio.cc
changeset 1997 46319c67b3d7
parent 1895 c121d94672cb
child 1998 cbac0f77a799
     1.1 --- a/src/audio/baudio/SDL_beaudio.cc	Thu Aug 31 21:43:25 2006 +0000
     1.2 +++ b/src/audio/baudio/SDL_beaudio.cc	Thu Aug 31 22:15:07 2006 +0000
     1.3 @@ -156,37 +156,78 @@
     1.4      int BE_OpenAudio(_THIS, SDL_AudioSpec * spec)
     1.5      {
     1.6          media_raw_audio_format format;
     1.7 +        SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format);
     1.8 +        int valid_datatype = 0;
     1.9 +
    1.10 +        /* Parse the audio format and fill the Be raw audio format */
    1.11 +        memset(&format, '\0', sizeof (media_raw_audio_format));
    1.12 +        format.byte_order = B_MEDIA_LITTLE_ENDIAN;
    1.13 +        format.frame_rate = (float) spec->freq;
    1.14 +        format.channel_count = spec->channels;  /* !!! FIXME: support > 2? */
    1.15 +        while ((!valid_datatype) && (test_format)) {
    1.16 +            spec->format = test_format;
    1.17 +            switch (test_format) {
    1.18 +                case AUDIO_S8:
    1.19 +                    valid_datatype = 1;
    1.20 +                    format.format = media_raw_audio_format::B_AUDIO_CHAR;
    1.21 +                    break;
    1.22 +
    1.23 +                case AUDIO_U8:
    1.24 +                    valid_datatype = 1;
    1.25 +                    format.format = media_raw_audio_format::B_AUDIO_UCHAR;
    1.26 +                    break;
    1.27 +
    1.28 +                case AUDIO_S16LSB:
    1.29 +                    valid_datatype = 1;
    1.30 +                    format.format = media_raw_audio_format::B_AUDIO_SHORT;
    1.31 +                    break;
    1.32 +
    1.33 +                case AUDIO_S16MSB:
    1.34 +                    valid_datatype = 1;
    1.35 +                    format.format = media_raw_audio_format::B_AUDIO_SHORT;
    1.36 +                    format.byte_order = B_MEDIA_BIG_ENDIAN;
    1.37 +                    break;
    1.38 +
    1.39 +                case AUDIO_S32LSB:
    1.40 +                    valid_datatype = 1;
    1.41 +                    format.format = media_raw_audio_format::B_AUDIO_INT;
    1.42 +                    break;
    1.43 +
    1.44 +                case AUDIO_S32MSB:
    1.45 +                    valid_datatype = 1;
    1.46 +                    format.format = media_raw_audio_format::B_AUDIO_INT;
    1.47 +                    format.byte_order = B_MEDIA_BIG_ENDIAN;
    1.48 +                    break;
    1.49 +
    1.50 +                case AUDIO_F32LSB:
    1.51 +                    valid_datatype = 1;
    1.52 +                    format.format = media_raw_audio_format::B_AUDIO_FLOAT;
    1.53 +                    break;
    1.54 +
    1.55 +                case AUDIO_F32MSB:
    1.56 +                    valid_datatype = 1;
    1.57 +                    format.format = media_raw_audio_format::B_AUDIO_FLOAT;
    1.58 +                    format.byte_order = B_MEDIA_BIG_ENDIAN;
    1.59 +                    break;
    1.60 +
    1.61 +                default:
    1.62 +                    test_format = SDL_NextAudioFormat();
    1.63 +                    break;
    1.64 +            }
    1.65 +        }
    1.66 +
    1.67 +        format.buffer_size = spec->samples;
    1.68 +
    1.69 +        if (!valid_datatype) { /* shouldn't happen, but just in case... */
    1.70 +            SDL_SetError("Unsupported audio format");
    1.71 +            return (-1);
    1.72 +        }
    1.73  
    1.74          /* Initialize the Be Application, if it's not already started */
    1.75          if (SDL_InitBeApp() < 0) {
    1.76              return (-1);
    1.77          }
    1.78  
    1.79 -        /* Parse the audio format and fill the Be raw audio format */
    1.80 -        format.frame_rate = (float) spec->freq;
    1.81 -        format.channel_count = spec->channels;
    1.82 -        switch (spec->format & ~0x1000) {
    1.83 -        case AUDIO_S8:
    1.84 -            /* Signed 8-bit audio unsupported, convert to U8 */
    1.85 -            spec->format = AUDIO_U8;
    1.86 -        case AUDIO_U8:
    1.87 -            format.format = media_raw_audio_format::B_AUDIO_UCHAR;
    1.88 -            format.byte_order = 0;
    1.89 -            break;
    1.90 -        case AUDIO_U16:
    1.91 -            /* Unsigned 16-bit audio unsupported, convert to S16 */
    1.92 -            spec->format ^= 0x8000;
    1.93 -        case AUDIO_S16:
    1.94 -            format.format = media_raw_audio_format::B_AUDIO_SHORT;
    1.95 -            if (spec->format & 0x1000) {
    1.96 -                format.byte_order = 1;  /* Big endian */
    1.97 -            } else {
    1.98 -                format.byte_order = 2;  /* Little endian */
    1.99 -            }
   1.100 -            break;
   1.101 -        }
   1.102 -        format.buffer_size = spec->samples;
   1.103 -
   1.104          /* Calculate the final parameters for this audio specification */
   1.105          SDL_CalculateAudioSpec(spec);
   1.106