-{ 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("<fatal> Error reading %s", filename);
- exit(1);
- }
- convertWAV2mono(&wav,&wav2, 44100);
- printWAVInfo(&wav);
- printWAVInfo(&wav2);
- samples = (U16*)wav2.data;
- numsamples = wav2.size/2;
-
- /* the following is a big hack to prevent against
- periods of total silence- these get written as
- blocks of length 0 by bladeenc, which causes
- the flashplayer to crash */
-
- for(t=0;t<wav2.size/2;t+=2)
- wav2.data[t]^=(t&2)<<1;
-
- memset(&swf,0x00,sizeof(SWF));
-
- swf.fileVersion = 4;
- swf.frameRate = 44100*256/(blocksize*2);
-
- 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("<notice> %d blocks", numsamples/(blocksize*2));
- for(t=0;t<numsamples/(blocksize*2);t++) {
- int s;
- U16*block1;
- U16*block2;
- tag = swf_InsertTag(tag, ST_SOUNDSTREAMBLOCK);
- logf("<notice> Writing block %d", t);
- block1 = &samples[(t*2+0)*blocksize];
- block2 = &samples[(t*2+1)*blocksize];
- swf_SetSoundStreamBlock(tag, block1, blocksize,1);
- swf_SetSoundStreamBlock(tag, block2, blocksize,0);
- 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;
+ float blockspersecond;
+ float framespersecond;
+ float framesperblock;
+ float framepos = 0;
+ U16* samples;
+ int numsamples;
+
+ processargs(argc, argv);
+
+ blocksize = 1152;
+ blockspersecond = 11025.0/blocksize;
+ framespersecond = blockspersecond;
+ if(framerate)
+ framespersecond = framerate/256.0;
+ framesperblock = framespersecond/blockspersecond;
+
+ initLog(0,-1,0,0,-1,verbose);
+
+ if(!readWAV(filename, &wav))
+ {
+ logf("<fatal> 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 = (int)(framespersecond*256);
+
+ 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("<notice> %d blocks", numsamples/(blocksize*2));
+ for(t=0;t<numsamples/(blocksize*2);t++) {
+ int s;
+ int oldframe, newframe;
+ U16*block1;
+ tag = swf_InsertTag(tag, ST_SOUNDSTREAMBLOCK);
+ logf("<notice> Writing block %d", t);
+ block1 = &samples[t*2*blocksize];
+ swf_SetSoundStreamBlock(tag, block1, 1);
+ oldframe = (int)framepos;
+ framepos += framesperblock;
+ newframe = (int)framepos;
+ for(s=oldframe;s<newframe;s++)
+ 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;