Let SDL convert to valid Dreamcast audio formats instead of failing if the
authorRyan C. Gordon <icculus@icculus.org>
Thu, 31 Aug 2006 23:16:23 +0000
changeset 20008c05b048c32c
parent 1999 dd4b184b3050
child 2001 02108bfd6550
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.
src/audio/dc/SDL_dcaudio.c
     1.1 --- a/src/audio/dc/SDL_dcaudio.c	Thu Aug 31 22:40:53 2006 +0000
     1.2 +++ b/src/audio/dc/SDL_dcaudio.c	Thu Aug 31 23:16:23 2006 +0000
     1.3 @@ -220,18 +220,31 @@
     1.4  static int
     1.5  DCAUD_OpenAudio(_THIS, SDL_AudioSpec * spec)
     1.6  {
     1.7 -    switch (spec->format & 0xff) {
     1.8 -    case 8:
     1.9 -        spec->format = AUDIO_S8;
    1.10 -        break;
    1.11 -    case 16:
    1.12 -        spec->format = AUDIO_S16LSB;
    1.13 -        break;
    1.14 -    default:
    1.15 +    SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format);
    1.16 +    int valid_datatype = 0;
    1.17 +    while ((!valid_datatype) && (test_format)) {
    1.18 +        spec->format = test_format;
    1.19 +        switch (test_format) {
    1.20 +            /* only formats Dreamcast accepts... */
    1.21 +            case AUDIO_S8:
    1.22 +            case AUDIO_S16LSB:
    1.23 +                valid_datatype = 1;
    1.24 +                break;
    1.25 +
    1.26 +            default:
    1.27 +                test_format = SDL_NextAudioFormat();
    1.28 +                break;
    1.29 +        }
    1.30 +    }
    1.31 +
    1.32 +    if (!valid_datatype) {  /* shouldn't happen, but just in case... */
    1.33          SDL_SetError("Unsupported audio format");
    1.34          return (-1);
    1.35      }
    1.36  
    1.37 +    if (spec->channels > 2)
    1.38 +        spec->channels = 2;  /* no more than stereo on the Dreamcast. */
    1.39 +
    1.40      /* Update the fragment size as size in bytes */
    1.41      SDL_CalculateAudioSpec(spec);
    1.42