Marc Le Douarain - Sat, 15 Feb 2003 14:46:41 +0100
authorSam Lantinga <slouken@libsdl.org>
Fri, 21 Feb 2003 16:54:24 +0000
changeset 216b813303a6119
parent 215 7d16b8c11a2b
child 217 74d2e4341a39
Marc Le Douarain - Sat, 15 Feb 2003 14:46:41 +0100
* Added 8SVX format support to the AIFF loader
CHANGES
load_aiff.c
     1.1 --- a/CHANGES	Fri Feb 21 16:52:02 2003 +0000
     1.2 +++ b/CHANGES	Fri Feb 21 16:54:24 2003 +0000
     1.3 @@ -1,4 +1,6 @@
     1.4  1.2.5:
     1.5 +Marc Le Douarain - Sat, 15 Feb 2003 14:46:41 +0100
     1.6 + * Added 8SVX format support to the AIFF loader
     1.7  Sam Lantinga Wed Feb 12 21:03:57 PST 2003
     1.8   * Fixed volume control on WAVE music chunks
     1.9  Ben Nason - Mon, 10 Feb 2003 11:50:27 -0800
     2.1 --- a/load_aiff.c	Fri Feb 21 16:52:02 2003 +0000
     2.2 +++ b/load_aiff.c	Fri Feb 21 16:54:24 2003 +0000
     2.3 @@ -22,6 +22,8 @@
     2.4      act as identically to SDL_LoadWAV_RW() as possible.
     2.5  
     2.6      This file by Torbjörn Andersson (torbjorn.andersson@eurotime.se)
     2.7 +    8SVX file support added by Marc Le Douarain (mavati@club-internet.fr)
     2.8 +    in december 2002.
     2.9  */
    2.10  
    2.11  /* $Id$ */
    2.12 @@ -37,10 +39,15 @@
    2.13  /* Define values for AIFF (IFF audio) format */
    2.14  /*********************************************/
    2.15  #define FORM		0x4d524f46		/* "FORM" */
    2.16 +
    2.17  #define AIFF		0x46464941		/* "AIFF" */
    2.18  #define SSND		0x444e5353		/* "SSND" */
    2.19  #define COMM		0x4d4d4f43		/* "COMM" */
    2.20  
    2.21 +#define _8SVX		0x58565338		/* "8SVX" */
    2.22 +#define VHDR		0x52444856		/* "VHDR" */
    2.23 +#define BODY		0x59444F42		/* "BODY" */
    2.24 +
    2.25  /* This function was taken from libsndfile. I don't pretend to fully
    2.26   * understand it.
    2.27   */
    2.28 @@ -64,6 +71,8 @@
    2.29  	int was_error;
    2.30  	int found_SSND;
    2.31  	int found_COMM;
    2.32 +	int found_VHDR;
    2.33 +	int found_BODY;
    2.34  	long start = 0;
    2.35  
    2.36  	Uint32 chunk_type;
    2.37 @@ -101,8 +110,8 @@
    2.38  	} else {
    2.39  		AIFFmagic    = SDL_ReadLE32(src);
    2.40  	}
    2.41 -	if ( (FORMchunk != FORM) || (AIFFmagic != AIFF) ) {
    2.42 -		SDL_SetError("Unrecognized file type (not AIFF)");
    2.43 +	if ( (FORMchunk != FORM) || ( (AIFFmagic != AIFF) && (AIFFmagic != _8SVX) ) ) {
    2.44 +		SDL_SetError("Unrecognized file type (not AIFF nor 8SVX)");
    2.45  		was_error = 1;
    2.46  		goto done;
    2.47  	}
    2.48 @@ -111,12 +120,13 @@
    2.49  
    2.50  	found_SSND = 0;
    2.51  	found_COMM = 0;
    2.52 +	found_VHDR = 0;
    2.53 +	found_BODY = 0;
    2.54  
    2.55  	do {
    2.56  		chunk_type	= SDL_ReadLE32(src);
    2.57  		chunk_length	= SDL_ReadBE32(src);
    2.58  		next_chunk	= SDL_RWtell(src) + chunk_length;
    2.59 -
    2.60  		/* Paranoia to avoid infinite loops */
    2.61  		if (chunk_length == 0)
    2.62  			break;
    2.63 @@ -143,24 +153,56 @@
    2.64  				}
    2.65  				break;
    2.66  
    2.67 +			case VHDR:
    2.68 +				found_VHDR	= 1;
    2.69 +				SDL_ReadBE32(src);
    2.70 +				SDL_ReadBE32(src);
    2.71 +				SDL_ReadBE32(src);
    2.72 +				frequency = SDL_ReadBE16(src);
    2.73 +				channels = 1;
    2.74 +				samplesize = 8;
    2.75 +				break;
    2.76 +
    2.77 +			case BODY:
    2.78 +				found_BODY	= 1;
    2.79 +				numsamples	= chunk_length;
    2.80 +				start		= SDL_RWtell(src);
    2.81 +				break;
    2.82 +
    2.83  			default:
    2.84  				break;
    2.85  		}
    2.86 -	} while ( ( !found_SSND || !found_COMM )
    2.87 +		/* a 0 pad byte can be stored for any odd-length chunk */
    2.88 +		if (chunk_length&1)
    2.89 +			next_chunk++;
    2.90 +	} while ( ( ( (AIFFmagic == AIFF) && ( !found_SSND || !found_COMM ) )
    2.91 +		  || ( (AIFFmagic == _8SVX ) && ( !found_VHDR || !found_BODY ) ) )
    2.92  		  && SDL_RWseek(src, next_chunk, SEEK_SET) != 1 );
    2.93  
    2.94 -	if ( !found_SSND ) {
    2.95 +	if ( (AIFFmagic == AIFF) && !found_SSND ) {
    2.96  		SDL_SetError("Bad AIFF (no SSND chunk)");
    2.97  		was_error = 1;
    2.98  		goto done;
    2.99  	}
   2.100  
   2.101 -	if ( !found_COMM ) {
   2.102 +	if ( (AIFFmagic == AIFF) && !found_COMM ) {
   2.103  		SDL_SetError("Bad AIFF (no COMM chunk)");
   2.104  		was_error = 1;
   2.105  		goto done;
   2.106  	}
   2.107  
   2.108 +	if ( (AIFFmagic == _8SVX) && !found_VHDR ) {
   2.109 +		SDL_SetError("Bad 8SVX (no VHDR chunk)");
   2.110 +		was_error = 1;
   2.111 +		goto done;
   2.112 +	}
   2.113 +
   2.114 +	if ( (AIFFmagic == _8SVX) && !found_BODY ) {
   2.115 +		SDL_SetError("Bad 8SVX (no BODY chunk)");
   2.116 +		was_error = 1;
   2.117 +		goto done;
   2.118 +	}
   2.119 +
   2.120  	/* Decode the audio data format */
   2.121  	memset(spec, 0, sizeof(*spec));
   2.122  	spec->freq = frequency;
   2.123 @@ -203,3 +245,4 @@
   2.124  	}
   2.125  	return(spec);
   2.126  }
   2.127 +