Esempio n. 1
0
        private double processModulation(object state)
        {
            if (!IsDisposed && ModulationEnabled)
            {
                double radian = 2 * Math.PI * (modulationStep / HighPrecisionTimer.TIMER_BASIC_1KHZ);

                double mdepth = 0;
                if (ParentModule.ModulationDepthes[NoteOnEvent.Channel] > 64)
                {
                    if (modulationStartCounter < 10d * HighPrecisionTimer.TIMER_BASIC_1KHZ)
                    {
                        modulationStartCounter += 1.0;
                    }

                    if (modulationStartCounter > ParentModule.GetModulationDelaySec(NoteOnEvent.Channel) * HighPrecisionTimer.TIMER_BASIC_1KHZ)
                    {
                        mdepth = (double)ParentModule.ModulationDepthes[NoteOnEvent.Channel] / 127d;
                    }
                }
                //急激な変化を抑制
                var mv = ((double)ParentModule.Modulations[NoteOnEvent.Channel] / 127d) + mdepth;
                if (mv != modulationLevel)
                {
                    modulationLevel += (mv - modulationLevel) / 1.25;
                }

                double modHz = radian * ParentModule.GetModulationRateHz(NoteOnEvent.Channel);
                ModultionDeltaNoteNumber  = modulationLevel * Math.Sin(modHz);
                ModultionDeltaNoteNumber *= ((double)ParentModule.ModulationDepthRangesNote[NoteOnEvent.Channel] +
                                             ((double)ParentModule.ModulationDepthRangesCent[NoteOnEvent.Channel] / 127d));

                OnPitchUpdated();

                if (modulationStep == 0 && IsSoundOff)
                {
                    return(-1);
                }

                modulationStep += 1.0;
                if (modHz > 2 * Math.PI)
                {
                    modulationStep = 0;
                }

                return(1);
            }
            return(-1);
        }