Esempio n. 1
0
        public override int Read(short[] buffer, int offset, int sampleCount)
        {
            for (int sample = 0; sample < sampleCount; sample++)
            {
                double currentsamplevalue = 0;

                for (int channel = 0; channel < CurrentPolyphony; channel++)
                {
                    if (Channels[channel].State == ChannelState.KeyOn)
                    {
                        Phase[channel, 0] = 0;
                    }
                    if (Channels[channel].State == ChannelState.KeyOn || Channels[channel].State == ChannelState.ReKeyOn)
                    {
                        Channels[channel].State = ChannelState.Active;
                    }
                    if (Channels[channel].State == ChannelState.Active || Channels[channel].State == ChannelState.KeyOff)
                    {
                        double commonsinpart = 2 * Math.PI / WaveFormat.SampleRate * (Channels[channel].Freq + Bending);
                        Phase[channel, 0] += commonsinpart;
                        //Main voice
                        double mainvoice = 0;
                        Z_nthCommon.Phase.Waveformswitcher(CurrentOption, Phase[channel, 0], ref mainvoice);

                        //Detunes
                        //Detune improvements needed:
                        //Accurate cent calculation (log)
                        //2 first detune half , others 1, 2, 3... * +-spread distance
                        double detunes = 0;
                        for (int i = 1; i <= Count; i++)
                        {
                            Phase[channel, i * 2]     += 2 * Math.PI / WaveFormat.SampleRate * (Channels[channel].Freq + Bending + i * Spread * 10);
                            Phase[channel, i * 2 - 1] += 2 * Math.PI / WaveFormat.SampleRate * (Channels[channel].Freq + Bending - i * Spread * 10);
                            Z_nthCommon.Phase.Waveformswitcher(CurrentOption, Phase[channel, i * 2], ref detunes);
                            Z_nthCommon.Phase.Waveformswitcher(CurrentOption, Phase[channel, i * 2 - 1], ref detunes);
                        }
                        detunes = detunes / (Count * 2);

                        currentsamplevalue += detunes * Mix + mainvoice * (1 - Mix);
                    }
                    if (Channels[channel].State == ChannelState.KeyOff)
                    {
                        if (Phase[channel, 0] > 2 * Math.PI)
                        {
                            Channels[channel].State = ChannelState.Inactive;
                        }
                    }
                    for (int i = 0; i < 11; i++)
                    {
                        if (Phase[channel, i] > 2 * Math.PI)
                        {
                            Phase[channel, i] -= 2 * Math.PI;
                        }
                    }
                }
                currentsamplevalue = currentsamplevalue / CurrentPolyphony;
                Filter.Process(ref currentsamplevalue);
                Echo.Process(ref currentsamplevalue);
                buffer[sample + offset] = OutLimiter(ref currentsamplevalue);
            }
            return(sampleCount);
        }
Esempio n. 2
0
        public override int Read(short[] buffer, int offset, int sampleCount)
        {
            for (int sample = 0; sample < sampleCount; sample++)
            {
                double bending = Bending;

                Leslie_Phase += 2 * Math.PI / WaveFormat.SampleRate * Leslie_Freq;
                if (Leslie_Phase > 2 * Math.PI)
                {
                    Leslie_Phase -= 2 * Math.PI;
                }
                double leslie = Math.Sin(Leslie_Phase) * Leslie_Rate;

                double currentsamplevalue = 0;

                for (int channel = 0; channel < CurrentPolyphony; channel++)
                {
                    if (Channels[channel].State == ChannelState.KeyOn)
                    {
                        for (int drawbar = 1; drawbar < 10; drawbar++)
                        {
                            Drawbars[drawbar].Phase[channel] = 0;
                        }
                    }
                    if (Channels[channel].State == ChannelState.KeyOn || Channels[channel].State == ChannelState.ReKeyOn)
                    {
                        Channels[channel].State = ChannelState.Active;
                    }
                    if (Channels[channel].State == ChannelState.Active || Channels[channel].State == ChannelState.KeyOff)
                    {
                        double commonsinpart = 2 * Math.PI / WaveFormat.SampleRate * (Channels[channel].Freq + leslie + bending);
                        for (int drawbar = 1; drawbar < 10; drawbar++)
                        {
                            if (Drawbars[drawbar].Phase[channel] >= 0)
                            {
                                Drawbars[drawbar].Phase[channel] += commonsinpart * Drawbars[drawbar].FreqMul;
                            }
                            if (Channels[channel].State == ChannelState.KeyOff)
                            {
                                if (Drawbars[drawbar].Phase[channel] >= 2 * Math.PI)
                                {
                                    Drawbars[drawbar].Phase[channel] = -100;
                                }
                            }
                            if (Drawbars[drawbar].Phase[channel] >= 0)
                            {
                                if (Drawbars[drawbar].Phase[channel] >= 2 * Math.PI)
                                {
                                    Drawbars[drawbar].Phase[channel] -= 2 * Math.PI;
                                }
                                currentsamplevalue += Simpleoverdrive(Math.Sin(Drawbars[drawbar].Phase[channel]), (double)overDrive / 10) * Drawbars[drawbar].Volume;
                            }
                        }
                    }
                    if (Channels[channel].State == ChannelState.KeyOff)
                    {
                        int drawbar;
                        for (drawbar = 1; drawbar < 10; drawbar++)
                        {
                            if (Drawbars[drawbar].Phase[channel] >= 0)
                            {
                                break;
                            }
                        }
                        if (drawbar == 10)
                        {
                            Channels[channel].State = ChannelState.Inactive;
                        }
                    }
                }
                //The 90 divider is for the drawbars. There are 9 of them. They have 10 position here.
                currentsamplevalue = currentsamplevalue / 90 / CurrentPolyphony;

                //Over volume + limit = kinda overdrive and distortion
                #region Volume/Overdrive/Limit
                currentsamplevalue = Simpleoverdrive(currentsamplevalue, amplify);
                #endregion Volume/Overdrive/Limit

                Echo.Process(ref currentsamplevalue);
                buffer[sample + offset] = OutLimiter(ref currentsamplevalue);
            }
            return(sampleCount);
        }