+#define SOUNDINFO_STOP 32
+#define SOUNDINFO_NOMULTIPLE 16
+#define SOUNDINFO_HASENVELOPE 8
+#define SOUNDINFO_HASLOOPS 4
+#define SOUNDINFO_HASOUTPOINT 2
+#define SOUNDINFO_HASINPOINT 1
+
+
+void swf_SetSoundInfo(TAG*tag, SOUNDINFO*info)
+{
+ U8 flags = (info->stop?SOUNDINFO_STOP:0)
+ |(info->nomultiple?SOUNDINFO_NOMULTIPLE:0)
+ |(info->envelopes?SOUNDINFO_HASENVELOPE:0)
+ |(info->loops?SOUNDINFO_HASLOOPS:0)
+ |(info->outpoint?SOUNDINFO_HASOUTPOINT:0)
+ |(info->inpoint?SOUNDINFO_HASINPOINT:0);
+ swf_SetU8(tag, flags);
+ if(flags&SOUNDINFO_HASINPOINT)
+ swf_SetU32(tag, info->inpoint);
+ if(flags&SOUNDINFO_HASOUTPOINT)
+ swf_SetU32(tag, info->outpoint);
+ if(flags&SOUNDINFO_HASLOOPS)
+ swf_SetU16(tag, info->loops);
+ if(flags&SOUNDINFO_HASENVELOPE) {
+ int t;
+ swf_SetU8(tag, info->envelopes);
+ for(t=0;t<info->envelopes;t++) {
+ swf_SetU32(tag, info->pos[t]);
+ swf_SetU16(tag, info->left[t]);
+ swf_SetU16(tag, info->right[t]);
+ }
+ }
+}
+
+
+void swf_SetSoundDefineMP3(TAG*tag, U8* data, unsigned length,
+ unsigned SampRate,
+ unsigned Channels,
+ unsigned NumFrames)
+{
+ U8 compression = 2; // 0 = raw, 1 = ADPCM, 2 = mp3, 3 = raw le, 6 = nellymoser
+ U8 rate; // 0 = 5.5 Khz, 1 = 11 Khz, 2 = 22 Khz, 3 = 44 Khz
+ U8 size = 1; // 0 = 8 bit, 1 = 16 bit
+ U8 type = Channels==2; // 0=mono, 1=stereo
+
+ rate = (SampRate >= 40000) ? 3
+ : (SampRate >= 19000) ? 2
+ : (SampRate >= 8000) ? 1
+ : 0;
+
+ swf_SetU8(tag,(compression<<4)|(rate<<2)|(size<<1)|type);
+
+ swf_SetU32(tag, NumFrames * 576);
+
+ swf_SetU16(tag, 0); //delayseek
+ swf_SetBlock(tag, data, length);
+}