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[] =
32 static int definesound = 0;
34 int args_callback_option(char*name,char*val)
36 if(!strcmp(name, "V")) {
37 printf("wav2swf - part of %s %s\n", PACKAGE, VERSION);
40 else if(!strcmp(name, "o")) {
44 else if(!strcmp(name, "d")) {
48 else if(!strcmp(name, "l")) {
52 else if(!strcmp(name, "v")) {
57 printf("Unknown option: -%s\n", name);
62 int args_callback_longoption(char*name,char*val)
64 return args_long2shortoption(options, name, val);
66 void args_callback_usage(char*name)
68 printf("Usage: %s [-o filename] file.wav\n", name);
69 printf("\t-v , --verbose\t\t\t Be more verbose\n");
70 printf("\t-d , --definesound\t\t\t Generate a DefineSound tag instead of streaming sound\n");
71 printf("\t-l , --loop n\t\t\t Loop sound n times (implies -d)\n");
72 printf("\t-o , --output filename\t\t set output filename (default: output.swf)\n");
73 printf("\t-V , --version\t\t\t Print program version and exit\n");
75 int args_callback_command(char*name,char*val)
78 fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
85 int main (int argc,char ** argv)
90 S32 width=300,height = 300;
101 processargs(argc, argv);
102 initLog(0,-1,0,0,-1,verbose);
104 if(!readWAV(filename, &wav))
106 logf("<fatal> Error reading %s", filename);
109 convertWAV2mono(&wav,&wav2, 44100);
110 //printWAVInfo(&wav);
111 //printWAVInfo(&wav2);
112 samples = (U16*)wav2.data;
113 numsamples = wav2.size/2;
115 memset(&swf,0x00,sizeof(SWF));
118 swf.frameRate = 11025*256/(blocksize);
120 swf.movieSize.xmax = 20*width;
121 swf.movieSize.ymax = 20*height;
123 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
128 swf_SetRGB(tag,&rgb);
132 tag = swf_InsertTag(tag, ST_SOUNDSTREAMHEAD);
133 swf_SetSoundStreamHead(tag, blocksize);
135 logf("<notice> %d blocks", numsamples/(blocksize*2));
136 for(t=0;t<numsamples/(blocksize*2);t++) {
139 tag = swf_InsertTag(tag, ST_SOUNDSTREAMBLOCK);
140 logf("<notice> Writing block %d", t);
141 block1 = &samples[t*2*blocksize];
142 swf_SetSoundStreamBlock(tag, block1, 1);
143 tag = swf_InsertTag(tag, ST_SHOWFRAME);
145 tag = swf_InsertTag(tag, ST_END);
148 tag = swf_InsertTag(tag, ST_DEFINESOUND);
149 swf_SetU16(tag, 24); //id
150 swf_SetSoundDefine(tag, samples, numsamples);
151 tag = swf_InsertTag(tag, ST_STARTSOUND);
152 swf_SetU16(tag, 24); //id
153 memset(&info, 0, sizeof(info));
155 swf_SetSoundInfo(tag, &info);
156 tag = swf_InsertTag(tag, ST_SHOWFRAME);
157 tag = swf_InsertTag(tag, ST_END);
160 f = open(outputname,O_WRONLY|O_CREAT|O_TRUNC, 0644);
161 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");