Ejemplo n.º 1
0
        public static Patch PushSound(RNG rng)
        {
            Patch result = new Patch();

            result.wave_type = (Wave)rng.Irnd((int)Wave.SIZE);
            if (result.wave_type == Wave.SINE)
            {
                result.wave_type = Wave.NOISE;
            }
            if (result.wave_type == Wave.SQUARE)
            {
                result.wave_type = Wave.NOISE;
            }
            result.base_freq = 0.1 + rng.Frnd(0.4);
            result.freq_ramp = 0.05 + rng.Frnd(0.2);

            result.env_attack  = 0.01 + rng.Frnd(0.09);
            result.env_sustain = 0.01 + rng.Frnd(0.09);
            result.env_decay   = 0.01 + rng.Frnd(0.09);

            result.repeat_speed = 0.3 + rng.Frnd(0.5);
            result.pha_offset   = -0.3 + rng.Frnd(0.9);
            result.pha_ramp     = -rng.Frnd(0.3);
            result.arp_speed    = 0.6 + rng.Frnd(0.3);
            result.arp_mod      = 0.8 - rng.Frnd(1.6);
            return(result);
        }
Ejemplo n.º 2
0
        public static Patch Jump(RNG rng)
        {
            Patch result = new Patch();

            result.wave_type = Wave.SQUARE;
            result.wave_type = (Wave)rng.Irnd((int)Wave.SIZE);
            if (result.wave_type == Wave.NOISE)
            {
                result.wave_type = Wave.SQUARE;
            }
            result.duty        = rng.Frnd(0.6);
            result.base_freq   = 0.3 + rng.Frnd(0.3);
            result.freq_ramp   = 0.1 + rng.Frnd(0.2);
            result.env_attack  = 0.0;
            result.env_sustain = 0.1 + rng.Frnd(0.3);
            result.env_decay   = 0.1 + rng.Frnd(0.2);
            if (rng.Rnd(1) != 0)
            {
                result.hpf_freq = rng.Frnd(0.3);
            }
            if (rng.Rnd(1) != 0)
            {
                result.lpf_freq = 1.0 - rng.Frnd(0.6);
            }
            return(result);
        }
Ejemplo n.º 3
0
        public static Patch BlipSelect(RNG rng)
        {
            Patch result = new Patch();

            result.wave_type = (Wave)rng.Rnd(1);
            result.wave_type = (Wave)rng.Irnd((int)Wave.SIZE);
            if (result.wave_type == Wave.NOISE)
            {
                result.wave_type = (Wave)rng.Rnd(1);
            }
            if (result.wave_type == Wave.SQUARE)
            {
                result.duty = rng.Frnd(0.6);
            }
            result.base_freq   = 0.2 + rng.Frnd(0.4);
            result.env_attack  = 0.0;
            result.env_sustain = 0.1 + rng.Frnd(0.1);
            result.env_decay   = rng.Frnd(0.2);
            result.hpf_freq    = 0.1;
            return(result);
        }
Ejemplo n.º 4
0
        public static Patch PowerUp(RNG rng)
        {
            Patch result = new Patch();

            if (rng.Rnd(1) != 0)
            {
                result.wave_type = Wave.SAWTOOTH;
            }
            else
            {
                result.duty = rng.Frnd(0.6);
            }
            result.wave_type = (Wave)rng.Irnd((int)Wave.SIZE);
            if (result.wave_type == Wave.NOISE)
            {
                result.wave_type = Wave.SQUARE;
            }
            if (rng.Rnd(1) != 0)
            {
                result.base_freq    = 0.2 + rng.Frnd(0.3);
                result.freq_ramp    = 0.1 + rng.Frnd(0.4);
                result.repeat_speed = 0.4 + rng.Frnd(0.4);
            }
            else
            {
                result.base_freq = 0.2 + rng.Frnd(0.3);
                result.freq_ramp = 0.05 + rng.Frnd(0.2);
                if (rng.Rnd(1) != 0)
                {
                    result.vib_strength = rng.Frnd(0.7);
                    result.vib_speed    = rng.Frnd(0.6);
                }
            }
            result.env_attack  = 0.0;
            result.env_sustain = rng.Frnd(0.4);
            result.env_decay   = 0.1 + rng.Frnd(0.4);
            return(result);
        }
Ejemplo n.º 5
0
        public static Patch PickupCoin(RNG rng)
        {
            Patch result = new Patch();

            result.wave_type = (Wave)rng.Irnd((int)Wave.SIZE);
            if (result.wave_type == Wave.NOISE)
            {
                result.wave_type = Wave.SQUARE;
            }
            result.base_freq   = 0.4 + rng.Frnd(0.5);
            result.env_attack  = 0.0;
            result.env_sustain = rng.Frnd(0.1);
            result.env_decay   = 0.1 + rng.Frnd(0.4);
            result.env_punch   = 0.3 + rng.Frnd(0.3);
            if (rng.Rnd(1) != 0)
            {
                result.arp_speed = 0.5 + rng.Frnd(0.2);
                float num = (rng.Irnd(7) | 1) + 1;
                float den = num + (rng.Irnd(7) | 1) + 2;
                result.arp_mod = num / den;
            }
            return(result);
        }
Ejemplo n.º 6
0
        public List <float> Generate()
        {
            List <float> output = new List <float>();

            // Misnomer, repeat resets things at start
            repeat();

            // Filter
            fltp   = 0.0f;
            fltdp  = 0.0f;
            fltw   = (float)Math.Pow(patch.lpf_freq, 3.0f) * 0.1f;
            fltw_d = 1.0f + (float)patch.lpf_ramp * 0.0001f;
            fltdmp = 5.0f / (1.0f + (float)Math.Pow(patch.lpf_resonance, 2.0f) * 20.0f) * (0.01f + fltw);
            if (fltdmp > 0.8f)
            {
                fltdmp = 0.8f;
            }
            fltphp  = 0.0f;
            flthp   = (float)Math.Pow(patch.hpf_freq, 2.0f) * 0.1f;
            flthp_d = 1.0f + (float)patch.hpf_ramp * 0.0003f;

            // Vibrato
            vib_phase = 0.0f;
            vib_speed = (float)Math.Pow(patch.vib_speed, 2.0f) * 0.01f;
            vib_amp   = (float)patch.vib_strength * 0.5f;

            // Envelope
            env_vol          = 0.0f;
            env_stage        = 0;
            env_time         = 0;
            env_length[0]    = (int)(patch.env_attack * patch.env_attack * 100000.0f);
            env_length[1]    = (int)(patch.env_sustain * patch.env_sustain * 100000.0f);
            env_length[2]    = (int)(patch.env_decay * patch.env_decay * 100000.0f);
            env_length_total = env_length[0] + env_length[1] + env_length[2];

            // Phaser
            phase  = 0;
            fphase = (float)Math.Pow(patch.pha_offset, 2.0f) * 1020.0f;
            if (patch.pha_offset < 0.0f)
            {
                fphase = -fphase;
            }
            fdphase = (float)Math.Pow(patch.pha_ramp, 2.0f) * 1.0f;
            if (patch.pha_ramp < 0.0f)
            {
                fdphase = -fdphase;
            }
            iphase = Math.Abs((int)fphase);
            ipp    = 0;
            for (int i = 0; i < 1024; i++)
            {
                phaser_buffer[i] = 0.0f;
            }

            // Noise
            for (int i = 0; i < 32; i++)
            {
                noise_buffer[i] = rng.Frnd(2.0f) - 1.0f;
            }

            // Repeat
            rep_limit = (int)(Math.Pow(1.0f - patch.repeat_speed, 2.0f) * 20000 + 32);
            if (patch.repeat_speed == 0.0f)
            {
                rep_limit = 0;
            }

            gain = Math.Exp(sound_vol) - 1.0;

            // Generate
            //bool buffer_complete = false;
            int buffer_length = env_length_total;

            for (int t = 0; ; ++t)
            {
                // Repeats
                if (rep_limit != 0 && ++rep_time >= rep_limit)
                {
                    repeat();
                }

                // Arpeggio (single)
                if (arp_limit != 0 && t >= arp_limit)
                {
                    arp_limit = 0;
                    fperiod  *= arp_mod;
                }

                // Frequency slide
                fslide  += fdslide;
                fperiod *= fslide;
                if (fperiod > fmaxperiod)
                {
                    fperiod = fmaxperiod;
                    if (patch.freq_limit > 0.0f)
                    {
                        //buffer_complete = true;
                    }
                }

                // Vibrato
                float rfperiod = (float)fperiod;
                if (vib_amp > 0.0f)
                {
                    vib_phase += vib_speed;
                    rfperiod   = (float)fperiod * (float)(1.0 + Math.Sin(vib_phase) * vib_amp);
                }
                period = (int)rfperiod;
                if (period < 8)
                {
                    period = 8;
                }

                // Duty cycle slide
                square_duty += square_slide;
                if (square_duty < 0.0f)
                {
                    square_duty = 0.0f;
                }
                if (square_duty > 0.5f)
                {
                    square_duty = 0.5f;
                }

                // Volume envelope
                env_time++;
                if (env_time > env_length[env_stage])
                {
                    env_time = 1;
                    env_stage++;
                    while (env_stage < 3 && env_length[env_stage] == 0)
                    {
                        env_stage++;
                    }
                    if (env_stage == 3)
                    {
                        break;
                    }
                }
                if (env_stage == 0)
                {
                    env_vol = (float)env_time / env_length[0];
                }
                else if (env_stage == 1)
                {
                    env_vol = 1.0f + (float)Math.Pow(1.0f - (float)env_time / env_length[1], 1.0f) * 2.0f * (float)patch.env_punch;
                }
                else
                {
                    // env_stage == 2
                    env_vol = 1.0f - (float)env_time / env_length[2];
                }

                // Phaser step
                fphase += fdphase;
                iphase  = Math.Abs((int)fphase);
                if (iphase > 1023)
                {
                    iphase = 1023;
                }

                if (flthp_d != 0.0f)
                {
                    flthp *= flthp_d;
                    if (flthp < 0.00001f)
                    {
                        flthp = 0.00001f;
                    }
                    if (flthp > 0.1f)
                    {
                        flthp = 0.1f;
                    }
                }

                // 8x supersampling
                float sample = 0.0f;
                for (int si = 0; si < 8; si++)
                {
                    float sub_sample = 0.0f;
                    phase++;
                    if (phase >= period)
                    {
                        phase %= period;
                        if (patch.wave_type == Wave.NOISE)
                        {
                            for (int i = 0; i < 32; i++)
                            {
                                noise_buffer[i] = rng.Frnd(2.0f) - 1.0f;
                            }
                        }
                    }
                    // base waveform
                    float fp = (float)phase / period;
                    switch (patch.wave_type)
                    {
                    case Wave.SQUARE:
                        if (fp < square_duty)
                        {
                            sub_sample = 0.5f;
                        }
                        else
                        {
                            sub_sample = -0.5f;
                        }
                        break;

                    case Wave.SAWTOOTH:
                        sub_sample = 1.0f - fp * 2.0f;
                        break;

                    case Wave.SINE:
                        sub_sample = (float)Math.Sin(fp * 2.0f * Global.PI);
                        break;

                    case Wave.NOISE:
                        sub_sample = noise_buffer[(int)(phase * 32 / period)];
                        break;

                    case Wave.TRIANGLE:
                        sub_sample = Math.Abs(1.0f - fp * 2.0f) - 1.0f;
                        break;

                    case Wave.BREAKER:
                        sub_sample = Math.Abs(1.0f - fp * fp * 2.0f) - 1.0f;
                        break;

                    default:
                        break;
                    }

                    // Low-pass filter
                    float pp = fltp;
                    fltw *= fltw_d;
                    if (fltw < 0.0f)
                    {
                        fltw = 0.0f;
                    }
                    if (fltw > 0.1f)
                    {
                        fltw = 0.1f;
                    }
                    if (patch.lpf_freq != 1.0f)
                    {
                        fltdp += (sub_sample - fltp) * fltw;
                        fltdp -= fltdp * fltdmp;
                    }
                    else
                    {
                        fltp  = sub_sample;
                        fltdp = 0.0f;
                    }
                    fltp += fltdp;

                    // High-pass filter
                    fltphp    += fltp - pp;
                    fltphp    -= fltphp * flthp;
                    sub_sample = fltphp;

                    // Phaser
                    phaser_buffer[ipp & 1023] = sub_sample;
                    sub_sample += phaser_buffer[(ipp - iphase + 1024) & 1023];
                    ipp         = (ipp + 1) & 1023;

                    // Final accumulation and envelope application
                    sample += sub_sample * env_vol;
                }
                sample  = sample / 8.0f * master_vol;
                sample *= (float)gain;

                output.Add(sample);
            }
            return(output);
        }
Ejemplo n.º 7
0
        public static Patch LaserShoot(RNG rng)
        {
            Patch result = new Patch();

            result.wave_type = (Wave)rng.Rnd(2);
            if (result.wave_type == Wave.SINE && rng.Rnd(1) != 0)
            {
                result.wave_type = (Wave)rng.Rnd(1);
            }
            result.wave_type = (Wave)rng.Irnd((int)Wave.SIZE);
            if (result.wave_type == Wave.NOISE)
            {
                result.wave_type = Wave.SQUARE;
            }
            result.base_freq  = 0.5 + rng.Frnd(0.5);
            result.freq_limit = result.base_freq - 0.2 - rng.Frnd(0.6);
            if (result.freq_limit < 0.2)
            {
                result.freq_limit = 0.2;
            }
            result.freq_ramp = -0.15 - rng.Frnd(0.2);
            if (rng.Rnd(2) == 0)
            {
                result.base_freq  = 0.3 + rng.Frnd(0.6);
                result.freq_limit = rng.Frnd(0.1);
                result.freq_ramp  = -0.35 - rng.Frnd(0.3);
            }
            if (rng.Rnd(1) != 0)
            {
                result.duty      = rng.Frnd(0.5);
                result.duty_ramp = rng.Frnd(0.2);
            }
            else
            {
                result.duty      = 0.4 + rng.Frnd(0.5);
                result.duty_ramp = -rng.Frnd(0.7);
            }
            result.env_attack  = 0.0;
            result.env_sustain = 0.1 + rng.Frnd(0.2);
            result.env_decay   = rng.Frnd(0.4);
            if (rng.Rnd(1) != 0)
            {
                result.env_punch = rng.Frnd(0.3);
            }
            if (rng.Rnd(2) == 0)
            {
                result.pha_offset = rng.Frnd(0.2);
                result.pha_ramp   = -rng.Frnd(0.2);
            }
            if (rng.Rnd(1) != 0)
            {
                result.hpf_freq = rng.Frnd(0.3);
            }
            return(result);
        }
Ejemplo n.º 8
0
        public static Patch Bird(RNG rng)
        {
            Patch result = new Patch();

            if (rng.Frnd(10) < 1)
            {
                result.wave_type = (Wave)rng.Irnd((int)Wave.SIZE);
                if (result.wave_type == Wave.NOISE)
                {
                    result.wave_type = Wave.SQUARE;
                }
                result.env_attack  = 0.4304400932967592 + rng.Frnd(0.2) - 0.1;
                result.env_sustain = 0.15739346034252394 + rng.Frnd(0.2) - 0.1;
                result.env_punch   = 0.004488201744871758 + rng.Frnd(0.2) - 0.1;
                result.env_decay   = 0.07478075528212291 + rng.Frnd(0.2) - 0.1;
                result.base_freq   = 0.9865265720147687 + rng.Frnd(0.2) - 0.1;
                result.freq_limit  = 0 + rng.Frnd(0.2) - 0.1;
                result.freq_ramp   = -0.2995018224359539 + rng.Frnd(0.2) - 0.1;
                if (rng.Frnd(1.0) < 0.5)
                {
                    result.freq_ramp = 0.1 + rng.Frnd(0.15);
                }
                result.freq_dramp    = 0.004598608156964473 + rng.Frnd(0.1) - 0.05;
                result.vib_strength  = -0.2202799497929496 + rng.Frnd(0.2) - 0.1;
                result.vib_speed     = 0.8084998703158364 + rng.Frnd(0.2) - 0.1;
                result.arp_mod       = 0;
                result.arp_speed     = 0;
                result.duty          = -0.9031808754347107 + rng.Frnd(0.2) - 0.1;
                result.duty_ramp     = -0.8128699999808343 + rng.Frnd(0.2) - 0.1;
                result.repeat_speed  = 0.6014860189319991 + rng.Frnd(0.2) - 0.1;
                result.pha_offset    = -0.9424902314367765 + rng.Frnd(0.2) - 0.1;
                result.pha_ramp      = -0.1055482222272056 + rng.Frnd(0.2) - 0.1;
                result.lpf_freq      = 0.9989765717851521 + rng.Frnd(0.2) - 0.1;
                result.lpf_ramp      = -0.25051720626043017 + rng.Frnd(0.2) - 0.1;
                result.lpf_resonance = 0.32777871505494693 + rng.Frnd(0.2) - 0.1;
                result.hpf_freq      = 0.0023548750981756753 + rng.Frnd(0.2) - 0.1;
                result.hpf_ramp      = -0.002375673204842568 + rng.Frnd(0.2) - 0.1;
                return(result);
            }

            if (rng.Frnd(10) < 1)
            {
                result.wave_type = (Wave)rng.Irnd((int)Wave.SIZE);
                if (result.wave_type == Wave.NOISE)
                {
                    result.wave_type = Wave.SQUARE;
                }
                result.env_attack    = 0.5277795946672003 + rng.Frnd(0.2) - 0.1;
                result.env_sustain   = 0.18243733568468432 + rng.Frnd(0.2) - 0.1;
                result.env_punch     = -0.020159754546840117 + rng.Frnd(0.2) - 0.1;
                result.env_decay     = 0.1561353422051903 + rng.Frnd(0.2) - 0.1;
                result.base_freq     = 0.9028855606533718 + rng.Frnd(0.2) - 0.1;
                result.freq_limit    = -0.008842787837148716;
                result.freq_ramp     = -0.1;
                result.freq_dramp    = -0.012891241489551925;
                result.vib_strength  = -0.17923136138403065 + rng.Frnd(0.2) - 0.1;
                result.vib_speed     = 0.908263385610142 + rng.Frnd(0.2) - 0.1;
                result.arp_mod       = 0.41690153355414894 + rng.Frnd(0.2) - 0.1;
                result.arp_speed     = 0.0010766233195860703 + rng.Frnd(0.2) - 0.1;
                result.duty          = -0.8735363011184684 + rng.Frnd(0.2) - 0.1;
                result.duty_ramp     = -0.7397985366747507 + rng.Frnd(0.2) - 0.1;
                result.repeat_speed  = 0.0591789344172107 + rng.Frnd(0.2) - 0.1;
                result.pha_offset    = -0.9961184222777699 + rng.Frnd(0.2) - 0.1;
                result.pha_ramp      = -0.08234769395850523 + rng.Frnd(0.2) - 0.1;
                result.lpf_freq      = 0.9412475115697335 + rng.Frnd(0.2) - 0.1;
                result.lpf_ramp      = -0.18261358925834958 + rng.Frnd(0.2) - 0.1;
                result.lpf_resonance = 0.24541438107389477 + rng.Frnd(0.2) - 0.1;
                result.hpf_freq      = -0.01831940280978611 + rng.Frnd(0.2) - 0.1;
                result.hpf_ramp      = -0.03857383633171346 + rng.Frnd(0.2) - 0.1;
                return(result);
            }
            if (rng.Frnd(10) < 1)
            {
                result.wave_type = (Wave)rng.Irnd((int)Wave.SIZE);
                if (result.wave_type == Wave.NOISE)
                {
                    result.wave_type = Wave.SQUARE;
                }
                result.env_attack    = 0.4304400932967592 + rng.Frnd(0.2) - 0.1;
                result.env_sustain   = 0.15739346034252394 + rng.Frnd(0.2) - 0.1;
                result.env_punch     = 0.004488201744871758 + rng.Frnd(0.2) - 0.1;
                result.env_decay     = 0.07478075528212291 + rng.Frnd(0.2) - 0.1;
                result.base_freq     = 0.9865265720147687 + rng.Frnd(0.2) - 0.1;
                result.freq_limit    = 0 + rng.Frnd(0.2) - 0.1;
                result.freq_ramp     = -0.2995018224359539 + rng.Frnd(0.2) - 0.1;
                result.freq_dramp    = 0.004598608156964473 + rng.Frnd(0.2) - 0.1;
                result.vib_strength  = -0.2202799497929496 + rng.Frnd(0.2) - 0.1;
                result.vib_speed     = 0.8084998703158364 + rng.Frnd(0.2) - 0.1;
                result.arp_mod       = -0.46410459213693644 + rng.Frnd(0.2) - 0.1;
                result.arp_speed     = -0.10955361249587248 + rng.Frnd(0.2) - 0.1;
                result.duty          = -0.9031808754347107 + rng.Frnd(0.2) - 0.1;
                result.duty_ramp     = -0.8128699999808343 + rng.Frnd(0.2) - 0.1;
                result.repeat_speed  = 0.7014860189319991 + rng.Frnd(0.2) - 0.1;
                result.pha_offset    = -0.9424902314367765 + rng.Frnd(0.2) - 0.1;
                result.pha_ramp      = -0.1055482222272056 + rng.Frnd(0.2) - 0.1;
                result.lpf_freq      = 0.9989765717851521 + rng.Frnd(0.2) - 0.1;
                result.lpf_ramp      = -0.25051720626043017 + rng.Frnd(0.2) - 0.1;
                result.lpf_resonance = 0.32777871505494693 + rng.Frnd(0.2) - 0.1;
                result.hpf_freq      = 0.0023548750981756753 + rng.Frnd(0.2) - 0.1;
                result.hpf_ramp      = -0.002375673204842568 + rng.Frnd(0.2) - 0.1;
                return(result);
            }
            if (rng.Frnd(5) > 1)
            {
                result.wave_type = (Wave)rng.Irnd((int)Wave.SIZE);
                if (result.wave_type == Wave.NOISE)
                {
                    result.wave_type = Wave.SQUARE;
                }
                if (rng.Rnd(1) != 0)
                {
                    result.arp_mod       = 0.2697849293151393 + rng.Frnd(0.2) - 0.1;
                    result.arp_speed     = -0.3131172257760948 + rng.Frnd(0.2) - 0.1;
                    result.base_freq     = 0.8090588299313949 + rng.Frnd(0.2) - 0.1;
                    result.duty          = -0.6210022920964955 + rng.Frnd(0.2) - 0.1;
                    result.duty_ramp     = -0.00043441813553182567 + rng.Frnd(0.2) - 0.1;
                    result.env_attack    = 0.004321877246874195 + rng.Frnd(0.2) - 0.1;
                    result.env_decay     = 0.1 + rng.Frnd(0.2) - 0.1;
                    result.env_punch     = 0.061737781504416146 + rng.Frnd(0.2) - 0.1;
                    result.env_sustain   = 0.4987252564798832 + rng.Frnd(0.2) - 0.1;
                    result.freq_dramp    = 0.31700340314222614 + rng.Frnd(0.2) - 0.1;
                    result.freq_limit    = 0 + rng.Frnd(0.2) - 0.1;
                    result.freq_ramp     = -0.163380391341416 + rng.Frnd(0.2) - 0.1;
                    result.hpf_freq      = 0.4709005021145149 + rng.Frnd(0.2) - 0.1;
                    result.hpf_ramp      = 0.6924667290539194 + rng.Frnd(0.2) - 0.1;
                    result.lpf_freq      = 0.8351398631384511 + rng.Frnd(0.2) - 0.1;
                    result.lpf_ramp      = 0.36616557192873134 + rng.Frnd(0.2) - 0.1;
                    result.lpf_resonance = -0.08685777111664439 + rng.Frnd(0.2) - 0.1;
                    result.pha_offset    = -0.036084571580025544 + rng.Frnd(0.2) - 0.1;
                    result.pha_ramp      = -0.014806445085568108 + rng.Frnd(0.2) - 0.1;
                    result.repeat_speed  = -0.8094368475518489 + rng.Frnd(0.2) - 0.1;
                    result.vib_speed     = 0.4496665457171294 + rng.Frnd(0.2) - 0.1;
                    result.vib_strength  = 0.23413762515532424 + rng.Frnd(0.2) - 0.1;
                }
                else
                {
                    result.arp_mod       = -0.35697118026766184 + rng.Frnd(0.2) - 0.1;
                    result.arp_speed     = 0.3581140690559588 + rng.Frnd(0.2) - 0.1;
                    result.base_freq     = 1.3260897696157528 + rng.Frnd(0.2) - 0.1;
                    result.duty          = -0.30984900436710694 + rng.Frnd(0.2) - 0.1;
                    result.duty_ramp     = -0.0014374759133411626 + rng.Frnd(0.2) - 0.1;
                    result.env_attack    = 0.3160357835682254 + rng.Frnd(0.2) - 0.1;
                    result.env_decay     = 0.1 + rng.Frnd(0.2) - 0.1;
                    result.env_punch     = 0.24323114016870148 + rng.Frnd(0.2) - 0.1;
                    result.env_sustain   = 0.4 + rng.Frnd(0.2) - 0.1;
                    result.freq_dramp    = 0.2866475886237244 + rng.Frnd(0.2) - 0.1;
                    result.freq_limit    = 0 + rng.Frnd(0.2) - 0.1;
                    result.freq_ramp     = -0.10956352368742976 + rng.Frnd(0.2) - 0.1;
                    result.hpf_freq      = 0.20772718017889846 + rng.Frnd(0.2) - 0.1;
                    result.hpf_ramp      = 0.1564090637378835 + rng.Frnd(0.2) - 0.1;
                    result.lpf_freq      = 0.6021372770637031 + rng.Frnd(0.2) - 0.1;
                    result.lpf_ramp      = 0.24016227139979027 + rng.Frnd(0.2) - 0.1;
                    result.lpf_resonance = -0.08787383821160144 + rng.Frnd(0.2) - 0.1;
                    result.pha_offset    = -0.381597686151701 + rng.Frnd(0.2) - 0.1;
                    result.pha_ramp      = -0.0002481687661373495 + rng.Frnd(0.2) - 0.1;
                    result.repeat_speed  = 0.07812112809425686 + rng.Frnd(0.2) - 0.1;
                    result.vib_speed     = -0.13648848579133943 + rng.Frnd(0.2) - 0.1;
                    result.vib_strength  = 0.0018874158972302657 + rng.Frnd(0.2) - 0.1;
                }
                return(result);
            }

            result.wave_type = (Wave)rng.Irnd((int)Wave.SIZE);
            if (result.wave_type == Wave.SAWTOOTH || result.wave_type == Wave.NOISE)
            {
                result.wave_type = Wave.SINE;
            }
            result.base_freq = 0.85 + rng.Frnd(0.15);
            result.freq_ramp = 0.3 + rng.Frnd(0.15);

            result.env_attack  = 0 + rng.Frnd(0.09);
            result.env_sustain = 0.2 + rng.Frnd(0.3);
            result.env_decay   = 0 + rng.Frnd(0.1);

            result.duty      = rng.Frnd(2.0) - 1.0;
            result.duty_ramp = (float)Math.Pow(rng.Frnd(2.0) - 1.0, 3.0);

            result.repeat_speed = 0.5 + rng.Frnd(0.1);

            result.pha_offset = -0.3 + rng.Frnd(0.9);
            result.pha_ramp   = -rng.Frnd(0.3);

            result.arp_speed = 0.4 + rng.Frnd(0.6);
            result.arp_mod   = 0.8 + rng.Frnd(0.1);

            result.lpf_resonance = rng.Frnd(2.0) - 1.0;
            result.lpf_freq      = 1.0 - (float)Math.Pow(rng.Frnd(1.0), 3.0);
            result.lpf_ramp      = (float)Math.Pow(rng.Frnd(2.0) - 1.0, 3.0);
            if (result.lpf_freq < 0.1 && result.lpf_ramp < -0.05)
            {
                result.lpf_ramp = -result.lpf_ramp;
            }
            result.hpf_freq = (float)Math.Pow(rng.Frnd(1.0), 5.0);
            result.hpf_ramp = (float)Math.Pow(rng.Frnd(2.0) - 1.0, 5.0);
            return(result);
        }
Ejemplo n.º 9
0
        public static Patch Random(RNG rng)
        {
            Patch result = new Patch();

            result.wave_type = (Wave)rng.Irnd((int)Wave.SIZE);
            result.base_freq = (float)Math.Pow(rng.Frnd(2.0) - 1.0, 2.0);
            if (rng.Rnd(1) != 0)
            {
                result.base_freq = (float)Math.Pow(rng.Frnd(2.0) - 1.0, 3.0) + 0.5;
            }
            result.freq_limit = 0.0;
            result.freq_ramp  = (float)Math.Pow(rng.Frnd(2.0) - 1.0, 5.0);
            if (result.base_freq > 0.7 && result.freq_ramp > 0.2)
            {
                result.freq_ramp = -result.freq_ramp;
            }
            if (result.base_freq < 0.2 && result.freq_ramp < -0.05)
            {
                result.freq_ramp = -result.freq_ramp;
            }
            result.freq_dramp   = (float)Math.Pow(rng.Frnd(2.0) - 1.0, 3.0);
            result.duty         = rng.Frnd(2.0) - 1.0;
            result.duty_ramp    = (float)Math.Pow(rng.Frnd(2.0) - 1.0, 3.0);
            result.vib_strength = (float)Math.Pow(rng.Frnd(2.0) - 1.0, 3.0);
            result.vib_speed    = rng.Frnd(2.0) - 1.0;
            result.env_attack   = (float)Math.Pow(rng.Frnd(2.0) - 1.0, 3.0);
            result.env_sustain  = (float)Math.Pow(rng.Frnd(2.0) - 1.0, 2.0);
            result.env_decay    = rng.Frnd(2.0) - 1.0;
            result.env_punch    = (float)Math.Pow(rng.Frnd(0.8), 2.0);
            if (result.env_attack + result.env_sustain + result.env_decay < 0.2)
            {
                result.env_sustain += 0.2 + rng.Frnd(0.3);
                result.env_decay   += 0.2 + rng.Frnd(0.3);
            }
            result.lpf_resonance = rng.Frnd(2.0) - 1.0;
            result.lpf_freq      = 1.0 - (float)Math.Pow(rng.Frnd(1.0), 3.0);
            result.lpf_ramp      = (float)Math.Pow(rng.Frnd(2.0) - 1.0, 3.0);
            if (result.lpf_freq < 0.1 && result.lpf_ramp < -0.05)
            {
                result.lpf_ramp = -result.lpf_ramp;
            }
            result.hpf_freq     = (float)Math.Pow(rng.Frnd(1.0), 5.0);
            result.hpf_ramp     = (float)Math.Pow(rng.Frnd(2.0) - 1.0, 5.0);
            result.pha_offset   = (float)Math.Pow(rng.Frnd(2.0) - 1.0, 3.0);
            result.pha_ramp     = (float)Math.Pow(rng.Frnd(2.0) - 1.0, 3.0);
            result.repeat_speed = rng.Frnd(2.0) - 1.0;
            result.arp_speed    = rng.Frnd(2.0) - 1.0;
            result.arp_mod      = rng.Frnd(2.0) - 1.0;
            return(result);
        }
Ejemplo n.º 10
0
        public static Patch Explosion(RNG rng)
        {
            Patch result = new Patch();

            if (rng.Rnd(1) != 0)
            {
                result.base_freq = 0.1 + rng.Frnd(0.4);
                result.freq_ramp = -0.1 + rng.Frnd(0.4);
            }
            else
            {
                result.base_freq = 0.2 + rng.Frnd(0.7);
                result.freq_ramp = -0.2 - rng.Frnd(0.2);
            }
            result.base_freq *= result.base_freq;
            if (rng.Rnd(4) == 0)
            {
                result.freq_ramp = 0.0;
            }
            if (rng.Rnd(2) == 0)
            {
                result.repeat_speed = 0.3 + rng.Frnd(0.5);
            }
            result.env_attack  = 0.0;
            result.env_sustain = 0.1 + rng.Frnd(0.3);
            result.env_decay   = rng.Frnd(0.5);
            if (rng.Rnd(1) == 0)
            {
                result.pha_offset = -0.3 + rng.Frnd(0.9);
                result.pha_ramp   = -rng.Frnd(0.3);
            }
            result.env_punch = 0.2 + rng.Frnd(0.6);
            if (rng.Rnd(1) != 0)
            {
                result.vib_strength = rng.Frnd(0.7);
                result.vib_speed    = rng.Frnd(0.6);
            }
            if (rng.Rnd(2) == 0)
            {
                result.arp_speed = 0.6 + rng.Frnd(0.3);
                result.arp_mod   = 0.8 - rng.Frnd(1.6);
            }
            return(result);
        }