AIFF fixes by Torbj�rn_Andersson
authorSam Lantinga <slouken@libsdl.org>
Thu, 06 Sep 2001 06:04:46 +0000
changeset 1096cbf105616e3
parent 108 c7c913d7970e
child 110 1885d27bab6c
AIFF fixes by Torbj�rn_Andersson
wavestream.c
     1.1 --- a/wavestream.c	Thu Sep 06 05:57:18 2001 +0000
     1.2 +++ b/wavestream.c	Thu Sep 06 06:04:46 2001 +0000
     1.3 @@ -142,8 +142,17 @@
     1.4  			if ( (theWave->stop - pos) < original_len ) {
     1.5  				original_len = (theWave->stop - pos);
     1.6  			}
     1.7 +			original_len = fread(theWave->cvt.buf,1,original_len,theWave->wavefp);
     1.8 +			/* At least at the time of writing, SDL_ConvertAudio()
     1.9 +			   does byte-order swapping starting at the end of the
    1.10 +			   buffer. Thus, if we are reading 16-bit samples, we
    1.11 +			   had better make damn sure that we get an even
    1.12 +			   number of bytes, or we'll get garbage.
    1.13 +			 */
    1.14 +			if ( (theWave->cvt.src_format & 0x0010) && (original_len & 1) ) {
    1.15 +				original_len--;
    1.16 +			}
    1.17  			theWave->cvt.len = original_len;
    1.18 -			fread(theWave->cvt.buf,original_len,1,theWave->wavefp);
    1.19  			SDL_ConvertAudio(&theWave->cvt);
    1.20  			memcpy(stream, theWave->cvt.buf, theWave->cvt.len_cvt);
    1.21  		} else {
    1.22 @@ -414,6 +423,9 @@
    1.23  
    1.24  	/* From what I understand of the specification, chunks may appear in
    1.25           * any order, and we should just ignore unknown ones.
    1.26 +	 *
    1.27 +	 * TODO: Better sanity-checking. E.g. what happens if the AIFF file
    1.28 +	 *       contains compressed sound data?
    1.29           */
    1.30  
    1.31  	found_SSND = 0;
    1.32 @@ -465,14 +477,14 @@
    1.33  	    goto done;
    1.34  	}
    1.35  
    1.36 -	*stop = *start + channels * numsamples * (samplesize / 8) - 1;
    1.37 +	*stop = *start + channels * numsamples * (samplesize / 8);
    1.38  
    1.39  	/* Decode the audio data format */
    1.40  	memset(spec, 0, (sizeof *spec));
    1.41  	spec->freq = frequency;
    1.42  	switch (samplesize) {
    1.43  		case 8:
    1.44 -			spec->format = AUDIO_U8;
    1.45 +			spec->format = AUDIO_S8;
    1.46  			break;
    1.47  		case 16:
    1.48  			spec->format = AUDIO_S16MSB;