+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);
+
+ 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);
+}
+