2 Allows to extract parts of the swf into a new file.
4 Part of the swftools package.
6 Copyright (c) 2001 Matthias Kramm <kramm@quiss.org>
8 This file is distributed under the GPL, see file COPYING for details */
12 #include "../lib/rfxswf.h"
13 #include "../lib/log.h"
14 #include "../lib/args.h"
18 char * outputname = "output.swf";
21 struct options_t options[] =
33 static int definesound = 0;
34 static int framerate = 0;
36 int args_callback_option(char*name,char*val)
38 if(!strcmp(name, "V")) {
39 printf("wav2swf - part of %s %s\n", PACKAGE, VERSION);
42 else if(!strcmp(name, "o")) {
46 else if(!strcmp(name, "d")) {
50 else if(!strcmp(name, "l")) {
54 else if(!strcmp(name, "v")) {
58 else if(!strcmp(name, "r")) {
60 sscanf(val, "%f", &f);
65 printf("Unknown option: -%s\n", name);
70 int args_callback_longoption(char*name,char*val)
72 return args_long2shortoption(options, name, val);
74 void args_callback_usage(char*name)
76 printf("Usage: %s [-o filename] file.wav\n", name);
77 printf("\t-v , --verbose\t\t\t Be more verbose\n");
78 printf("\t-d , --definesound\t\t\t Generate a DefineSound tag instead of streaming sound\n");
79 printf("\t-l , --loop n\t\t\t Loop sound n times (implies -d)\n");
80 printf("\t-r , --framerate fps\t\t\t Set framerate to fps frames per seond\n");
81 printf("\t-o , --output filename\t\t set output filename (default: output.swf)\n");
82 printf("\t-V , --version\t\t\t Print program version and exit\n");
84 int args_callback_command(char*name,char*val)
87 fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
94 int main (int argc,char ** argv)
99 S32 width=300,height = 300;
107 float blockspersecond;
108 float framespersecond;
109 float framesperblock;
114 processargs(argc, argv);
117 blockspersecond = 11025.0/blocksize;
118 framespersecond = blockspersecond;
120 framespersecond = framerate/256.0;
121 framesperblock = framespersecond/blockspersecond;
123 initLog(0,-1,0,0,-1,verbose);
125 if(!readWAV(filename, &wav))
127 logf("<fatal> Error reading %s", filename);
130 convertWAV2mono(&wav,&wav2, 44100);
131 //printWAVInfo(&wav);
132 //printWAVInfo(&wav2);
133 samples = (U16*)wav2.data;
134 numsamples = wav2.size/2;
136 memset(&swf,0x00,sizeof(SWF));
139 swf.frameRate = (int)(framespersecond*256);
141 swf.movieSize.xmax = 20*width;
142 swf.movieSize.ymax = 20*height;
144 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
149 swf_SetRGB(tag,&rgb);
153 tag = swf_InsertTag(tag, ST_SOUNDSTREAMHEAD);
154 swf_SetSoundStreamHead(tag, blocksize);
156 logf("<notice> %d blocks", numsamples/(blocksize*2));
157 for(t=0;t<numsamples/(blocksize*2);t++) {
159 int oldframe, newframe;
161 tag = swf_InsertTag(tag, ST_SOUNDSTREAMBLOCK);
162 logf("<notice> Writing block %d", t);
163 block1 = &samples[t*2*blocksize];
164 swf_SetSoundStreamBlock(tag, block1, 1);
166 oldframe = (int)framepos;
167 framepos += framesperblock;
168 newframe = (int)framepos;
169 for(s=oldframe;s<newframe;s++)
170 tag = swf_InsertTag(tag, ST_SHOWFRAME);
172 tag = swf_InsertTag(tag, ST_END);
175 tag = swf_InsertTag(tag, ST_DEFINESOUND);
176 swf_SetU16(tag, 24); //id
177 swf_SetSoundDefine(tag, samples, numsamples);
178 tag = swf_InsertTag(tag, ST_STARTSOUND);
179 swf_SetU16(tag, 24); //id
180 memset(&info, 0, sizeof(info));
182 swf_SetSoundInfo(tag, &info);
183 tag = swf_InsertTag(tag, ST_SHOWFRAME);
184 tag = swf_InsertTag(tag, ST_END);
187 f = open(outputname,O_WRONLY|O_CREAT|O_TRUNC, 0644);
188 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");