From b8168756415138e2741a2aedd37ac233161bf336 Mon Sep 17 00:00:00 2001 From: kramm Date: Sat, 27 Mar 2004 09:42:12 +0000 Subject: [PATCH] added handling for RAW and ADPCM sounds --- src/swfextract.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/swfextract.c b/src/swfextract.c index a5f549a..c7e7ec0 100644 --- a/src/swfextract.c +++ b/src/swfextract.c @@ -841,25 +841,40 @@ void handledefinesound(TAG*tag) char buf[128]; char*filename = buf; FILE*fi; + char*extension = 0; + int format; U16 id; + int rate,bits,stereo; + char*rates[] = {"5500","11025","22050","44100"}; id = swf_GetU16(tag); //id - sprintf(buf, "sound%d.mp3", id); + + flags = swf_GetU8(tag); + format = flags>>4; + rate = (flags>>2)&3; + bits = flags&2?16:8; + stereo = flags&1; + + samples = swf_GetU32(tag); + if(format == 2) { // mp3 + swf_GetU16(tag); //numsamples_seek + extension = "mp3"; + } else if(format == 0) { // raw + printf("Sound is RAW, format: %s samples/sec, %d bit, %s\n", rates[rate], bits, stereo?"stereo":"mono"); + // TODO: convert to WAV + extension = "raw"; + } else if(format == 1) { // adpcm + printf("Sound is ADPCM, format: %s samples/sec, %d bit, %s\n", rates[rate], bits, stereo?"stereo":"mono"); + extension = "adpcm"; + } + sprintf(buf, "sound%d.%s", id, extension); if(numextracts==1) { filename = destfilename; - if(!strcmp(filename,"output.swf")) - filename = "output.mp3"; - } - flags = swf_GetU8(tag); - if((flags>>4)!=2) { - printf("Sorry, can only extract MP3 sounds. Sound %d is ADPCM or RAW.\n", id); - /* not mp3 */ - return; + if(!strcmp(filename,"output.swf")) { + sprintf(buf, "output.%s", extension); + filename = buf; + } } - samples = swf_GetU32(tag); - - swf_GetU16(tag); //(only for mp3) numsamples_seek - fi = save_fopen(filename, "wb"); fwrite(&tag->data[tag->pos], tag->len - tag->pos, 1, fi); fclose(fi); -- 1.7.10.4