X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=src%2Fwav2swf.c;h=72919e5d3e8739ddd2d2e35d2eb09ef90619a3d3;hp=89add267044b0325643b9e8bd3152b4553d19a01;hb=f29d8006b1d8253c50808d6eb4941bdeb808c601;hpb=a5f50be98c64a4f4cd25758a43386528a6998aad diff --git a/src/wav2swf.c b/src/wav2swf.c index 89add26..72919e5 100644 --- a/src/wav2swf.c +++ b/src/wav2swf.c @@ -4,34 +4,50 @@ Part of the swftools package. Copyright (c) 2001 Matthias Kramm + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. - This file is distributed under the GPL, see file COPYING for details */ + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include "../lib/rfxswf.h" #include "../lib/log.h" #include "../lib/args.h" -#include "wav.h" +#include "../lib/wav.h" char * filename = 0; char * outputname = "output.swf"; int verbose = 2; +int stopframe0 = 0; +int stopframe1 = 0; #define DEFINESOUND_MP3 1 //define sound uses mp3?- undefine for raw sound. -struct options_t options[] = -{ - {"o","output"}, - {"v","verbose"}, - {"d","definesound"}, - {"l","loop"}, - {"r","framerate"}, - {"s","samplerate"}, - {"b","bitrate"}, - {"C","cgi"}, - {"V","version"}, - {0,0} +static struct options_t options[] = { +{"h", "help"}, +{"V", "version"}, +{"o", "output"}, +{"r", "framerate"}, +{"s", "samplerate"}, +{"d", "definesound"}, +{"l", "loop"}, +{"C", "cgi"}, +{"S", "stop"}, +{"E", "end"}, +{"b", "bitrate"}, +{"v", "verbose"}, +{0,0} }; static int loop = 0; @@ -67,6 +83,14 @@ int args_callback_option(char*name,char*val) verbose ++; return 0; } + else if(!strcmp(name, "S")) { + stopframe0 = 1; + return 0; + } + else if(!strcmp(name, "E")) { + stopframe1 = 1; + return 0; + } else if(!strcmp(name, "C")) { do_cgi = 1; return 0; @@ -89,7 +113,7 @@ int args_callback_option(char*name,char*val) samplerate = 44100; else { fprintf(stderr, "Invalid samplerate: %d\n", samplerate); - fprintf(stderr, "Allowed values: 11025, 22050\n", samplerate); + fprintf(stderr, "Allowed values: 11025, 22050, 44100\n"); exit(1); } return 1; @@ -128,18 +152,24 @@ int args_callback_longoption(char*name,char*val) { return args_long2shortoption(options, name, val); } -void args_callback_usage(char*name) +void args_callback_usage(char *name) { + printf("\n"); 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 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-r , --framerate fps\t\t Set framerate to fps frames per second\n"); - printf("\t-s , --samplerate sps\t\t Set samplerate to sps frames per second (default: 11025)\n"); - printf("\t-b , --bitrate bps\t\t Set mp3 bitrate (default: 32)\n"); - printf("\t-o , --output filename\t\t set output filename (default: output.swf)\n"); - printf("\t-C , --cgi\t\t\t For use as CGI- prepend http header, write to stdout\n"); - printf("\t-V , --version\t\t\t Print program version and exit\n"); + printf("\n"); + printf("-h , --help Print short help message and exit\n"); + printf("-V , --version Print version info and exit\n"); + printf("-o , --output Explicitly specify output file. (Otherwise, output will go to output.swf)\n"); + printf("-r , --framerate Set file framerate to frames per second.\n"); + printf("-s , --samplerate Set samplerate to frames per second (default: 11025).\n"); + printf("-d , --definesound Generate a DefineSound tag instead of streaming sound.\n"); + printf("-l , --loop n (Only used with -d)\n"); + printf("-C , --cgi For use as CGI- prepend http header, write to stdout.\n"); + printf("-S , --stop Stop the movie at frame 0\n"); + printf("-E , --end Stop the movie at the end frame\n"); + printf("-b , --bitrate Set mp3 bitrate to (default: 32)\n"); + printf("-v , --verbose Be more verbose\n"); + printf("\n"); } int args_callback_command(char*name,char*val) { @@ -178,7 +208,8 @@ int main (int argc,char ** argv) processargs(argc, argv); - blocksize = 576; + blocksize = (samplerate > 22050) ? 1152 : 576; + blockspersecond = (float)samplerate/blocksize; framespersecond = blockspersecond; @@ -196,17 +227,38 @@ int main (int argc,char ** argv) exit(1); } - if(!readWAV(filename, &wav)) + if(!wav_read(&wav, filename)) { msg(" Error reading %s", filename); exit(1); } - convertWAV2mono(&wav,&wav2, samplerate); - //printWAVInfo(&wav); - //printWAVInfo(&wav2); + wav_convert2mono(&wav,&wav2, samplerate); + //wav_print(&wav); + //wav_print(&wav2); samples = (U16*)wav2.data; numsamples = wav2.size/2; +#ifdef WORDS_BIGENDIAN + /* swap bytes */ + for(t=0;t>8)&0xff | (samples[t]<<8)&0xff00; + } +#endif + + if(numsamples%blocksize != 0) + { + // apply padding, so that block is a multiple of blocksize + int numblocks = (numsamples+blocksize-1)/blocksize; + int numsamples2; + U16* samples2; + numsamples2 = numblocks * blocksize; + samples2 = malloc(sizeof(U16)*numsamples2); + memcpy(samples2, samples, numsamples*sizeof(U16)); + memset(&samples2[numsamples], 0, sizeof(U16)*(numsamples2 - numsamples)); + numsamples = numsamples2; + samples = samples2; + } + memset(&swf,0x00,sizeof(SWF)); swf.fileVersion = 5; @@ -221,6 +273,17 @@ int main (int argc,char ** argv) rgb.g = 0xff; rgb.b = 0xff; swf_SetRGB(tag,&rgb); + + if(stopframe0) { + ActionTAG*action = 0; + tag = swf_InsertTag(tag, ST_DOACTION); + action = action_Stop(action); + action = action_End(action); + swf_ActionSet(tag, action); + swf_ActionFree(action); + + tag = swf_InsertTag(tag, ST_SHOWFRAME); + } swf_mp3_bitrate = bitrate; swf_mp3_out_samplerate = samplerate; @@ -276,7 +339,7 @@ int main (int argc,char ** argv) #else swf_SetU8(tag,(/*compression*/0<<4)|(/*rate*/3<<2)|(/*size*/1<<1)|/*mono*/0); swf_SetU32(tag, numsamples); // 44100 -> 11025 - swf_SetBlock(tag, wav2.data, numsamples*2); + swf_SetBlock(tag, samples, numsamples*2); #endif @@ -286,6 +349,15 @@ int main (int argc,char ** argv) info.loops = loop; swf_SetSoundInfo(tag, &info); tag = swf_InsertTag(tag, ST_SHOWFRAME); + if(stopframe1) { + ActionTAG*action = 0; + tag = swf_InsertTag(tag, ST_DOACTION); + action = action_Stop(action); + action = action_End(action); + swf_ActionSet(tag, action); + swf_ActionFree(action); + tag = swf_InsertTag(tag, ST_SHOWFRAME); + } tag = swf_InsertTag(tag, ST_END); }