From cf851f286068797c94cddcdadfa47ecb6ac41c3e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 21 Feb 2003 16:54:24 +0000 Subject: [PATCH] Marc Le Douarain - Sat, 15 Feb 2003 14:46:41 +0100 * Added 8SVX format support to the AIFF loader --- CHANGES | 2 ++ load_aiff.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index ba941209..400c6750 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,6 @@ 1.2.5: +Marc Le Douarain - Sat, 15 Feb 2003 14:46:41 +0100 + * Added 8SVX format support to the AIFF loader Sam Lantinga Wed Feb 12 21:03:57 PST 2003 * Fixed volume control on WAVE music chunks Ben Nason - Mon, 10 Feb 2003 11:50:27 -0800 diff --git a/load_aiff.c b/load_aiff.c index 23e39480..c74a4c8e 100644 --- a/load_aiff.c +++ b/load_aiff.c @@ -22,6 +22,8 @@ act as identically to SDL_LoadWAV_RW() as possible. This file by Torbjörn Andersson (torbjorn.andersson@eurotime.se) + 8SVX file support added by Marc Le Douarain (mavati@club-internet.fr) + in december 2002. */ /* $Id$ */ @@ -37,10 +39,15 @@ /* Define values for AIFF (IFF audio) format */ /*********************************************/ #define FORM 0x4d524f46 /* "FORM" */ + #define AIFF 0x46464941 /* "AIFF" */ #define SSND 0x444e5353 /* "SSND" */ #define COMM 0x4d4d4f43 /* "COMM" */ +#define _8SVX 0x58565338 /* "8SVX" */ +#define VHDR 0x52444856 /* "VHDR" */ +#define BODY 0x59444F42 /* "BODY" */ + /* This function was taken from libsndfile. I don't pretend to fully * understand it. */ @@ -64,6 +71,8 @@ SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, int freesrc, int was_error; int found_SSND; int found_COMM; + int found_VHDR; + int found_BODY; long start = 0; Uint32 chunk_type; @@ -101,8 +110,8 @@ SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, int freesrc, } else { AIFFmagic = SDL_ReadLE32(src); } - if ( (FORMchunk != FORM) || (AIFFmagic != AIFF) ) { - SDL_SetError("Unrecognized file type (not AIFF)"); + if ( (FORMchunk != FORM) || ( (AIFFmagic != AIFF) && (AIFFmagic != _8SVX) ) ) { + SDL_SetError("Unrecognized file type (not AIFF nor 8SVX)"); was_error = 1; goto done; } @@ -111,12 +120,13 @@ SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, int freesrc, found_SSND = 0; found_COMM = 0; + found_VHDR = 0; + found_BODY = 0; do { chunk_type = SDL_ReadLE32(src); chunk_length = SDL_ReadBE32(src); next_chunk = SDL_RWtell(src) + chunk_length; - /* Paranoia to avoid infinite loops */ if (chunk_length == 0) break; @@ -143,24 +153,56 @@ SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, int freesrc, } break; + case VHDR: + found_VHDR = 1; + SDL_ReadBE32(src); + SDL_ReadBE32(src); + SDL_ReadBE32(src); + frequency = SDL_ReadBE16(src); + channels = 1; + samplesize = 8; + break; + + case BODY: + found_BODY = 1; + numsamples = chunk_length; + start = SDL_RWtell(src); + break; + default: break; } - } while ( ( !found_SSND || !found_COMM ) + /* a 0 pad byte can be stored for any odd-length chunk */ + if (chunk_length&1) + next_chunk++; + } while ( ( ( (AIFFmagic == AIFF) && ( !found_SSND || !found_COMM ) ) + || ( (AIFFmagic == _8SVX ) && ( !found_VHDR || !found_BODY ) ) ) && SDL_RWseek(src, next_chunk, SEEK_SET) != 1 ); - if ( !found_SSND ) { + if ( (AIFFmagic == AIFF) && !found_SSND ) { SDL_SetError("Bad AIFF (no SSND chunk)"); was_error = 1; goto done; } - if ( !found_COMM ) { + if ( (AIFFmagic == AIFF) && !found_COMM ) { SDL_SetError("Bad AIFF (no COMM chunk)"); was_error = 1; goto done; } + if ( (AIFFmagic == _8SVX) && !found_VHDR ) { + SDL_SetError("Bad 8SVX (no VHDR chunk)"); + was_error = 1; + goto done; + } + + if ( (AIFFmagic == _8SVX) && !found_BODY ) { + SDL_SetError("Bad 8SVX (no BODY chunk)"); + was_error = 1; + goto done; + } + /* Decode the audio data format */ memset(spec, 0, sizeof(*spec)); spec->freq = frequency; @@ -203,3 +245,4 @@ SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, int freesrc, } return(spec); } +