src/audio/SDL_wave.c
changeset 1260 80f8c94b5199
parent 769 b8d311d90021
child 1312 c9b51268668f
     1.1 --- a/src/audio/SDL_wave.c	Tue Jan 24 06:36:43 2006 +0000
     1.2 +++ b/src/audio/SDL_wave.c	Tue Jan 24 07:20:18 2006 +0000
     1.3 @@ -418,8 +418,9 @@
     1.4  
     1.5  	/* WAV magic header */
     1.6  	Uint32 RIFFchunk;
     1.7 -	Uint32 wavelen;
     1.8 +	Uint32 wavelen = 0;
     1.9  	Uint32 WAVEmagic;
    1.10 +	Uint32 headerDiff = 0;
    1.11  
    1.12  	/* FMT chunk */
    1.13  	WaveFMT *format = NULL;
    1.14 @@ -446,6 +447,7 @@
    1.15  		was_error = 1;
    1.16  		goto done;
    1.17  	}
    1.18 +	headerDiff += sizeof(Uint32); // for WAVE
    1.19  
    1.20  	/* Read the audio data format chunk */
    1.21  	chunk.data = NULL;
    1.22 @@ -458,6 +460,8 @@
    1.23  			was_error = 1;
    1.24  			goto done;
    1.25  		}
    1.26 +		// 2 Uint32's for chunk header+len, plus the lenread
    1.27 +		headerDiff += lenread + 2 * sizeof(Uint32);
    1.28  	} while ( (chunk.magic == FACT) || (chunk.magic == LIST) );
    1.29  
    1.30  	/* Decode the audio data format */
    1.31 @@ -535,7 +539,9 @@
    1.32  		}
    1.33  		*audio_len = lenread;
    1.34  		*audio_buf = chunk.data;
    1.35 +		if(chunk.magic != DATA) headerDiff += lenread + 2 * sizeof(Uint32);
    1.36  	} while ( chunk.magic != DATA );
    1.37 +	headerDiff += 2 * sizeof(Uint32); // for the data chunk and len
    1.38  
    1.39  	if ( MS_ADPCM_encoded ) {
    1.40  		if ( MS_ADPCM_decode(audio_buf, audio_len) < 0 ) {
    1.41 @@ -561,6 +567,10 @@
    1.42  	if ( freesrc && src ) {
    1.43  		SDL_RWclose(src);
    1.44  	}
    1.45 +	else {
    1.46 +		// seek to the end of the file (given by the RIFF chunk)
    1.47 +		SDL_RWseek(src, wavelen - chunk.length - headerDiff, SEEK_CUR);
    1.48 +	}
    1.49  	if ( was_error ) {
    1.50  		spec = NULL;
    1.51  	}