Added Mix_OpenAudioDevice() so you can specify the audio device to open
authorSam Lantinga <slouken@libsdl.org>
Fri, 29 Jan 2016 12:44:13 -0800
changeset 718fb0562cc1559
parent 717 27eb690edafc
child 719 d9b3684ca715
Added Mix_OpenAudioDevice() so you can specify the audio device to open
CHANGES.txt
SDL_mixer.h
effect_position.c
mixer.c
mixer.h
music.c
native_midi/native_midi_mac.c
native_midi/native_midi_macosx.c
wavestream.c
     1.1 --- a/CHANGES.txt	Tue Jan 12 05:56:16 2016 -0800
     1.2 +++ b/CHANGES.txt	Fri Jan 29 12:44:13 2016 -0800
     1.3 @@ -1,3 +1,7 @@
     1.4 +2.0.1:
     1.5 +Juha Kuikka - Fri Jan 29 12:44:01 PST 2016
     1.6 + * Added Mix_OpenAudioDevice() so you can specify the audio device to open
     1.7 +
     1.8  2.0.1:
     1.9  Sam Lantinga - Tue Jul  7 11:40:33 PDT 2015
    1.10   * Added support for 'smpl' format loop points in music WAV files
     2.1 --- a/SDL_mixer.h	Tue Jan 12 05:56:16 2016 -0800
     2.2 +++ b/SDL_mixer.h	Fri Jan 29 12:44:13 2016 -0800
     2.3 @@ -133,6 +133,9 @@
     2.4  /* Open the mixer with a certain audio format */
     2.5  extern DECLSPEC int SDLCALL Mix_OpenAudio(int frequency, Uint16 format, int channels, int chunksize);
     2.6  
     2.7 +/* Open the mixer with specific device and certain audio format */
     2.8 +extern DECLSPEC int SDLCALL Mix_OpenAudioDevice(int frequency, Uint16 format, int channels, int chunksize, const char* device, int allowed_changes);
     2.9 +
    2.10  /* Dynamically change the number of channels managed by the mixer.
    2.11     If decreasing the number of channels, the upper channels are
    2.12     stopped.
     3.1 --- a/effect_position.c	Tue Jan 12 05:56:16 2016 -0800
     3.2 +++ b/effect_position.c	Fri Jan 29 12:44:13 2016 -0800
     3.3 @@ -31,8 +31,9 @@
     3.4  #include <string.h>
     3.5  
     3.6  #include "SDL.h"
     3.7 +#include "SDL_endian.h"
     3.8  #include "SDL_mixer.h"
     3.9 -#include "SDL_endian.h"
    3.10 +#include "mixer.h"
    3.11  
    3.12  #define __MIX_INTERNAL_EFFECT__
    3.13  #include "effects_internal.h"
    3.14 @@ -1453,10 +1454,10 @@
    3.15      if (f == NULL)
    3.16          return(0);
    3.17  
    3.18 -    SDL_LockAudio();
    3.19 +    Mix_LockAudio();
    3.20      args = get_position_arg(channel);
    3.21      if (!args) {
    3.22 -        SDL_UnlockAudio();
    3.23 +        Mix_UnlockAudio();
    3.24          return(0);
    3.25      }
    3.26  
    3.27 @@ -1464,10 +1465,10 @@
    3.28      if ((args->distance_u8 == 255) && (left == 255) && (right == 255)) {
    3.29          if (args->in_use) {
    3.30              retval = _Mix_UnregisterEffect_locked(channel, f);
    3.31 -            SDL_UnlockAudio();
    3.32 +            Mix_UnlockAudio();
    3.33              return(retval);
    3.34          } else {
    3.35 -            SDL_UnlockAudio();
    3.36 +            Mix_UnlockAudio();
    3.37              return(1);
    3.38          }
    3.39      }
    3.40 @@ -1483,7 +1484,7 @@
    3.41          retval=_Mix_RegisterEffect_locked(channel, f, _Eff_PositionDone, (void*)args);
    3.42      }
    3.43  
    3.44 -    SDL_UnlockAudio();
    3.45 +    Mix_UnlockAudio();
    3.46      return(retval);
    3.47  }
    3.48  
    3.49 @@ -1501,10 +1502,10 @@
    3.50      if (f == NULL)
    3.51          return(0);
    3.52  
    3.53 -    SDL_LockAudio();
    3.54 +    Mix_LockAudio();
    3.55      args = get_position_arg(channel);
    3.56      if (!args) {
    3.57 -        SDL_UnlockAudio();
    3.58 +        Mix_UnlockAudio();
    3.59          return(0);
    3.60      }
    3.61  
    3.62 @@ -1514,10 +1515,10 @@
    3.63      if ((distance == 255) && (args->left_u8 == 255) && (args->right_u8 == 255)) {
    3.64          if (args->in_use) {
    3.65              retval = _Mix_UnregisterEffect_locked(channel, f);
    3.66 -            SDL_UnlockAudio();
    3.67 +            Mix_UnlockAudio();
    3.68              return(retval);
    3.69          } else {
    3.70 -            SDL_UnlockAudio();
    3.71 +            Mix_UnlockAudio();
    3.72              return(1);
    3.73          }
    3.74      }
    3.75 @@ -1529,7 +1530,7 @@
    3.76          retval = _Mix_RegisterEffect_locked(channel, f, _Eff_PositionDone, (void *) args);
    3.77      }
    3.78  
    3.79 -    SDL_UnlockAudio();
    3.80 +    Mix_UnlockAudio();
    3.81      return(retval);
    3.82  }
    3.83  
    3.84 @@ -1550,10 +1551,10 @@
    3.85  
    3.86      angle = SDL_abs(angle) % 360;  /* make angle between 0 and 359. */
    3.87  
    3.88 -    SDL_LockAudio();
    3.89 +    Mix_LockAudio();
    3.90      args = get_position_arg(channel);
    3.91      if (!args) {
    3.92 -        SDL_UnlockAudio();
    3.93 +        Mix_UnlockAudio();
    3.94          return(0);
    3.95      }
    3.96  
    3.97 @@ -1561,10 +1562,10 @@
    3.98      if ((!distance) && (!angle)) {
    3.99          if (args->in_use) {
   3.100              retval = _Mix_UnregisterEffect_locked(channel, f);
   3.101 -            SDL_UnlockAudio();
   3.102 +            Mix_UnlockAudio();
   3.103              return(retval);
   3.104          } else {
   3.105 -            SDL_UnlockAudio();
   3.106 +            Mix_UnlockAudio();
   3.107              return(1);
   3.108          }
   3.109      }
   3.110 @@ -1610,7 +1611,7 @@
   3.111          retval = _Mix_RegisterEffect_locked(channel, f, _Eff_PositionDone, (void *) args);
   3.112      }
   3.113  
   3.114 -    SDL_UnlockAudio();
   3.115 +    Mix_UnlockAudio();
   3.116      return(retval);
   3.117  }
   3.118  
     4.1 --- a/mixer.c	Tue Jan 12 05:56:16 2016 -0800
     4.2 +++ b/mixer.c	Fri Jan 29 12:44:13 2016 -0800
     4.3 @@ -30,6 +30,7 @@
     4.4  #include "SDL_timer.h"
     4.5  
     4.6  #include "SDL_mixer.h"
     4.7 +#include "mixer.h"
     4.8  #include "load_aiff.h"
     4.9  #include "load_voc.h"
    4.10  #include "load_mp3.h"
    4.11 @@ -55,6 +56,7 @@
    4.12  
    4.13  static int audio_opened = 0;
    4.14  static SDL_AudioSpec mixer;
    4.15 +static SDL_AudioDeviceID audio_device;
    4.16  
    4.17  typedef struct _Mix_effectinfo
    4.18  {
    4.19 @@ -257,7 +259,7 @@
    4.20  
    4.21  /*
    4.22   * rcg06122001 Cleanup effect callbacks.
    4.23 - *  MAKE SURE SDL_LockAudio() is called before this (or you're in the
    4.24 + *  MAKE SURE Mix_LockAudio() is called before this (or you're in the
    4.25   *   audio callback).
    4.26   */
    4.27  static void _Mix_channel_done_playing(int channel)
    4.28 @@ -362,7 +364,7 @@
    4.29                      }
    4.30  
    4.31                      mix_input = Mix_DoEffects(i, mix_channel[i].samples, mixable);
    4.32 -                    SDL_MixAudio(stream+index,mix_input,mixable,volume);
    4.33 +                    SDL_MixAudioFormat(stream+index,mix_input,mixer.format,mixable,volume);
    4.34                      if (mix_input != mix_channel[i].samples)
    4.35                          SDL_free(mix_input);
    4.36  
    4.37 @@ -386,7 +388,7 @@
    4.38                      }
    4.39  
    4.40                      mix_input = Mix_DoEffects(i, mix_channel[i].chunk->abuf, remaining);
    4.41 -                    SDL_MixAudio(stream+index, mix_input, remaining, volume);
    4.42 +                    SDL_MixAudioFormat(stream+index, mix_input, mixer.format, remaining, volume);
    4.43                      if (mix_input != mix_channel[i].chunk->abuf)
    4.44                          SDL_free(mix_input);
    4.45  
    4.46 @@ -426,9 +428,9 @@
    4.47  }
    4.48  #endif
    4.49  
    4.50 -
    4.51  /* Open the mixer with a certain desired audio format */
    4.52 -int Mix_OpenAudio(int frequency, Uint16 format, int nchannels, int chunksize)
    4.53 +int Mix_OpenAudioDevice(int frequency, Uint16 format, int nchannels, int chunksize,
    4.54 +			const char* device, int allowed_changes)
    4.55  {
    4.56      int i;
    4.57      SDL_AudioSpec desired;
    4.58 @@ -453,7 +455,7 @@
    4.59      desired.userdata = NULL;
    4.60  
    4.61      /* Accept nearly any audio format */
    4.62 -    if ( SDL_OpenAudio(&desired, &mixer) < 0 ) {
    4.63 +    if ( (audio_device = SDL_OpenAudioDevice(device, 0, &desired, &mixer, allowed_changes)) == 0 ) {
    4.64          return(-1);
    4.65      }
    4.66  #if 0
    4.67 @@ -462,7 +464,7 @@
    4.68  
    4.69      /* Initialize the music players */
    4.70      if ( open_music(&mixer) < 0 ) {
    4.71 -        SDL_CloseAudio();
    4.72 +        SDL_CloseAudioDevice(audio_device);
    4.73          return(-1);
    4.74      }
    4.75  
    4.76 @@ -502,10 +504,17 @@
    4.77  #endif
    4.78  
    4.79      audio_opened = 1;
    4.80 -    SDL_PauseAudio(0);
    4.81 +    SDL_PauseAudioDevice(audio_device, 0);
    4.82      return(0);
    4.83  }
    4.84  
    4.85 +/* Open the mixer with a certain desired audio format */
    4.86 +int Mix_OpenAudio(int frequency, Uint16 format, int nchannels, int chunksize)
    4.87 +{
    4.88 +    return Mix_OpenAudioDevice(frequency, format, nchannels, chunksize,
    4.89 +			       NULL, SDL_AUDIO_ALLOW_ANY_CHANGE);
    4.90 +}
    4.91 +
    4.92  /* Dynamically change the number of channels managed by the mixer.
    4.93     If decreasing the number of channels, the upper channels are
    4.94     stopped.
    4.95 @@ -523,7 +532,7 @@
    4.96              Mix_HaltChannel(i);
    4.97          }
    4.98      }
    4.99 -    SDL_LockAudio();
   4.100 +    Mix_LockAudio();
   4.101      mix_channel = (struct _Mix_Channel *) SDL_realloc(mix_channel, numchans * sizeof(struct _Mix_Channel));
   4.102      if ( numchans > num_channels ) {
   4.103          /* Initialize the new channels */
   4.104 @@ -543,7 +552,7 @@
   4.105          }
   4.106      }
   4.107      num_channels = numchans;
   4.108 -    SDL_UnlockAudio();
   4.109 +    Mix_UnlockAudio();
   4.110      return(num_channels);
   4.111  }
   4.112  
   4.113 @@ -786,7 +795,7 @@
   4.114      /* Caution -- if the chunk is playing, the mixer will crash */
   4.115      if ( chunk ) {
   4.116          /* Guarantee that this chunk isn't playing */
   4.117 -        SDL_LockAudio();
   4.118 +        Mix_LockAudio();
   4.119          if ( mix_channel ) {
   4.120              for ( i=0; i<num_channels; ++i ) {
   4.121                  if ( chunk == mix_channel[i].chunk ) {
   4.122 @@ -795,7 +804,7 @@
   4.123                  }
   4.124              }
   4.125          }
   4.126 -        SDL_UnlockAudio();
   4.127 +        Mix_UnlockAudio();
   4.128          /* Actually free the chunk */
   4.129          if ( chunk->allocated ) {
   4.130              SDL_free(chunk->abuf);
   4.131 @@ -811,10 +820,10 @@
   4.132  void Mix_SetPostMix(void (*mix_func)
   4.133                      (void *udata, Uint8 *stream, int len), void *arg)
   4.134  {
   4.135 -    SDL_LockAudio();
   4.136 +    Mix_LockAudio();
   4.137      mix_postmix_data = arg;
   4.138      mix_postmix = mix_func;
   4.139 -    SDL_UnlockAudio();
   4.140 +    Mix_UnlockAudio();
   4.141  }
   4.142  
   4.143  /* Add your own music player or mixer function.
   4.144 @@ -823,7 +832,7 @@
   4.145  void Mix_HookMusic(void (*mix_func)(void *udata, Uint8 *stream, int len),
   4.146                                                                  void *arg)
   4.147  {
   4.148 -    SDL_LockAudio();
   4.149 +    Mix_LockAudio();
   4.150      if ( mix_func != NULL ) {
   4.151          music_data = arg;
   4.152          mix_music = mix_func;
   4.153 @@ -831,7 +840,7 @@
   4.154          music_data = NULL;
   4.155          mix_music = music_mixer;
   4.156      }
   4.157 -    SDL_UnlockAudio();
   4.158 +    Mix_UnlockAudio();
   4.159  }
   4.160  
   4.161  void *Mix_GetMusicHookData(void)
   4.162 @@ -841,9 +850,9 @@
   4.163  
   4.164  void Mix_ChannelFinished(void (*channel_finished)(int channel))
   4.165  {
   4.166 -    SDL_LockAudio();
   4.167 +    Mix_LockAudio();
   4.168      channel_done_callback = channel_finished;
   4.169 -    SDL_UnlockAudio();
   4.170 +    Mix_UnlockAudio();
   4.171  }
   4.172  
   4.173  
   4.174 @@ -890,7 +899,7 @@
   4.175      }
   4.176  
   4.177      /* Lock the mixer while modifying the playing channels */
   4.178 -    SDL_LockAudio();
   4.179 +    Mix_LockAudio();
   4.180      {
   4.181          /* If which is -1, play on the first free channel */
   4.182          if ( which == -1 ) {
   4.183 @@ -921,7 +930,7 @@
   4.184              mix_channel[which].expire = (ticks>0) ? (sdl_ticks + ticks) : 0;
   4.185          }
   4.186      }
   4.187 -    SDL_UnlockAudio();
   4.188 +    Mix_UnlockAudio();
   4.189  
   4.190      /* Return the channel on which the sound is being played */
   4.191      return(which);
   4.192 @@ -938,9 +947,9 @@
   4.193              status += Mix_ExpireChannel(i, ticks);
   4.194          }
   4.195      } else if ( which < num_channels ) {
   4.196 -        SDL_LockAudio();
   4.197 +        Mix_LockAudio();
   4.198          mix_channel[which].expire = (ticks>0) ? (SDL_GetTicks() + ticks) : 0;
   4.199 -        SDL_UnlockAudio();
   4.200 +        Mix_UnlockAudio();
   4.201          ++ status;
   4.202      }
   4.203      return(status);
   4.204 @@ -961,7 +970,7 @@
   4.205      }
   4.206  
   4.207      /* Lock the mixer while modifying the playing channels */
   4.208 -    SDL_LockAudio();
   4.209 +    Mix_LockAudio();
   4.210      {
   4.211          /* If which is -1, play on the first free channel */
   4.212          if ( which == -1 ) {
   4.213 @@ -995,7 +1004,7 @@
   4.214              mix_channel[which].expire = (ticks > 0) ? (sdl_ticks+ticks) : 0;
   4.215          }
   4.216      }
   4.217 -    SDL_UnlockAudio();
   4.218 +    Mix_UnlockAudio();
   4.219  
   4.220      /* Return the channel on which the sound is being played */
   4.221      return(which);
   4.222 @@ -1048,7 +1057,7 @@
   4.223              Mix_HaltChannel(i);
   4.224          }
   4.225      } else if ( which < num_channels ) {
   4.226 -        SDL_LockAudio();
   4.227 +        Mix_LockAudio();
   4.228          if (mix_channel[which].playing) {
   4.229              _Mix_channel_done_playing(which);
   4.230              mix_channel[which].playing = 0;
   4.231 @@ -1058,7 +1067,7 @@
   4.232          if(mix_channel[which].fading != MIX_NO_FADING) /* Restore volume */
   4.233              mix_channel[which].volume = mix_channel[which].fade_volume_reset;
   4.234          mix_channel[which].fading = MIX_NO_FADING;
   4.235 -        SDL_UnlockAudio();
   4.236 +        Mix_UnlockAudio();
   4.237      }
   4.238      return(0);
   4.239  }
   4.240 @@ -1090,7 +1099,7 @@
   4.241                  status += Mix_FadeOutChannel(i, ms);
   4.242              }
   4.243          } else if ( which < num_channels ) {
   4.244 -            SDL_LockAudio();
   4.245 +            Mix_LockAudio();
   4.246              if ( mix_channel[which].playing &&
   4.247                  (mix_channel[which].volume > 0) &&
   4.248                  (mix_channel[which].fading != MIX_FADING_OUT) ) {
   4.249 @@ -1105,7 +1114,7 @@
   4.250                  }
   4.251                  ++status;
   4.252              }
   4.253 -            SDL_UnlockAudio();
   4.254 +            Mix_UnlockAudio();
   4.255          }
   4.256      }
   4.257      return(status);
   4.258 @@ -1186,7 +1195,8 @@
   4.259              close_music();
   4.260              Mix_HaltChannel(-1);
   4.261              _Mix_DeinitEffects();
   4.262 -            SDL_CloseAudio();
   4.263 +            SDL_CloseAudioDevice(audio_device);
   4.264 +	    audio_device = 0;
   4.265              SDL_free(mix_channel);
   4.266              mix_channel = NULL;
   4.267  
   4.268 @@ -1223,7 +1233,7 @@
   4.269  {
   4.270      Uint32 sdl_ticks = SDL_GetTicks();
   4.271  
   4.272 -    SDL_LockAudio();
   4.273 +    Mix_LockAudio();
   4.274      if ( which == -1 ) {
   4.275          int i;
   4.276  
   4.277 @@ -1241,7 +1251,7 @@
   4.278              mix_channel[which].paused = 0;
   4.279          }
   4.280      }
   4.281 -    SDL_UnlockAudio();
   4.282 +    Mix_UnlockAudio();
   4.283  }
   4.284  
   4.285  int Mix_Paused(int which)
   4.286 @@ -1268,9 +1278,9 @@
   4.287      if ( which < 0 || which > num_channels )
   4.288          return(0);
   4.289  
   4.290 -    SDL_LockAudio();
   4.291 +    Mix_LockAudio();
   4.292      mix_channel[which].tag = tag;
   4.293 -    SDL_UnlockAudio();
   4.294 +    Mix_UnlockAudio();
   4.295      return(1);
   4.296  }
   4.297  
   4.298 @@ -1347,7 +1357,7 @@
   4.299   *  as Mix_SetPanning().
   4.300   */
   4.301  
   4.302 -/* MAKE SURE you hold the audio lock (SDL_LockAudio()) before calling this! */
   4.303 +/* MAKE SURE you hold the audio lock (Mix_LockAudio()) before calling this! */
   4.304  static int _Mix_register_effect(effect_info **e, Mix_EffectFunc_t f,
   4.305                  Mix_EffectDone_t d, void *arg)
   4.306  {
   4.307 @@ -1392,7 +1402,7 @@
   4.308  }
   4.309  
   4.310  
   4.311 -/* MAKE SURE you hold the audio lock (SDL_LockAudio()) before calling this! */
   4.312 +/* MAKE SURE you hold the audio lock (Mix_LockAudio()) before calling this! */
   4.313  static int _Mix_remove_effect(int channel, effect_info **e, Mix_EffectFunc_t f)
   4.314  {
   4.315      effect_info *cur;
   4.316 @@ -1427,7 +1437,7 @@
   4.317  }
   4.318  
   4.319  
   4.320 -/* MAKE SURE you hold the audio lock (SDL_LockAudio()) before calling this! */
   4.321 +/* MAKE SURE you hold the audio lock (Mix_LockAudio()) before calling this! */
   4.322  static int _Mix_remove_all_effects(int channel, effect_info **e)
   4.323  {
   4.324      effect_info *cur;
   4.325 @@ -1451,7 +1461,7 @@
   4.326  }
   4.327  
   4.328  
   4.329 -/* MAKE SURE you hold the audio lock (SDL_LockAudio()) before calling this! */
   4.330 +/* MAKE SURE you hold the audio lock (Mix_LockAudio()) before calling this! */
   4.331  int _Mix_RegisterEffect_locked(int channel, Mix_EffectFunc_t f,
   4.332              Mix_EffectDone_t d, void *arg)
   4.333  {
   4.334 @@ -1474,14 +1484,14 @@
   4.335              Mix_EffectDone_t d, void *arg)
   4.336  {
   4.337      int retval;
   4.338 -    SDL_LockAudio();
   4.339 +    Mix_LockAudio();
   4.340      retval = _Mix_RegisterEffect_locked(channel, f, d, arg);
   4.341 -    SDL_UnlockAudio();
   4.342 +    Mix_UnlockAudio();
   4.343      return retval;
   4.344  }
   4.345  
   4.346  
   4.347 -/* MAKE SURE you hold the audio lock (SDL_LockAudio()) before calling this! */
   4.348 +/* MAKE SURE you hold the audio lock (Mix_LockAudio()) before calling this! */
   4.349  int _Mix_UnregisterEffect_locked(int channel, Mix_EffectFunc_t f)
   4.350  {
   4.351      effect_info **e = NULL;
   4.352 @@ -1502,13 +1512,13 @@
   4.353  int Mix_UnregisterEffect(int channel, Mix_EffectFunc_t f)
   4.354  {
   4.355      int retval;
   4.356 -    SDL_LockAudio();
   4.357 +    Mix_LockAudio();
   4.358      retval = _Mix_UnregisterEffect_locked(channel, f);
   4.359 -    SDL_UnlockAudio();
   4.360 +    Mix_UnlockAudio();
   4.361      return(retval);
   4.362  }
   4.363  
   4.364 -/* MAKE SURE you hold the audio lock (SDL_LockAudio()) before calling this! */
   4.365 +/* MAKE SURE you hold the audio lock (Mix_LockAudio()) before calling this! */
   4.366  int _Mix_UnregisterAllEffects_locked(int channel)
   4.367  {
   4.368      effect_info **e = NULL;
   4.369 @@ -1529,11 +1539,21 @@
   4.370  int Mix_UnregisterAllEffects(int channel)
   4.371  {
   4.372      int retval;
   4.373 -    SDL_LockAudio();
   4.374 +    Mix_LockAudio();
   4.375      retval = _Mix_UnregisterAllEffects_locked(channel);
   4.376 -    SDL_UnlockAudio();
   4.377 +    Mix_UnlockAudio();
   4.378      return(retval);
   4.379  }
   4.380  
   4.381 +void Mix_LockAudio()
   4.382 +{
   4.383 +    SDL_LockAudioDevice(audio_device);
   4.384 +}
   4.385 +
   4.386 +void Mix_UnlockAudio()
   4.387 +{
   4.388 +    SDL_UnlockAudioDevice(audio_device);
   4.389 +}
   4.390 +
   4.391  /* end of mixer.c ... */
   4.392  
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/mixer.h	Fri Jan 29 12:44:13 2016 -0800
     5.3 @@ -0,0 +1,25 @@
     5.4 +/*
     5.5 +  SDL_mixer:  An audio mixer library based on the SDL library
     5.6 +  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
     5.7 +
     5.8 +  This software is provided 'as-is', without any express or implied
     5.9 +  warranty.  In no event will the authors be held liable for any damages
    5.10 +  arising from the use of this software.
    5.11 +
    5.12 +  Permission is granted to anyone to use this software for any purpose,
    5.13 +  including commercial applications, and to alter it and redistribute it
    5.14 +  freely, subject to the following restrictions:
    5.15 +
    5.16 +  1. The origin of this software must not be misrepresented; you must not
    5.17 +     claim that you wrote the original software. If you use this software
    5.18 +     in a product, an acknowledgment in the product documentation would be
    5.19 +     appreciated but is not required.
    5.20 +  2. Altered source versions must be plainly marked as such, and must not be
    5.21 +     misrepresented as being the original software.
    5.22 +  3. This notice may not be removed or altered from any source distribution.
    5.23 +*/
    5.24 +
    5.25 +/* Locking wrapper functions */
    5.26 +void Mix_LockAudio();
    5.27 +void Mix_UnlockAudio();
    5.28 +
     6.1 --- a/music.c	Tue Jan 12 05:56:16 2016 -0800
     6.2 +++ b/music.c	Fri Jan 29 12:44:13 2016 -0800
     6.3 @@ -30,6 +30,7 @@
     6.4  #include "SDL_timer.h"
     6.5  
     6.6  #include "SDL_mixer.h"
     6.7 +#include "mixer.h"
     6.8  
     6.9  #ifdef CMD_MUSIC
    6.10  #include "music_cmd.h"
    6.11 @@ -185,9 +186,9 @@
    6.12  
    6.13  void Mix_HookMusicFinished(void (*music_finished)(void))
    6.14  {
    6.15 -    SDL_LockAudio();
    6.16 +    Mix_LockAudio();
    6.17      music_finished_hook = music_finished;
    6.18 -    SDL_UnlockAudio();
    6.19 +    Mix_UnlockAudio();
    6.20  }
    6.21  
    6.22  
    6.23 @@ -765,19 +766,19 @@
    6.24  {
    6.25      if ( music ) {
    6.26          /* Stop the music if it's currently playing */
    6.27 -        SDL_LockAudio();
    6.28 +        Mix_LockAudio();
    6.29          if ( music == music_playing ) {
    6.30              /* Wait for any fade out to finish */
    6.31              while ( music->fading == MIX_FADING_OUT ) {
    6.32 -                SDL_UnlockAudio();
    6.33 +                Mix_UnlockAudio();
    6.34                  SDL_Delay(100);
    6.35 -                SDL_LockAudio();
    6.36 +                Mix_LockAudio();
    6.37              }
    6.38              if ( music == music_playing ) {
    6.39                  music_internal_halt();
    6.40              }
    6.41          }
    6.42 -        SDL_UnlockAudio();
    6.43 +        Mix_UnlockAudio();
    6.44          switch (music->type) {
    6.45  #ifdef CMD_MUSIC
    6.46              case MUS_CMD:
    6.47 @@ -861,11 +862,11 @@
    6.48      if ( music ) {
    6.49          type = music->type;
    6.50      } else {
    6.51 -        SDL_LockAudio();
    6.52 +        Mix_LockAudio();
    6.53          if ( music_playing ) {
    6.54              type = music_playing->type;
    6.55          }
    6.56 -        SDL_UnlockAudio();
    6.57 +        Mix_UnlockAudio();
    6.58      }
    6.59      return(type);
    6.60  }
    6.61 @@ -1018,12 +1019,12 @@
    6.62      music->fade_steps = ms/ms_per_step;
    6.63  
    6.64      /* Play the puppy */
    6.65 -    SDL_LockAudio();
    6.66 +    Mix_LockAudio();
    6.67      /* If the current music is fading out, wait for the fade to complete */
    6.68      while ( music_playing && (music_playing->fading == MIX_FADING_OUT) ) {
    6.69 -        SDL_UnlockAudio();
    6.70 +        Mix_UnlockAudio();
    6.71          SDL_Delay(100);
    6.72 -        SDL_LockAudio();
    6.73 +        Mix_LockAudio();
    6.74      }
    6.75      music_active = 1;
    6.76      if (loops == 1) {
    6.77 @@ -1032,7 +1033,7 @@
    6.78      }
    6.79      music_loops = loops;
    6.80      retval = music_internal_play(music, position);
    6.81 -    SDL_UnlockAudio();
    6.82 +    Mix_UnlockAudio();
    6.83  
    6.84      return(retval);
    6.85  }
    6.86 @@ -1096,7 +1097,7 @@
    6.87  {
    6.88      int retval;
    6.89  
    6.90 -    SDL_LockAudio();
    6.91 +    Mix_LockAudio();
    6.92      if ( music_playing ) {
    6.93          retval = music_internal_position(position);
    6.94          if ( retval < 0 ) {
    6.95 @@ -1106,7 +1107,7 @@
    6.96          Mix_SetError("Music isn't playing");
    6.97          retval = -1;
    6.98      }
    6.99 -    SDL_UnlockAudio();
   6.100 +    Mix_UnlockAudio();
   6.101  
   6.102      return(retval);
   6.103  }
   6.104 @@ -1204,11 +1205,11 @@
   6.105          volume = SDL_MIX_MAXVOLUME;
   6.106      }
   6.107      music_volume = volume;
   6.108 -    SDL_LockAudio();
   6.109 +    Mix_LockAudio();
   6.110      if ( music_playing ) {
   6.111          music_internal_volume(music_volume);
   6.112      }
   6.113 -    SDL_UnlockAudio();
   6.114 +    Mix_UnlockAudio();
   6.115      return(prev_volume);
   6.116  }
   6.117  
   6.118 @@ -1289,14 +1290,14 @@
   6.119  }
   6.120  int Mix_HaltMusic(void)
   6.121  {
   6.122 -    SDL_LockAudio();
   6.123 +    Mix_LockAudio();
   6.124      if ( music_playing ) {
   6.125          music_internal_halt();
   6.126          if ( music_finished_hook ) {
   6.127              music_finished_hook();
   6.128          }
   6.129      }
   6.130 -    SDL_UnlockAudio();
   6.131 +    Mix_UnlockAudio();
   6.132  
   6.133      return(0);
   6.134  }
   6.135 @@ -1316,7 +1317,7 @@
   6.136          return 1;
   6.137      }
   6.138  
   6.139 -    SDL_LockAudio();
   6.140 +    Mix_LockAudio();
   6.141      if ( music_playing) {
   6.142                  int fade_steps = (ms + ms_per_step - 1)/ms_per_step;
   6.143                  if ( music_playing->fading == MIX_NO_FADING ) {
   6.144 @@ -1337,7 +1338,7 @@
   6.145          music_playing->fade_steps = fade_steps;
   6.146          retval = 1;
   6.147      }
   6.148 -    SDL_UnlockAudio();
   6.149 +    Mix_UnlockAudio();
   6.150  
   6.151      return(retval);
   6.152  }
   6.153 @@ -1346,11 +1347,11 @@
   6.154  {
   6.155      Mix_Fading fading = MIX_NO_FADING;
   6.156  
   6.157 -    SDL_LockAudio();
   6.158 +    Mix_LockAudio();
   6.159      if ( music_playing ) {
   6.160          fading = music_playing->fading;
   6.161      }
   6.162 -    SDL_UnlockAudio();
   6.163 +    Mix_UnlockAudio();
   6.164  
   6.165      return(fading);
   6.166  }
   6.167 @@ -1478,11 +1479,11 @@
   6.168  {
   6.169      int playing = 0;
   6.170  
   6.171 -    SDL_LockAudio();
   6.172 +    Mix_LockAudio();
   6.173      if ( music_playing ) {
   6.174          playing = music_loops || music_internal_playing();
   6.175      }
   6.176 -    SDL_UnlockAudio();
   6.177 +    Mix_UnlockAudio();
   6.178  
   6.179      return(playing);
   6.180  }
     7.1 --- a/native_midi/native_midi_mac.c	Tue Jan 12 05:56:16 2016 -0800
     7.2 +++ b/native_midi/native_midi_mac.c	Fri Jan 29 12:44:13 2016 -0800
     7.3 @@ -20,6 +20,7 @@
     7.4  */
     7.5  #include "SDL_config.h"
     7.6  #include "SDL_endian.h"
     7.7 +#include "../mixer.h"
     7.8  
     7.9  #if __MACOS__ /*|| __MACOSX__ */
    7.10  
    7.11 @@ -187,7 +188,7 @@
    7.12      assert (loops == 0);
    7.13  
    7.14      SDL_PauseAudio(1);
    7.15 -    SDL_UnlockAudio();
    7.16 +    Mix_UnlockAudio();
    7.17  
    7.18      /* First, stop the currently playing music */
    7.19      native_midi_stop();
    7.20 @@ -237,7 +238,7 @@
    7.21      }
    7.22  
    7.23  done:
    7.24 -    SDL_LockAudio();
    7.25 +    Mix_LockAudio();
    7.26      SDL_PauseAudio(0);
    7.27  }
    7.28  
     8.1 --- a/native_midi/native_midi_macosx.c	Tue Jan 12 05:56:16 2016 -0800
     8.2 +++ b/native_midi/native_midi_macosx.c	Fri Jan 29 12:44:13 2016 -0800
     8.3 @@ -31,8 +31,9 @@
     8.4  #include <AudioToolbox/AudioToolbox.h>
     8.5  #include <AvailabilityMacros.h>
     8.6  
     8.7 +#include "SDL_endian.h"
     8.8  #include "../SDL_mixer.h"
     8.9 -#include "SDL_endian.h"
    8.10 +#include "../mixer.h"
    8.11  #include "native_midi.h"
    8.12  
    8.13  /* Native Midi song */
    8.14 @@ -264,7 +265,7 @@
    8.15          return;
    8.16  
    8.17      SDL_PauseAudio(1);
    8.18 -    SDL_UnlockAudio();
    8.19 +    Mix_UnlockAudio();
    8.20  
    8.21      if (currentsong)
    8.22          MusicPlayerStop(currentsong->player);
    8.23 @@ -282,7 +283,7 @@
    8.24      latched_volume++;  /* just make this not match. */
    8.25      native_midi_setvolume(vol);
    8.26  
    8.27 -    SDL_LockAudio();
    8.28 +    Mix_LockAudio();
    8.29      SDL_PauseAudio(0);
    8.30  }
    8.31  
    8.32 @@ -290,10 +291,10 @@
    8.33  {
    8.34      if (currentsong) {
    8.35          SDL_PauseAudio(1);
    8.36 -        SDL_UnlockAudio();
    8.37 +        Mix_UnlockAudio();
    8.38          MusicPlayerStop(currentsong->player);
    8.39          currentsong = NULL;
    8.40 -        SDL_LockAudio();
    8.41 +        Mix_LockAudio();
    8.42          SDL_PauseAudio(0);
    8.43      }
    8.44  }
     9.1 --- a/wavestream.c	Tue Jan 12 05:56:16 2016 -0800
     9.2 +++ b/wavestream.c	Fri Jan 29 12:44:13 2016 -0800
     9.3 @@ -241,7 +241,7 @@
     9.4          }
     9.5          music->cvt.len = original_len;
     9.6          SDL_ConvertAudio(&music->cvt);
     9.7 -        SDL_MixAudio(stream, music->cvt.buf, music->cvt.len_cvt, wavestream_volume);
     9.8 +        SDL_MixAudioFormat(stream, music->cvt.buf, mixer.format,music->cvt.len_cvt, wavestream_volume);
     9.9          consumed = music->cvt.len_cvt;
    9.10      } else {
    9.11          Uint8 *data;
    9.12 @@ -251,7 +251,7 @@
    9.13          data = SDL_stack_alloc(Uint8, len);
    9.14          if (data) {
    9.15              len = SDL_RWread(music->src, data, 1, len);
    9.16 -            SDL_MixAudio(stream, data, len, wavestream_volume);
    9.17 +            SDL_MixAudioFormat(stream, data, mixer.format, len, wavestream_volume);
    9.18              SDL_stack_free(data);
    9.19          }
    9.20          consumed = len;