Ejemplo n.º 1
0
        public override float getSampleAtTime(int note, int channel, int synthSampleRate, ref double time)
        {
            double freq = SynthHelper.NoteToFrequency(note);

            if (freq * time > 1.0)
            {
                time = 0.0;
            }
            switch (type)
            {
            case SynthHelper.WaveFormType.Sine:
                return(SynthHelper.Sine(freq, time) * SynthHelper.DEFAULT_AMPLITUDE);

            case SynthHelper.WaveFormType.Sawtooth:
                return(SynthHelper.Sawtooth(freq, time) * SynthHelper.DEFAULT_AMPLITUDE);

            case SynthHelper.WaveFormType.Square:
                return(SynthHelper.Square(freq, time) * SynthHelper.DEFAULT_AMPLITUDE);

            case SynthHelper.WaveFormType.Triangle:
                return(SynthHelper.Triangle(freq, time) * SynthHelper.DEFAULT_AMPLITUDE);

            case SynthHelper.WaveFormType.WhiteNoise:
                return(SynthHelper.WhiteNoise(note, time) * SynthHelper.DEFAULT_AMPLITUDE);

            default:
                return(0.0f);
            }
        }
Ejemplo n.º 2
0
        public override float getSampleAtTime(int note, int channel, int synthSampleRate, ref double time)
        {
            double freq  = SynthHelper.NoteToFrequency(note);
            double delta = (1.0 / freq); //Position in wave form in 2PI * (time* frequency)

            if (time >= delta)           //Waveform repeates at 1.0 / freq
            {
                time = time % delta;
            }
            switch (type)
            {
            case SynthHelper.WaveFormType.Sine:
                return(SynthHelper.Sine(freq, time) * SynthHelper.DEFAULT_AMPLITUDE);

            case SynthHelper.WaveFormType.Sawtooth:
                return(SynthHelper.Sawtooth(freq, time) * SynthHelper.DEFAULT_AMPLITUDE);

            case SynthHelper.WaveFormType.Square:
                return(SynthHelper.Square(freq, time) * SynthHelper.DEFAULT_AMPLITUDE);

            case SynthHelper.WaveFormType.Triangle:
                return(SynthHelper.Triangle(freq, time) * SynthHelper.DEFAULT_AMPLITUDE);

            case SynthHelper.WaveFormType.WhiteNoise:
                return(SynthHelper.WhiteNoise(note, time) * SynthHelper.DEFAULT_AMPLITUDE);

            default:
                return(0.0f);
            }
        }
Ejemplo n.º 3
0
        public override float getSampleAtTime(int note, int channel, int synthSampleRate, ref double time)
        {
            //time
            if (time > end_time)
            {
                if (looping)
                {
                    time = start_time;
                }
                else
                {
                    time = end_time;
                    return(0.0f);
                }
            }
            double freq = SynthHelper.NoteToFrequency(note);

            //modulation
            switch (modWaveType)
            {
            case SynthHelper.WaveFormType.Sine:
                freq = freq + (SynthHelper.Sine(mfreq.doProcess(freq), time) * mamp.doProcess(SynthHelper.DEFAULT_AMPLITUDE));
                break;

            case SynthHelper.WaveFormType.Sawtooth:
                freq = freq + (SynthHelper.Sawtooth(mfreq.doProcess(freq), time) * mamp.doProcess(SynthHelper.DEFAULT_AMPLITUDE));
                break;

            case SynthHelper.WaveFormType.Square:
                freq = freq + (SynthHelper.Square(mfreq.doProcess(freq), time) * mamp.doProcess(SynthHelper.DEFAULT_AMPLITUDE));
                break;

            case SynthHelper.WaveFormType.Triangle:
                freq = freq + (SynthHelper.Triangle(mfreq.doProcess(freq), time) * mamp.doProcess(SynthHelper.DEFAULT_AMPLITUDE));
                break;

            case SynthHelper.WaveFormType.WhiteNoise:
                freq = freq + (SynthHelper.WhiteNoise(0, time) * mamp.doProcess(SynthHelper.DEFAULT_AMPLITUDE));
                break;

            default:
                break;
            }
            //carrier
            switch (baseWaveType)
            {
            case SynthHelper.WaveFormType.Sine:
                return(SynthHelper.Sine(freq, time) * env.doProcess(time));

            case SynthHelper.WaveFormType.Sawtooth:
                return(SynthHelper.Sawtooth(freq, time) * env.doProcess(time));

            case SynthHelper.WaveFormType.Square:
                return(SynthHelper.Square(freq, time) * env.doProcess(time));

            case SynthHelper.WaveFormType.Triangle:
                return(SynthHelper.Triangle(freq, time) * env.doProcess(time));

            case SynthHelper.WaveFormType.WhiteNoise:
                return(SynthHelper.WhiteNoise(note, time) * env.doProcess(time));

            default:
                return(0.0f);
            }
        }
Ejemplo n.º 4
0
        public override float getSampleAtTime(int note, int channel, int synthSampleRate, ref double time)
        {
            //time
            if (time >= end_time)
            {
                if (looping)
                {
                    time = time % start_time;
                }
                else
                {
                    time = end_time;
                    return(0.0f);
                }
            }

            double freq = SynthHelper.NoteToFrequency(note);

            double timeM = time;
            double timeC = time;
            double delta = (1.0 / freq); //Position in wave form in 2PI * (time* frequency)

            timeM = time % delta;

            double c1 = mfreq.inputSelect == 0 ? freq : SynthHelper.DEFAULT_AMPLITUDE;
            double c2 = mfreq.inputSelect == 1 ? SynthHelper.DEFAULT_AMPLITUDE : freq;

            //modulation
            switch (modWaveType)
            {
            case SynthHelper.WaveFormType.Sine:
                freq += (SynthHelper.Sine(mfreq.doProcess(c1), timeC) * mamp.doProcess(c2));
                break;

            case SynthHelper.WaveFormType.Sawtooth:
                freq += (SynthHelper.Sawtooth(mfreq.doProcess(c1), timeC) * mamp.doProcess(c2));
                break;

            case SynthHelper.WaveFormType.Square:
                freq += (SynthHelper.Square(mfreq.doProcess(c1), timeC) * mamp.doProcess(c2));
                break;

            case SynthHelper.WaveFormType.Triangle:
                freq += (SynthHelper.Triangle(mfreq.doProcess(c1), timeC) * mamp.doProcess(c2));
                break;

            case SynthHelper.WaveFormType.WhiteNoise:
                freq += (SynthHelper.WhiteNoise(0, timeC) * mamp.doProcess(c2));
                break;

            default:
                break;
            }

            delta = (1.0 / freq);      //Position in wave form in 2PI * (time* frequency)
            timeC = time % delta;

            //carrier
            switch (baseWaveType)
            {
            case SynthHelper.WaveFormType.Sine:
                return(SynthHelper.Sine(freq, timeM) * env.doProcess(time));

            case SynthHelper.WaveFormType.Sawtooth:
                return(SynthHelper.Sawtooth(freq, timeM) * env.doProcess(time));

            case SynthHelper.WaveFormType.Square:
                return(SynthHelper.Square(freq, timeM) * env.doProcess(time));

            case SynthHelper.WaveFormType.Triangle:
                return(SynthHelper.Triangle(freq, timeM) * env.doProcess(time));

            case SynthHelper.WaveFormType.WhiteNoise:
                return(SynthHelper.WhiteNoise(note, timeM) * env.doProcess(time));

            default:
                return(0.0f);
            }
        }