public override float Interpolate(float theBlend)
        {
            switch (mode)
            {
            case CCInterpolationMode.IN:
                return((theBlend == 0) ? 0 : theBlend *CCMath.Pow(2, 10 *(theBlend - 1)));

            case CCInterpolationMode.OUT:
                return((theBlend == 1) ? 1 : (-CCMath.Pow(2, -10 * theBlend) + 1));
            }
            if ((theBlend) < 0.5)
            {
                return(0.5f * CCMath.Pow(2, 10 * (theBlend - 1)));
            }
            return(0.5f * (-CCMath.Pow(2, -10 * (theBlend - 1)) + 2));
        }
        public override float Interpolate(float theBlend)
        {
            switch (mode)
            {
            case CCInterpolationMode.IN:
                return(CCMath.Pow(theBlend, pow));

            case CCInterpolationMode.OUT:
                return(1 - CCMath.Pow(1 - theBlend, pow));
            }
            if (theBlend < 0.5f)
            {
                return(CCMath.Pow(theBlend * 2, pow) / 2);
            }
            return(1 - CCMath.Pow((1 - theBlend) * 2, pow) / 2);
        }
Example #3
0
        protected internal override void CalcCoeff()
        {
            calcpoles();


            // System.out.println("ChebFilter is calculating coefficients...");

            // initialize our arrays
            for (int i = 0; i < 23; ++i)
            {
                ca[i] = cb[i] = ta[i] = tb[i] = 0.0f;
            }

            // I don't know why this must be done
            ca[2] = 1.0f;
            cb[2] = 1.0f;

            // calculate two poles at a time
            for (int p = 1; p <= poles / 2; p++)
            {
                // calc pair p, put the results in pa and pb
                calcTwoPole(p, pa, pb);

                // copy ca and cb into ta and tb
                Array.Copy(ca, 0, ta, 0, ta.Length);
                Array.Copy(cb, 0, tb, 0, tb.Length);

                // add coefficients to the cascade
                for (int i = 2; i < 23; i++)
                {
                    ca[i] = pa[0] * ta[i] + pa[1] * ta[i - 1] + pa[2] * ta[i - 2];
                    cb[i] = tb[i] - pb[0] * tb[i - 1] - pb[1] * tb[i - 2];
                }
            }

            // final stage of combining coefficients
            cb[2] = 0;
            for (int i = 0; i < 21; i++)
            {
                ca[i] = ca[i + 2];
                cb[i] = -cb[i + 2];
            }

            // normalize the gain
            float sa = 0;
            float sb = 0;

            for (int i = 0; i < 21; i++)
            {
                if (type == ChebFilterType.LP)
                {
                    sa += ca[i];
                    sb += cb[i];
                }
                else
                {
                    sa += ca[i] * CCMath.Pow(-1, i);
                    sb += cb[i] * CCMath.Pow(-1, i);
                }
            }

            float gain = sa / (1 - sb);

            for (int i = 0; i < 21; i++)
            {
                ca[i] /= gain;
            }

            // initialize the coefficient arrays used by process()
            // but only if the number of poles has changed
            if (a == null || a.Length != poles + 1)
            {
                a = new float[poles + 1];
            }
            if (b == null || b.Length != poles)
            {
                b = new float[poles];
            }
            // copy the values from ca and cb into a and b
            // in this implementation cb[0] = 0 and cb[1] is where
            // the b coefficients begin, so they are numbered the way
            // one normally numbers coefficients when talking about IIR filters
            // however, process() expects b[0] to be the coefficient B1
            // so we copy cb over to b starting at index 1
            Array.Copy(ca, 0, a, 0, a.Length);
            Array.Copy(cb, 1, b, 0, b.Length);
        }