diff --git a/plugins/channelrx/wdsprx/wdsprxsink.cpp b/plugins/channelrx/wdsprx/wdsprxsink.cpp index d114d176b..45fe96d60 100644 --- a/plugins/channelrx/wdsprx/wdsprxsink.cpp +++ b/plugins/channelrx/wdsprx/wdsprxsink.cpp @@ -373,8 +373,8 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force) if ((m_settings.m_rit != settings.m_rit) || (m_settings.m_ritFrequency != settings.m_ritFrequency) || force) { - WDSP::SHIFT::SetShiftFreq(*m_rxa, settings.m_ritFrequency); - WDSP::SHIFT::SetShiftRun(*m_rxa, settings.m_rit ? 1 : 0); + m_rxa->shift->SetFreq(settings.m_ritFrequency); + m_rxa->shift->SetRun(settings.m_rit ? 1 : 0); } // Filter and mode diff --git a/wdsp/RXA.cpp b/wdsp/RXA.cpp index a7a848b25..b514abea4 100644 --- a/wdsp/RXA.cpp +++ b/wdsp/RXA.cpp @@ -119,7 +119,7 @@ RXA* RXA::create_rxa ( ); // Ftequency shifter - shift to select a slice of spectrum - rxa->shift = SHIFT::create_shift ( + rxa->shift = new SHIFT( 0, // run rxa->dsp_insize, // input buffer size rxa->inbuff, // pointer to input buffer @@ -128,7 +128,7 @@ RXA* RXA::create_rxa ( 0.0); // amount to shift (Hz) // Input resampler - resample to dsp rate for main processing - rxa->rsmpin = RESAMPLE::create_resample ( + rxa->rsmpin = new RESAMPLE( 0, // run - will be turned ON below if needed rxa->dsp_insize, // input buffer size rxa->inbuff, // pointer to input buffer @@ -555,7 +555,7 @@ RXA* RXA::create_rxa ( // AM squelch apply - absent but in the block diagram // Output resampler - rxa->rsmpout = RESAMPLE::create_resample ( + rxa->rsmpout = new RESAMPLE( 0, // run - will be turned ON below if needed rxa->dsp_size, // input buffer size rxa->midbuff, // pointer to input buffer @@ -573,7 +573,7 @@ RXA* RXA::create_rxa ( void RXA::destroy_rxa (RXA *rxa) { - RESAMPLE::destroy_resample (rxa->rsmpout); + delete (rxa->rsmpout); PANEL::destroy_panel (rxa->panel); SSQL::destroy_ssql (rxa->ssql); MPEAK::destroy_mpeak (rxa->mpeak); @@ -599,8 +599,8 @@ void RXA::destroy_rxa (RXA *rxa) NOTCHDB::destroy_notchdb (rxa->ndb); METER::destroy_meter (rxa->adcmeter); GEN::destroy_gen (rxa->gen0); - RESAMPLE::destroy_resample (rxa->rsmpin); - SHIFT::destroy_shift (rxa->shift); + delete (rxa->rsmpin); + delete (rxa->shift); delete (rxa->nob); delete (rxa->anb); delete[] (rxa->midbuff); @@ -616,8 +616,8 @@ void RXA::flush_rxa (RXA *rxa) std::fill(rxa->midbuff, rxa->midbuff + 2 * rxa->dsp_size * 2, 0); rxa->anb->flush(); rxa->nob->flush(); - SHIFT::flush_shift (rxa->shift); - RESAMPLE::flush_resample (rxa->rsmpin); + rxa->shift->flush(); + rxa->rsmpin->flush(); GEN::flush_gen (rxa->gen0); METER::flush_meter (rxa->adcmeter); NBP::flush_nbp (rxa->nbp0); @@ -642,15 +642,15 @@ void RXA::flush_rxa (RXA *rxa) MPEAK::flush_mpeak (rxa->mpeak); SSQL::flush_ssql (rxa->ssql); PANEL::flush_panel (rxa->panel); - RESAMPLE::flush_resample (rxa->rsmpout); + rxa->rsmpout->flush(); } void RXA::xrxa (RXA *rxa) { rxa->anb->execute(); rxa->nob->execute(); - SHIFT::xshift (rxa->shift); - RESAMPLE::xresample (rxa->rsmpin); + rxa->shift->execute(); + rxa->rsmpin->execute(); GEN::xgen (rxa->gen0); METER::xmeter (rxa->adcmeter); BPSNBA::xbpsnbain (rxa->bpsnba, 0); @@ -683,7 +683,7 @@ void RXA::xrxa (RXA *rxa) SSQL::xssql (rxa->ssql); PANEL::xpanel (rxa->panel); AMSQ::xamsq (rxa->amsq); - RESAMPLE::xresample (rxa->rsmpout); + rxa->rsmpout->execute(); } void RXA::setInputSamplerate (RXA *rxa, int in_rate) @@ -706,13 +706,13 @@ void RXA::setInputSamplerate (RXA *rxa, int in_rate) rxa->nob->setSize(rxa->dsp_insize); rxa->nob->setSamplerate(rxa->in_rate); // shift - SHIFT::setBuffers_shift (rxa->shift, rxa->inbuff, rxa->inbuff); - SHIFT::setSize_shift (rxa->shift, rxa->dsp_insize); - SHIFT::setSamplerate_shift (rxa->shift, rxa->in_rate); + rxa->shift->setBuffers(rxa->inbuff, rxa->inbuff); + rxa->shift->setSize(rxa->dsp_insize); + rxa->shift->setSamplerate(rxa->in_rate); // input resampler - RESAMPLE::setBuffers_resample (rxa->rsmpin, rxa->inbuff, rxa->midbuff); - RESAMPLE::setSize_resample (rxa->rsmpin, rxa->dsp_insize); - RESAMPLE::setInRate_resample (rxa->rsmpin, rxa->in_rate); + rxa->rsmpin->setBuffers(rxa->inbuff, rxa->midbuff); + rxa->rsmpin->setSize(rxa->dsp_insize); + rxa->rsmpin->setInRate(rxa->in_rate); ResCheck (*rxa); } @@ -728,8 +728,8 @@ void RXA::setOutputSamplerate (RXA *rxa, int out_rate) delete[] (rxa->outbuff); rxa->outbuff = new float[1 * rxa->dsp_outsize * 2]; // (float *)malloc0(1 * ch.dsp_outsize * sizeof(complex)); // output resampler - RESAMPLE::setBuffers_resample (rxa->rsmpout, rxa->midbuff, rxa->outbuff); - RESAMPLE::setOutRate_resample (rxa->rsmpout, rxa->out_rate); + rxa->rsmpout->setBuffers(rxa->midbuff, rxa->outbuff); + rxa->rsmpout->setOutRate(rxa->out_rate); ResCheck (*rxa); } @@ -758,12 +758,12 @@ void RXA::setDSPSamplerate (RXA *rxa, int dsp_rate) rxa->nob->setBuffers(rxa->inbuff, rxa->inbuff); rxa->nob->setSize(rxa->dsp_insize); // shift - SHIFT::setBuffers_shift (rxa->shift, rxa->inbuff, rxa->inbuff); - SHIFT::setSize_shift (rxa->shift, rxa->dsp_insize); + rxa->shift->setBuffers(rxa->inbuff, rxa->inbuff); + rxa->shift->setSize(rxa->dsp_insize); // input resampler - RESAMPLE::setBuffers_resample (rxa->rsmpin, rxa->inbuff, rxa->midbuff); - RESAMPLE::setSize_resample (rxa->rsmpin, rxa->dsp_insize); - RESAMPLE::setOutRate_resample (rxa->rsmpin, rxa->dsp_rate); + rxa->rsmpin->setBuffers(rxa->inbuff, rxa->midbuff); + rxa->rsmpin->setSize(rxa->dsp_insize); + rxa->rsmpin->setOutRate(rxa->dsp_rate); // dsp_rate blocks GEN::setSamplerate_gen (rxa->gen0, rxa->dsp_rate); METER::setSamplerate_meter (rxa->adcmeter, rxa->dsp_rate); @@ -791,8 +791,8 @@ void RXA::setDSPSamplerate (RXA *rxa, int dsp_rate) SSQL::setSamplerate_ssql (rxa->ssql, rxa->dsp_rate); PANEL::setSamplerate_panel (rxa->panel, rxa->dsp_rate); // output resampler - RESAMPLE::setBuffers_resample (rxa->rsmpout, rxa->midbuff, rxa->outbuff); - RESAMPLE::setInRate_resample (rxa->rsmpout, rxa->dsp_rate); + rxa->rsmpout->setBuffers(rxa->midbuff, rxa->outbuff); + rxa->rsmpout->setInRate(rxa->dsp_rate); ResCheck (*rxa); } @@ -823,11 +823,11 @@ void RXA::setDSPBuffsize (RXA *rxa, int dsp_size) rxa->nob->setBuffers(rxa->inbuff, rxa->inbuff); rxa->nob->setSize(rxa->dsp_insize); // shift - SHIFT::setBuffers_shift (rxa->shift, rxa->inbuff, rxa->inbuff); - SHIFT::setSize_shift (rxa->shift, rxa->dsp_insize); + rxa->shift->setBuffers(rxa->inbuff, rxa->inbuff); + rxa->shift->setSize(rxa->dsp_insize); // input resampler - RESAMPLE::setBuffers_resample (rxa->rsmpin, rxa->inbuff, rxa->midbuff); - RESAMPLE::setSize_resample (rxa->rsmpin, rxa->dsp_insize); + rxa->rsmpin->setBuffers(rxa->inbuff, rxa->midbuff); + rxa->rsmpin->setSize(rxa->dsp_insize); // dsp_size blocks GEN::setBuffers_gen (rxa->gen0, rxa->midbuff, rxa->midbuff); GEN::setSize_gen (rxa->gen0, rxa->dsp_size); @@ -878,8 +878,8 @@ void RXA::setDSPBuffsize (RXA *rxa, int dsp_size) PANEL::setBuffers_panel (rxa->panel, rxa->midbuff, rxa->midbuff); PANEL::setSize_panel (rxa->panel, rxa->dsp_size); // output resampler - RESAMPLE::setBuffers_resample (rxa->rsmpout, rxa->midbuff, rxa->outbuff); - RESAMPLE::setSize_resample (rxa->rsmpout, rxa->dsp_size); + rxa->rsmpout->setBuffers(rxa->midbuff, rxa->outbuff); + rxa->rsmpout->setSize(rxa->dsp_size); } void RXA::setSpectrumProbe(BufferProbe *spectrumProbe) diff --git a/wdsp/TXA.cpp b/wdsp/TXA.cpp index 5331cd35e..7a9f8e802 100644 --- a/wdsp/TXA.cpp +++ b/wdsp/TXA.cpp @@ -82,7 +82,7 @@ TXA* TXA::create_txa ( txa->outbuff = new float[1 * txa->dsp_outsize * 2]; // (float *) malloc0 (1 * txa->dsp_outsize * sizeof (complex)); txa->midbuff = new float[3 * txa->dsp_size * 2]; //(float *) malloc0 (2 * txa->dsp_size * sizeof (complex)); - txa->rsmpin.p = RESAMPLE::create_resample ( + txa->rsmpin.p = new RESAMPLE( 0, // run - will be turned on below if needed txa->dsp_insize, // input buffer size txa->inbuff, // pointer to input buffer @@ -486,7 +486,7 @@ TXA* TXA::create_txa ( 0.0, // raised-cosine transition width 0); // window type - txa->rsmpout.p = RESAMPLE::create_resample ( + txa->rsmpout.p = new RESAMPLE( 0, // run - will be turned ON below if needed txa->dsp_size, // input size txa->midbuff, // pointer to input buffer @@ -520,7 +520,7 @@ void TXA::destroy_txa (TXA *txa) { // in reverse order, free each item we created METER::destroy_meter (txa->outmeter.p); - RESAMPLE::destroy_resample (txa->rsmpout.p); + delete (txa->rsmpout.p); CFIR::destroy_cfir(txa->cfir.p); // destroy_calcc (txa->calcc.p); IQC::destroy_iqc (txa->iqc.p0); @@ -549,7 +549,7 @@ void TXA::destroy_txa (TXA *txa) PHROT::destroy_phrot (txa->phrot.p); PANEL::destroy_panel (txa->panel.p); GEN::destroy_gen (txa->gen0.p); - RESAMPLE::destroy_resample (txa->rsmpin.p); + delete (txa->rsmpin.p); delete[] (txa->midbuff); delete[] (txa->outbuff); delete[] (txa->inbuff); @@ -561,7 +561,7 @@ void TXA::flush_txa (TXA* txa) std::fill(txa->inbuff, txa->inbuff + 1 * txa->dsp_insize * 2, 0); std::fill(txa->outbuff, txa->outbuff + 1 * txa->dsp_outsize * 2, 0); std::fill(txa->midbuff, txa->midbuff + 2 * txa->dsp_size * 2, 0); - RESAMPLE::flush_resample (txa->rsmpin.p); + txa->rsmpin.p->flush(); GEN::flush_gen (txa->gen0.p); PANEL::flush_panel (txa->panel.p); PHROT::flush_phrot (txa->phrot.p); @@ -589,13 +589,13 @@ void TXA::flush_txa (TXA* txa) SIPHON::flush_siphon (txa->sip1.p); IQC::flush_iqc (txa->iqc.p0); CFIR::flush_cfir(txa->cfir.p); - RESAMPLE::flush_resample (txa->rsmpout.p); + txa->rsmpout.p->flush(); METER::flush_meter (txa->outmeter.p); } void xtxa (TXA* txa) { - RESAMPLE::xresample (txa->rsmpin.p); // input resampler + txa->rsmpin.p->execute(); // input resampler GEN::xgen (txa->gen0.p); // input signal generator PANEL::xpanel (txa->panel.p); // includes MIC gain PHROT::xphrot (txa->phrot.p); // phase rotator @@ -625,7 +625,7 @@ void xtxa (TXA* txa) SIPHON::xsiphon (txa->sip1.p, 0); // siphon data for display IQC::xiqc (txa->iqc.p0); // PureSignal correction CFIR::xcfir(txa->cfir.p); // compensating FIR filter (used Protocol_2 only) - RESAMPLE::xresample (txa->rsmpout.p); // output resampler + txa->rsmpout.p->execute(); // output resampler METER::xmeter (txa->outmeter.p); // output meter // print_peak_env ("env_exception.txt", txa->dsp_outsize, txa->outbuff, 0.7); } @@ -642,9 +642,9 @@ void TXA::setInputSamplerate (TXA *txa, int in_rate) delete[] (txa->inbuff); txa->inbuff = new float[1 * txa->dsp_insize * 2]; //(float *)malloc0(1 * txa->dsp_insize * sizeof(complex)); // input resampler - RESAMPLE::setBuffers_resample (txa->rsmpin.p, txa->inbuff, txa->midbuff); - RESAMPLE::setSize_resample (txa->rsmpin.p, txa->dsp_insize); - RESAMPLE::setInRate_resample (txa->rsmpin.p, txa->in_rate); + txa->rsmpin.p->setBuffers(txa->inbuff, txa->midbuff); + txa->rsmpin.p->setSize(txa->dsp_insize); + txa->rsmpin.p->setInRate(txa->in_rate); ResCheck (*txa); } @@ -662,8 +662,8 @@ void TXA::setOutputSamplerate (TXA* txa, int out_rate) // cfir - needs to know input rate of firmware CIC CFIR::setOutRate_cfir (txa->cfir.p, txa->out_rate); // output resampler - RESAMPLE::setBuffers_resample (txa->rsmpout.p, txa->midbuff, txa->outbuff); - RESAMPLE::setOutRate_resample (txa->rsmpout.p, txa->out_rate); + txa->rsmpout.p->setBuffers(txa->midbuff, txa->outbuff); + txa->rsmpout.p->setOutRate(txa->out_rate); ResCheck (*txa); // output meter METER::setBuffers_meter (txa->outmeter.p, txa->outbuff); @@ -690,9 +690,9 @@ void TXA::setDSPSamplerate (TXA *txa, int dsp_rate) delete[] (txa->outbuff); txa->outbuff = new float[1 * txa->dsp_outsize * 2]; // (float *)malloc0(1 * txa->dsp_outsize * sizeof(complex)); // input resampler - RESAMPLE::setBuffers_resample (txa->rsmpin.p, txa->inbuff, txa->midbuff); - RESAMPLE::setSize_resample (txa->rsmpin.p, txa->dsp_insize); - RESAMPLE::setOutRate_resample (txa->rsmpin.p, txa->dsp_rate); + txa->rsmpin.p->setBuffers(txa->inbuff, txa->midbuff); + txa->rsmpin.p->setSize(txa->dsp_insize); + txa->rsmpin.p->setOutRate(txa->dsp_rate); // dsp_rate blocks GEN::setSamplerate_gen (txa->gen0.p, txa->dsp_rate); PANEL::setSamplerate_panel (txa->panel.p, txa->dsp_rate); @@ -722,8 +722,8 @@ void TXA::setDSPSamplerate (TXA *txa, int dsp_rate) IQC::setSamplerate_iqc (txa->iqc.p0, txa->dsp_rate); CFIR::setSamplerate_cfir (txa->cfir.p, txa->dsp_rate); // output resampler - RESAMPLE::setBuffers_resample (txa->rsmpout.p, txa->midbuff, txa->outbuff); - RESAMPLE::setInRate_resample (txa->rsmpout.p, txa->dsp_rate); + txa->rsmpout.p->setBuffers(txa->midbuff, txa->outbuff); + txa->rsmpout.p->setInRate(txa->dsp_rate); ResCheck (*txa); // output meter METER::setBuffers_meter (txa->outmeter.p, txa->outbuff); @@ -751,8 +751,8 @@ void TXA::setDSPBuffsize (TXA *txa, int dsp_size) delete[] (txa->outbuff); txa->outbuff = new float[1 * txa->dsp_outsize * 2]; // (float *)malloc0(1 * txa->dsp_outsize * sizeof(complex)); // input resampler - RESAMPLE::setBuffers_resample (txa->rsmpin.p, txa->inbuff, txa->midbuff); - RESAMPLE::setSize_resample (txa->rsmpin.p, txa->dsp_insize); + txa->rsmpin.p->setBuffers(txa->inbuff, txa->midbuff); + txa->rsmpin.p->setSize(txa->dsp_insize); // dsp_size blocks GEN::setBuffers_gen (txa->gen0.p, txa->midbuff, txa->midbuff); GEN::setSize_gen (txa->gen0.p, txa->dsp_size); @@ -809,8 +809,8 @@ void TXA::setDSPBuffsize (TXA *txa, int dsp_size) CFIR::setBuffers_cfir (txa->cfir.p, txa->midbuff, txa->midbuff); CFIR::setSize_cfir (txa->cfir.p, txa->dsp_size); // output resampler - RESAMPLE::setBuffers_resample (txa->rsmpout.p, txa->midbuff, txa->outbuff); - RESAMPLE::setSize_resample (txa->rsmpout.p, txa->dsp_size); + txa->rsmpout.p->setBuffers(txa->midbuff, txa->outbuff); + txa->rsmpout.p->setSize(txa->dsp_size); // output meter METER::setBuffers_meter (txa->outmeter.p, txa->outbuff); METER::setSize_meter (txa->outmeter.p, txa->dsp_outsize); diff --git a/wdsp/resample.cpp b/wdsp/resample.cpp index 02ba5b4b9..ba94436c2 100644 --- a/wdsp/resample.cpp +++ b/wdsp/resample.cpp @@ -37,7 +37,7 @@ namespace WDSP { * * ************************************************************************************************/ -void RESAMPLE::calc_resample (RESAMPLE *a) +void RESAMPLE::calc_resample() { int x, y, z; int i, j, k; @@ -45,10 +45,10 @@ void RESAMPLE::calc_resample (RESAMPLE *a) double full_rate; double fc_norm_high, fc_norm_low; float* impulse; - a->fc = a->fcin; - a->ncoef = a->ncoefin; - x = a->in_rate; - y = a->out_rate; + fc = fcin; + ncoef = ncoefin; + x = in_rate; + y = out_rate; while (y != 0) { @@ -57,220 +57,214 @@ void RESAMPLE::calc_resample (RESAMPLE *a) x = z; } - a->L = a->out_rate / x; - a->M = a->in_rate / x; + L = out_rate / x; + M = in_rate / x; - a->L = a->L <= 0 ? 1 : a->L; - a->M = a->M <= 0 ? 1 : a->M; + L = L <= 0 ? 1 : L; + M = M <= 0 ? 1 : M; - if (a->in_rate < a->out_rate) - min_rate = a->in_rate; + if (in_rate < out_rate) + min_rate = in_rate; else - min_rate = a->out_rate; + min_rate = out_rate; - if (a->fc == 0.0) - a->fc = 0.45 * (float)min_rate; + if (fc == 0.0) + fc = 0.45 * (float)min_rate; - full_rate = (double) (a->in_rate * a->L); - fc_norm_high = a->fc / full_rate; + full_rate = (double) (in_rate * L); + fc_norm_high = fc / full_rate; - if (a->fc_low < 0.0) + if (fc_low < 0.0) fc_norm_low = - fc_norm_high; else - fc_norm_low = a->fc_low / full_rate; + fc_norm_low = fc_low / full_rate; - if (a->ncoef == 0) - a->ncoef = (int)(140.0 * full_rate / min_rate); + if (ncoef == 0) + ncoef = (int)(140.0 * full_rate / min_rate); - a->ncoef = (a->ncoef / a->L + 1) * a->L; - a->cpp = a->ncoef / a->L; - a->h = new double[a->ncoef]; // (float *)malloc0(a->ncoef * sizeof(float)); - impulse = FIR::fir_bandpass(a->ncoef, fc_norm_low, fc_norm_high, 1.0, 1, 0, a->gain * (double)a->L); + ncoef = (ncoef / L + 1) * L; + cpp = ncoef / L; + h = new double[ncoef]; // (float *)malloc0(ncoef * sizeof(float)); + impulse = FIR::fir_bandpass(ncoef, fc_norm_low, fc_norm_high, 1.0, 1, 0, gain * (double)L); i = 0; - for (j = 0; j < a->L; j++) + for (j = 0; j < L; j++) { - for (k = 0; k < a->ncoef; k += a->L) - a->h[i++] = impulse[j + k]; + for (k = 0; k < ncoef; k += L) + h[i++] = impulse[j + k]; } - a->ringsize = a->cpp; - a->ring = new double[a->ringsize]; // (float *)malloc0(a->ringsize * sizeof(complex)); - a->idx_in = a->ringsize - 1; - a->phnum = 0; + ringsize = cpp; + ring = new double[ringsize]; // (float *)malloc0(ringsize * sizeof(complex)); + idx_in = ringsize - 1; + phnum = 0; delete[] (impulse); } -void RESAMPLE::decalc_resample (RESAMPLE *a) +void RESAMPLE::decalc_resample() { - delete[] (a->ring); - delete[] (a->h); + delete[] ring; + delete[] h; } -RESAMPLE* RESAMPLE::create_resample ( - int run, - int size, - float* in, - float* out, - int in_rate, - int out_rate, - double fc, - int ncoef, - double gain +RESAMPLE::RESAMPLE ( + int _run, + int _size, + float* _in, + float* _out, + int _in_rate, + int _out_rate, + double _fc, + int _ncoef, + double _gain ) { - RESAMPLE *a = new RESAMPLE; - - a->run = run; - a->size = size; - a->in = in; - a->out = out; - a->in_rate = in_rate; - a->out_rate = out_rate; - a->fcin = fc; - a->fc_low = -1.0; // could add to create_resample() parameters - a->ncoefin = ncoef; - a->gain = gain; - calc_resample (a); - return a; + run = _run; + size = _size; + in = _in; + out = _out; + in_rate = _in_rate; + out_rate = _out_rate; + fcin = _fc; + fc_low = -1.0; // could add to create_resample() parameters + ncoefin = _ncoef; + gain = _gain; + calc_resample(); } - -void RESAMPLE::destroy_resample (RESAMPLE *a) +RESAMPLE::~RESAMPLE() { - decalc_resample (a); - delete (a); + decalc_resample(); } -void RESAMPLE::flush_resample (RESAMPLE *a) +void RESAMPLE::flush() { - std::fill(a->ring, a->ring + 2 * a->ringsize, 0); - a->idx_in = a->ringsize - 1; - a->phnum = 0; + std::fill(ring, ring + 2 * ringsize, 0); + idx_in = ringsize - 1; + phnum = 0; } - -int RESAMPLE::xresample (RESAMPLE *a) +int RESAMPLE::execute() { int outsamps = 0; - if (a->run) + if (run) { int i, j, n; int idx_out; double I, Q; - for (i = 0; i < a->size; i++) + for (i = 0; i < size; i++) { - a->ring[2 * a->idx_in + 0] = a->in[2 * i + 0]; - a->ring[2 * a->idx_in + 1] = a->in[2 * i + 1]; + ring[2 * idx_in + 0] = in[2 * i + 0]; + ring[2 * idx_in + 1] = in[2 * i + 1]; - while (a->phnum < a->L) + while (phnum < L) { I = 0.0; Q = 0.0; - n = a->cpp * a->phnum; + n = cpp * phnum; - for (j = 0; j < a->cpp; j++) + for (j = 0; j < cpp; j++) { - if ((idx_out = a->idx_in + j) >= a->ringsize) - idx_out -= a->ringsize; + if ((idx_out = idx_in + j) >= ringsize) + idx_out -= ringsize; - I += a->h[n + j] * a->ring[2 * idx_out + 0]; - Q += a->h[n + j] * a->ring[2 * idx_out + 1]; + I += h[n + j] * ring[2 * idx_out + 0]; + Q += h[n + j] * ring[2 * idx_out + 1]; } - a->out[2 * outsamps + 0] = I; - a->out[2 * outsamps + 1] = Q; + out[2 * outsamps + 0] = I; + out[2 * outsamps + 1] = Q; outsamps++; - a->phnum += a->M; + phnum += M; } - a->phnum -= a->L; + phnum -= L; - if (--a->idx_in < 0) - a->idx_in = a->ringsize - 1; + if (--idx_in < 0) + idx_in = ringsize - 1; } } - else if (a->in != a->out) + else if (in != out) { - std::copy( a->in, a->in + a->size * 2, a->out); + std::copy( in, in + size * 2, out); } return outsamps; } -void RESAMPLE::setBuffers_resample(RESAMPLE *a, float* in, float* out) +void RESAMPLE::setBuffers(float* _in, float* _out) { - a->in = in; - a->out = out; + in = _in; + out = _out; } -void RESAMPLE::setSize_resample(RESAMPLE *a, int size) +void RESAMPLE::setSize(int _size) { - a->size = size; - flush_resample (a); + size = _size; + flush(); } -void RESAMPLE::setInRate_resample(RESAMPLE *a, int rate) +void RESAMPLE::setInRate(int _rate) { - decalc_resample (a); - a->in_rate = rate; - calc_resample (a); + decalc_resample(); + in_rate = _rate; + calc_resample(); } -void RESAMPLE::setOutRate_resample(RESAMPLE *a, int rate) +void RESAMPLE::setOutRate(int _rate) { - decalc_resample (a); - a->out_rate = rate; - calc_resample (a); + decalc_resample(); + out_rate = _rate; + calc_resample(); } -void RESAMPLE::setFCLow_resample (RESAMPLE *a, double fc_low) +void RESAMPLE::setFCLow(double _fc_low) { - if (fc_low != a->fc_low) + if (fc_low != _fc_low) { - decalc_resample (a); - a->fc_low = fc_low; - calc_resample (a); + decalc_resample(); + fc_low = _fc_low; + calc_resample(); } } -void RESAMPLE::setBandwidth_resample (RESAMPLE *a, double fc_low, double fc_high) +void RESAMPLE::setBandwidth(double _fc_low, double _fc_high) { - if (fc_low != a->fc_low || fc_high != a->fcin) + if (fc_low != _fc_low || _fc_high != fcin) { - decalc_resample (a); - a->fc_low = fc_low; - a->fcin = fc_high; - calc_resample (a); + decalc_resample(); + fc_low = _fc_low; + fcin = _fc_high; + calc_resample(); } } // exported calls -void* RESAMPLE::create_resampleV (int in_rate, int out_rate) +void* RESAMPLE::createV (int in_rate, int out_rate) { - return (void *)create_resample (1, 0, 0, 0, in_rate, out_rate, 0.0, 0, 1.0); + return (void *) new RESAMPLE(1, 0, 0, 0, in_rate, out_rate, 0.0, 0, 1.0); } -void RESAMPLE::xresampleV (float* input, float* output, int numsamps, int* outsamps, void* ptr) +void RESAMPLE::executeV (float* input, float* output, int numsamps, int* outsamps, void* ptr) { RESAMPLE *a = (RESAMPLE*) ptr; a->in = input; a->out = output; a->size = numsamps; - *outsamps = xresample(a); + *outsamps = a->execute(); } -void RESAMPLE::destroy_resampleV (void* ptr) +void RESAMPLE::destroyV (void* ptr) { - destroy_resample ( (RESAMPLE*) ptr ); + delete ( (RESAMPLE*) ptr ); } } // namespace WDSP diff --git a/wdsp/resample.hpp b/wdsp/resample.hpp index f834ef5b2..3880c146f 100644 --- a/wdsp/resample.hpp +++ b/wdsp/resample.hpp @@ -62,7 +62,7 @@ public: int cpp; // coefficients of the phase int phnum; // phase number - static RESAMPLE* create_resample ( + RESAMPLE ( int run, int size, float* in, @@ -73,23 +73,24 @@ public: int ncoef, double gain ); - static void destroy_resample (RESAMPLE *a); - static void flush_resample (RESAMPLE *a); - static int xresample (RESAMPLE *a); - static void setBuffers_resample (RESAMPLE *a, float* in, float* out); - static void setSize_resample(RESAMPLE *a, int size); - static void setInRate_resample(RESAMPLE *a, int rate); - static void setOutRate_resample(RESAMPLE *a, int rate); - static void setFCLow_resample (RESAMPLE *a, double fc_low); - static void setBandwidth_resample (RESAMPLE *a, double fc_low, double fc_high); + ~RESAMPLE(); + + void flush(); + int execute(); + void setBuffers(float* in, float* out); + void setSize(int size); + void setInRate(int rate); + void setOutRate(int rate); + void setFCLow(double fc_low); + void setBandwidth(double fc_low, double fc_high); // Exported calls - static void* create_resampleV (int in_rate, int out_rate); - static void xresampleV (float* input, float* output, int numsamps, int* outsamps, void* ptr); - static void destroy_resampleV (void* ptr); + static void* createV (int in_rate, int out_rate); + static void executeV (float* input, float* output, int numsamps, int* outsamps, void* ptr); + static void destroyV (void* ptr); private: - static void calc_resample (RESAMPLE *a); - static void decalc_resample (RESAMPLE *a); + void calc_resample(); + void decalc_resample(); }; } // namespace WDSP diff --git a/wdsp/shift.cpp b/wdsp/shift.cpp index 8ab78fad3..f5ebae214 100644 --- a/wdsp/shift.cpp +++ b/wdsp/shift.cpp @@ -31,105 +31,98 @@ warren@wpratt.com namespace WDSP { -void SHIFT::calc_shift (SHIFT *a) +void SHIFT::calc_shift() { - a->delta = TWOPI * a->shift / a->rate; - a->cos_delta = cos (a->delta); - a->sin_delta = sin (a->delta); + delta = TWOPI * shift / rate; + cos_delta = cos (delta); + sin_delta = sin (delta); } -SHIFT* SHIFT::create_shift (int run, int size, float* in, float* out, int rate, double fshift) +SHIFT::SHIFT (int _run, int _size, float* _in, float* _out, int _rate, double _fshift) { - SHIFT *a = new SHIFT; - a->run = run; - a->size = size; - a->in = in; - a->out = out; - a->rate = (double) rate; - a->shift = fshift; - a->phase = 0.0; - calc_shift (a); - return a; + run = _run; + size = _size; + in = _in; + out = _out; + rate = (double) _rate; + shift = _fshift; + phase = 0.0; + calc_shift(); } -void SHIFT::destroy_shift (SHIFT *a) +void SHIFT::flush() { - delete (a); + phase = 0.0; } -void SHIFT::flush_shift (SHIFT *a) +void SHIFT::execute() { - a->phase = 0.0; -} - -void SHIFT::xshift (SHIFT *a) -{ - if (a->run) + if (run) { int i; double I1, Q1, t1, t2; - double cos_phase = cos (a->phase); - double sin_phase = sin (a->phase); + double cos_phase = cos (phase); + double sin_phase = sin (phase); - for (i = 0; i < a->size; i++) + for (i = 0; i < size; i++) { - I1 = a->in[2 * i + 0]; - Q1 = a->in[2 * i + 1]; - a->out[2 * i + 0] = I1 * cos_phase - Q1 * sin_phase; - a->out[2 * i + 1] = I1 * sin_phase + Q1 * cos_phase; + I1 = in[2 * i + 0]; + Q1 = in[2 * i + 1]; + out[2 * i + 0] = I1 * cos_phase - Q1 * sin_phase; + out[2 * i + 1] = I1 * sin_phase + Q1 * cos_phase; t1 = cos_phase; t2 = sin_phase; - cos_phase = t1 * a->cos_delta - t2 * a->sin_delta; - sin_phase = t1 * a->sin_delta + t2 * a->cos_delta; - a->phase += a->delta; + cos_phase = t1 * cos_delta - t2 * sin_delta; + sin_phase = t1 * sin_delta + t2 * cos_delta; + phase += delta; - if (a->phase >= TWOPI) - a->phase -= TWOPI; + if (phase >= TWOPI) + phase -= TWOPI; - if (a->phase < 0.0 ) - a->phase += TWOPI; + if (phase < 0.0 ) + phase += TWOPI; } } - else if (a->in != a->out) + else if (in != out) { - std::copy( a->in, a->in + a->size * 2, a->out); + std::copy( in, in + size * 2, out); } } -void SHIFT::setBuffers_shift(SHIFT *a, float* in, float* out) +void SHIFT::setBuffers(float* _in, float* _out) { - a->in = in; - a->out = out; + in = _in; + out = _out; } -void SHIFT::setSamplerate_shift (SHIFT *a, int rate) +void SHIFT::setSamplerate(int _rate) { - a->rate = rate; - a->phase = 0.0; - calc_shift(a); + rate = _rate; + phase = 0.0; + calc_shift(); } -void SHIFT::setSize_shift (SHIFT *a, int size) +void SHIFT::setSize(int _size) { - a->size = size; - flush_shift (a); + size = _size; + flush(); } /******************************************************************************************************** * * -* RXA Properties * +* Non static * * * ********************************************************************************************************/ -void SHIFT::SetShiftRun (RXA& rxa, int run) +void SHIFT::SetRun (int _run) { - rxa.shift->run = run; + run = _run; } -void SHIFT::SetShiftFreq (RXA& rxa, double fshift) +void SHIFT::SetFreq(double fshift) { - rxa.shift->shift = fshift; - calc_shift (rxa.shift); + shift = fshift; + calc_shift(); } } // namespace WDSP diff --git a/wdsp/shift.hpp b/wdsp/shift.hpp index 7e8deb346..aaed8701e 100644 --- a/wdsp/shift.hpp +++ b/wdsp/shift.hpp @@ -48,19 +48,20 @@ public: double cos_delta; double sin_delta; - static SHIFT* create_shift (int run, int size, float* in, float* out, int rate, double fshift); - static void destroy_shift (SHIFT *a); - static void flush_shift (SHIFT *a); - static void xshift (SHIFT *a); - static void setBuffers_shift (SHIFT *a, float* in, float* out); - static void setSamplerate_shift (SHIFT *a, int rate); - static void setSize_shift (SHIFT *a, int size); - // RXA Properties - static void SetShiftRun (RXA& rxa, int run); - static void SetShiftFreq (RXA& rxa, double fshift); + SHIFT(int run, int size, float* in, float* out, int rate, double fshift); + ~SHIFT() = default; + + void flush(); + void execute(); + void setBuffers(float* in, float* out); + void setSamplerate(int rate); + void setSize(int size); + // Noin static + void SetRun (int run); + void SetFreq (double fshift); private: - static void calc_shift (SHIFT *a); + void calc_shift (); }; } // namespace WDSP diff --git a/wdsp/snba.cpp b/wdsp/snba.cpp index ff7d4f176..4ad4e901c 100644 --- a/wdsp/snba.cpp +++ b/wdsp/snba.cpp @@ -56,7 +56,7 @@ void SNBA::calc_snba (SNBA *d) else d->resamprun = 0; - d->inresamp = RESAMPLE::create_resample ( + d->inresamp = new RESAMPLE( d->resamprun, d->bsize, d->in, @@ -67,8 +67,8 @@ void SNBA::calc_snba (SNBA *d) 0, 2.0 ); - RESAMPLE::setFCLow_resample (d->inresamp, 250.0); - d->outresamp = RESAMPLE::create_resample ( + d->inresamp->setFCLow(250.0); + d->outresamp = new RESAMPLE( d->resamprun, d->isize, d->outbuff, @@ -79,7 +79,7 @@ void SNBA::calc_snba (SNBA *d) 0, 2.0 ); - RESAMPLE::setFCLow_resample (d->outresamp, 200.0); + d->outresamp->setFCLow(200.0); d->incr = d->xsize / d->ovrlp; if (d->incr > d->isize) @@ -182,8 +182,8 @@ SNBA* SNBA::create_snba ( void SNBA::decalc_snba (SNBA *d) { - RESAMPLE::destroy_resample (d->outresamp); - RESAMPLE::destroy_resample (d->inresamp); + delete (d->outresamp); + delete (d->inresamp); delete[] (d->outbuff); delete[] (d->inbuff); delete[] (d->outaccum); @@ -243,8 +243,8 @@ void SNBA::flush_snba (SNBA *d) std::fill(d->inbuff, d->inbuff + d->isize * 2, 0); std::fill(d->outbuff, d->outbuff + d->isize * 2, 0); - RESAMPLE::flush_resample (d->inresamp); - RESAMPLE::flush_resample (d->outresamp); + d->inresamp->flush(); + d->outresamp->flush(); } void SNBA::setBuffers_snba (SNBA *a, float* in, float* out) @@ -675,7 +675,7 @@ void SNBA::xsnba (SNBA *d) if (d->run) { int i; - RESAMPLE::xresample (d->inresamp); + d->inresamp->execute(); for (i = 0; i < 2 * d->isize; i += 2) { @@ -703,7 +703,7 @@ void SNBA::xsnba (SNBA *d) d->oaoutidx = (d->oaoutidx + 1) % d->oasize; } - RESAMPLE::xresample (d->outresamp); + d->outresamp->execute(); } else if (d->out != d->in) { @@ -824,7 +824,7 @@ void SNBA::SetSNBAOutputBandwidth (RXA& rxa, double flow, double fhigh) f_high = std::min (a->out_high_cut, absmax); } - RESAMPLE::setBandwidth_resample (d, f_low, f_high); + d->setBandwidth(f_low, f_high); } } // namespace