+ return 1;
+}
+#endif
+
+static FILE*mp3file=0;
+void handlesoundstream(TAG*tag)
+{
+ char*filename = "output.mp3";
+ if(numextracts==1) {
+ filename = destfilename;
+ if(!strcmp(filename,"output.swf"))
+ filename = "output.mp3";
+ }
+ switch(tag->id) {
+ case ST_SOUNDSTREAMHEAD:
+ if((tag->data[1]&0x30) == 0x20) { //mp3 compression
+ mp3file = fopen(filename, "wb");
+ msg("<notice> Writing mp3 data to %s",filename);
+ }
+ else
+ msg("<error> Soundstream is not mp3");
+ break;
+ case ST_SOUNDSTREAMHEAD2:
+ if((tag->data[1]&0x30) == 0x20) {//mp3 compression
+ mp3file = fopen(filename, "wb");
+ msg("<notice> Writing mp3 data to %s",filename);
+ }
+ else
+ msg("<error> Soundstream is not mp3 (2)");
+ break;
+ case ST_SOUNDSTREAMBLOCK:
+ if(mp3file)
+ fwrite(&tag->data[4],tag->len-4,1,mp3file);
+ break;
+ }
+}
+
+int handledefinesound(TAG*tag)
+{
+ U8 flags;
+ U32 samples;
+ char buf[128];
+ char*filename = buf;
+ FILE*fi;
+ char*extension = 0;
+ int format;
+ U16 id;
+ int rate,bits,stereo;
+ char*rates[] = {"5500","11025","22050","44100"};
+ id = swf_GetU16(tag); //id
+
+ flags = swf_GetU8(tag);
+ format = flags>>4;
+ rate = (flags>>2)&3;
+ bits = flags&2?16:8;
+ stereo = flags&1;
+
+ samples = swf_GetU32(tag);
+
+ extension = "raw";
+
+ if(format == 2) { // mp3
+ swf_GetU16(tag); //numsamples_seek
+ extension = "mp3";
+ } else if(format == 0) { // raw
+ printf("Sound is RAW, format: %s samples/sec, %d bit, %s\n", rates[rate], bits, stereo?"stereo":"mono");
+ // TODO: convert to WAV
+ extension = "raw";
+ } else if(format == 1) { // adpcm
+ printf("Sound is ADPCM, format: %s samples/sec, %d bit, %s\n", rates[rate], bits, stereo?"stereo":"mono");
+ extension = "adpcm";
+ } else {
+ return 0;
+ }
+ prepare_name(buf, sizeof(buf), "sound", extension, id);
+ if(numextracts==1) {
+ filename = destfilename;
+ if(!strcmp(filename,"output.swf")) {
+ sprintf(buf, "output.%s", extension);
+ filename = buf;
+ }
+ }
+ fi = save_fopen(filename, "wb");
+ fwrite(&tag->data[tag->pos], tag->len - tag->pos, 1, fi);
+ fclose(fi);
+ return 1;
+}
+
+int handlebinary(TAG*tag) {
+ FILE *fout = NULL;
+ char buf[100];
+ char *filename = buf;
+ int len = tag->memsize;
+ int dx = 6; // offset to binary data
+ if (tag->id!=ST_DEFINEBINARY) {
+ if (!extractanyids) {
+ fprintf(stderr, "Object %d is not a binary entity!\n",
+ GET16(tag->data));
+ }
+ return 0;
+ }
+ prepare_name(buf, sizeof(buf), "binary", "bin", GET16(tag->data));
+ if(numextracts==1) {
+ filename = destfilename;
+ if(!strcmp(filename,"output.swf")) {
+ sprintf(buf, "output.bin");
+ filename = buf;
+ }
+ }
+ fout = fopen(filename, "wb");
+ fwrite(tag->data+dx,len-dx,1,fout);
+ fclose(fout);
+ return 1;