public override void tick() { if (!_active) { return; } SignalBuffer dbin = getSignalInputBuffer(ioIn); SignalBuffer dbout = getSignalOutputBuffer(ioOut); if (!active) { if ((dbin != null) && (dbout != null)) { dbout.CopyFrom(dbin); } return; } SignalBuffer dbf = getSignalInputBuffer(ioF); SignalBuffer dbq = getSignalInputBuffer(ioQ); if (dbout == null) { return; } if (dbin == null) { return; } if (filter == null) { if (HighPass) { filter = new BiQuad(owner.sampleRate, BiQuad.BiQuadOrder.Second, BiQuad.BiQuadMode.HighPass, Math.Sqrt(f1 * f2), Math.Pow(10, (q1 + q2) / 2 / 20)); } else { filter = new BiQuad(owner.sampleRate, BiQuad.BiQuadOrder.Second, BiQuad.BiQuadMode.LowPass, Math.Sqrt(f1 * f2), Math.Pow(10, (q1 + q2) / 2 / 20)); } } for (int i = 0; i < owner.blockSize; i++) { double fin = (dbf != null) ? dbf.data[i] : 0; double qin = (dbq != null) ? dbq.data[i] : 0; double sig = (dbin != null) ? dbin.data[i]:0; fin = f1 * Math.Pow(f2 / f1, (fin + 1.0) / 2.0); qin = Math.Pow(10, (q1 + (q2 - q1) * (qin + 1.0) / 2) / 20); filter.frequency = fin; filter.Q = qin; sig = filter.filter(sig); dbout.data[i] = sig; } }
public override void tick() { if (!_active) { return; } SignalBuffer IN = getSignalInputBuffer(ioIn); SignalBuffer SIN = getSignalInputBuffer(ioRef0); SignalBuffer COS = getSignalInputBuffer(ioRef90); SignalBuffer OUTI = getSignalOutputBuffer(ioOI); SignalBuffer OUTQ = getSignalOutputBuffer(ioOQ); SignalBuffer OUTA = getSignalOutputBuffer(ioA); if ((IN == null) || (SIN == null) || (COS == null)) { return; } if ((OUTI == null) && (OUTQ == null) && (OUTA == null)) { return; } if (stage1a == null) { stage1a = new BiQuad(owner.sampleRate, BiQuad.BiQuadOrder.Second, BiQuad.BiQuadMode.LowPass, fc, Math.Sqrt(Math.Sqrt(2))); stage2a = new BiQuad(owner.sampleRate, BiQuad.BiQuadOrder.Second, BiQuad.BiQuadMode.LowPass, fc, Math.Sqrt(Math.Sqrt(2))); stage1b = new BiQuad(owner.sampleRate, BiQuad.BiQuadOrder.Second, BiQuad.BiQuadMode.LowPass, fc, Math.Sqrt(Math.Sqrt(2))); stage2b = new BiQuad(owner.sampleRate, BiQuad.BiQuadOrder.Second, BiQuad.BiQuadMode.LowPass, fc, Math.Sqrt(Math.Sqrt(2))); updateNeeded = false; } if (updateNeeded) { stage1a.frequency = fc; stage1b.frequency = fc; stage2a.frequency = fc; stage2b.frequency = fc; updateNeeded = false; } for (int i = 0; i < owner.blockSize; i++) { sval = SIN.data[i] * IN.data[i]; cval = COS.data[i] * IN.data[i]; double sout = stage2a.filter(stage1a.filter(sval)); double cout = stage2b.filter(stage1b.filter(cval)); if (OUTI != null) { OUTI.data[i] = sout; } if (OUTQ != null) { OUTQ.data[i] = cout; } if (OUTA != null) { OUTA.data[i] = Math.Sqrt(sout * sout + cout * cout); } } }
public override void tick() { if (!_active) { return; } if (loopstage == null) { loopstage = new BiQuad(owner.sampleRate, BiQuad.BiQuadOrder.Second, BiQuad.BiQuadMode.LoopFilter, fl, 1.0 / Math.Sqrt(2), 1000); fclpa = new BiQuadC(owner.sampleRate, BiQuadC.BiQuadOrder.Second, BiQuadC.BiQuadMode.LowPass, fc * 1.2, 1.0 / Math.Sqrt(2)); fclpb = new BiQuadC(owner.sampleRate, BiQuadC.BiQuadOrder.Second, BiQuadC.BiQuadMode.LowPass, fc * 1.2, 1.0); fchpa = new BiQuadC(owner.sampleRate, BiQuadC.BiQuadOrder.Second, BiQuadC.BiQuadMode.HighPass, fc / 1.2, 1.0 / Math.Sqrt(2)); fchpb = new BiQuadC(owner.sampleRate, BiQuadC.BiQuadOrder.Second, BiQuadC.BiQuadMode.HighPass, fc / 1.2, 1.0); //lp1 = new BiQuadC(owner.sampleRate, BiQuadC.BiQuadOrder.Second, BiQuadC.BiQuadMode.LowPass, fc / 2, 1.0 / Math.Sqrt(2)); //lp2 = new BiQuadC(owner.sampleRate, BiQuadC.BiQuadOrder.Second, BiQuadC.BiQuadMode.LowPass, fc / 2, 1.0); lp1 = new BiQuad(owner.sampleRate, BiQuad.BiQuadOrder.Second, BiQuad.BiQuadMode.LowPass, fc / 2, 1.0 / Math.Sqrt(2)); lp2 = new BiQuad(owner.sampleRate, BiQuad.BiQuadOrder.Second, BiQuad.BiQuadMode.LowPass, fc / 2, 1.0); lp3 = new BiQuad(owner.sampleRate, BiQuad.BiQuadOrder.Second, BiQuad.BiQuadMode.LowPass, fc / 2, 1.0 / Math.Sqrt(2)); lp4 = new BiQuad(owner.sampleRate, BiQuad.BiQuadOrder.Second, BiQuad.BiQuadMode.LowPass, fc / 2, 1.0); updateNeeded = false; } if (updateNeeded) { loopstage.frequency = fl; loopstage.KA = Math.Pow(10, KA / 20); fclpa.frequency = fc * 1.2; fclpb.frequency = fc * 1.2; fchpa.frequency = fc / 1.2; fchpb.frequency = fc / 1.2; lp1.frequency = fc / 2; lp2.frequency = fc / 2; lp3.frequency = fc / 2; lp4.frequency = fc / 2; updateNeeded = false; } SignalBuffer INI = getSignalInputBuffer(ioII); SignalBuffer INQ = getSignalInputBuffer(ioIQ); SignalBuffer OUTI = getSignalOutputBuffer(ioOI); SignalBuffer OUTQ = getSignalOutputBuffer(ioOQ); SignalBuffer OUTA = getSignalOutputBuffer(ioA); SignalBuffer OUTF = getSignalOutputBuffer(ioF); for (int i = 0; i < owner.blockSize; i++) { double ini = (INI != null) ? INI.data[i] : 0.0; double inq = (INQ != null) ? INQ.data[i] : 0.0; Complex inv = new Complex(ini, inq); Complex inf = fclpa.filter(fclpb.filter(fchpa.filter(fchpb.filter(inv)))); double infa = inf.abs; double sval = Math.Sin(phs); double cval = Math.Cos(phs); double lin = Complex.arg(inf * Complex.conj(Complex.exp(new Complex(0, phs)))); double lout = loopstage.filter(lin); phs = lout; phs -= 2 * Math.PI * Math.Floor(phs / (2 * Math.PI)); double xr = sval * ini + cval * inq; double xi = sval * inq - cval * ini; // Complex o = lp2.filter(lp1.filter(new Complex(xr, xi))); double o = lp2.filter(lp1.filter(Math.Abs(xr * xr + xi * xi))); double p = lp4.filter(lp3.filter(Math.Atan2(xi, xr))); if (OUTI != null) { OUTI.data[i] = sval; } if (OUTQ != null) { OUTQ.data[i] = cval; } if (OUTA != null) { // OUTA.data[i] = o.abs; OUTA.data[i] = o; } if (OUTF != null) { OUTF.data[i] = p; // o.phi; } } }