Fail when trying to use timidity with unsupported audio formats instead of playing garbage
authorSam Lantinga <slouken@libsdl.org>
Sat, 21 Oct 2017 02:47:18 -0700
changeset 803d1deb5a4c3f5
parent 802 98ee7bc3833a
child 804 daf5b3cc29cb
Fail when trying to use timidity with unsupported audio formats instead of playing garbage
timidity/timidity.c
     1.1 --- a/timidity/timidity.c	Sat Oct 21 02:35:44 2017 -0700
     1.2 +++ b/timidity/timidity.c	Sat Oct 21 02:47:18 2017 -0700
     1.3 @@ -494,26 +494,29 @@
     1.4        song->encoding |= PE_SIGNED;
     1.5    if (audio->channels == 1)
     1.6        song->encoding |= PE_MONO;
     1.7 +  else if (audio->channels > 2) {
     1.8 +      SDL_SetError("Surround sound not supported");
     1.9 +      return NULL;
    1.10 +  }
    1.11    switch (audio->format) {
    1.12 -      case AUDIO_S8:
    1.13 +  case AUDIO_S8:
    1.14  	  song->write = s32tos8;
    1.15  	  break;
    1.16 -      case AUDIO_U8:
    1.17 +  case AUDIO_U8:
    1.18  	  song->write = s32tou8;
    1.19  	  break;
    1.20 -      case AUDIO_S16LSB:
    1.21 +  case AUDIO_S16LSB:
    1.22  	  song->write = s32tos16l;
    1.23  	  break;
    1.24 -      case AUDIO_S16MSB:
    1.25 +  case AUDIO_S16MSB:
    1.26  	  song->write = s32tos16b;
    1.27  	  break;
    1.28 -      case AUDIO_U16LSB:
    1.29 +  case AUDIO_U16LSB:
    1.30  	  song->write = s32tou16l;
    1.31  	  break;
    1.32 -      default:
    1.33 -	  SNDDBG(("Unsupported audio format"));
    1.34 -	  song->write = s32tou16l;
    1.35 -	  break;
    1.36 +  default:
    1.37 +	  SDL_SetError("Unsupported audio format");
    1.38 +      return NULL;
    1.39    }
    1.40  
    1.41    song->buffer_size = audio->samples;