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")) {
55 else if(!strcmp(name, "v")) {
59 else if(!strcmp(name, "r")) {
61 sscanf(val, "%f", &f);
66 printf("Unknown option: -%s\n", name);
71 int args_callback_longoption(char*name,char*val)
73 return args_long2shortoption(options, name, val);
75 void args_callback_usage(char*name)
77 printf("Usage: %s [-o filename] file.wav\n", name);
78 printf("\t-v , --verbose\t\t\t Be more verbose\n");
79 printf("\t-d , --definesound\t\t\t Generate a DefineSound tag instead of streaming sound\n");
80 printf("\t-l , --loop n\t\t\t Loop sound n times (implies -d)\n");
81 printf("\t-r , --framerate fps\t\t\t Set framerate to fps frames per seond\n");
82 printf("\t-o , --output filename\t\t set output filename (default: output.swf)\n");
83 printf("\t-V , --version\t\t\t Print program version and exit\n");
85 int args_callback_command(char*name,char*val)
88 fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
95 int main (int argc,char ** argv)
100 S32 width=300,height = 300;
108 float blockspersecond;
109 float framespersecond;
110 float framesperblock;
115 processargs(argc, argv);
117 if(!definesound && framerate) {
118 printf("Warning! The -r option is experimental and won't work without -d\n");
122 blockspersecond = 11025.0/blocksize;
123 framespersecond = blockspersecond;
125 framespersecond = framerate/256.0;
126 framesperblock = framespersecond/blockspersecond;
128 initLog(0,-1,0,0,-1,verbose);
130 if(!readWAV(filename, &wav))
132 logf("<fatal> Error reading %s", filename);
135 convertWAV2mono(&wav,&wav2, 44100);
136 //printWAVInfo(&wav);
137 //printWAVInfo(&wav2);
138 samples = (U16*)wav2.data;
139 numsamples = wav2.size/2;
141 memset(&swf,0x00,sizeof(SWF));
144 swf.frameRate = (int)(framespersecond*256);
146 swf.movieSize.xmax = 20*width;
147 swf.movieSize.ymax = 20*height;
149 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
154 swf_SetRGB(tag,&rgb);
158 tag = swf_InsertTag(tag, ST_SOUNDSTREAMHEAD);
159 swf_SetSoundStreamHead(tag, blocksize);
161 logf("<notice> %d blocks", numsamples/(blocksize*2));
162 for(t=0;t<numsamples/(blocksize*2);t++) {
164 int oldframe, newframe;
166 tag = swf_InsertTag(tag, ST_SOUNDSTREAMBLOCK);
167 logf("<notice> Writing block %d", t);
168 block1 = &samples[t*2*blocksize];
169 swf_SetSoundStreamBlock(tag, block1, 0, 1);
171 oldframe = (int)framepos;
172 framepos += framesperblock;
173 newframe = (int)framepos;
174 for(s=oldframe;s<newframe;s++)
175 tag = swf_InsertTag(tag, ST_SHOWFRAME);
177 tag = swf_InsertTag(tag, ST_END);
180 tag = swf_InsertTag(tag, ST_DEFINESOUND);
181 swf_SetU16(tag, 24); //id
182 swf_SetSoundDefine(tag, samples, numsamples);
183 tag = swf_InsertTag(tag, ST_STARTSOUND);
184 swf_SetU16(tag, 24); //id
185 memset(&info, 0, sizeof(info));
187 swf_SetSoundInfo(tag, &info);
188 tag = swf_InsertTag(tag, ST_SHOWFRAME);
189 tag = swf_InsertTag(tag, ST_END);
192 f = open(outputname,O_WRONLY|O_CREAT|O_TRUNC, 0644);
193 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");