NScumm.Core.Audio.SoftSynth.ExternalFilter.UpdateClock C# (CSharp) Method

UpdateClock() public method

public UpdateClock ( int delta_t, int Vi ) : void
delta_t int
Vi int
return void
        public void UpdateClock(int delta_t, int Vi)
        {
            // This is handy for testing.
            if (!IsEnabled)
            {
                // Remove maximum DC level since there is no filter to do it.
                Vlp = Vhp = 0;
                Vo = Vi - mixer_DC;
                return;
            }

            // Maximum delta cycles for the external filter to work satisfactorily
            // is approximately 8.
            var delta_t_flt = 8;

            while (delta_t != 0)
            {
                if (delta_t < delta_t_flt)
                {
                    delta_t_flt = delta_t;
                }

                // delta_t is converted to seconds given a 1MHz clock by dividing
                // with 1 000 000.

                // Calculate filter outputs.
                // Vo  = Vlp - Vhp;
                // Vlp = Vlp + w0lp*(Vi - Vlp)*delta_t;
                // Vhp = Vhp + w0hp*(Vlp - Vhp)*delta_t;

                var dVlp = (w0lp * delta_t_flt >> 8) * (Vi - Vlp) >> 12;
                var dVhp = w0hp * delta_t_flt * (Vlp - Vhp) >> 20;
                Vo = Vlp - Vhp;
                Vlp += dVlp;
                Vhp += dVhp;

                delta_t -= delta_t_flt;
            }
        }