load_aiff.c
changeset 216 b813303a6119
parent 142 59564a17ae18
child 241 503416fca921
     1.1 --- a/load_aiff.c	Fri Feb 21 16:52:02 2003 +0000
     1.2 +++ b/load_aiff.c	Fri Feb 21 16:54:24 2003 +0000
     1.3 @@ -22,6 +22,8 @@
     1.4      act as identically to SDL_LoadWAV_RW() as possible.
     1.5  
     1.6      This file by Torbjörn Andersson (torbjorn.andersson@eurotime.se)
     1.7 +    8SVX file support added by Marc Le Douarain (mavati@club-internet.fr)
     1.8 +    in december 2002.
     1.9  */
    1.10  
    1.11  /* $Id$ */
    1.12 @@ -37,10 +39,15 @@
    1.13  /* Define values for AIFF (IFF audio) format */
    1.14  /*********************************************/
    1.15  #define FORM		0x4d524f46		/* "FORM" */
    1.16 +
    1.17  #define AIFF		0x46464941		/* "AIFF" */
    1.18  #define SSND		0x444e5353		/* "SSND" */
    1.19  #define COMM		0x4d4d4f43		/* "COMM" */
    1.20  
    1.21 +#define _8SVX		0x58565338		/* "8SVX" */
    1.22 +#define VHDR		0x52444856		/* "VHDR" */
    1.23 +#define BODY		0x59444F42		/* "BODY" */
    1.24 +
    1.25  /* This function was taken from libsndfile. I don't pretend to fully
    1.26   * understand it.
    1.27   */
    1.28 @@ -64,6 +71,8 @@
    1.29  	int was_error;
    1.30  	int found_SSND;
    1.31  	int found_COMM;
    1.32 +	int found_VHDR;
    1.33 +	int found_BODY;
    1.34  	long start = 0;
    1.35  
    1.36  	Uint32 chunk_type;
    1.37 @@ -101,8 +110,8 @@
    1.38  	} else {
    1.39  		AIFFmagic    = SDL_ReadLE32(src);
    1.40  	}
    1.41 -	if ( (FORMchunk != FORM) || (AIFFmagic != AIFF) ) {
    1.42 -		SDL_SetError("Unrecognized file type (not AIFF)");
    1.43 +	if ( (FORMchunk != FORM) || ( (AIFFmagic != AIFF) && (AIFFmagic != _8SVX) ) ) {
    1.44 +		SDL_SetError("Unrecognized file type (not AIFF nor 8SVX)");
    1.45  		was_error = 1;
    1.46  		goto done;
    1.47  	}
    1.48 @@ -111,12 +120,13 @@
    1.49  
    1.50  	found_SSND = 0;
    1.51  	found_COMM = 0;
    1.52 +	found_VHDR = 0;
    1.53 +	found_BODY = 0;
    1.54  
    1.55  	do {
    1.56  		chunk_type	= SDL_ReadLE32(src);
    1.57  		chunk_length	= SDL_ReadBE32(src);
    1.58  		next_chunk	= SDL_RWtell(src) + chunk_length;
    1.59 -
    1.60  		/* Paranoia to avoid infinite loops */
    1.61  		if (chunk_length == 0)
    1.62  			break;
    1.63 @@ -143,24 +153,56 @@
    1.64  				}
    1.65  				break;
    1.66  
    1.67 +			case VHDR:
    1.68 +				found_VHDR	= 1;
    1.69 +				SDL_ReadBE32(src);
    1.70 +				SDL_ReadBE32(src);
    1.71 +				SDL_ReadBE32(src);
    1.72 +				frequency = SDL_ReadBE16(src);
    1.73 +				channels = 1;
    1.74 +				samplesize = 8;
    1.75 +				break;
    1.76 +
    1.77 +			case BODY:
    1.78 +				found_BODY	= 1;
    1.79 +				numsamples	= chunk_length;
    1.80 +				start		= SDL_RWtell(src);
    1.81 +				break;
    1.82 +
    1.83  			default:
    1.84  				break;
    1.85  		}
    1.86 -	} while ( ( !found_SSND || !found_COMM )
    1.87 +		/* a 0 pad byte can be stored for any odd-length chunk */
    1.88 +		if (chunk_length&1)
    1.89 +			next_chunk++;
    1.90 +	} while ( ( ( (AIFFmagic == AIFF) && ( !found_SSND || !found_COMM ) )
    1.91 +		  || ( (AIFFmagic == _8SVX ) && ( !found_VHDR || !found_BODY ) ) )
    1.92  		  && SDL_RWseek(src, next_chunk, SEEK_SET) != 1 );
    1.93  
    1.94 -	if ( !found_SSND ) {
    1.95 +	if ( (AIFFmagic == AIFF) && !found_SSND ) {
    1.96  		SDL_SetError("Bad AIFF (no SSND chunk)");
    1.97  		was_error = 1;
    1.98  		goto done;
    1.99  	}
   1.100  
   1.101 -	if ( !found_COMM ) {
   1.102 +	if ( (AIFFmagic == AIFF) && !found_COMM ) {
   1.103  		SDL_SetError("Bad AIFF (no COMM chunk)");
   1.104  		was_error = 1;
   1.105  		goto done;
   1.106  	}
   1.107  
   1.108 +	if ( (AIFFmagic == _8SVX) && !found_VHDR ) {
   1.109 +		SDL_SetError("Bad 8SVX (no VHDR chunk)");
   1.110 +		was_error = 1;
   1.111 +		goto done;
   1.112 +	}
   1.113 +
   1.114 +	if ( (AIFFmagic == _8SVX) && !found_BODY ) {
   1.115 +		SDL_SetError("Bad 8SVX (no BODY chunk)");
   1.116 +		was_error = 1;
   1.117 +		goto done;
   1.118 +	}
   1.119 +
   1.120  	/* Decode the audio data format */
   1.121  	memset(spec, 0, sizeof(*spec));
   1.122  	spec->freq = frequency;
   1.123 @@ -203,3 +245,4 @@
   1.124  	}
   1.125  	return(spec);
   1.126  }
   1.127 +