+typedef struct _sound_t
+{
+ U16 id;
+ TAG*tag;
+} sound_t;
+
+void s_sound(char*name, char*filename)
+{
+ struct WAV wav, wav2;
+ sound_t* sound;
+ U16*samples;
+ int numsamples;
+
+ if(!readWAV(filename, &wav)) {
+ warning("Couldn't read wav file \"%s\"", filename);
+ samples = 0;
+ numsamples = 0;
+ } else {
+ convertWAV2mono(&wav, &wav2, 44100);
+ samples = (U16*)wav2.data;
+ numsamples = wav2.size/2;
+ free(wav.data);
+ }
+
+ tag = swf_InsertTag(tag, ST_DEFINESOUND);
+ swf_SetU16(tag, id); //id
+ swf_SetSoundDefine(tag, samples, numsamples);
+
+ sound = (sound_t*)malloc(sizeof(sound_t)); /* mem leak */
+ sound->tag = tag;
+ sound->id = id;
+
+ if(dictionary_lookup(&sounds, name))
+ syntaxerror("sound %s defined twice", name);
+ dictionary_put2(&sounds, name, sound);
+
+ incrementid();
+
+ if(samples)
+ free(samples);
+}
+
+void s_playsound(char*name, int loops, int nomultiple, int stop)
+{
+ sound_t* sound = dictionary_lookup(&sounds, name);
+ SOUNDINFO info;
+ if(!sound)
+ syntaxerror("Don't know anything about sound \"%s\"", name);
+
+ tag = swf_InsertTag(tag, ST_STARTSOUND);
+ swf_SetU16(tag, sound->id); //id
+ memset(&info, 0, sizeof(info));
+ info.stop = stop;
+ info.loops = loops;
+ info.nomultiple = nomultiple;
+ swf_SetSoundInfo(tag, &info);
+}
+