From: kramm Date: Sat, 4 Jan 2003 13:55:03 +0000 (+0000) Subject: added support for definesound. X-Git-Tag: old_makefiles2~8 X-Git-Url: http://git.asbjorn.it/?a=commitdiff_plain;h=23cda857a4248617d746a37dca4652604ef11a1e;p=swftools.git added support for definesound. --- diff --git a/src/swfdump.c b/src/swfdump.c index 0278ec8..3a87f42 100644 --- a/src/swfdump.c +++ b/src/swfdump.c @@ -653,7 +653,23 @@ int main (int argc,char ** argv) printf(" frees object %04d", swf_GetPlaceID(tag)); } else if(tag->id == ST_STARTSOUND) { - printf(" starts id %04d", swf_GetPlaceID(tag)); + U8 flags; + U16 id; + id = swf_GetU16(tag); + flags = swf_GetU8(tag); + if(flags & 32) + printf(" stops sound with id %04d", id); + else + printf(" starts sound with id %04d", id); + if(flags & 16) + printf(" (if not already playing)"); + if(flags & 1) + swf_GetU32(tag); + if(flags & 2) + swf_GetU32(tag); + if(flags & 4) { + printf(" looping %d times", swf_GetU16(tag)); + } } else if(tag->id == ST_FRAMELABEL) { int l = strlen(tag->data); diff --git a/src/wav2swf.c b/src/wav2swf.c index 4734186..0b233c7 100644 --- a/src/wav2swf.c +++ b/src/wav2swf.c @@ -22,10 +22,15 @@ struct options_t options[] = { {"o","output"}, {"v","verbose"}, + {"d","definesound"}, + {"l","loop"}, {"V","version"}, {0,0} }; +static int loop = 0; +static int definesound = 0; + int args_callback_option(char*name,char*val) { if(!strcmp(name, "V")) { @@ -36,6 +41,14 @@ int args_callback_option(char*name,char*val) outputname = val; return 1; } + else if(!strcmp(name, "d")) { + definesound = 1; + return 0; + } + else if(!strcmp(name, "l")) { + loop = atoi(val); + return 1; + } else if(!strcmp(name, "v")) { verbose ++; return 0; @@ -54,6 +67,8 @@ void args_callback_usage(char*name) { printf("Usage: %s [-o filename] file.wav\n", name); printf("\t-v , --verbose\t\t\t Be more verbose\n"); + printf("\t-d , --definesound\t\t\t Generate a DefineSound tag instead of streaming sound\n"); + printf("\t-l , --loop n\t\t\t Loop sound n times (implies -d)\n"); printf("\t-o , --output filename\t\t set output filename (default: output.swf)\n"); printf("\t-V , --version\t\t\t Print program version and exit\n"); } @@ -68,69 +83,86 @@ int args_callback_command(char*name,char*val) } int main (int argc,char ** argv) -{ SWF swf; - RGBA rgb; - SRECT r; - S32 width=300,height = 300; - TAG * tag; - - int f,i,ls1,fs1; - int count; - int t; - struct WAV wav,wav2; - int blocksize = 1152; - U16* samples; - int numsamples; - - processargs(argc, argv); - initLog(0,-1,0,0,-1,verbose); - - if(!readWAV(filename, &wav)) - { - logf(" Error reading %s", filename); - exit(1); - } - convertWAV2mono(&wav,&wav2, 44100); - //printWAVInfo(&wav); - //printWAVInfo(&wav2); - samples = (U16*)wav2.data; - numsamples = wav2.size/2; - - memset(&swf,0x00,sizeof(SWF)); - - swf.fileVersion = 4; - swf.frameRate = 11025*256/(blocksize); - - swf.movieSize.xmax = 20*width; - swf.movieSize.ymax = 20*height; - - swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR); - tag = swf.firstTag; - rgb.r = 0xff; - rgb.g = 0xff; - rgb.b = 0xff; - swf_SetRGB(tag,&rgb); - - tag = swf_InsertTag(tag, ST_SOUNDSTREAMHEAD); - swf_SetSoundStreamHead(tag, blocksize); - - logf(" %d blocks", numsamples/(blocksize*2)); - for(t=0;t Writing block %d", t); - block1 = &samples[t*2*blocksize]; - swf_SetSoundStreamBlock(tag, block1, 1); - tag = swf_InsertTag(tag, ST_SHOWFRAME); - } - - f = open(outputname,O_WRONLY|O_CREAT|O_TRUNC, 0644); - if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n"); - close(f); - - swf_FreeTags(&swf); - return 0; +{ + SWF swf; + RGBA rgb; + SRECT r; + S32 width=300,height = 300; + TAG * tag; + + int f,i,ls1,fs1; + int count; + int t; + struct WAV wav,wav2; + int blocksize = 1152; + U16* samples; + int numsamples; + + processargs(argc, argv); + initLog(0,-1,0,0,-1,verbose); + + if(!readWAV(filename, &wav)) + { + logf(" Error reading %s", filename); + exit(1); + } + convertWAV2mono(&wav,&wav2, 44100); + //printWAVInfo(&wav); + //printWAVInfo(&wav2); + samples = (U16*)wav2.data; + numsamples = wav2.size/2; + + memset(&swf,0x00,sizeof(SWF)); + + swf.fileVersion = 5; + swf.frameRate = 11025*256/(blocksize); + + swf.movieSize.xmax = 20*width; + swf.movieSize.ymax = 20*height; + + swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR); + tag = swf.firstTag; + rgb.r = 0xff; + rgb.g = 0xff; + rgb.b = 0xff; + swf_SetRGB(tag,&rgb); + + if(!definesound) + { + tag = swf_InsertTag(tag, ST_SOUNDSTREAMHEAD); + swf_SetSoundStreamHead(tag, blocksize); + + logf(" %d blocks", numsamples/(blocksize*2)); + for(t=0;t Writing block %d", t); + block1 = &samples[t*2*blocksize]; + swf_SetSoundStreamBlock(tag, block1, 1); + tag = swf_InsertTag(tag, ST_SHOWFRAME); + } + tag = swf_InsertTag(tag, ST_END); + } else { + SOUNDINFO info; + tag = swf_InsertTag(tag, ST_DEFINESOUND); + swf_SetU16(tag, 24); //id + swf_SetSoundDefine(tag, samples, numsamples); + tag = swf_InsertTag(tag, ST_STARTSOUND); + swf_SetU16(tag, 24); //id + memset(&info, 0, sizeof(info)); + info.loops = loop; + swf_SetSoundInfo(tag, &info); + tag = swf_InsertTag(tag, ST_SHOWFRAME); + tag = swf_InsertTag(tag, ST_END); + } + + f = open(outputname,O_WRONLY|O_CREAT|O_TRUNC, 0644); + if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n"); + close(f); + + swf_FreeTags(&swf); + return 0; }