Fixed bug #18
authorSam Lantinga <slouken@libsdl.org>
Tue, 21 Mar 2006 06:45:47 +0000
changeset 15621d487a3fab41
parent 1561 c724c4a99759
child 1563 b054590b967a
Fixed bug #18
Reordered the audio thread loop so there's no initial wait.
src/audio/SDL_audio.c
     1.1 --- a/src/audio/SDL_audio.c	Tue Mar 21 00:56:10 2006 +0000
     1.2 +++ b/src/audio/SDL_audio.c	Tue Mar 21 06:45:47 2006 +0000
     1.3 @@ -174,11 +174,6 @@
     1.4  		stream_len = audio->spec.size;
     1.5  	}
     1.6  
     1.7 -	stream = audio->GetAudioBuf(audio);
     1.8 -	if ( stream == NULL ) {
     1.9 -		stream = audio->fake_stream;
    1.10 -	}
    1.11 -
    1.12  #if SDL_AUDIO_DRIVER_AHI
    1.13  	SDL_mutexV(audio->mixer_lock);
    1.14  	D(bug("Entering audio loop...\n"));
    1.15 @@ -208,16 +203,6 @@
    1.16  	/* Loop, filling the audio buffers */
    1.17  	while ( audio->enabled ) {
    1.18  
    1.19 -		/* Wait for new current buffer to finish playing */
    1.20 -		if ( stream == audio->fake_stream ) {
    1.21 -			SDL_Delay((audio->spec.samples*1000)/audio->spec.freq);
    1.22 -		} else {
    1.23 -#if SDL_AUDIO_DRIVER_AHI
    1.24 -			if ( started > 1 )
    1.25 -#endif
    1.26 -			audio->WaitAudio(audio);
    1.27 -		}
    1.28 -
    1.29  		/* Fill the current buffer with sound */
    1.30  		if ( audio->convert.needed ) {
    1.31  			if ( audio->convert.buf ) {
    1.32 @@ -253,12 +238,16 @@
    1.33  		/* Ready current buffer for play and change current buffer */
    1.34  		if ( stream != audio->fake_stream ) {
    1.35  			audio->PlayAudio(audio);
    1.36 -#if SDL_AUDIO_DRIVER_AHI
    1.37 -/* AmigaOS don't have to wait the first time audio is played! */
    1.38 -			started++;
    1.39 -#endif
    1.40 +		}
    1.41 +
    1.42 +		/* Wait for an audio buffer to become available */
    1.43 +		if ( stream == audio->fake_stream ) {
    1.44 +			SDL_Delay((audio->spec.samples*1000)/audio->spec.freq);
    1.45 +		} else {
    1.46 +			audio->WaitAudio(audio);
    1.47  		}
    1.48  	}
    1.49 +
    1.50  	/* Wait for the audio to drain.. */
    1.51  	if ( audio->WaitDone ) {
    1.52  		audio->WaitDone(audio);