music_mad.c: reload AudioStream when playing Frankenstein streams.
authorOzkan Sezer
Sun, 22 Dec 2019 15:55:50 +0300
changeset 11135a0c021c1f5d
parent 1112 75207bc3188e
child 1114 5ca667177b34
music_mad.c: reload AudioStream when playing Frankenstein streams.

Thanks Vitaly Novichkov.
src/codecs/music_mad.c
     1.1 --- a/src/codecs/music_mad.c	Sun Dec 22 08:56:10 2019 +0300
     1.2 +++ b/src/codecs/music_mad.c	Sun Dec 22 15:55:50 2019 +0300
     1.3 @@ -147,6 +147,8 @@
     1.4      int volume;
     1.5      int status;
     1.6      SDL_AudioStream *audiostream;
     1.7 +    unsigned short last_nchannels;
     1.8 +    unsigned int last_samplerate;
     1.9  
    1.10      unsigned char input_buffer[MAD_INPUT_BUFFER_SIZE + MAD_BUFFER_GUARD];
    1.11  } MAD_Music;
    1.12 @@ -300,11 +302,17 @@
    1.13      mad_synth_frame(&music->synth, &music->frame);
    1.14      pcm = &music->synth.pcm;
    1.15  
    1.16 -    if (!music->audiostream) {
    1.17 -        music->audiostream = SDL_NewAudioStream(AUDIO_S16, (Uint8)pcm->channels, (int)pcm->samplerate, music_spec.format, music_spec.channels, music_spec.freq);
    1.18 +    if (!music->audiostream || music->last_nchannels != pcm->channels || music->last_samplerate != pcm->samplerate) {
    1.19 +        if (music->audiostream) {
    1.20 +            SDL_FreeAudioStream(music->audiostream);
    1.21 +        }
    1.22 +        music->audiostream = SDL_NewAudioStream(AUDIO_S16, (Uint8)pcm->channels, (int)pcm->samplerate,
    1.23 +                                                music_spec.format, music_spec.channels, music_spec.freq);
    1.24          if (!music->audiostream) {
    1.25              return SDL_FALSE;
    1.26          }
    1.27 +        music->last_nchannels = pcm->channels;
    1.28 +        music->last_samplerate = pcm->samplerate;
    1.29      }
    1.30  
    1.31      nchannels = pcm->channels;