effect_position.c
changeset 442 884a700fb3ff
parent 441 f86cc112a195
child 518 8bc9b5fd2aae
     1.1 --- a/effect_position.c	Sat Oct 10 17:05:45 2009 +0000
     1.2 +++ b/effect_position.c	Sun Oct 11 02:59:12 2009 +0000
     1.3 @@ -1427,6 +1427,8 @@
     1.4      int channels;
     1.5      Uint16 format;
     1.6      position_args *args = NULL;
     1.7 +    int retval = 1;
     1.8 +
     1.9      Mix_QuerySpec(NULL, &format, &channels);
    1.10  
    1.11      if (channels != 2 && channels != 4 && channels != 6)    /* it's a no-op; we call that successful. */
    1.12 @@ -1449,16 +1451,22 @@
    1.13      if (f == NULL)
    1.14          return(0);
    1.15  
    1.16 +    SDL_LockAudio();
    1.17      args = get_position_arg(channel);
    1.18 -    if (!args)
    1.19 +    if (!args) {
    1.20 +        SDL_UnlockAudio();
    1.21          return(0);
    1.22 +    }
    1.23  
    1.24          /* it's a no-op; unregister the effect, if it's registered. */
    1.25      if ((args->distance_u8 == 255) && (left == 255) && (right == 255)) {
    1.26          if (args->in_use) {
    1.27 -            return(Mix_UnregisterEffect(channel, f));
    1.28 +            retval = _Mix_UnregisterEffect_locked(channel, f);
    1.29 +            SDL_UnlockAudio();
    1.30 +            return(retval);
    1.31          } else {
    1.32 -	  return(1);
    1.33 +            SDL_UnlockAudio();
    1.34 +            return(1);
    1.35          }
    1.36      }
    1.37  
    1.38 @@ -1470,10 +1478,11 @@
    1.39  
    1.40      if (!args->in_use) {
    1.41          args->in_use = 1;
    1.42 -        return(Mix_RegisterEffect(channel, f, _Eff_PositionDone, (void *) args));
    1.43 +        retval=_Mix_RegisterEffect_locked(channel, f, _Eff_PositionDone, (void*)args);
    1.44      }
    1.45  
    1.46 -    return(1);
    1.47 +    SDL_UnlockAudio();
    1.48 +    return(retval);
    1.49  }
    1.50  
    1.51  
    1.52 @@ -1483,23 +1492,30 @@
    1.53      Uint16 format;
    1.54      position_args *args = NULL;
    1.55      int channels;
    1.56 +    int retval = 1;
    1.57  
    1.58      Mix_QuerySpec(NULL, &format, &channels);
    1.59      f = get_position_effect_func(format, channels);
    1.60      if (f == NULL)
    1.61          return(0);
    1.62  
    1.63 +    SDL_LockAudio();
    1.64      args = get_position_arg(channel);
    1.65 -    if (!args)
    1.66 +    if (!args) {
    1.67 +        SDL_UnlockAudio();
    1.68          return(0);
    1.69 +    }
    1.70  
    1.71      distance = 255 - distance;  /* flip it to our scale. */
    1.72  
    1.73          /* it's a no-op; unregister the effect, if it's registered. */
    1.74      if ((distance == 255) && (args->left_u8 == 255) && (args->right_u8 == 255)) {
    1.75          if (args->in_use) {
    1.76 -            return(Mix_UnregisterEffect(channel, f));
    1.77 +            retval = _Mix_UnregisterEffect_locked(channel, f);
    1.78 +            SDL_UnlockAudio();
    1.79 +            return(retval);
    1.80          } else {
    1.81 +            SDL_UnlockAudio();
    1.82              return(1);
    1.83          }
    1.84      }
    1.85 @@ -1508,10 +1524,11 @@
    1.86      args->distance_f = ((float) distance) / 255.0f;
    1.87      if (!args->in_use) {
    1.88          args->in_use = 1;
    1.89 -        return(Mix_RegisterEffect(channel, f, _Eff_PositionDone, (void *) args));
    1.90 +        retval = _Mix_RegisterEffect_locked(channel, f, _Eff_PositionDone, (void *) args);
    1.91      }
    1.92  
    1.93 -    return(1);
    1.94 +    SDL_UnlockAudio();
    1.95 +    return(retval);
    1.96  }
    1.97  
    1.98  
    1.99 @@ -1522,6 +1539,7 @@
   1.100      int channels;
   1.101      position_args *args = NULL;
   1.102      Sint16 room_angle = 0;
   1.103 +    int retval = 1;
   1.104  
   1.105      Mix_QuerySpec(NULL, &format, &channels);
   1.106      f = get_position_effect_func(format, channels);
   1.107 @@ -1530,17 +1548,23 @@
   1.108  
   1.109      angle = SDL_abs(angle) % 360;  /* make angle between 0 and 359. */
   1.110  
   1.111 +    SDL_LockAudio();
   1.112      args = get_position_arg(channel);
   1.113 -    if (!args)
   1.114 +    if (!args) {
   1.115 +        SDL_UnlockAudio();
   1.116          return(0);
   1.117 +    }
   1.118  
   1.119          /* it's a no-op; unregister the effect, if it's registered. */
   1.120      if ((!distance) && (!angle)) {
   1.121          if (args->in_use) {
   1.122 -            return(Mix_UnregisterEffect(channel, f));
   1.123 +            retval = _Mix_UnregisterEffect_locked(channel, f);
   1.124 +            SDL_UnlockAudio();
   1.125 +            return(retval);
   1.126          } else {
   1.127 -	  return(1);
   1.128 -	}
   1.129 +            SDL_UnlockAudio();
   1.130 +            return(1);
   1.131 +        }
   1.132      }
   1.133  
   1.134      if (channels == 2)
   1.135 @@ -1581,10 +1605,11 @@
   1.136      args->room_angle = room_angle;
   1.137      if (!args->in_use) {
   1.138          args->in_use = 1;
   1.139 -        return(Mix_RegisterEffect(channel, f, _Eff_PositionDone, (void *) args));
   1.140 +        retval = _Mix_RegisterEffect_locked(channel, f, _Eff_PositionDone, (void *) args);
   1.141      }
   1.142  
   1.143 -    return(1);
   1.144 +    SDL_UnlockAudio();
   1.145 +    return(retval);
   1.146  }
   1.147  
   1.148