Example #1
0
        private Sound parseSound(LuaArgs args, int index)
        {
            LuaTable table            = args.GetTable(index);
            string   waveform         = table.IsNil("waveform") ? "square" : table.GetString("waveform");
            float    volume           = table.IsNil("volume") ? 1.0f : table.GetFloat("volume");
            float    duty             = table.IsNil("duty") ? 0.5f : table.GetFloat("duty");
            float    duration         = table.GetFloat("duration");
            float    attack           = table.IsNil("attack") ? 0.0f : table.GetFloat("attack");
            float    decay            = table.IsNil("decay") ? 0.0f : table.GetFloat("decay");
            float    frequency        = table.GetFloat("frequency");
            float    slide            = table.IsNil("slide") ? 0.0f : table.GetFloat("slide");
            float    vibratoDepth     = table.IsNil("vibrato_depth") ? 0.0f : table.GetFloat("vibrato_depth");
            float    vibratoFrequency = table.IsNil("vibrato_frequency") ? 0.0f : table.GetFloat("vibrato_frequency");
            bool     loop             = table.IsNil("loop") ? false : table.GetBool("loop");

            var sound = new Sound();

            sound.Waveform         = ParseWaveform(waveform);
            sound.Volume           = Clamp(volume, 0.0f, 1.0f);
            sound.Duty             = Clamp(duty, 0.0f, 1.0f);
            sound.Attack           = Math.Max(attack, 0.0f);
            sound.Duration         = Math.Max(duration, 0.0f);
            sound.Decay            = Math.Max(decay, 0.0f);
            sound.Frequency        = Math.Max(frequency, 0.0f);
            sound.Slide            = slide;
            sound.VibratoDepth     = Math.Max(vibratoDepth, 0.0f);
            sound.VibratoFrequency = Math.Max(vibratoFrequency, 0.0f);
            sound.Loop             = loop;

            return(sound);
        }