+void 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";
+ }
+ sprintf(buf, "sound%d.%s", id, extension);
+ 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);
+}
+
+void 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) {
+ fprintf(stderr, "Object %d is not a binary entity!\n",
+ GET16(tag->data));
+ return;
+ }
+ sprintf(buf, "binary%d.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);
+}
+