+FILE*mp3file;
+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");
+ logf("<notice> Writing mp3 data to %s",filename);
+ }
+ else
+ logf("<error> Soundstream is not mp3");
+ break;
+ case ST_SOUNDSTREAMHEAD2:
+ if((tag->data[1]&0x30) == 0x20) {//mp3 compression
+ mp3file = fopen(filename, "wb");
+ logf("<notice> Writing mp3 data to %s",filename);
+ }
+ else
+ logf("<error> Soundstream is not mp3 (2)");
+ break;
+ case ST_SOUNDSTREAMBLOCK:
+ if(mp3file)
+ fwrite(&tag->data[4],tag->len-4,1,mp3file);
+ break;
+ }
+}
+
+void handledefinesound(TAG*tag)
+{
+ U8 flags;
+ U32 samples;
+ char buf[128];
+ char*filename = buf;
+ FILE*fi;
+ U16 id;
+ id = swf_GetU16(tag); //id
+ sprintf(buf, "sound%d.mp3", id);
+
+ if(numextracts==1) {
+ filename = destfilename;
+ if(!strcmp(filename,"output.swf"))
+ filename = "output.mp3";
+ }
+ flags = swf_GetU8(tag);
+ if((flags>>4)!=2) {
+ printf("Sorry, can only extract MP3 sounds. Sound %d is ADPCM or RAW.\n", id);
+ /* not mp3 */
+ return;
+ }
+ samples = swf_GetU32(tag);
+
+ swf_GetU16(tag); //(only for mp3) numsamples_seek
+
+ fi = save_fopen(filename, "wb");
+ fwrite(&tag->data[tag->pos], tag->len - tag->pos, 1, fi);
+ fclose(fi);
+}
+