From b2bb755bca484696a3fcfea897354b5c4c26d0f2 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 6 Sep 2001 06:04:46 +0000 Subject: [PATCH] AIFF fixes by Torbj?rn_Andersson --- wavestream.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/wavestream.c b/wavestream.c index 8d5ab9eb..d5cbc6e1 100644 --- a/wavestream.c +++ b/wavestream.c @@ -142,8 +142,17 @@ extern void WAVStream_PlaySome(Uint8 *stream, int len) if ( (theWave->stop - pos) < original_len ) { original_len = (theWave->stop - pos); } + original_len = fread(theWave->cvt.buf,1,original_len,theWave->wavefp); + /* At least at the time of writing, SDL_ConvertAudio() + does byte-order swapping starting at the end of the + buffer. Thus, if we are reading 16-bit samples, we + had better make damn sure that we get an even + number of bytes, or we'll get garbage. + */ + if ( (theWave->cvt.src_format & 0x0010) && (original_len & 1) ) { + original_len--; + } theWave->cvt.len = original_len; - fread(theWave->cvt.buf,original_len,1,theWave->wavefp); SDL_ConvertAudio(&theWave->cvt); memcpy(stream, theWave->cvt.buf, theWave->cvt.len_cvt); } else { @@ -414,6 +423,9 @@ static FILE *LoadAIFFStream (const char *file, SDL_AudioSpec *spec, /* From what I understand of the specification, chunks may appear in * any order, and we should just ignore unknown ones. + * + * TODO: Better sanity-checking. E.g. what happens if the AIFF file + * contains compressed sound data? */ found_SSND = 0; @@ -465,14 +477,14 @@ static FILE *LoadAIFFStream (const char *file, SDL_AudioSpec *spec, goto done; } - *stop = *start + channels * numsamples * (samplesize / 8) - 1; + *stop = *start + channels * numsamples * (samplesize / 8); /* Decode the audio data format */ memset(spec, 0, (sizeof *spec)); spec->freq = frequency; switch (samplesize) { case 8: - spec->format = AUDIO_U8; + spec->format = AUDIO_S8; break; case 16: spec->format = AUDIO_S16MSB;