Ejemplo n.º 1
0
        private int LrsSrcUp(float[] x, float[] y, double factor, int nx, int nwing, float lpScl, float[] imp, float[] impD, bool interp)
        {
            float[] xpArray = x;
            int     xpIndex;

            float[] ypArray = y;
            int     ypIndex = 0;

            float v;

            double currentTime = _time;
            double dt;
            double endTime;

            dt = 1.0 / factor;

            endTime = currentTime + nx;
            while (currentTime < endTime)
            {
                double leftPhase  = currentTime - Math.Floor(currentTime);
                double rightPhase = 1.0 - leftPhase;

                xpIndex = (int)currentTime;
                v       = ArbitraryFilterKit.LrsFilterUp(imp, impD, nwing, interp, xpArray, xpIndex++, leftPhase, -1);
                v      += ArbitraryFilterKit.LrsFilterUp(imp, impD, nwing, interp, xpArray, xpIndex, rightPhase, 1);
                v      *= lpScl;

                ypArray[ypIndex++] = v;
                currentTime       += dt;
            }

            _time = currentTime;

            return(ypIndex);
        }
Ejemplo n.º 2
0
        private void Init(bool highQuality, double minFactor, double maxFactor)
        {
            if (minFactor <= 0.0 || maxFactor <= 0.0)
            {
                throw new ArgumentException("minFactor and maxFactor must be positive");
            }
            if (maxFactor < minFactor)
            {
                throw new ArgumentException("minFactor must be less or equal to maxFactor");
            }

            _minFactor = minFactor;
            _maxFactor = maxFactor;
            _nmult     = highQuality ? 35 : 11;
            _lpScl     = 1.0f;
            _nwing     = ArbitraryFilterKit.Npc * (_nmult - 1) / 2; // # of filter coeffs in right wing

            const double rolloff = 0.90;
            const double beta    = 6;

            var imp64 = new double[_nwing];

            ArbitraryFilterKit.LrsLpFilter(imp64, _nwing, 0.5 * rolloff, beta, ArbitraryFilterKit.Npc);
            _imp  = new float[_nwing];
            _impD = new float[_nwing];

            for (var i = 0; i < _nwing; i++)
            {
                _imp[i] = (float)imp64[i];
            }

            for (var i = 0; i < _nwing - 1; i++)
            {
                _impD[i] = _imp[i + 1] - _imp[i];
            }

            _impD[_nwing - 1] = -_imp[_nwing - 1];

            var xoffMin = (int)(((_nmult + 1) / 2.0) * Math.Max(1.0, 1.0 / minFactor) + 10);
            var xoffMax = (int)(((_nmult + 1) / 2.0) * Math.Max(1.0, 1.0 / maxFactor) + 10);

            _xoff = Math.Max(xoffMin, xoffMax);

            _xSize = Math.Max(2 * _xoff + 10, 4096);
            _x     = new float[_xSize + _xoff];
            _xp    = _xoff;
            _xread = _xoff;

            var ySize = (int)(_xSize * maxFactor + 2.0);

            _y  = new float[ySize];
            _yp = 0;

            _time = _xoff;
        }