mixer.c
changeset 617 87116a42526e
parent 601 05123263dab3
child 621 944412baab72
     1.1 --- a/mixer.c	Tue May 21 21:09:26 2013 -0700
     1.2 +++ b/mixer.c	Tue May 21 21:21:23 2013 -0700
     1.3 @@ -43,40 +43,40 @@
     1.4  #include "effects_internal.h"
     1.5  
     1.6  /* Magic numbers for various audio file formats */
     1.7 -#define RIFF		0x46464952		/* "RIFF" */
     1.8 -#define WAVE		0x45564157		/* "WAVE" */
     1.9 -#define FORM		0x4d524f46		/* "FORM" */
    1.10 -#define OGGS		0x5367674f		/* "OggS" */
    1.11 -#define CREA		0x61657243		/* "Crea" */
    1.12 -#define FLAC		0x43614C66		/* "fLaC" */
    1.13 +#define RIFF        0x46464952      /* "RIFF" */
    1.14 +#define WAVE        0x45564157      /* "WAVE" */
    1.15 +#define FORM        0x4d524f46      /* "FORM" */
    1.16 +#define OGGS        0x5367674f      /* "OggS" */
    1.17 +#define CREA        0x61657243      /* "Crea" */
    1.18 +#define FLAC        0x43614C66      /* "fLaC" */
    1.19  
    1.20  static int audio_opened = 0;
    1.21  static SDL_AudioSpec mixer;
    1.22  
    1.23  typedef struct _Mix_effectinfo
    1.24  {
    1.25 -	Mix_EffectFunc_t callback;
    1.26 -	Mix_EffectDone_t done_callback;
    1.27 -	void *udata;
    1.28 -	struct _Mix_effectinfo *next;
    1.29 +    Mix_EffectFunc_t callback;
    1.30 +    Mix_EffectDone_t done_callback;
    1.31 +    void *udata;
    1.32 +    struct _Mix_effectinfo *next;
    1.33  } effect_info;
    1.34  
    1.35  static struct _Mix_Channel {
    1.36 -	Mix_Chunk *chunk;
    1.37 -	int playing;
    1.38 -	int paused;
    1.39 -	Uint8 *samples;
    1.40 -	int volume;
    1.41 -	int looping;
    1.42 -	int tag;
    1.43 -	Uint32 expire;
    1.44 -	Uint32 start_time;
    1.45 -	Mix_Fading fading;
    1.46 -	int fade_volume;
    1.47 -	int fade_volume_reset;
    1.48 -	Uint32 fade_length;
    1.49 -	Uint32 ticks_fade;
    1.50 -	effect_info *effects;
    1.51 +    Mix_Chunk *chunk;
    1.52 +    int playing;
    1.53 +    int paused;
    1.54 +    Uint8 *samples;
    1.55 +    int volume;
    1.56 +    int looping;
    1.57 +    int tag;
    1.58 +    Uint32 expire;
    1.59 +    Uint32 start_time;
    1.60 +    Mix_Fading fading;
    1.61 +    int fade_volume;
    1.62 +    int fade_volume_reset;
    1.63 +    Uint32 fade_length;
    1.64 +    Uint32 ticks_fade;
    1.65 +    effect_info *effects;
    1.66  } *mix_channel = NULL;
    1.67  
    1.68  static effect_info *posteffects = NULL;
    1.69 @@ -113,124 +113,124 @@
    1.70  
    1.71  int Mix_GetNumChunkDecoders(void)
    1.72  {
    1.73 -	return(num_decoders);
    1.74 +    return(num_decoders);
    1.75  }
    1.76  
    1.77  const char *Mix_GetChunkDecoder(int index)
    1.78  {
    1.79 -	if ((index < 0) || (index >= num_decoders)) {
    1.80 -		return NULL;
    1.81 -	}
    1.82 -	return(chunk_decoders[index]);
    1.83 +    if ((index < 0) || (index >= num_decoders)) {
    1.84 +        return NULL;
    1.85 +    }
    1.86 +    return(chunk_decoders[index]);
    1.87  }
    1.88  
    1.89  static void add_chunk_decoder(const char *decoder)
    1.90  {
    1.91 -	void *ptr = SDL_realloc(chunk_decoders, (num_decoders + 1) * sizeof (const char **));
    1.92 -	if (ptr == NULL) {
    1.93 -		return;  /* oh well, go on without it. */
    1.94 -	}
    1.95 -	chunk_decoders = (const char **) ptr;
    1.96 -	chunk_decoders[num_decoders++] = decoder;
    1.97 +    void *ptr = SDL_realloc(chunk_decoders, (num_decoders + 1) * sizeof (const char **));
    1.98 +    if (ptr == NULL) {
    1.99 +        return;  /* oh well, go on without it. */
   1.100 +    }
   1.101 +    chunk_decoders = (const char **) ptr;
   1.102 +    chunk_decoders[num_decoders++] = decoder;
   1.103  }
   1.104  
   1.105  /* rcg06192001 get linked library's version. */
   1.106  const SDL_version *Mix_Linked_Version(void)
   1.107  {
   1.108 -	static SDL_version linked_version;
   1.109 -	SDL_MIXER_VERSION(&linked_version);
   1.110 -	return(&linked_version);
   1.111 +    static SDL_version linked_version;
   1.112 +    SDL_MIXER_VERSION(&linked_version);
   1.113 +    return(&linked_version);
   1.114  }
   1.115  
   1.116  static int initialized = 0;
   1.117  
   1.118  int Mix_Init(int flags)
   1.119  {
   1.120 -	int result = 0;
   1.121 +    int result = 0;
   1.122  
   1.123 -	if (flags & MIX_INIT_FLUIDSYNTH) {
   1.124 +    if (flags & MIX_INIT_FLUIDSYNTH) {
   1.125  #ifdef USE_FLUIDSYNTH_MIDI
   1.126 -		if ((initialized & MIX_INIT_FLUIDSYNTH) || Mix_InitFluidSynth() == 0) {
   1.127 -			result |= MIX_INIT_FLUIDSYNTH;
   1.128 -		}
   1.129 +        if ((initialized & MIX_INIT_FLUIDSYNTH) || Mix_InitFluidSynth() == 0) {
   1.130 +            result |= MIX_INIT_FLUIDSYNTH;
   1.131 +        }
   1.132  #else
   1.133 -		Mix_SetError("Mixer not built with FluidSynth support");
   1.134 +        Mix_SetError("Mixer not built with FluidSynth support");
   1.135  #endif
   1.136 -	}
   1.137 -	if (flags & MIX_INIT_FLAC) {
   1.138 +    }
   1.139 +    if (flags & MIX_INIT_FLAC) {
   1.140  #ifdef FLAC_MUSIC
   1.141 -		if ((initialized & MIX_INIT_FLAC) || Mix_InitFLAC() == 0) {
   1.142 -			result |= MIX_INIT_FLAC;
   1.143 -		}
   1.144 +        if ((initialized & MIX_INIT_FLAC) || Mix_InitFLAC() == 0) {
   1.145 +            result |= MIX_INIT_FLAC;
   1.146 +        }
   1.147  #else
   1.148 -		Mix_SetError("Mixer not built with FLAC support");
   1.149 +        Mix_SetError("Mixer not built with FLAC support");
   1.150  #endif
   1.151 -	}
   1.152 -	if (flags & MIX_INIT_MOD) {
   1.153 +    }
   1.154 +    if (flags & MIX_INIT_MOD) {
   1.155  #ifdef MOD_MUSIC
   1.156 -		if ((initialized & MIX_INIT_MOD) || Mix_InitMOD() == 0) {
   1.157 -			result |= MIX_INIT_MOD;
   1.158 -		}
   1.159 +        if ((initialized & MIX_INIT_MOD) || Mix_InitMOD() == 0) {
   1.160 +            result |= MIX_INIT_MOD;
   1.161 +        }
   1.162  #else
   1.163 -		Mix_SetError("Mixer not built with MOD support");
   1.164 +        Mix_SetError("Mixer not built with MOD support");
   1.165  #endif
   1.166 -	}
   1.167 -	if (flags & MIX_INIT_MP3) {
   1.168 +    }
   1.169 +    if (flags & MIX_INIT_MP3) {
   1.170  #ifdef MP3_MUSIC
   1.171 -		if ((initialized & MIX_INIT_MP3) || Mix_InitMP3() == 0) {
   1.172 -			result |= MIX_INIT_MP3;
   1.173 -		}
   1.174 +        if ((initialized & MIX_INIT_MP3) || Mix_InitMP3() == 0) {
   1.175 +            result |= MIX_INIT_MP3;
   1.176 +        }
   1.177  #else
   1.178 -		Mix_SetError("Mixer not built with MP3 support");
   1.179 +        Mix_SetError("Mixer not built with MP3 support");
   1.180  #endif
   1.181 -	}
   1.182 -	if (flags & MIX_INIT_OGG) {
   1.183 +    }
   1.184 +    if (flags & MIX_INIT_OGG) {
   1.185  #ifdef OGG_MUSIC
   1.186 -		if ((initialized & MIX_INIT_OGG) || Mix_InitOgg() == 0) {
   1.187 -			result |= MIX_INIT_OGG;
   1.188 -		}
   1.189 +        if ((initialized & MIX_INIT_OGG) || Mix_InitOgg() == 0) {
   1.190 +            result |= MIX_INIT_OGG;
   1.191 +        }
   1.192  #else
   1.193 -		Mix_SetError("Mixer not built with Ogg Vorbis support");
   1.194 +        Mix_SetError("Mixer not built with Ogg Vorbis support");
   1.195  #endif
   1.196 -	}
   1.197 -	initialized |= result;
   1.198 +    }
   1.199 +    initialized |= result;
   1.200  
   1.201 -	return (result);
   1.202 +    return (result);
   1.203  }
   1.204  
   1.205  void Mix_Quit()
   1.206  {
   1.207  #ifdef USE_FLUIDSYNTH_MIDI
   1.208 -	if (initialized & MIX_INIT_FLUIDSYNTH) {
   1.209 -		Mix_QuitFluidSynth();
   1.210 -	}
   1.211 +    if (initialized & MIX_INIT_FLUIDSYNTH) {
   1.212 +        Mix_QuitFluidSynth();
   1.213 +    }
   1.214  #endif
   1.215  #ifdef FLAC_MUSIC
   1.216 -	if (initialized & MIX_INIT_FLAC) {
   1.217 -		Mix_QuitFLAC();
   1.218 -	}
   1.219 +    if (initialized & MIX_INIT_FLAC) {
   1.220 +        Mix_QuitFLAC();
   1.221 +    }
   1.222  #endif
   1.223  #ifdef MOD_MUSIC
   1.224 -	if (initialized & MIX_INIT_MOD) {
   1.225 -		Mix_QuitMOD();
   1.226 -	}
   1.227 +    if (initialized & MIX_INIT_MOD) {
   1.228 +        Mix_QuitMOD();
   1.229 +    }
   1.230  #endif
   1.231  #ifdef MP3_MUSIC
   1.232 -	if (initialized & MIX_INIT_MP3) {
   1.233 -		Mix_QuitMP3();
   1.234 -	}
   1.235 +    if (initialized & MIX_INIT_MP3) {
   1.236 +        Mix_QuitMP3();
   1.237 +    }
   1.238  #endif
   1.239  #ifdef OGG_MUSIC
   1.240 -	if (initialized & MIX_INIT_OGG) {
   1.241 -		Mix_QuitOgg();
   1.242 -	}
   1.243 +    if (initialized & MIX_INIT_OGG) {
   1.244 +        Mix_QuitOgg();
   1.245 +    }
   1.246  #endif
   1.247  #ifdef MID_MUSIC
   1.248 -	if (soundfont_paths) {
   1.249 -		SDL_free(soundfont_paths);
   1.250 -	}
   1.251 +    if (soundfont_paths) {
   1.252 +        SDL_free(soundfont_paths);
   1.253 +    }
   1.254  #endif
   1.255 -	initialized = 0;
   1.256 +    initialized = 0;
   1.257  }
   1.258  
   1.259  static int _Mix_remove_all_effects(int channel, effect_info **e);
   1.260 @@ -242,163 +242,163 @@
   1.261   */
   1.262  static void _Mix_channel_done_playing(int channel)
   1.263  {
   1.264 -	if (channel_done_callback) {
   1.265 -	    channel_done_callback(channel);
   1.266 -	}
   1.267 +    if (channel_done_callback) {
   1.268 +        channel_done_callback(channel);
   1.269 +    }
   1.270  
   1.271 -	/*
   1.272 -	 * Call internal function directly, to avoid locking audio from
   1.273 -	 *   inside audio callback.
   1.274 -	 */
   1.275 -	_Mix_remove_all_effects(channel, &mix_channel[channel].effects);
   1.276 +    /*
   1.277 +     * Call internal function directly, to avoid locking audio from
   1.278 +     *   inside audio callback.
   1.279 +     */
   1.280 +    _Mix_remove_all_effects(channel, &mix_channel[channel].effects);
   1.281  }
   1.282  
   1.283  
   1.284  static void *Mix_DoEffects(int chan, void *snd, int len)
   1.285  {
   1.286 -	int posteffect = (chan == MIX_CHANNEL_POST);
   1.287 -	effect_info *e = ((posteffect) ? posteffects : mix_channel[chan].effects);
   1.288 -	void *buf = snd;
   1.289 +    int posteffect = (chan == MIX_CHANNEL_POST);
   1.290 +    effect_info *e = ((posteffect) ? posteffects : mix_channel[chan].effects);
   1.291 +    void *buf = snd;
   1.292  
   1.293 -	if (e != NULL) {    /* are there any registered effects? */
   1.294 -		/* if this is the postmix, we can just overwrite the original. */
   1.295 -		if (!posteffect) {
   1.296 -			buf = SDL_malloc(len);
   1.297 -			if (buf == NULL) {
   1.298 -				return(snd);
   1.299 -			}
   1.300 -			memcpy(buf, snd, len);
   1.301 -		}
   1.302 +    if (e != NULL) {    /* are there any registered effects? */
   1.303 +        /* if this is the postmix, we can just overwrite the original. */
   1.304 +        if (!posteffect) {
   1.305 +            buf = SDL_malloc(len);
   1.306 +            if (buf == NULL) {
   1.307 +                return(snd);
   1.308 +            }
   1.309 +            memcpy(buf, snd, len);
   1.310 +        }
   1.311  
   1.312 -		for (; e != NULL; e = e->next) {
   1.313 -			if (e->callback != NULL) {
   1.314 -				e->callback(chan, buf, len, e->udata);
   1.315 -			}
   1.316 -		}
   1.317 -	}
   1.318 +        for (; e != NULL; e = e->next) {
   1.319 +            if (e->callback != NULL) {
   1.320 +                e->callback(chan, buf, len, e->udata);
   1.321 +            }
   1.322 +        }
   1.323 +    }
   1.324  
   1.325 -	/* be sure to SDL_free() the return value if != snd ... */
   1.326 -	return(buf);
   1.327 +    /* be sure to SDL_free() the return value if != snd ... */
   1.328 +    return(buf);
   1.329  }
   1.330  
   1.331  
   1.332  /* Mixing function */
   1.333  static void mix_channels(void *udata, Uint8 *stream, int len)
   1.334  {
   1.335 -	Uint8 *mix_input;
   1.336 -	int i, mixable, volume = SDL_MIX_MAXVOLUME;
   1.337 -	Uint32 sdl_ticks;
   1.338 +    Uint8 *mix_input;
   1.339 +    int i, mixable, volume = SDL_MIX_MAXVOLUME;
   1.340 +    Uint32 sdl_ticks;
   1.341  
   1.342  #if SDL_VERSION_ATLEAST(1, 3, 0)
   1.343 -	/* Need to initialize the stream in SDL 1.3+ */
   1.344 -	memset(stream, mixer.silence, len);
   1.345 +    /* Need to initialize the stream in SDL 1.3+ */
   1.346 +    memset(stream, mixer.silence, len);
   1.347  #endif
   1.348  
   1.349 -	/* Mix the music (must be done before the channels are added) */
   1.350 -	if ( music_active || (mix_music != music_mixer) ) {
   1.351 -		mix_music(music_data, stream, len);
   1.352 -	}
   1.353 +    /* Mix the music (must be done before the channels are added) */
   1.354 +    if ( music_active || (mix_music != music_mixer) ) {
   1.355 +        mix_music(music_data, stream, len);
   1.356 +    }
   1.357  
   1.358 -	/* Mix any playing channels... */
   1.359 -	sdl_ticks = SDL_GetTicks();
   1.360 -	for ( i=0; i<num_channels; ++i ) {
   1.361 -		if( ! mix_channel[i].paused ) {
   1.362 -			if ( mix_channel[i].expire > 0 && mix_channel[i].expire < sdl_ticks ) {
   1.363 -				/* Expiration delay for that channel is reached */
   1.364 -				mix_channel[i].playing = 0;
   1.365 -				mix_channel[i].looping = 0;
   1.366 -				mix_channel[i].fading = MIX_NO_FADING;
   1.367 -				mix_channel[i].expire = 0;
   1.368 -				_Mix_channel_done_playing(i);
   1.369 -			} else if ( mix_channel[i].fading != MIX_NO_FADING ) {
   1.370 -				Uint32 ticks = sdl_ticks - mix_channel[i].ticks_fade;
   1.371 -				if( ticks > mix_channel[i].fade_length ) {
   1.372 -				    Mix_Volume(i, mix_channel[i].fade_volume_reset); /* Restore the volume */
   1.373 -					if( mix_channel[i].fading == MIX_FADING_OUT ) {
   1.374 -						mix_channel[i].playing = 0;
   1.375 -						mix_channel[i].looping = 0;
   1.376 -						mix_channel[i].expire = 0;
   1.377 -						_Mix_channel_done_playing(i);
   1.378 -					}
   1.379 -					mix_channel[i].fading = MIX_NO_FADING;
   1.380 -				} else {
   1.381 -					if( mix_channel[i].fading == MIX_FADING_OUT ) {
   1.382 -						Mix_Volume(i, (mix_channel[i].fade_volume * (mix_channel[i].fade_length-ticks))
   1.383 -								   / mix_channel[i].fade_length );
   1.384 -					} else {
   1.385 -						Mix_Volume(i, (mix_channel[i].fade_volume * ticks) / mix_channel[i].fade_length );
   1.386 -					}
   1.387 -				}
   1.388 -			}
   1.389 -			if ( mix_channel[i].playing > 0 ) {
   1.390 -				int index = 0;
   1.391 -				int remaining = len;
   1.392 -				while (mix_channel[i].playing > 0 && index < len) {
   1.393 -					remaining = len - index;
   1.394 -					volume = (mix_channel[i].volume*mix_channel[i].chunk->volume) / MIX_MAX_VOLUME;
   1.395 -					mixable = mix_channel[i].playing;
   1.396 -					if ( mixable > remaining ) {
   1.397 -						mixable = remaining;
   1.398 -					}
   1.399 +    /* Mix any playing channels... */
   1.400 +    sdl_ticks = SDL_GetTicks();
   1.401 +    for ( i=0; i<num_channels; ++i ) {
   1.402 +        if( ! mix_channel[i].paused ) {
   1.403 +            if ( mix_channel[i].expire > 0 && mix_channel[i].expire < sdl_ticks ) {
   1.404 +                /* Expiration delay for that channel is reached */
   1.405 +                mix_channel[i].playing = 0;
   1.406 +                mix_channel[i].looping = 0;
   1.407 +                mix_channel[i].fading = MIX_NO_FADING;
   1.408 +                mix_channel[i].expire = 0;
   1.409 +                _Mix_channel_done_playing(i);
   1.410 +            } else if ( mix_channel[i].fading != MIX_NO_FADING ) {
   1.411 +                Uint32 ticks = sdl_ticks - mix_channel[i].ticks_fade;
   1.412 +                if( ticks > mix_channel[i].fade_length ) {
   1.413 +                    Mix_Volume(i, mix_channel[i].fade_volume_reset); /* Restore the volume */
   1.414 +                    if( mix_channel[i].fading == MIX_FADING_OUT ) {
   1.415 +                        mix_channel[i].playing = 0;
   1.416 +                        mix_channel[i].looping = 0;
   1.417 +                        mix_channel[i].expire = 0;
   1.418 +                        _Mix_channel_done_playing(i);
   1.419 +                    }
   1.420 +                    mix_channel[i].fading = MIX_NO_FADING;
   1.421 +                } else {
   1.422 +                    if( mix_channel[i].fading == MIX_FADING_OUT ) {
   1.423 +                        Mix_Volume(i, (mix_channel[i].fade_volume * (mix_channel[i].fade_length-ticks))
   1.424 +                                   / mix_channel[i].fade_length );
   1.425 +                    } else {
   1.426 +                        Mix_Volume(i, (mix_channel[i].fade_volume * ticks) / mix_channel[i].fade_length );
   1.427 +                    }
   1.428 +                }
   1.429 +            }
   1.430 +            if ( mix_channel[i].playing > 0 ) {
   1.431 +                int index = 0;
   1.432 +                int remaining = len;
   1.433 +                while (mix_channel[i].playing > 0 && index < len) {
   1.434 +                    remaining = len - index;
   1.435 +                    volume = (mix_channel[i].volume*mix_channel[i].chunk->volume) / MIX_MAX_VOLUME;
   1.436 +                    mixable = mix_channel[i].playing;
   1.437 +                    if ( mixable > remaining ) {
   1.438 +                        mixable = remaining;
   1.439 +                    }
   1.440  
   1.441 -					mix_input = Mix_DoEffects(i, mix_channel[i].samples, mixable);
   1.442 -					SDL_MixAudio(stream+index,mix_input,mixable,volume);
   1.443 -					if (mix_input != mix_channel[i].samples)
   1.444 -						SDL_free(mix_input);
   1.445 +                    mix_input = Mix_DoEffects(i, mix_channel[i].samples, mixable);
   1.446 +                    SDL_MixAudio(stream+index,mix_input,mixable,volume);
   1.447 +                    if (mix_input != mix_channel[i].samples)
   1.448 +                        SDL_free(mix_input);
   1.449  
   1.450 -					mix_channel[i].samples += mixable;
   1.451 -					mix_channel[i].playing -= mixable;
   1.452 -					index += mixable;
   1.453 +                    mix_channel[i].samples += mixable;
   1.454 +                    mix_channel[i].playing -= mixable;
   1.455 +                    index += mixable;
   1.456  
   1.457 -					/* rcg06072001 Alert app if channel is done playing. */
   1.458 -					if (!mix_channel[i].playing && !mix_channel[i].looping) {
   1.459 -						_Mix_channel_done_playing(i);
   1.460 -					}
   1.461 -				}
   1.462 +                    /* rcg06072001 Alert app if channel is done playing. */
   1.463 +                    if (!mix_channel[i].playing && !mix_channel[i].looping) {
   1.464 +                        _Mix_channel_done_playing(i);
   1.465 +                    }
   1.466 +                }
   1.467  
   1.468 -				/* If looping the sample and we are at its end, make sure
   1.469 -				   we will still return a full buffer */
   1.470 -				while ( mix_channel[i].looping && index < len ) {
   1.471 -					int alen = mix_channel[i].chunk->alen;
   1.472 -					remaining = len - index;
   1.473 -					if (remaining > alen) {
   1.474 -						remaining = alen;
   1.475 -					}
   1.476 +                /* If looping the sample and we are at its end, make sure
   1.477 +                   we will still return a full buffer */
   1.478 +                while ( mix_channel[i].looping && index < len ) {
   1.479 +                    int alen = mix_channel[i].chunk->alen;
   1.480 +                    remaining = len - index;
   1.481 +                    if (remaining > alen) {
   1.482 +                        remaining = alen;
   1.483 +                    }
   1.484  
   1.485 -					mix_input = Mix_DoEffects(i, mix_channel[i].chunk->abuf, remaining);
   1.486 -					SDL_MixAudio(stream+index, mix_input, remaining, volume);
   1.487 -					if (mix_input != mix_channel[i].chunk->abuf)
   1.488 -						SDL_free(mix_input);
   1.489 +                    mix_input = Mix_DoEffects(i, mix_channel[i].chunk->abuf, remaining);
   1.490 +                    SDL_MixAudio(stream+index, mix_input, remaining, volume);
   1.491 +                    if (mix_input != mix_channel[i].chunk->abuf)
   1.492 +                        SDL_free(mix_input);
   1.493  
   1.494 -					--mix_channel[i].looping;
   1.495 -					mix_channel[i].samples = mix_channel[i].chunk->abuf + remaining;
   1.496 -					mix_channel[i].playing = mix_channel[i].chunk->alen - remaining;
   1.497 -					index += remaining;
   1.498 -				}
   1.499 -				if ( ! mix_channel[i].playing && mix_channel[i].looping ) {
   1.500 -					--mix_channel[i].looping;
   1.501 -					mix_channel[i].samples = mix_channel[i].chunk->abuf;
   1.502 -					mix_channel[i].playing = mix_channel[i].chunk->alen;
   1.503 -				}
   1.504 -			}
   1.505 -		}
   1.506 -	}
   1.507 +                    --mix_channel[i].looping;
   1.508 +                    mix_channel[i].samples = mix_channel[i].chunk->abuf + remaining;
   1.509 +                    mix_channel[i].playing = mix_channel[i].chunk->alen - remaining;
   1.510 +                    index += remaining;
   1.511 +                }
   1.512 +                if ( ! mix_channel[i].playing && mix_channel[i].looping ) {
   1.513 +                    --mix_channel[i].looping;
   1.514 +                    mix_channel[i].samples = mix_channel[i].chunk->abuf;
   1.515 +                    mix_channel[i].playing = mix_channel[i].chunk->alen;
   1.516 +                }
   1.517 +            }
   1.518 +        }
   1.519 +    }
   1.520  
   1.521 -	/* rcg06122001 run posteffects... */
   1.522 -	Mix_DoEffects(MIX_CHANNEL_POST, stream, len);
   1.523 +    /* rcg06122001 run posteffects... */
   1.524 +    Mix_DoEffects(MIX_CHANNEL_POST, stream, len);
   1.525  
   1.526 -	if ( mix_postmix ) {
   1.527 -		mix_postmix(mix_postmix_data, stream, len);
   1.528 -	}
   1.529 +    if ( mix_postmix ) {
   1.530 +        mix_postmix(mix_postmix_data, stream, len);
   1.531 +    }
   1.532  }
   1.533  
   1.534  #if 0
   1.535  static void PrintFormat(char *title, SDL_AudioSpec *fmt)
   1.536  {
   1.537 -	printf("%s: %d bit %s audio (%s) at %u Hz\n", title, (fmt->format&0xFF),
   1.538 -			(fmt->format&0x8000) ? "signed" : "unsigned",
   1.539 -			(fmt->channels > 2) ? "surround" :
   1.540 -			(fmt->channels > 1) ? "stereo" : "mono", fmt->freq);
   1.541 +    printf("%s: %d bit %s audio (%s) at %u Hz\n", title, (fmt->format&0xFF),
   1.542 +            (fmt->format&0x8000) ? "signed" : "unsigned",
   1.543 +            (fmt->channels > 2) ? "surround" :
   1.544 +            (fmt->channels > 1) ? "stereo" : "mono", fmt->freq);
   1.545  }
   1.546  #endif
   1.547  
   1.548 @@ -406,77 +406,77 @@
   1.549  /* Open the mixer with a certain desired audio format */
   1.550  int Mix_OpenAudio(int frequency, Uint16 format, int nchannels, int chunksize)
   1.551  {
   1.552 -	int i;
   1.553 -	SDL_AudioSpec desired;
   1.554 +    int i;
   1.555 +    SDL_AudioSpec desired;
   1.556  
   1.557 -	/* If the mixer is already opened, increment open count */
   1.558 -	if ( audio_opened ) {
   1.559 -		if ( format == mixer.format && nchannels == mixer.channels ) {
   1.560 -			++audio_opened;
   1.561 -			return(0);
   1.562 -		}
   1.563 -		while ( audio_opened ) {
   1.564 -			Mix_CloseAudio();
   1.565 -		}
   1.566 -	}
   1.567 +    /* If the mixer is already opened, increment open count */
   1.568 +    if ( audio_opened ) {
   1.569 +        if ( format == mixer.format && nchannels == mixer.channels ) {
   1.570 +            ++audio_opened;
   1.571 +            return(0);
   1.572 +        }
   1.573 +        while ( audio_opened ) {
   1.574 +            Mix_CloseAudio();
   1.575 +        }
   1.576 +    }
   1.577  
   1.578 -	/* Set the desired format and frequency */
   1.579 -	desired.freq = frequency;
   1.580 -	desired.format = format;
   1.581 -	desired.channels = nchannels;
   1.582 -	desired.samples = chunksize;
   1.583 -	desired.callback = mix_channels;
   1.584 -	desired.userdata = NULL;
   1.585 +    /* Set the desired format and frequency */
   1.586 +    desired.freq = frequency;
   1.587 +    desired.format = format;
   1.588 +    desired.channels = nchannels;
   1.589 +    desired.samples = chunksize;
   1.590 +    desired.callback = mix_channels;
   1.591 +    desired.userdata = NULL;
   1.592  
   1.593 -	/* Accept nearly any audio format */
   1.594 -	if ( SDL_OpenAudio(&desired, &mixer) < 0 ) {
   1.595 -		return(-1);
   1.596 -	}
   1.597 +    /* Accept nearly any audio format */
   1.598 +    if ( SDL_OpenAudio(&desired, &mixer) < 0 ) {
   1.599 +        return(-1);
   1.600 +    }
   1.601  #if 0
   1.602 -	PrintFormat("Audio device", &mixer);
   1.603 +    PrintFormat("Audio device", &mixer);
   1.604  #endif
   1.605  
   1.606 -	/* Initialize the music players */
   1.607 -	if ( open_music(&mixer) < 0 ) {
   1.608 -		SDL_CloseAudio();
   1.609 -		return(-1);
   1.610 -	}
   1.611 +    /* Initialize the music players */
   1.612 +    if ( open_music(&mixer) < 0 ) {
   1.613 +        SDL_CloseAudio();
   1.614 +        return(-1);
   1.615 +    }
   1.616  
   1.617 -	num_channels = MIX_CHANNELS;
   1.618 -	mix_channel = (struct _Mix_Channel *) SDL_malloc(num_channels * sizeof(struct _Mix_Channel));
   1.619 +    num_channels = MIX_CHANNELS;
   1.620 +    mix_channel = (struct _Mix_Channel *) SDL_malloc(num_channels * sizeof(struct _Mix_Channel));
   1.621  
   1.622 -	/* Clear out the audio channels */
   1.623 -	for ( i=0; i<num_channels; ++i ) {
   1.624 -		mix_channel[i].chunk = NULL;
   1.625 -		mix_channel[i].playing = 0;
   1.626 -		mix_channel[i].looping = 0;
   1.627 -		mix_channel[i].volume = SDL_MIX_MAXVOLUME;
   1.628 -		mix_channel[i].fade_volume = SDL_MIX_MAXVOLUME;
   1.629 -		mix_channel[i].fade_volume_reset = SDL_MIX_MAXVOLUME;
   1.630 -		mix_channel[i].fading = MIX_NO_FADING;
   1.631 -		mix_channel[i].tag = -1;
   1.632 -		mix_channel[i].expire = 0;
   1.633 -		mix_channel[i].effects = NULL;
   1.634 -		mix_channel[i].paused = 0;
   1.635 -	}
   1.636 -	Mix_VolumeMusic(SDL_MIX_MAXVOLUME);
   1.637 +    /* Clear out the audio channels */
   1.638 +    for ( i=0; i<num_channels; ++i ) {
   1.639 +        mix_channel[i].chunk = NULL;
   1.640 +        mix_channel[i].playing = 0;
   1.641 +        mix_channel[i].looping = 0;
   1.642 +        mix_channel[i].volume = SDL_MIX_MAXVOLUME;
   1.643 +        mix_channel[i].fade_volume = SDL_MIX_MAXVOLUME;
   1.644 +        mix_channel[i].fade_volume_reset = SDL_MIX_MAXVOLUME;
   1.645 +        mix_channel[i].fading = MIX_NO_FADING;
   1.646 +        mix_channel[i].tag = -1;
   1.647 +        mix_channel[i].expire = 0;
   1.648 +        mix_channel[i].effects = NULL;
   1.649 +        mix_channel[i].paused = 0;
   1.650 +    }
   1.651 +    Mix_VolumeMusic(SDL_MIX_MAXVOLUME);
   1.652  
   1.653 -	_Mix_InitEffects();
   1.654 +    _Mix_InitEffects();
   1.655  
   1.656 -	/* This list is (currently) decided at build time. */
   1.657 -	add_chunk_decoder("WAVE");
   1.658 -	add_chunk_decoder("AIFF");
   1.659 -	add_chunk_decoder("VOC");
   1.660 +    /* This list is (currently) decided at build time. */
   1.661 +    add_chunk_decoder("WAVE");
   1.662 +    add_chunk_decoder("AIFF");
   1.663 +    add_chunk_decoder("VOC");
   1.664  #ifdef OGG_MUSIC
   1.665 -	add_chunk_decoder("OGG");
   1.666 +    add_chunk_decoder("OGG");
   1.667  #endif
   1.668  #ifdef FLAC_MUSIC
   1.669 -	add_chunk_decoder("FLAC");
   1.670 +    add_chunk_decoder("FLAC");
   1.671  #endif
   1.672  
   1.673 -	audio_opened = 1;
   1.674 -	SDL_PauseAudio(0);
   1.675 -	return(0);
   1.676 +    audio_opened = 1;
   1.677 +    SDL_PauseAudio(0);
   1.678 +    return(0);
   1.679  }
   1.680  
   1.681  /* Dynamically change the number of channels managed by the mixer.
   1.682 @@ -485,56 +485,56 @@
   1.683   */
   1.684  int Mix_AllocateChannels(int numchans)
   1.685  {
   1.686 -	if ( numchans<0 || numchans==num_channels )
   1.687 -		return(num_channels);
   1.688 +    if ( numchans<0 || numchans==num_channels )
   1.689 +        return(num_channels);
   1.690  
   1.691 -	if ( numchans < num_channels ) {
   1.692 -		/* Stop the affected channels */
   1.693 -		int i;
   1.694 -		for(i=numchans; i < num_channels; i++) {
   1.695 -			Mix_UnregisterAllEffects(i);
   1.696 -			Mix_HaltChannel(i);
   1.697 -		}
   1.698 -	}
   1.699 -	SDL_LockAudio();
   1.700 -	mix_channel = (struct _Mix_Channel *) SDL_realloc(mix_channel, numchans * sizeof(struct _Mix_Channel));
   1.701 -	if ( numchans > num_channels ) {
   1.702 -		/* Initialize the new channels */
   1.703 -		int i;
   1.704 -		for(i=num_channels; i < numchans; i++) {
   1.705 -			mix_channel[i].chunk = NULL;
   1.706 -			mix_channel[i].playing = 0;
   1.707 -			mix_channel[i].looping = 0;
   1.708 -			mix_channel[i].volume = SDL_MIX_MAXVOLUME;
   1.709 -			mix_channel[i].fade_volume = SDL_MIX_MAXVOLUME;
   1.710 -			mix_channel[i].fade_volume_reset = SDL_MIX_MAXVOLUME;
   1.711 -			mix_channel[i].fading = MIX_NO_FADING;
   1.712 -			mix_channel[i].tag = -1;
   1.713 -			mix_channel[i].expire = 0;
   1.714 -			mix_channel[i].effects = NULL;
   1.715 -			mix_channel[i].paused = 0;
   1.716 -		}
   1.717 -	}
   1.718 -	num_channels = numchans;
   1.719 -	SDL_UnlockAudio();
   1.720 -	return(num_channels);
   1.721 +    if ( numchans < num_channels ) {
   1.722 +        /* Stop the affected channels */
   1.723 +        int i;
   1.724 +        for(i=numchans; i < num_channels; i++) {
   1.725 +            Mix_UnregisterAllEffects(i);
   1.726 +            Mix_HaltChannel(i);
   1.727 +        }
   1.728 +    }
   1.729 +    SDL_LockAudio();
   1.730 +    mix_channel = (struct _Mix_Channel *) SDL_realloc(mix_channel, numchans * sizeof(struct _Mix_Channel));
   1.731 +    if ( numchans > num_channels ) {
   1.732 +        /* Initialize the new channels */
   1.733 +        int i;
   1.734 +        for(i=num_channels; i < numchans; i++) {
   1.735 +            mix_channel[i].chunk = NULL;
   1.736 +            mix_channel[i].playing = 0;
   1.737 +            mix_channel[i].looping = 0;
   1.738 +            mix_channel[i].volume = SDL_MIX_MAXVOLUME;
   1.739 +            mix_channel[i].fade_volume = SDL_MIX_MAXVOLUME;
   1.740 +            mix_channel[i].fade_volume_reset = SDL_MIX_MAXVOLUME;
   1.741 +            mix_channel[i].fading = MIX_NO_FADING;
   1.742 +            mix_channel[i].tag = -1;
   1.743 +            mix_channel[i].expire = 0;
   1.744 +            mix_channel[i].effects = NULL;
   1.745 +            mix_channel[i].paused = 0;
   1.746 +        }
   1.747 +    }
   1.748 +    num_channels = numchans;
   1.749 +    SDL_UnlockAudio();
   1.750 +    return(num_channels);
   1.751  }
   1.752  
   1.753  /* Return the actual mixer parameters */
   1.754  int Mix_QuerySpec(int *frequency, Uint16 *format, int *channels)
   1.755  {
   1.756 -	if ( audio_opened ) {
   1.757 -		if ( frequency ) {
   1.758 -			*frequency = mixer.freq;
   1.759 -		}
   1.760 -		if ( format ) {
   1.761 -			*format = mixer.format;
   1.762 -		}
   1.763 -		if ( channels ) {
   1.764 -			*channels = mixer.channels;
   1.765 -		}
   1.766 -	}
   1.767 -	return(audio_opened);
   1.768 +    if ( audio_opened ) {
   1.769 +        if ( frequency ) {
   1.770 +            *frequency = mixer.freq;
   1.771 +        }
   1.772 +        if ( format ) {
   1.773 +            *format = mixer.format;
   1.774 +        }
   1.775 +        if ( channels ) {
   1.776 +            *channels = mixer.channels;
   1.777 +        }
   1.778 +    }
   1.779 +    return(audio_opened);
   1.780  }
   1.781  
   1.782  
   1.783 @@ -546,213 +546,213 @@
   1.784  /* Load a wave file */
   1.785  Mix_Chunk *Mix_LoadWAV_RW(SDL_RWops *src, int freesrc)
   1.786  {
   1.787 -	Uint32 magic;
   1.788 -	Mix_Chunk *chunk;
   1.789 -	SDL_AudioSpec wavespec, *loaded;
   1.790 -	SDL_AudioCVT wavecvt;
   1.791 -	int samplesize;
   1.792 +    Uint32 magic;
   1.793 +    Mix_Chunk *chunk;
   1.794 +    SDL_AudioSpec wavespec, *loaded;
   1.795 +    SDL_AudioCVT wavecvt;
   1.796 +    int samplesize;
   1.797  
   1.798 -	/* rcg06012001 Make sure src is valid */
   1.799 -	if ( ! src ) {
   1.800 -		SDL_SetError("Mix_LoadWAV_RW with NULL src");
   1.801 -		return(NULL);
   1.802 -	}
   1.803 +    /* rcg06012001 Make sure src is valid */
   1.804 +    if ( ! src ) {
   1.805 +        SDL_SetError("Mix_LoadWAV_RW with NULL src");
   1.806 +        return(NULL);
   1.807 +    }
   1.808  
   1.809 -	/* Make sure audio has been opened */
   1.810 -	if ( ! audio_opened ) {
   1.811 -		SDL_SetError("Audio device hasn't been opened");
   1.812 -		if ( freesrc && src ) {
   1.813 -			SDL_RWclose(src);
   1.814 -		}
   1.815 -		return(NULL);
   1.816 -	}
   1.817 +    /* Make sure audio has been opened */
   1.818 +    if ( ! audio_opened ) {
   1.819 +        SDL_SetError("Audio device hasn't been opened");
   1.820 +        if ( freesrc && src ) {
   1.821 +            SDL_RWclose(src);
   1.822 +        }
   1.823 +        return(NULL);
   1.824 +    }
   1.825  
   1.826 -	/* Allocate the chunk memory */
   1.827 -	chunk = (Mix_Chunk *)SDL_malloc(sizeof(Mix_Chunk));
   1.828 -	if ( chunk == NULL ) {
   1.829 -		SDL_SetError("Out of memory");
   1.830 -		if ( freesrc ) {
   1.831 -			SDL_RWclose(src);
   1.832 -		}
   1.833 -		return(NULL);
   1.834 -	}
   1.835 +    /* Allocate the chunk memory */
   1.836 +    chunk = (Mix_Chunk *)SDL_malloc(sizeof(Mix_Chunk));
   1.837 +    if ( chunk == NULL ) {
   1.838 +        SDL_SetError("Out of memory");
   1.839 +        if ( freesrc ) {
   1.840 +            SDL_RWclose(src);
   1.841 +        }
   1.842 +        return(NULL);
   1.843 +    }
   1.844  
   1.845 -	/* Find out what kind of audio file this is */
   1.846 -	magic = SDL_ReadLE32(src);
   1.847 -	/* Seek backwards for compatibility with older loaders */
   1.848 -	SDL_RWseek(src, -(int)sizeof(Uint32), RW_SEEK_CUR);
   1.849 +    /* Find out what kind of audio file this is */
   1.850 +    magic = SDL_ReadLE32(src);
   1.851 +    /* Seek backwards for compatibility with older loaders */
   1.852 +    SDL_RWseek(src, -(int)sizeof(Uint32), RW_SEEK_CUR);
   1.853  
   1.854 -	switch (magic) {
   1.855 -		case WAVE:
   1.856 -		case RIFF:
   1.857 -			loaded = SDL_LoadWAV_RW(src, freesrc, &wavespec,
   1.858 -					(Uint8 **)&chunk->abuf, &chunk->alen);
   1.859 -			break;
   1.860 -		case FORM:
   1.861 -			loaded = Mix_LoadAIFF_RW(src, freesrc, &wavespec,
   1.862 -					(Uint8 **)&chunk->abuf, &chunk->alen);
   1.863 -			break;
   1.864 +    switch (magic) {
   1.865 +        case WAVE:
   1.866 +        case RIFF:
   1.867 +            loaded = SDL_LoadWAV_RW(src, freesrc, &wavespec,
   1.868 +                    (Uint8 **)&chunk->abuf, &chunk->alen);
   1.869 +            break;
   1.870 +        case FORM:
   1.871 +            loaded = Mix_LoadAIFF_RW(src, freesrc, &wavespec,
   1.872 +                    (Uint8 **)&chunk->abuf, &chunk->alen);
   1.873 +            break;
   1.874  #ifdef OGG_MUSIC
   1.875 -		case OGGS:
   1.876 -			loaded = Mix_LoadOGG_RW(src, freesrc, &wavespec,
   1.877 -					(Uint8 **)&chunk->abuf, &chunk->alen);
   1.878 -			break;
   1.879 +        case OGGS:
   1.880 +            loaded = Mix_LoadOGG_RW(src, freesrc, &wavespec,
   1.881 +                    (Uint8 **)&chunk->abuf, &chunk->alen);
   1.882 +            break;
   1.883  #endif
   1.884  #ifdef FLAC_MUSIC
   1.885 -		case FLAC:
   1.886 -			loaded = Mix_LoadFLAC_RW(src, freesrc, &wavespec,
   1.887 -					(Uint8 **)&chunk->abuf, &chunk->alen);
   1.888 -			break;
   1.889 +        case FLAC:
   1.890 +            loaded = Mix_LoadFLAC_RW(src, freesrc, &wavespec,
   1.891 +                    (Uint8 **)&chunk->abuf, &chunk->alen);
   1.892 +            break;
   1.893  #endif
   1.894 -		case CREA:
   1.895 -			loaded = Mix_LoadVOC_RW(src, freesrc, &wavespec,
   1.896 -					(Uint8 **)&chunk->abuf, &chunk->alen);
   1.897 -			break;
   1.898 -		default:
   1.899 -			SDL_SetError("Unrecognized sound file type");
   1.900 -			if ( freesrc ) {
   1.901 -				SDL_RWclose(src);
   1.902 -			}
   1.903 -			loaded = NULL;
   1.904 -			break;
   1.905 -	}
   1.906 -	if ( !loaded ) {
   1.907 -		/* The individual loaders have closed src if needed */
   1.908 -		SDL_free(chunk);
   1.909 -		return(NULL);
   1.910 -	}
   1.911 +        case CREA:
   1.912 +            loaded = Mix_LoadVOC_RW(src, freesrc, &wavespec,
   1.913 +                    (Uint8 **)&chunk->abuf, &chunk->alen);
   1.914 +            break;
   1.915 +        default:
   1.916 +            SDL_SetError("Unrecognized sound file type");
   1.917 +            if ( freesrc ) {
   1.918 +                SDL_RWclose(src);
   1.919 +            }
   1.920 +            loaded = NULL;
   1.921 +            break;
   1.922 +    }
   1.923 +    if ( !loaded ) {
   1.924 +        /* The individual loaders have closed src if needed */
   1.925 +        SDL_free(chunk);
   1.926 +        return(NULL);
   1.927 +    }
   1.928  
   1.929  #if 0
   1.930 -	PrintFormat("Audio device", &mixer);
   1.931 -	PrintFormat("-- Wave file", &wavespec);
   1.932 +    PrintFormat("Audio device", &mixer);
   1.933 +    PrintFormat("-- Wave file", &wavespec);
   1.934  #endif
   1.935  
   1.936 -	/* Build the audio converter and create conversion buffers */
   1.937 -	if ( wavespec.format != mixer.format ||
   1.938 -		 wavespec.channels != mixer.channels ||
   1.939 -		 wavespec.freq != mixer.freq ) {
   1.940 -		if ( SDL_BuildAudioCVT(&wavecvt,
   1.941 -				wavespec.format, wavespec.channels, wavespec.freq,
   1.942 -				mixer.format, mixer.channels, mixer.freq) < 0 ) {
   1.943 -			SDL_free(chunk->abuf);
   1.944 -			SDL_free(chunk);
   1.945 -			return(NULL);
   1.946 -		}
   1.947 -		samplesize = ((wavespec.format & 0xFF)/8)*wavespec.channels;
   1.948 -		wavecvt.len = chunk->alen & ~(samplesize-1);
   1.949 -		wavecvt.buf = (Uint8 *)SDL_calloc(1, wavecvt.len*wavecvt.len_mult);
   1.950 -		if ( wavecvt.buf == NULL ) {
   1.951 -			SDL_SetError("Out of memory");
   1.952 -			SDL_free(chunk->abuf);
   1.953 -			SDL_free(chunk);
   1.954 -			return(NULL);
   1.955 -		}
   1.956 -		memcpy(wavecvt.buf, chunk->abuf, chunk->alen);
   1.957 -		SDL_free(chunk->abuf);
   1.958 +    /* Build the audio converter and create conversion buffers */
   1.959 +    if ( wavespec.format != mixer.format ||
   1.960 +         wavespec.channels != mixer.channels ||
   1.961 +         wavespec.freq != mixer.freq ) {
   1.962 +        if ( SDL_BuildAudioCVT(&wavecvt,
   1.963 +                wavespec.format, wavespec.channels, wavespec.freq,
   1.964 +                mixer.format, mixer.channels, mixer.freq) < 0 ) {
   1.965 +            SDL_free(chunk->abuf);
   1.966 +            SDL_free(chunk);
   1.967 +            return(NULL);
   1.968 +        }
   1.969 +        samplesize = ((wavespec.format & 0xFF)/8)*wavespec.channels;
   1.970 +        wavecvt.len = chunk->alen & ~(samplesize-1);
   1.971 +        wavecvt.buf = (Uint8 *)SDL_calloc(1, wavecvt.len*wavecvt.len_mult);
   1.972 +        if ( wavecvt.buf == NULL ) {
   1.973 +            SDL_SetError("Out of memory");
   1.974 +            SDL_free(chunk->abuf);
   1.975 +            SDL_free(chunk);
   1.976 +            return(NULL);
   1.977 +        }
   1.978 +        memcpy(wavecvt.buf, chunk->abuf, chunk->alen);
   1.979 +        SDL_free(chunk->abuf);
   1.980  
   1.981 -		/* Run the audio converter */
   1.982 -		if ( SDL_ConvertAudio(&wavecvt) < 0 ) {
   1.983 -			SDL_free(wavecvt.buf);
   1.984 -			SDL_free(chunk);
   1.985 -			return(NULL);
   1.986 -		}
   1.987 +        /* Run the audio converter */
   1.988 +        if ( SDL_ConvertAudio(&wavecvt) < 0 ) {
   1.989 +            SDL_free(wavecvt.buf);
   1.990 +            SDL_free(chunk);
   1.991 +            return(NULL);
   1.992 +        }
   1.993  
   1.994 -		chunk->abuf = wavecvt.buf;
   1.995 -		chunk->alen = wavecvt.len_cvt;
   1.996 -	}
   1.997 +        chunk->abuf = wavecvt.buf;
   1.998 +        chunk->alen = wavecvt.len_cvt;
   1.999 +    }
  1.1000  
  1.1001 -	chunk->allocated = 1;
  1.1002 -	chunk->volume = MIX_MAX_VOLUME;
  1.1003 +    chunk->allocated = 1;
  1.1004 +    chunk->volume = MIX_MAX_VOLUME;
  1.1005  
  1.1006 -	return(chunk);
  1.1007 +    return(chunk);
  1.1008  }
  1.1009  
  1.1010  /* Load a wave file of the mixer format from a memory buffer */
  1.1011  Mix_Chunk *Mix_QuickLoad_WAV(Uint8 *mem)
  1.1012  {
  1.1013 -	Mix_Chunk *chunk;
  1.1014 -	Uint8 magic[4];
  1.1015 +    Mix_Chunk *chunk;
  1.1016 +    Uint8 magic[4];
  1.1017  
  1.1018 -	/* Make sure audio has been opened */
  1.1019 -	if ( ! audio_opened ) {
  1.1020 -		SDL_SetError("Audio device hasn't been opened");
  1.1021 -		return(NULL);
  1.1022 -	}
  1.1023 +    /* Make sure audio has been opened */
  1.1024 +    if ( ! audio_opened ) {
  1.1025 +        SDL_SetError("Audio device hasn't been opened");
  1.1026 +        return(NULL);
  1.1027 +    }
  1.1028  
  1.1029 -	/* Allocate the chunk memory */
  1.1030 -	chunk = (Mix_Chunk *)SDL_calloc(1,sizeof(Mix_Chunk));
  1.1031 -	if ( chunk == NULL ) {
  1.1032 -		SDL_SetError("Out of memory");
  1.1033 -		return(NULL);
  1.1034 -	}
  1.1035 +    /* Allocate the chunk memory */
  1.1036 +    chunk = (Mix_Chunk *)SDL_calloc(1,sizeof(Mix_Chunk));
  1.1037 +    if ( chunk == NULL ) {
  1.1038 +        SDL_SetError("Out of memory");
  1.1039 +        return(NULL);
  1.1040 +    }
  1.1041  
  1.1042 -	/* Essentially just skip to the audio data (no error checking - fast) */
  1.1043 -	chunk->allocated = 0;
  1.1044 -	mem += 12; /* WAV header */
  1.1045 -	do {
  1.1046 -		memcpy(magic, mem, 4);
  1.1047 -		mem += 4;
  1.1048 -		chunk->alen = ((mem[3]<<24)|(mem[2]<<16)|(mem[1]<<8)|(mem[0]));
  1.1049 -		mem += 4;
  1.1050 -		chunk->abuf = mem;
  1.1051 -		mem += chunk->alen;
  1.1052 -	} while ( memcmp(magic, "data", 4) != 0 );
  1.1053 -	chunk->volume = MIX_MAX_VOLUME;
  1.1054 +    /* Essentially just skip to the audio data (no error checking - fast) */
  1.1055 +    chunk->allocated = 0;
  1.1056 +    mem += 12; /* WAV header */
  1.1057 +    do {
  1.1058 +        memcpy(magic, mem, 4);
  1.1059 +        mem += 4;
  1.1060 +        chunk->alen = ((mem[3]<<24)|(mem[2]<<16)|(mem[1]<<8)|(mem[0]));
  1.1061 +        mem += 4;
  1.1062 +        chunk->abuf = mem;
  1.1063 +        mem += chunk->alen;
  1.1064 +    } while ( memcmp(magic, "data", 4) != 0 );
  1.1065 +    chunk->volume = MIX_MAX_VOLUME;
  1.1066  
  1.1067 -	return(chunk);
  1.1068 +    return(chunk);
  1.1069  }
  1.1070  
  1.1071  /* Load raw audio data of the mixer format from a memory buffer */
  1.1072  Mix_Chunk *Mix_QuickLoad_RAW(Uint8 *mem, Uint32 len)
  1.1073  {
  1.1074 -	Mix_Chunk *chunk;
  1.1075 +    Mix_Chunk *chunk;
  1.1076  
  1.1077 -	/* Make sure audio has been opened */
  1.1078 -	if ( ! audio_opened ) {
  1.1079 -		SDL_SetError("Audio device hasn't been opened");
  1.1080 -		return(NULL);
  1.1081 -	}
  1.1082 +    /* Make sure audio has been opened */
  1.1083 +    if ( ! audio_opened ) {
  1.1084 +        SDL_SetError("Audio device hasn't been opened");
  1.1085 +        return(NULL);
  1.1086 +    }
  1.1087  
  1.1088 -	/* Allocate the chunk memory */
  1.1089 -	chunk = (Mix_Chunk *)SDL_malloc(sizeof(Mix_Chunk));
  1.1090 -	if ( chunk == NULL ) {
  1.1091 -		SDL_SetError("Out of memory");
  1.1092 -		return(NULL);
  1.1093 -	}
  1.1094 +    /* Allocate the chunk memory */
  1.1095 +    chunk = (Mix_Chunk *)SDL_malloc(sizeof(Mix_Chunk));
  1.1096 +    if ( chunk == NULL ) {
  1.1097 +        SDL_SetError("Out of memory");
  1.1098 +        return(NULL);
  1.1099 +    }
  1.1100  
  1.1101 -	/* Essentially just point at the audio data (no error checking - fast) */
  1.1102 -	chunk->allocated = 0;
  1.1103 -	chunk->alen = len;
  1.1104 -	chunk->abuf = mem;
  1.1105 -	chunk->volume = MIX_MAX_VOLUME;
  1.1106 +    /* Essentially just point at the audio data (no error checking - fast) */
  1.1107 +    chunk->allocated = 0;
  1.1108 +    chunk->alen = len;
  1.1109 +    chunk->abuf = mem;
  1.1110 +    chunk->volume = MIX_MAX_VOLUME;
  1.1111  
  1.1112 -	return(chunk);
  1.1113 +    return(chunk);
  1.1114  }
  1.1115  
  1.1116  /* Free an audio chunk previously loaded */
  1.1117  void Mix_FreeChunk(Mix_Chunk *chunk)
  1.1118  {
  1.1119 -	int i;
  1.1120 +    int i;
  1.1121  
  1.1122 -	/* Caution -- if the chunk is playing, the mixer will crash */
  1.1123 -	if ( chunk ) {
  1.1124 -		/* Guarantee that this chunk isn't playing */
  1.1125 -		SDL_LockAudio();
  1.1126 -		if ( mix_channel ) {
  1.1127 -			for ( i=0; i<num_channels; ++i ) {
  1.1128 -				if ( chunk == mix_channel[i].chunk ) {
  1.1129 -					mix_channel[i].playing = 0;
  1.1130 -					mix_channel[i].looping = 0;
  1.1131 -				}
  1.1132 -			}
  1.1133 -		}
  1.1134 -		SDL_UnlockAudio();
  1.1135 -		/* Actually free the chunk */
  1.1136 -		if ( chunk->allocated ) {
  1.1137 -			SDL_free(chunk->abuf);
  1.1138 -		}
  1.1139 -		SDL_free(chunk);
  1.1140 -	}
  1.1141 +    /* Caution -- if the chunk is playing, the mixer will crash */
  1.1142 +    if ( chunk ) {
  1.1143 +        /* Guarantee that this chunk isn't playing */
  1.1144 +        SDL_LockAudio();
  1.1145 +        if ( mix_channel ) {
  1.1146 +            for ( i=0; i<num_channels; ++i ) {
  1.1147 +                if ( chunk == mix_channel[i].chunk ) {
  1.1148 +                    mix_channel[i].playing = 0;
  1.1149 +                    mix_channel[i].looping = 0;
  1.1150 +                }
  1.1151 +            }
  1.1152 +        }
  1.1153 +        SDL_UnlockAudio();
  1.1154 +        /* Actually free the chunk */
  1.1155 +        if ( chunk->allocated ) {
  1.1156 +            SDL_free(chunk->abuf);
  1.1157 +        }
  1.1158 +        SDL_free(chunk);
  1.1159 +    }
  1.1160  }
  1.1161  
  1.1162  /* Set a function that is called after all mixing is performed.
  1.1163 @@ -762,10 +762,10 @@
  1.1164  void Mix_SetPostMix(void (*mix_func)
  1.1165                      (void *udata, Uint8 *stream, int len), void *arg)
  1.1166  {
  1.1167 -	SDL_LockAudio();
  1.1168 -	mix_postmix_data = arg;
  1.1169 -	mix_postmix = mix_func;
  1.1170 -	SDL_UnlockAudio();
  1.1171 +    SDL_LockAudio();
  1.1172 +    mix_postmix_data = arg;
  1.1173 +    mix_postmix = mix_func;
  1.1174 +    SDL_UnlockAudio();
  1.1175  }
  1.1176  
  1.1177  /* Add your own music player or mixer function.
  1.1178 @@ -774,27 +774,27 @@
  1.1179  void Mix_HookMusic(void (*mix_func)(void *udata, Uint8 *stream, int len),
  1.1180                                                                  void *arg)
  1.1181  {
  1.1182 -	SDL_LockAudio();
  1.1183 -	if ( mix_func != NULL ) {
  1.1184 -		music_data = arg;
  1.1185 -		mix_music = mix_func;
  1.1186 -	} else {
  1.1187 -		music_data = NULL;
  1.1188 -		mix_music = music_mixer;
  1.1189 -	}
  1.1190 -	SDL_UnlockAudio();
  1.1191 +    SDL_LockAudio();
  1.1192 +    if ( mix_func != NULL ) {
  1.1193 +        music_data = arg;
  1.1194 +        mix_music = mix_func;
  1.1195 +    } else {
  1.1196 +        music_data = NULL;
  1.1197 +        mix_music = music_mixer;
  1.1198 +    }
  1.1199 +    SDL_UnlockAudio();
  1.1200  }
  1.1201  
  1.1202  void *Mix_GetMusicHookData(void)
  1.1203  {
  1.1204 -	return(music_data);
  1.1205 +    return(music_data);
  1.1206  }
  1.1207  
  1.1208  void Mix_ChannelFinished(void (*channel_finished)(int channel))
  1.1209  {
  1.1210 -	SDL_LockAudio();
  1.1211 -	channel_done_callback = channel_finished;
  1.1212 -	SDL_UnlockAudio();
  1.1213 +    SDL_LockAudio();
  1.1214 +    channel_done_callback = channel_finished;
  1.1215 +    SDL_UnlockAudio();
  1.1216  }
  1.1217  
  1.1218  
  1.1219 @@ -804,20 +804,20 @@
  1.1220   */
  1.1221  int Mix_ReserveChannels(int num)
  1.1222  {
  1.1223 -	if (num > num_channels)
  1.1224 -		num = num_channels;
  1.1225 -	reserved_channels = num;
  1.1226 -	return num;
  1.1227 +    if (num > num_channels)
  1.1228 +        num = num_channels;
  1.1229 +    reserved_channels = num;
  1.1230 +    return num;
  1.1231  }
  1.1232  
  1.1233  static int checkchunkintegral(Mix_Chunk *chunk)
  1.1234  {
  1.1235 -	int frame_width = 1;
  1.1236 +    int frame_width = 1;
  1.1237  
  1.1238 -	if ((mixer.format & 0xFF) == 16) frame_width = 2;
  1.1239 -	frame_width *= mixer.channels;
  1.1240 -	while (chunk->alen % frame_width) chunk->alen--;
  1.1241 -	return chunk->alen;
  1.1242 +    if ((mixer.format & 0xFF) == 16) frame_width = 2;
  1.1243 +    frame_width *= mixer.channels;
  1.1244 +    while (chunk->alen % frame_width) chunk->alen--;
  1.1245 +    return chunk->alen;
  1.1246  }
  1.1247  
  1.1248  /* Play an audio chunk on a specific channel.
  1.1249 @@ -828,259 +828,259 @@
  1.1250  */
  1.1251  int Mix_PlayChannelTimed(int which, Mix_Chunk *chunk, int loops, int ticks)
  1.1252  {
  1.1253 -	int i;
  1.1254 +    int i;
  1.1255  
  1.1256 -	/* Don't play null pointers :-) */
  1.1257 -	if ( chunk == NULL ) {
  1.1258 -		Mix_SetError("Tried to play a NULL chunk");
  1.1259 -		return(-1);
  1.1260 -	}
  1.1261 -	if ( !checkchunkintegral(chunk)) {
  1.1262 -		Mix_SetError("Tried to play a chunk with a bad frame");
  1.1263 -		return(-1);
  1.1264 -	}
  1.1265 +    /* Don't play null pointers :-) */
  1.1266 +    if ( chunk == NULL ) {
  1.1267 +        Mix_SetError("Tried to play a NULL chunk");
  1.1268 +        return(-1);
  1.1269 +    }
  1.1270 +    if ( !checkchunkintegral(chunk)) {
  1.1271 +        Mix_SetError("Tried to play a chunk with a bad frame");
  1.1272 +        return(-1);
  1.1273 +    }
  1.1274  
  1.1275 -	/* Lock the mixer while modifying the playing channels */
  1.1276 -	SDL_LockAudio();
  1.1277 -	{
  1.1278 -		/* If which is -1, play on the first free channel */
  1.1279 -		if ( which == -1 ) {
  1.1280 -			for ( i=reserved_channels; i<num_channels; ++i ) {
  1.1281 -				if ( mix_channel[i].playing <= 0 )
  1.1282 -					break;
  1.1283 -			}
  1.1284 -			if ( i == num_channels ) {
  1.1285 -				Mix_SetError("No free channels available");
  1.1286 -				which = -1;
  1.1287 -			} else {
  1.1288 -				which = i;
  1.1289 -			}
  1.1290 -		}
  1.1291 +    /* Lock the mixer while modifying the playing channels */
  1.1292 +    SDL_LockAudio();
  1.1293 +    {
  1.1294 +        /* If which is -1, play on the first free channel */
  1.1295 +        if ( which == -1 ) {
  1.1296 +            for ( i=reserved_channels; i<num_channels; ++i ) {
  1.1297 +                if ( mix_channel[i].playing <= 0 )
  1.1298 +                    break;
  1.1299 +            }
  1.1300 +            if ( i == num_channels ) {
  1.1301 +                Mix_SetError("No free channels available");
  1.1302 +                which = -1;
  1.1303 +            } else {
  1.1304 +                which = i;
  1.1305 +            }
  1.1306 +        }
  1.1307  
  1.1308 -		/* Queue up the audio data for this channel */
  1.1309 -		if ( which >= 0 && which < num_channels ) {
  1.1310 -			Uint32 sdl_ticks = SDL_GetTicks();
  1.1311 -			if (Mix_Playing(which))
  1.1312 -				_Mix_channel_done_playing(which);
  1.1313 -			mix_channel[which].samples = chunk->abuf;
  1.1314 -			mix_channel[which].playing = chunk->alen;
  1.1315 -			mix_channel[which].looping = loops;
  1.1316 -			mix_channel[which].chunk = chunk;
  1.1317 -			mix_channel[which].paused = 0;
  1.1318 -			mix_channel[which].fading = MIX_NO_FADING;
  1.1319 -			mix_channel[which].start_time = sdl_ticks;
  1.1320 -			mix_channel[which].expire = (ticks>0) ? (sdl_ticks + ticks) : 0;
  1.1321 -		}
  1.1322 -	}
  1.1323 -	SDL_UnlockAudio();
  1.1324 +        /* Queue up the audio data for this channel */
  1.1325 +        if ( which >= 0 && which < num_channels ) {
  1.1326 +            Uint32 sdl_ticks = SDL_GetTicks();
  1.1327 +            if (Mix_Playing(which))
  1.1328 +                _Mix_channel_done_playing(which);
  1.1329 +            mix_channel[which].samples = chunk->abuf;
  1.1330 +            mix_channel[which].playing = chunk->alen;
  1.1331 +            mix_channel[which].looping = loops;
  1.1332 +            mix_channel[which].chunk = chunk;
  1.1333 +            mix_channel[which].paused = 0;
  1.1334 +            mix_channel[which].fading = MIX_NO_FADING;
  1.1335 +            mix_channel[which].start_time = sdl_ticks;
  1.1336 +            mix_channel[which].expire = (ticks>0) ? (sdl_ticks + ticks) : 0;
  1.1337 +        }
  1.1338 +    }
  1.1339 +    SDL_UnlockAudio();
  1.1340  
  1.1341 -	/* Return the channel on which the sound is being played */
  1.1342 -	return(which);
  1.1343 +    /* Return the channel on which the sound is being played */
  1.1344 +    return(which);
  1.1345  }
  1.1346  
  1.1347  /* Change the expiration delay for a channel */
  1.1348  int Mix_ExpireChannel(int which, int ticks)
  1.1349  {
  1.1350 -	int status = 0;
  1.1351 +    int status = 0;
  1.1352  
  1.1353 -	if ( which == -1 ) {
  1.1354 -		int i;
  1.1355 -		for ( i=0; i < num_channels; ++ i ) {
  1.1356 -			status += Mix_ExpireChannel(i, ticks);
  1.1357 -		}
  1.1358 -	} else if ( which < num_channels ) {
  1.1359 -		SDL_LockAudio();
  1.1360 -		mix_channel[which].expire = (ticks>0) ? (SDL_GetTicks() + ticks) : 0;
  1.1361 -		SDL_UnlockAudio();
  1.1362 -		++ status;
  1.1363 -	}
  1.1364 -	return(status);
  1.1365 +    if ( which == -1 ) {
  1.1366 +        int i;
  1.1367 +        for ( i=0; i < num_channels; ++ i ) {
  1.1368 +            status += Mix_ExpireChannel(i, ticks);
  1.1369 +        }
  1.1370 +    } else if ( which < num_channels ) {
  1.1371 +        SDL_LockAudio();
  1.1372 +        mix_channel[which].expire = (ticks>0) ? (SDL_GetTicks() + ticks) : 0;
  1.1373 +        SDL_UnlockAudio();
  1.1374 +        ++ status;
  1.1375 +    }
  1.1376 +    return(status);
  1.1377  }
  1.1378  
  1.1379  /* Fade in a sound on a channel, over ms milliseconds */
  1.1380  int Mix_FadeInChannelTimed(int which, Mix_Chunk *chunk, int loops, int ms, int ticks)
  1.1381  {
  1.1382 -	int i;
  1.1383 +    int i;
  1.1384  
  1.1385 -	/* Don't play null pointers :-) */
  1.1386 -	if ( chunk == NULL ) {
  1.1387 -		return(-1);
  1.1388 -	}
  1.1389 -	if ( !checkchunkintegral(chunk)) {
  1.1390 -		Mix_SetError("Tried to play a chunk with a bad frame");
  1.1391 -		return(-1);
  1.1392 -	}
  1.1393 +    /* Don't play null pointers :-) */
  1.1394 +    if ( chunk == NULL ) {
  1.1395 +        return(-1);
  1.1396 +    }
  1.1397 +    if ( !checkchunkintegral(chunk)) {
  1.1398 +        Mix_SetError("Tried to play a chunk with a bad frame");
  1.1399 +        return(-1);
  1.1400 +    }
  1.1401  
  1.1402 -	/* Lock the mixer while modifying the playing channels */
  1.1403 -	SDL_LockAudio();
  1.1404 -	{
  1.1405 -		/* If which is -1, play on the first free channel */
  1.1406 -		if ( which == -1 ) {
  1.1407 -			for ( i=reserved_channels; i<num_channels; ++i ) {
  1.1408 -				if ( mix_channel[i].playing <= 0 )
  1.1409 -					break;
  1.1410 -			}
  1.1411 -			if ( i == num_channels ) {
  1.1412 -				which = -1;
  1.1413 -			} else {
  1.1414 -				which = i;
  1.1415 -			}
  1.1416 -		}
  1.1417 +    /* Lock the mixer while modifying the playing channels */
  1.1418 +    SDL_LockAudio();
  1.1419 +    {
  1.1420 +        /* If which is -1, play on the first free channel */
  1.1421 +        if ( which == -1 ) {
  1.1422 +            for ( i=reserved_channels; i<num_channels; ++i ) {
  1.1423 +                if ( mix_channel[i].playing <= 0 )
  1.1424 +                    break;
  1.1425 +            }
  1.1426 +            if ( i == num_channels ) {
  1.1427 +                which = -1;
  1.1428 +            } else {
  1.1429 +                which = i;
  1.1430 +            }
  1.1431 +        }
  1.1432  
  1.1433 -		/* Queue up the audio data for this channel */
  1.1434 -		if ( which >= 0 && which < num_channels ) {
  1.1435 -			Uint32 sdl_ticks = SDL_GetTicks();
  1.1436 -			if (Mix_Playing(which))
  1.1437 -				_Mix_channel_done_playing(which);
  1.1438 -			mix_channel[which].samples = chunk->abuf;
  1.1439 -			mix_channel[which].playing = chunk->alen;
  1.1440 -			mix_channel[which].looping = loops;
  1.1441 -			mix_channel[which].chunk = chunk;
  1.1442 -			mix_channel[which].paused = 0;
  1.1443 -			mix_channel[which].fading = MIX_FADING_IN;
  1.1444 -			mix_channel[which].fade_volume = mix_channel[which].volume;
  1.1445 -			mix_channel[which].fade_volume_reset = mix_channel[which].volume;
  1.1446 -			mix_channel[which].volume = 0;
  1.1447 -			mix_channel[which].fade_length = (Uint32)ms;
  1.1448 -			mix_channel[which].start_time = mix_channel[which].ticks_fade = sdl_ticks;
  1.1449 -			mix_channel[which].expire = (ticks > 0) ? (sdl_ticks+ticks) : 0;
  1.1450 -		}
  1.1451 -	}
  1.1452 -	SDL_UnlockAudio();
  1.1453 +        /* Queue up the audio data for this channel */
  1.1454 +        if ( which >= 0 && which < num_channels ) {
  1.1455 +            Uint32 sdl_ticks = SDL_GetTicks();
  1.1456 +            if (Mix_Playing(which))
  1.1457 +                _Mix_channel_done_playing(which);
  1.1458 +            mix_channel[which].samples = chunk->abuf;
  1.1459 +            mix_channel[which].playing = chunk->alen;
  1.1460 +            mix_channel[which].looping = loops;
  1.1461 +            mix_channel[which].chunk = chunk;
  1.1462 +            mix_channel[which].paused = 0;
  1.1463 +            mix_channel[which].fading = MIX_FADING_IN;
  1.1464 +            mix_channel[which].fade_volume = mix_channel[which].volume;
  1.1465 +            mix_channel[which].fade_volume_reset = mix_channel[which].volume;
  1.1466 +            mix_channel[which].volume = 0;
  1.1467 +            mix_channel[which].fade_length = (Uint32)ms;
  1.1468 +            mix_channel[which].start_time = mix_channel[which].ticks_fade = sdl_ticks;
  1.1469 +            mix_channel[which].expire = (ticks > 0) ? (sdl_ticks+ticks) : 0;
  1.1470 +        }
  1.1471 +    }
  1.1472 +    SDL_UnlockAudio();
  1.1473  
  1.1474 -	/* Return the channel on which the sound is being played */
  1.1475 -	return(which);
  1.1476 +    /* Return the channel on which the sound is being played */
  1.1477 +    return(which);
  1.1478  }
  1.1479  
  1.1480  /* Set volume of a particular channel */
  1.1481  int Mix_Volume(int which, int volume)
  1.1482  {
  1.1483 -	int i;
  1.1484 -	int prev_volume = 0;
  1.1485 +    int i;
  1.1486 +    int prev_volume = 0;
  1.1487  
  1.1488 -	if ( which == -1 ) {
  1.1489 -		for ( i=0; i<num_channels; ++i ) {
  1.1490 -			prev_volume += Mix_Volume(i, volume);
  1.1491 -		}
  1.1492 -		prev_volume /= num_channels;
  1.1493 -	} else if ( which < num_channels ) {
  1.1494 -		prev_volume = mix_channel[which].volume;
  1.1495 -		if ( volume >= 0 ) {
  1.1496 -			if ( volume > SDL_MIX_MAXVOLUME ) {
  1.1497 -				volume = SDL_MIX_MAXVOLUME;
  1.1498 -			}
  1.1499 -			mix_channel[which].volume = volume;
  1.1500 -		}
  1.1501 -	}
  1.1502 -	return(prev_volume);
  1.1503 +    if ( which == -1 ) {
  1.1504 +        for ( i=0; i<num_channels; ++i ) {
  1.1505 +            prev_volume += Mix_Volume(i, volume);
  1.1506 +        }
  1.1507 +        prev_volume /= num_channels;
  1.1508 +    } else if ( which < num_channels ) {
  1.1509 +        prev_volume = mix_channel[which].volume;
  1.1510 +        if ( volume >= 0 ) {
  1.1511 +            if ( volume > SDL_MIX_MAXVOLUME ) {
  1.1512 +                volume = SDL_MIX_MAXVOLUME;
  1.1513 +            }
  1.1514 +            mix_channel[which].volume = volume;
  1.1515 +        }
  1.1516 +    }
  1.1517 +    return(prev_volume);
  1.1518  }
  1.1519  /* Set volume of a particular chunk */
  1.1520  int Mix_VolumeChunk(Mix_Chunk *chunk, int volume)
  1.1521  {
  1.1522 -	int prev_volume;
  1.1523 +    int prev_volume;
  1.1524  
  1.1525 -	prev_volume = chunk->volume;
  1.1526 -	if ( volume >= 0 ) {
  1.1527 -		if ( volume > MIX_MAX_VOLUME ) {
  1.1528 -			volume = MIX_MAX_VOLUME;
  1.1529 -		}
  1.1530 -		chunk->volume = volume;
  1.1531 -	}
  1.1532 -	return(prev_volume);
  1.1533 +    prev_volume = chunk->volume;
  1.1534 +    if ( volume >= 0 ) {
  1.1535 +        if ( volume > MIX_MAX_VOLUME ) {
  1.1536 +            volume = MIX_MAX_VOLUME;
  1.1537 +        }
  1.1538 +        chunk->volume = volume;
  1.1539 +    }
  1.1540 +    return(prev_volume);
  1.1541  }
  1.1542  
  1.1543  /* Halt playing of a particular channel */
  1.1544  int Mix_HaltChannel(int which)
  1.1545  {
  1.1546 -	int i;
  1.1547 +    int i;
  1.1548  
  1.1549 -	if ( which == -1 ) {
  1.1550 -		for ( i=0; i<num_channels; ++i ) {
  1.1551 -			Mix_HaltChannel(i);
  1.1552 -		}
  1.1553 -	} else if ( which < num_channels ) {
  1.1554 -		SDL_LockAudio();
  1.1555 -		if (mix_channel[which].playing) {
  1.1556 -			_Mix_channel_done_playing(which);
  1.1557 -			mix_channel[which].playing = 0;
  1.1558 -			mix_channel[which].looping = 0;
  1.1559 -		}
  1.1560 -		mix_channel[which].expire = 0;
  1.1561 -		if(mix_channel[which].fading != MIX_NO_FADING) /* Restore volume */
  1.1562 -			mix_channel[which].volume = mix_channel[which].fade_volume_reset;
  1.1563 -		mix_channel[which].fading = MIX_NO_FADING;
  1.1564 -		SDL_UnlockAudio();
  1.1565 -	}
  1.1566 -	return(0);
  1.1567 +    if ( which == -1 ) {
  1.1568 +        for ( i=0; i<num_channels; ++i ) {
  1.1569 +            Mix_HaltChannel(i);
  1.1570 +        }
  1.1571 +    } else if ( which < num_channels ) {
  1.1572 +        SDL_LockAudio();
  1.1573 +        if (mix_channel[which].playing) {
  1.1574 +            _Mix_channel_done_playing(which);
  1.1575 +            mix_channel[which].playing = 0;
  1.1576 +            mix_channel[which].looping = 0;
  1.1577 +        }
  1.1578 +        mix_channel[which].expire = 0;
  1.1579 +        if(mix_channel[which].fading != MIX_NO_FADING) /* Restore volume */
  1.1580 +            mix_channel[which].volume = mix_channel[which].fade_volume_reset;
  1.1581 +        mix_channel[which].fading = MIX_NO_FADING;
  1.1582 +        SDL_UnlockAudio();
  1.1583 +    }
  1.1584 +    return(0);
  1.1585  }
  1.1586  
  1.1587  /* Halt playing of a particular group of channels */
  1.1588  int Mix_HaltGroup(int tag)
  1.1589  {
  1.1590 -	int i;
  1.1591 +    int i;
  1.1592  
  1.1593 -	for ( i=0; i<num_channels; ++i ) {
  1.1594 -		if( mix_channel[i].tag == tag ) {
  1.1595 -			Mix_HaltChannel(i);
  1.1596 -		}
  1.1597 -	}
  1.1598 -	return(0);
  1.1599 +    for ( i=0; i<num_channels; ++i ) {
  1.1600 +        if( mix_channel[i].tag == tag ) {
  1.1601 +            Mix_HaltChannel(i);
  1.1602 +        }
  1.1603 +    }
  1.1604 +    return(0);
  1.1605  }
  1.1606  
  1.1607  /* Fade out a channel and then stop it automatically */
  1.1608  int Mix_FadeOutChannel(int which, int ms)
  1.1609  {
  1.1610 -	int status;
  1.1611 +    int status;
  1.1612  
  1.1613 -	status = 0;
  1.1614 -	if ( audio_opened ) {
  1.1615 -		if ( which == -1 ) {
  1.1616 -			int i;
  1.1617 +    status = 0;
  1.1618 +    if ( audio_opened ) {
  1.1619 +        if ( which == -1 ) {
  1.1620 +            int i;
  1.1621  
  1.1622 -			for ( i=0; i<num_channels; ++i ) {
  1.1623 -				status += Mix_FadeOutChannel(i, ms);
  1.1624 -			}
  1.1625 -		} else if ( which < num_channels ) {
  1.1626 -			SDL_LockAudio();
  1.1627 -			if ( mix_channel[which].playing && 
  1.1628 -			    (mix_channel[which].volume > 0) &&
  1.1629 -			    (mix_channel[which].fading != MIX_FADING_OUT) ) {
  1.1630 -				mix_channel[which].fade_volume = mix_channel[which].volume;
  1.1631 -				mix_channel[which].fading = MIX_FADING_OUT;
  1.1632 -				mix_channel[which].fade_length = ms;
  1.1633 -				mix_channel[which].ticks_fade = SDL_GetTicks();
  1.1634 +            for ( i=0; i<num_channels; ++i ) {
  1.1635 +                status += Mix_FadeOutChannel(i, ms);
  1.1636 +            }
  1.1637 +        } else if ( which < num_channels ) {
  1.1638 +            SDL_LockAudio();
  1.1639 +            if ( mix_channel[which].playing &&
  1.1640 +                (mix_channel[which].volume > 0) &&
  1.1641 +                (mix_channel[which].fading != MIX_FADING_OUT) ) {
  1.1642 +                mix_channel[which].fade_volume = mix_channel[which].volume;
  1.1643 +                mix_channel[which].fading = MIX_FADING_OUT;
  1.1644 +                mix_channel[which].fade_length = ms;
  1.1645 +                mix_channel[which].ticks_fade = SDL_GetTicks();
  1.1646  
  1.1647 -				/* only change fade_volume_reset if we're not fading. */
  1.1648 -				if (mix_channel[which].fading == MIX_NO_FADING) {
  1.1649 -				    mix_channel[which].fade_volume_reset = mix_channel[which].volume;
  1.1650 -				}
  1.1651 -				++status;
  1.1652 -			}
  1.1653 -			SDL_UnlockAudio();
  1.1654 -		}
  1.1655 -	}
  1.1656 -	return(status);
  1.1657 +                /* only change fade_volume_reset if we're not fading. */
  1.1658 +                if (mix_channel[which].fading == MIX_NO_FADING) {
  1.1659 +                    mix_channel[which].fade_volume_reset = mix_channel[which].volume;
  1.1660 +                }
  1.1661 +                ++status;
  1.1662 +            }
  1.1663 +            SDL_UnlockAudio();
  1.1664 +        }
  1.1665 +    }
  1.1666 +    return(status);
  1.1667  }
  1.1668  
  1.1669  /* Halt playing of a particular group of channels */
  1.1670  int Mix_FadeOutGroup(int tag, int ms)
  1.1671  {
  1.1672 -	int i;
  1.1673 -	int status = 0;
  1.1674 -	for ( i=0; i<num_channels; ++i ) {
  1.1675 -		if( mix_channel[i].tag == tag ) {
  1.1676 -			status += Mix_FadeOutChannel(i,ms);
  1.1677 -		}
  1.1678 -	}
  1.1679 -	return(status);
  1.1680 +    int i;
  1.1681 +    int status = 0;
  1.1682 +    for ( i=0; i<num_channels; ++i ) {
  1.1683 +        if( mix_channel[i].tag == tag ) {
  1.1684 +            status += Mix_FadeOutChannel(i,ms);
  1.1685 +        }
  1.1686 +    }
  1.1687 +    return(status);
  1.1688  }
  1.1689  
  1.1690  Mix_Fading Mix_FadingChannel(int which)
  1.1691  {
  1.1692 -	if ( which < 0 || which >= num_channels ) {
  1.1693 -		return MIX_NO_FADING;
  1.1694 -	}
  1.1695 -	return mix_channel[which].fading;
  1.1696 +    if ( which < 0 || which >= num_channels ) {
  1.1697 +        return MIX_NO_FADING;
  1.1698 +    }
  1.1699 +    return mix_channel[which].fading;
  1.1700  }
  1.1701  
  1.1702  /* Check the status of a specific channel.
  1.1703 @@ -1088,206 +1088,206 @@
  1.1704  */
  1.1705  int Mix_Playing(int which)
  1.1706  {
  1.1707 -	int status;
  1.1708 +    int status;
  1.1709  
  1.1710 -	status = 0;
  1.1711 -	if ( which == -1 ) {
  1.1712 -		int i;
  1.1713 +    status = 0;
  1.1714 +    if ( which == -1 ) {
  1.1715 +        int i;
  1.1716  
  1.1717 -		for ( i=0; i<num_channels; ++i ) {
  1.1718 -			if ((mix_channel[i].playing > 0) ||
  1.1719 -				(mix_channel[i].looping > 0))
  1.1720 -			{
  1.1721 -				++status;
  1.1722 -			}
  1.1723 -		}
  1.1724 -	} else if ( which < num_channels ) {
  1.1725 -		if ( (mix_channel[which].playing > 0) ||
  1.1726 -		     (mix_channel[which].looping > 0) )
  1.1727 -		{
  1.1728 -			++status;
  1.1729 -		}
  1.1730 -	}
  1.1731 -	return(status);
  1.1732 +        for ( i=0; i<num_channels; ++i ) {
  1.1733 +            if ((mix_channel[i].playing > 0) ||
  1.1734 +                (mix_channel[i].looping > 0))
  1.1735 +            {
  1.1736 +                ++status;
  1.1737 +            }
  1.1738 +        }
  1.1739 +    } else if ( which < num_channels ) {
  1.1740 +        if ( (mix_channel[which].playing > 0) ||
  1.1741 +             (mix_channel[which].looping > 0) )
  1.1742 +        {
  1.1743 +            ++status;
  1.1744 +        }
  1.1745 +    }
  1.1746 +    return(status);
  1.1747  }
  1.1748  
  1.1749  /* rcg06072001 Get the chunk associated with a channel. */
  1.1750  Mix_Chunk *Mix_GetChunk(int channel)
  1.1751  {
  1.1752 -	Mix_Chunk *retval = NULL;
  1.1753 +    Mix_Chunk *retval = NULL;
  1.1754  
  1.1755 -	if ((channel >= 0) && (channel < num_channels)) {
  1.1756 -		retval = mix_channel[channel].chunk;
  1.1757 -	}
  1.1758 +    if ((channel >= 0) && (channel < num_channels)) {
  1.1759 +        retval = mix_channel[channel].chunk;
  1.1760 +    }
  1.1761  
  1.1762 -	return(retval);
  1.1763 +    return(retval);
  1.1764  }
  1.1765  
  1.1766  /* Close the mixer, halting all playing audio */
  1.1767  void Mix_CloseAudio(void)
  1.1768  {
  1.1769 -	int i;
  1.1770 +    int i;
  1.1771  
  1.1772 -	if ( audio_opened ) {
  1.1773 -		if ( audio_opened == 1 ) {
  1.1774 -			for (i = 0; i < num_channels; i++) {
  1.1775 -				Mix_UnregisterAllEffects(i);
  1.1776 -			}
  1.1777 -			Mix_UnregisterAllEffects(MIX_CHANNEL_POST);
  1.1778 -			close_music();
  1.1779 -			Mix_HaltChannel(-1);
  1.1780 -			_Mix_DeinitEffects();
  1.1781 -			SDL_CloseAudio();
  1.1782 -			SDL_free(mix_channel);
  1.1783 -			mix_channel = NULL;
  1.1784 +    if ( audio_opened ) {
  1.1785 +        if ( audio_opened == 1 ) {
  1.1786 +            for (i = 0; i < num_channels; i++) {
  1.1787 +                Mix_UnregisterAllEffects(i);
  1.1788 +            }
  1.1789 +            Mix_UnregisterAllEffects(MIX_CHANNEL_POST);
  1.1790 +            close_music();
  1.1791 +            Mix_HaltChannel(-1);
  1.1792 +            _Mix_DeinitEffects();
  1.1793 +            SDL_CloseAudio();
  1.1794 +            SDL_free(mix_channel);
  1.1795 +            mix_channel = NULL;
  1.1796  
  1.1797 -			/* rcg06042009 report available decoders at runtime. */
  1.1798 -			SDL_free(chunk_decoders);
  1.1799 -			chunk_decoders = NULL;
  1.1800 -			num_decoders = 0;
  1.1801 -		}
  1.1802 -		--audio_opened;
  1.1803 -	}
  1.1804 +            /* rcg06042009 report available decoders at runtime. */
  1.1805 +            SDL_free(chunk_decoders);
  1.1806 +            chunk_decoders = NULL;
  1.1807 +            num_decoders = 0;
  1.1808 +        }
  1.1809 +        --audio_opened;
  1.1810 +    }
  1.1811  }
  1.1812  
  1.1813  /* Pause a particular channel (or all) */
  1.1814  void Mix_Pause(int which)
  1.1815  {
  1.1816 -	Uint32 sdl_ticks = SDL_GetTicks();
  1.1817 -	if ( which == -1 ) {
  1.1818 -		int i;
  1.1819 +    Uint32 sdl_ticks = SDL_GetTicks();
  1.1820 +    if ( which == -1 ) {
  1.1821 +        int i;
  1.1822  
  1.1823 -		for ( i=0; i<num_channels; ++i ) {
  1.1824 -			if ( mix_channel[i].playing > 0 ) {
  1.1825 -				mix_channel[i].paused = sdl_ticks;
  1.1826 -			}
  1.1827 -		}
  1.1828 -	} else if ( which < num_channels ) {
  1.1829 -		if ( mix_channel[which].playing > 0 ) {
  1.1830 -			mix_channel[which].paused = sdl_ticks;
  1.1831 -		}
  1.1832 -	}
  1.1833 +        for ( i=0; i<num_channels; ++i ) {
  1.1834 +            if ( mix_channel[i].playing > 0 ) {
  1.1835 +                mix_channel[i].paused = sdl_ticks;
  1.1836 +            }
  1.1837 +        }
  1.1838 +    } else if ( which < num_channels ) {
  1.1839 +        if ( mix_channel[which].playing > 0 ) {
  1.1840 +            mix_channel[which].paused = sdl_ticks;
  1.1841 +        }
  1.1842 +    }
  1.1843  }
  1.1844  
  1.1845  /* Resume a paused channel */
  1.1846  void Mix_Resume(int which)
  1.1847  {
  1.1848 -	Uint32 sdl_ticks = SDL_GetTicks();
  1.1849 +    Uint32 sdl_ticks = SDL_GetTicks();
  1.1850  
  1.1851 -	SDL_LockAudio();
  1.1852 -	if ( which == -1 ) {
  1.1853 -		int i;
  1.1854 +    SDL_LockAudio();
  1.1855 +    if ( which == -1 ) {
  1.1856 +        int i;
  1.1857  
  1.1858 -		for ( i=0; i<num_channels; ++i ) {
  1.1859 -			if ( mix_channel[i].playing > 0 ) {
  1.1860 -				if(mix_channel[i].expire > 0)
  1.1861 -					mix_channel[i].expire += sdl_ticks - mix_channel[i].paused;
  1.1862 -				mix_channel[i].paused = 0;
  1.1863 -			}
  1.1864 -		}
  1.1865 -	} else if ( which < num_channels ) {
  1.1866 -		if ( mix_channel[which].playing > 0 ) {
  1.1867 -			if(mix_channel[which].expire > 0)
  1.1868 -				mix_channel[which].expire += sdl_ticks - mix_channel[which].paused;
  1.1869 -			mix_channel[which].paused = 0;
  1.1870 -		}
  1.1871 -	}
  1.1872 -	SDL_UnlockAudio();
  1.1873 +        for ( i=0; i<num_channels; ++i ) {
  1.1874 +            if ( mix_channel[i].playing > 0 ) {
  1.1875 +                if(mix_channel[i].expire > 0)
  1.1876 +                    mix_channel[i].expire += sdl_ticks - mix_channel[i].paused;
  1.1877 +                mix_channel[i].paused = 0;
  1.1878 +            }
  1.1879 +        }
  1.1880 +    } else if ( which < num_channels ) {
  1.1881 +        if ( mix_channel[which].playing > 0 ) {
  1.1882 +            if(mix_channel[which].expire > 0)
  1.1883 +                mix_channel[which].expire += sdl_ticks - mix_channel[which].paused;
  1.1884 +            mix_channel[which].paused = 0;
  1.1885 +        }
  1.1886 +    }
  1.1887 +    SDL_UnlockAudio();
  1.1888  }
  1.1889  
  1.1890  int Mix_Paused(int which)
  1.1891  {
  1.1892 -	if ( which < 0 ) {
  1.1893 -		int status = 0;
  1.1894 -		int i;
  1.1895 -		for( i=0; i < num_channels; ++i ) {
  1.1896 -			if ( mix_channel[i].paused ) {
  1.1897 -				++ status;
  1.1898 -			}
  1.1899 -		}
  1.1900 -		return(status);
  1.1901 -	} else if ( which < num_channels ) {
  1.1902 -		return(mix_channel[which].paused != 0);
  1.1903 -	} else {
  1.1904 -		return(0);
  1.1905 -	}
  1.1906 +    if ( which < 0 ) {
  1.1907 +        int status = 0;
  1.1908 +        int i;
  1.1909 +        for( i=0; i < num_channels; ++i ) {
  1.1910 +            if ( mix_channel[i].paused ) {
  1.1911 +                ++ status;
  1.1912 +            }
  1.1913 +        }
  1.1914 +        return(status);
  1.1915 +    } else if ( which < num_channels ) {
  1.1916 +        return(mix_channel[which].paused != 0);
  1.1917 +    } else {
  1.1918 +        return(0);
  1.1919 +    }
  1.1920  }
  1.1921  
  1.1922  /* Change the group of a channel */
  1.1923  int Mix_GroupChannel(int which, int tag)
  1.1924  {
  1.1925 -	if ( which < 0 || which > num_channels )
  1.1926 -		return(0);
  1.1927 +    if ( which < 0 || which > num_channels )
  1.1928 +        return(0);
  1.1929  
  1.1930 -	SDL_LockAudio();
  1.1931 -	mix_channel[which].tag = tag;
  1.1932 -	SDL_UnlockAudio();
  1.1933 -	return(1);
  1.1934 +    SDL_LockAudio();
  1.1935 +    mix_channel[which].tag = tag;
  1.1936 +    SDL_UnlockAudio();
  1.1937 +    return(1);
  1.1938  }
  1.1939  
  1.1940  /* Assign several consecutive channels to a group */
  1.1941  int Mix_GroupChannels(int from, int to, int tag)
  1.1942  {
  1.1943 -	int status = 0;
  1.1944 -	for( ; from <= to; ++ from ) {
  1.1945 -		status += Mix_GroupChannel(from, tag);
  1.1946 -	}
  1.1947 -	return(status);
  1.1948 +    int status = 0;
  1.1949 +    for( ; from <= to; ++ from ) {
  1.1950 +        status += Mix_GroupChannel(from, tag);
  1.1951 +    }
  1.1952 +    return(status);
  1.1953  }
  1.1954  
  1.1955  /* Finds the first available channel in a group of channels */
  1.1956  int Mix_GroupAvailable(int tag)
  1.1957  {
  1.1958 -	int i;
  1.1959 -	for( i=0; i < num_channels; i ++ ) {
  1.1960 -		if ( ((tag == -1) || (tag == mix_channel[i].tag)) &&
  1.1961 -		                    (mix_channel[i].playing <= 0) )
  1.1962 -			return i;
  1.1963 -	}
  1.1964 -	return(-1);
  1.1965 +    int i;
  1.1966 +    for( i=0; i < num_channels; i ++ ) {
  1.1967 +        if ( ((tag == -1) || (tag == mix_channel[i].tag)) &&
  1.1968 +                            (mix_channel[i].playing <= 0) )
  1.1969 +            return i;
  1.1970 +    }
  1.1971 +    return(-1);
  1.1972  }
  1.1973  
  1.1974  int Mix_GroupCount(int tag)
  1.1975  {
  1.1976 -	int count = 0;
  1.1977 -	int i;
  1.1978 -	for( i=0; i < num_channels; i ++ ) {
  1.1979 -		if ( mix_channel[i].tag==tag || tag==-1 )
  1.1980 -			++ count;
  1.1981 -	}
  1.1982 -	return(count);
  1.1983 +    int count = 0;
  1.1984 +    int i;
  1.1985 +    for( i=0; i < num_channels; i ++ ) {
  1.1986 +        if ( mix_channel[i].tag==tag || tag==-1 )
  1.1987 +            ++ count;
  1.1988 +    }
  1.1989 +    return(count);
  1.1990  }
  1.1991  
  1.1992  /* Finds the "oldest" sample playing in a group of channels */
  1.1993  int Mix_GroupOldest(int tag)
  1.1994  {
  1.1995 -	int chan = -1;
  1.1996 -	Uint32 mintime = SDL_GetTicks();
  1.1997 -	int i;
  1.1998 -	for( i=0; i < num_channels; i ++ ) {
  1.1999 -		if ( (mix_channel[i].tag==tag || tag==-1) && mix_channel[i].playing > 0
  1.2000 -			 && mix_channel[i].start_time <= mintime ) {
  1.2001 -			mintime = mix_channel[i].start_time;
  1.2002 -			chan = i;
  1.2003 -		}
  1.2004 -	}
  1.2005 -	return(chan);
  1.2006 +    int chan = -1;
  1.2007 +    Uint32 mintime = SDL_GetTicks();
  1.2008 +    int i;
  1.2009 +    for( i=0; i < num_channels; i ++ ) {
  1.2010 +        if ( (mix_channel[i].tag==tag || tag==-1) && mix_channel[i].playing > 0
  1.2011 +             && mix_channel[i].start_time <= mintime ) {
  1.2012 +            mintime = mix_channel[i].start_time;
  1.2013 +            chan = i;
  1.2014 +        }
  1.2015 +    }
  1.2016 +    return(chan);
  1.2017  }
  1.2018  
  1.2019  /* Finds the "most recent" (i.e. last) sample playing in a group of channels */
  1.2020  int Mix_GroupNewer(int tag)
  1.2021  {
  1.2022 -	int chan = -1;
  1.2023 -	Uint32 maxtime = 0;
  1.2024 -	int i;
  1.2025 -	for( i=0; i < num_channels; i ++ ) {
  1.2026 -		if ( (mix_channel[i].tag==tag || tag==-1) && mix_channel[i].playing > 0
  1.2027 -			 && mix_channel[i].start_time >= maxtime ) {
  1.2028 -			maxtime = mix_channel[i].start_time;
  1.2029 -			chan = i;
  1.2030 -		}
  1.2031 -	}
  1.2032 -	return(chan);
  1.2033 +    int chan = -1;
  1.2034 +    Uint32 maxtime = 0;
  1.2035 +    int i;
  1.2036 +    for( i=0; i < num_channels; i ++ ) {
  1.2037 +        if ( (mix_channel[i].tag==tag || tag==-1) && mix_channel[i].playing > 0
  1.2038 +             && mix_channel[i].start_time >= maxtime ) {
  1.2039 +            maxtime = mix_channel[i].start_time;
  1.2040 +            chan = i;
  1.2041 +        }
  1.2042 +    }
  1.2043 +    return(chan);
  1.2044  }
  1.2045  
  1.2046  
  1.2047 @@ -1300,134 +1300,134 @@
  1.2048  
  1.2049  /* MAKE SURE you hold the audio lock (SDL_LockAudio()) before calling this! */
  1.2050  static int _Mix_register_effect(effect_info **e, Mix_EffectFunc_t f,
  1.2051 -				Mix_EffectDone_t d, void *arg)
  1.2052 +                Mix_EffectDone_t d, void *arg)
  1.2053  {
  1.2054 -	effect_info *new_e;
  1.2055 +    effect_info *new_e;
  1.2056  
  1.2057 -	if (!e) {
  1.2058 -		Mix_SetError("Internal error");
  1.2059 -		return(0);
  1.2060 -	}
  1.2061 +    if (!e) {
  1.2062 +        Mix_SetError("Internal error");
  1.2063 +        return(0);
  1.2064 +    }
  1.2065  
  1.2066 -	if (f == NULL) {
  1.2067 -		Mix_SetError("NULL effect callback");
  1.2068 -		return(0);
  1.2069 -	}
  1.2070 +    if (f == NULL) {
  1.2071 +        Mix_SetError("NULL effect callback");
  1.2072 +        return(0);
  1.2073 +    }
  1.2074  
  1.2075 -	new_e = SDL_malloc(sizeof (effect_info));
  1.2076 -	if (new_e == NULL) {
  1.2077 -		Mix_SetError("Out of memory");
  1.2078 -		return(0);
  1.2079 -	}
  1.2080 +    new_e = SDL_malloc(sizeof (effect_info));
  1.2081 +    if (new_e == NULL) {
  1.2082 +        Mix_SetError("Out of memory");
  1.2083 +        return(0);
  1.2084 +    }
  1.2085  
  1.2086 -	new_e->callback = f;
  1.2087 -	new_e->done_callback = d;
  1.2088 -	new_e->udata = arg;
  1.2089 -	new_e->next = NULL;
  1.2090 +    new_e->callback = f;
  1.2091 +    new_e->done_callback = d;
  1.2092 +    new_e->udata = arg;
  1.2093 +    new_e->next = NULL;
  1.2094  
  1.2095 -	/* add new effect to end of linked list... */
  1.2096 -	if (*e == NULL) {
  1.2097 -		*e = new_e;
  1.2098 -	} else {
  1.2099 -		effect_info *cur = *e;
  1.2100 -		while (1) {
  1.2101 -			if (cur->next == NULL) {
  1.2102 -				cur->next = new_e;
  1.2103 -				break;
  1.2104 -			}
  1.2105 -			cur = cur->next;
  1.2106 -		}
  1.2107 -	}
  1.2108 +    /* add new effect to end of linked list... */
  1.2109 +    if (*e == NULL) {
  1.2110 +        *e = new_e;
  1.2111 +    } else {
  1.2112 +        effect_info *cur = *e;
  1.2113 +        while (1) {
  1.2114 +            if (cur->next == NULL) {
  1.2115 +                cur->next = new_e;
  1.2116 +                break;
  1.2117 +            }
  1.2118 +            cur = cur->next;
  1.2119 +        }
  1.2120 +    }
  1.2121  
  1.2122 -	return(1);
  1.2123 +    return(1);
  1.2124  }
  1.2125  
  1.2126  
  1.2127  /* MAKE SURE you hold the audio lock (SDL_LockAudio()) before calling this! */
  1.2128  static int _Mix_remove_effect(int channel, effect_info **e, Mix_EffectFunc_t f)
  1.2129  {
  1.2130 -	effect_info *cur;
  1.2131 -	effect_info *prev = NULL;
  1.2132 -	effect_info *next = NULL;
  1.2133 +    effect_info *cur;
  1.2134 +    effect_info *prev = NULL;
  1.2135 +    effect_info *next = NULL;
  1.2136  
  1.2137 -	if (!e) {
  1.2138 -		Mix_SetError("Internal error");
  1.2139 -		return(0);
  1.2140 -	}
  1.2141 +    if (!e) {
  1.2142 +        Mix_SetError("Internal error");
  1.2143 +        return(0);
  1.2144 +    }
  1.2145  
  1.2146 -	for (cur = *e; cur != NULL; cur = cur->next) {
  1.2147 -		if (cur->callback == f) {
  1.2148 -			next = cur->next;
  1.2149 -			if (cur->done_callback != NULL) {
  1.2150 -				cur->done_callback(channel, cur->udata);
  1.2151 -			}
  1.2152 -			SDL_free(cur);
  1.2153 +    for (cur = *e; cur != NULL; cur = cur->next) {
  1.2154 +        if (cur->callback == f) {
  1.2155 +            next = cur->next;
  1.2156 +            if (cur->done_callback != NULL) {
  1.2157 +                cur->done_callback(channel, cur->udata);
  1.2158 +            }
  1.2159 +            SDL_free(cur);
  1.2160  
  1.2161 -			if (prev == NULL) {   /* removing first item of list? */
  1.2162 -				*e = next;
  1.2163 -			} else {
  1.2164 -				prev->next = next;
  1.2165 -			}
  1.2166 -			return(1);
  1.2167 -		}
  1.2168 -		prev = cur;
  1.2169 -	}
  1.2170 +            if (prev == NULL) {   /* removing first item of list? */
  1.2171 +                *e = next;
  1.2172 +            } else {
  1.2173 +                prev->next = next;
  1.2174 +            }
  1.2175 +            return(1);
  1.2176 +        }
  1.2177 +        prev = cur;
  1.2178 +    }
  1.2179  
  1.2180 -	Mix_SetError("No such effect registered");
  1.2181 -	return(0);
  1.2182 +    Mix_SetError("No such effect registered");
  1.2183 +    return(0);
  1.2184  }
  1.2185  
  1.2186  
  1.2187  /* MAKE SURE you hold the audio lock (SDL_LockAudio()) before calling this! */
  1.2188  static int _Mix_remove_all_effects(int channel, effect_info **e)
  1.2189  {
  1.2190 -	effect_info *cur;
  1.2191 -	effect_info *next;
  1.2192 +    effect_info *cur;
  1.2193 +    effect_info *next;
  1.2194  
  1.2195 -	if (!e) {
  1.2196 -		Mix_SetError("Internal error");
  1.2197 -		return(0);
  1.2198 -	}
  1.2199 +    if (!e) {
  1.2200 +        Mix_SetError("Internal error");
  1.2201 +        return(0);
  1.2202 +    }
  1.2203  
  1.2204 -	for (cur = *e; cur != NULL; cur = next) {
  1.2205 -		next = cur->next;
  1.2206 -		if (cur->done_callback != NULL) {
  1.2207 -			cur->done_callback(channel, cur->udata);
  1.2208 -		}
  1.2209 -		SDL_free(cur);
  1.2210 -	}
  1.2211 -	*e = NULL;
  1.2212 +    for (cur = *e; cur != NULL; cur = next) {
  1.2213 +        next = cur->next;
  1.2214 +        if (cur->done_callback != NULL) {
  1.2215 +            cur->done_callback(channel, cur->udata);
  1.2216 +        }
  1.2217 +        SDL_free(cur);
  1.2218 +    }
  1.2219 +    *e = NULL;
  1.2220  
  1.2221 -	return(1);
  1.2222 +    return(1);
  1.2223  }
  1.2224  
  1.2225  
  1.2226  /* MAKE SURE you hold the audio lock (SDL_LockAudio()) before calling this! */
  1.2227  int _Mix_RegisterEffect_locked(int channel, Mix_EffectFunc_t f,
  1.2228 -			Mix_EffectDone_t d, void *arg)
  1.2229 +            Mix_EffectDone_t d, void *arg)
  1.2230  {
  1.2231 -	effect_info **e = NULL;
  1.2232 +    effect_info **e = NULL;
  1.2233  
  1.2234 -	if (channel == MIX_CHANNEL_POST) {
  1.2235 -		e = &posteffects;
  1.2236 -	} else {
  1.2237 -		if ((channel < 0) || (channel >= num_channels)) {
  1.2238 -			Mix_SetError("Invalid channel number");
  1.2239 -			return(0);
  1.2240 -		}
  1.2241 -		e = &mix_channel[channel].effects;
  1.2242 -	}
  1.2243 +    if (channel == MIX_CHANNEL_POST) {
  1.2244 +        e = &posteffects;
  1.2245 +    } else {
  1.2246 +        if ((channel < 0) || (channel >= num_channels)) {
  1.2247 +            Mix_SetError("Invalid channel number");
  1.2248 +            return(0);
  1.2249 +        }
  1.2250 +        e = &mix_channel[channel].effects;
  1.2251 +    }
  1.2252  
  1.2253 -	return _Mix_register_effect(e, f, d, arg);
  1.2254 +    return _Mix_register_effect(e, f, d, arg);
  1.2255  }
  1.2256  
  1.2257  int Mix_RegisterEffect(int channel, Mix_EffectFunc_t f,
  1.2258 -			Mix_EffectDone_t d, void *arg)
  1.2259 +            Mix_EffectDone_t d, void *arg)
  1.2260  {
  1.2261      int retval;
  1.2262 -	SDL_LockAudio();
  1.2263 -	retval = _Mix_RegisterEffect_locked(channel, f, d, arg);
  1.2264 -	SDL_UnlockAudio();
  1.2265 +    SDL_LockAudio();
  1.2266 +    retval = _Mix_RegisterEffect_locked(channel, f, d, arg);
  1.2267 +    SDL_UnlockAudio();
  1.2268      return retval;
  1.2269  }
  1.2270  
  1.2271 @@ -1435,55 +1435,55 @@
  1.2272  /* MAKE SURE you hold the audio lock (SDL_LockAudio()) before calling this! */
  1.2273  int _Mix_UnregisterEffect_locked(int channel, Mix_EffectFunc_t f)
  1.2274  {
  1.2275 -	effect_info **e = NULL;
  1.2276 +    effect_info **e = NULL;
  1.2277  
  1.2278 -	if (channel == MIX_CHANNEL_POST) {
  1.2279 -		e = &posteffects;
  1.2280 -	} else {
  1.2281 -		if ((channel < 0) || (channel >= num_channels)) {
  1.2282 -			Mix_SetError("Invalid channel number");
  1.2283 -			return(0);
  1.2284 -		}
  1.2285 -		e = &mix_channel[channel].effects;
  1.2286 -	}
  1.2287 +    if (channel == MIX_CHANNEL_POST) {
  1.2288 +        e = &posteffects;
  1.2289 +    } else {
  1.2290 +        if ((channel < 0) || (channel >= num_channels)) {
  1.2291 +            Mix_SetError("Invalid channel number");
  1.2292 +            return(0);
  1.2293 +        }
  1.2294 +        e = &mix_channel[channel].effects;
  1.2295 +    }
  1.2296  
  1.2297 -	return _Mix_remove_effect(channel, e, f);
  1.2298 +    return _Mix_remove_effect(channel, e, f);
  1.2299  }
  1.2300  
  1.2301  int Mix_UnregisterEffect(int channel, Mix_EffectFunc_t f)
  1.2302  {
  1.2303 -	int retval;
  1.2304 -	SDL_LockAudio();
  1.2305 -	retval = _Mix_UnregisterEffect_locked(channel, f);
  1.2306 -	SDL_UnlockAudio();
  1.2307 -	return(retval);
  1.2308 +    int retval;
  1.2309 +    SDL_LockAudio();
  1.2310 +    retval = _Mix_UnregisterEffect_locked(channel, f);
  1.2311 +    SDL_UnlockAudio();
  1.2312 +    return(retval);
  1.2313  }
  1.2314  
  1.2315  /* MAKE SURE you hold the audio lock (SDL_LockAudio()) before calling this! */
  1.2316  int _Mix_UnregisterAllEffects_locked(int channel)
  1.2317  {
  1.2318 -	effect_info **e = NULL;
  1.2319 +    effect_info **e = NULL;
  1.2320  
  1.2321 -	if (channel == MIX_CHANNEL_POST) {
  1.2322 -		e = &posteffects;
  1.2323 -	} else {
  1.2324 -		if ((channel < 0) || (channel >= num_channels)) {
  1.2325 -			Mix_SetError("Invalid channel number");
  1.2326 -			return(0);
  1.2327 -		}
  1.2328 -		e = &mix_channel[channel].effects;
  1.2329 -	}
  1.2330 +    if (channel == MIX_CHANNEL_POST) {
  1.2331 +        e = &posteffects;
  1.2332 +    } else {
  1.2333 +        if ((channel < 0) || (channel >= num_channels)) {
  1.2334 +            Mix_SetError("Invalid channel number");
  1.2335 +            return(0);
  1.2336 +        }
  1.2337 +        e = &mix_channel[channel].effects;
  1.2338 +    }
  1.2339  
  1.2340 -	return _Mix_remove_all_effects(channel, e);
  1.2341 +    return _Mix_remove_all_effects(channel, e);
  1.2342  }
  1.2343  
  1.2344  int Mix_UnregisterAllEffects(int channel)
  1.2345  {
  1.2346 -	int retval;
  1.2347 -	SDL_LockAudio();
  1.2348 -	retval = _Mix_UnregisterAllEffects_locked(channel);
  1.2349 -	SDL_UnlockAudio();
  1.2350 -	return(retval);
  1.2351 +    int retval;
  1.2352 +    SDL_LockAudio();
  1.2353 +    retval = _Mix_UnregisterAllEffects_locked(channel);
  1.2354 +    SDL_UnlockAudio();
  1.2355 +    return(retval);
  1.2356  }
  1.2357  
  1.2358  /* end of mixer.c ... */