src/audio/SDL_wave.c
changeset 1487 dc6b59e925a2
parent 1465 8dfa9a6d69a5
child 1612 97d0966f4bf7
equal deleted inserted replaced
1486:9d77fc9d0ace 1487:dc6b59e925a2
   431 	if ( (RIFFchunk != RIFF) || (WAVEmagic != WAVE) ) {
   431 	if ( (RIFFchunk != RIFF) || (WAVEmagic != WAVE) ) {
   432 		SDL_SetError("Unrecognized file type (not WAVE)");
   432 		SDL_SetError("Unrecognized file type (not WAVE)");
   433 		was_error = 1;
   433 		was_error = 1;
   434 		goto done;
   434 		goto done;
   435 	}
   435 	}
   436 	headerDiff += sizeof(Uint32); // for WAVE
   436 	headerDiff += sizeof(Uint32); /* for WAVE */
   437 
   437 
   438 	/* Read the audio data format chunk */
   438 	/* Read the audio data format chunk */
   439 	chunk.data = NULL;
   439 	chunk.data = NULL;
   440 	do {
   440 	do {
   441 		if ( chunk.data != NULL ) {
   441 		if ( chunk.data != NULL ) {
   444 		lenread = ReadChunk(src, &chunk);
   444 		lenread = ReadChunk(src, &chunk);
   445 		if ( lenread < 0 ) {
   445 		if ( lenread < 0 ) {
   446 			was_error = 1;
   446 			was_error = 1;
   447 			goto done;
   447 			goto done;
   448 		}
   448 		}
   449 		// 2 Uint32's for chunk header+len, plus the lenread
   449 		/* 2 Uint32's for chunk header+len, plus the lenread */
   450 		headerDiff += lenread + 2 * sizeof(Uint32);
   450 		headerDiff += lenread + 2 * sizeof(Uint32);
   451 	} while ( (chunk.magic == FACT) || (chunk.magic == LIST) );
   451 	} while ( (chunk.magic == FACT) || (chunk.magic == LIST) );
   452 
   452 
   453 	/* Decode the audio data format */
   453 	/* Decode the audio data format */
   454 	format = (WaveFMT *)chunk.data;
   454 	format = (WaveFMT *)chunk.data;
   525 		}
   525 		}
   526 		*audio_len = lenread;
   526 		*audio_len = lenread;
   527 		*audio_buf = chunk.data;
   527 		*audio_buf = chunk.data;
   528 		if(chunk.magic != DATA) headerDiff += lenread + 2 * sizeof(Uint32);
   528 		if(chunk.magic != DATA) headerDiff += lenread + 2 * sizeof(Uint32);
   529 	} while ( chunk.magic != DATA );
   529 	} while ( chunk.magic != DATA );
   530 	headerDiff += 2 * sizeof(Uint32); // for the data chunk and len
   530 	headerDiff += 2 * sizeof(Uint32); /* for the data chunk and len */
   531 
   531 
   532 	if ( MS_ADPCM_encoded ) {
   532 	if ( MS_ADPCM_encoded ) {
   533 		if ( MS_ADPCM_decode(audio_buf, audio_len) < 0 ) {
   533 		if ( MS_ADPCM_decode(audio_buf, audio_len) < 0 ) {
   534 			was_error = 1;
   534 			was_error = 1;
   535 			goto done;
   535 			goto done;
   552 	}
   552 	}
   553 	if ( src ) {
   553 	if ( src ) {
   554 		if ( freesrc ) {
   554 		if ( freesrc ) {
   555 			SDL_RWclose(src);
   555 			SDL_RWclose(src);
   556 		} else {
   556 		} else {
   557 			// seek to the end of the file (given by the RIFF chunk)
   557 			/* seek to the end of the file (given by the RIFF chunk) */
   558 			SDL_RWseek(src, wavelen - chunk.length - headerDiff, RW_SEEK_CUR);
   558 			SDL_RWseek(src, wavelen - chunk.length - headerDiff, RW_SEEK_CUR);
   559 		}
   559 		}
   560 	}
   560 	}
   561 	if ( was_error ) {
   561 	if ( was_error ) {
   562 		spec = NULL;
   562 		spec = NULL;