1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-06-25 05:25:27 -04:00

WDSP: shift and resampler: replaced static methods

This commit is contained in:
f4exb 2024-07-24 04:33:42 +02:00
parent 71a5d7a1b4
commit e81c9cc5b0
8 changed files with 257 additions and 268 deletions

View File

@ -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) if ((m_settings.m_rit != settings.m_rit) || (m_settings.m_ritFrequency != settings.m_ritFrequency) || force)
{ {
WDSP::SHIFT::SetShiftFreq(*m_rxa, settings.m_ritFrequency); m_rxa->shift->SetFreq(settings.m_ritFrequency);
WDSP::SHIFT::SetShiftRun(*m_rxa, settings.m_rit ? 1 : 0); m_rxa->shift->SetRun(settings.m_rit ? 1 : 0);
} }
// Filter and mode // Filter and mode

View File

@ -119,7 +119,7 @@ RXA* RXA::create_rxa (
); );
// Ftequency shifter - shift to select a slice of spectrum // Ftequency shifter - shift to select a slice of spectrum
rxa->shift = SHIFT::create_shift ( rxa->shift = new SHIFT(
0, // run 0, // run
rxa->dsp_insize, // input buffer size rxa->dsp_insize, // input buffer size
rxa->inbuff, // pointer to input buffer rxa->inbuff, // pointer to input buffer
@ -128,7 +128,7 @@ RXA* RXA::create_rxa (
0.0); // amount to shift (Hz) 0.0); // amount to shift (Hz)
// Input resampler - resample to dsp rate for main processing // 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 0, // run - will be turned ON below if needed
rxa->dsp_insize, // input buffer size rxa->dsp_insize, // input buffer size
rxa->inbuff, // pointer to input buffer rxa->inbuff, // pointer to input buffer
@ -555,7 +555,7 @@ RXA* RXA::create_rxa (
// AM squelch apply - absent but in the block diagram // AM squelch apply - absent but in the block diagram
// Output resampler // Output resampler
rxa->rsmpout = RESAMPLE::create_resample ( rxa->rsmpout = new RESAMPLE(
0, // run - will be turned ON below if needed 0, // run - will be turned ON below if needed
rxa->dsp_size, // input buffer size rxa->dsp_size, // input buffer size
rxa->midbuff, // pointer to input buffer rxa->midbuff, // pointer to input buffer
@ -573,7 +573,7 @@ RXA* RXA::create_rxa (
void RXA::destroy_rxa (RXA *rxa) void RXA::destroy_rxa (RXA *rxa)
{ {
RESAMPLE::destroy_resample (rxa->rsmpout); delete (rxa->rsmpout);
PANEL::destroy_panel (rxa->panel); PANEL::destroy_panel (rxa->panel);
SSQL::destroy_ssql (rxa->ssql); SSQL::destroy_ssql (rxa->ssql);
MPEAK::destroy_mpeak (rxa->mpeak); MPEAK::destroy_mpeak (rxa->mpeak);
@ -599,8 +599,8 @@ void RXA::destroy_rxa (RXA *rxa)
NOTCHDB::destroy_notchdb (rxa->ndb); NOTCHDB::destroy_notchdb (rxa->ndb);
METER::destroy_meter (rxa->adcmeter); METER::destroy_meter (rxa->adcmeter);
GEN::destroy_gen (rxa->gen0); GEN::destroy_gen (rxa->gen0);
RESAMPLE::destroy_resample (rxa->rsmpin); delete (rxa->rsmpin);
SHIFT::destroy_shift (rxa->shift); delete (rxa->shift);
delete (rxa->nob); delete (rxa->nob);
delete (rxa->anb); delete (rxa->anb);
delete[] (rxa->midbuff); 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); std::fill(rxa->midbuff, rxa->midbuff + 2 * rxa->dsp_size * 2, 0);
rxa->anb->flush(); rxa->anb->flush();
rxa->nob->flush(); rxa->nob->flush();
SHIFT::flush_shift (rxa->shift); rxa->shift->flush();
RESAMPLE::flush_resample (rxa->rsmpin); rxa->rsmpin->flush();
GEN::flush_gen (rxa->gen0); GEN::flush_gen (rxa->gen0);
METER::flush_meter (rxa->adcmeter); METER::flush_meter (rxa->adcmeter);
NBP::flush_nbp (rxa->nbp0); NBP::flush_nbp (rxa->nbp0);
@ -642,15 +642,15 @@ void RXA::flush_rxa (RXA *rxa)
MPEAK::flush_mpeak (rxa->mpeak); MPEAK::flush_mpeak (rxa->mpeak);
SSQL::flush_ssql (rxa->ssql); SSQL::flush_ssql (rxa->ssql);
PANEL::flush_panel (rxa->panel); PANEL::flush_panel (rxa->panel);
RESAMPLE::flush_resample (rxa->rsmpout); rxa->rsmpout->flush();
} }
void RXA::xrxa (RXA *rxa) void RXA::xrxa (RXA *rxa)
{ {
rxa->anb->execute(); rxa->anb->execute();
rxa->nob->execute(); rxa->nob->execute();
SHIFT::xshift (rxa->shift); rxa->shift->execute();
RESAMPLE::xresample (rxa->rsmpin); rxa->rsmpin->execute();
GEN::xgen (rxa->gen0); GEN::xgen (rxa->gen0);
METER::xmeter (rxa->adcmeter); METER::xmeter (rxa->adcmeter);
BPSNBA::xbpsnbain (rxa->bpsnba, 0); BPSNBA::xbpsnbain (rxa->bpsnba, 0);
@ -683,7 +683,7 @@ void RXA::xrxa (RXA *rxa)
SSQL::xssql (rxa->ssql); SSQL::xssql (rxa->ssql);
PANEL::xpanel (rxa->panel); PANEL::xpanel (rxa->panel);
AMSQ::xamsq (rxa->amsq); AMSQ::xamsq (rxa->amsq);
RESAMPLE::xresample (rxa->rsmpout); rxa->rsmpout->execute();
} }
void RXA::setInputSamplerate (RXA *rxa, int in_rate) 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->setSize(rxa->dsp_insize);
rxa->nob->setSamplerate(rxa->in_rate); rxa->nob->setSamplerate(rxa->in_rate);
// shift // shift
SHIFT::setBuffers_shift (rxa->shift, rxa->inbuff, rxa->inbuff); rxa->shift->setBuffers(rxa->inbuff, rxa->inbuff);
SHIFT::setSize_shift (rxa->shift, rxa->dsp_insize); rxa->shift->setSize(rxa->dsp_insize);
SHIFT::setSamplerate_shift (rxa->shift, rxa->in_rate); rxa->shift->setSamplerate(rxa->in_rate);
// input resampler // input resampler
RESAMPLE::setBuffers_resample (rxa->rsmpin, rxa->inbuff, rxa->midbuff); rxa->rsmpin->setBuffers(rxa->inbuff, rxa->midbuff);
RESAMPLE::setSize_resample (rxa->rsmpin, rxa->dsp_insize); rxa->rsmpin->setSize(rxa->dsp_insize);
RESAMPLE::setInRate_resample (rxa->rsmpin, rxa->in_rate); rxa->rsmpin->setInRate(rxa->in_rate);
ResCheck (*rxa); ResCheck (*rxa);
} }
@ -728,8 +728,8 @@ void RXA::setOutputSamplerate (RXA *rxa, int out_rate)
delete[] (rxa->outbuff); delete[] (rxa->outbuff);
rxa->outbuff = new float[1 * rxa->dsp_outsize * 2]; // (float *)malloc0(1 * ch.dsp_outsize * sizeof(complex)); rxa->outbuff = new float[1 * rxa->dsp_outsize * 2]; // (float *)malloc0(1 * ch.dsp_outsize * sizeof(complex));
// output resampler // output resampler
RESAMPLE::setBuffers_resample (rxa->rsmpout, rxa->midbuff, rxa->outbuff); rxa->rsmpout->setBuffers(rxa->midbuff, rxa->outbuff);
RESAMPLE::setOutRate_resample (rxa->rsmpout, rxa->out_rate); rxa->rsmpout->setOutRate(rxa->out_rate);
ResCheck (*rxa); ResCheck (*rxa);
} }
@ -758,12 +758,12 @@ void RXA::setDSPSamplerate (RXA *rxa, int dsp_rate)
rxa->nob->setBuffers(rxa->inbuff, rxa->inbuff); rxa->nob->setBuffers(rxa->inbuff, rxa->inbuff);
rxa->nob->setSize(rxa->dsp_insize); rxa->nob->setSize(rxa->dsp_insize);
// shift // shift
SHIFT::setBuffers_shift (rxa->shift, rxa->inbuff, rxa->inbuff); rxa->shift->setBuffers(rxa->inbuff, rxa->inbuff);
SHIFT::setSize_shift (rxa->shift, rxa->dsp_insize); rxa->shift->setSize(rxa->dsp_insize);
// input resampler // input resampler
RESAMPLE::setBuffers_resample (rxa->rsmpin, rxa->inbuff, rxa->midbuff); rxa->rsmpin->setBuffers(rxa->inbuff, rxa->midbuff);
RESAMPLE::setSize_resample (rxa->rsmpin, rxa->dsp_insize); rxa->rsmpin->setSize(rxa->dsp_insize);
RESAMPLE::setOutRate_resample (rxa->rsmpin, rxa->dsp_rate); rxa->rsmpin->setOutRate(rxa->dsp_rate);
// dsp_rate blocks // dsp_rate blocks
GEN::setSamplerate_gen (rxa->gen0, rxa->dsp_rate); GEN::setSamplerate_gen (rxa->gen0, rxa->dsp_rate);
METER::setSamplerate_meter (rxa->adcmeter, 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); SSQL::setSamplerate_ssql (rxa->ssql, rxa->dsp_rate);
PANEL::setSamplerate_panel (rxa->panel, rxa->dsp_rate); PANEL::setSamplerate_panel (rxa->panel, rxa->dsp_rate);
// output resampler // output resampler
RESAMPLE::setBuffers_resample (rxa->rsmpout, rxa->midbuff, rxa->outbuff); rxa->rsmpout->setBuffers(rxa->midbuff, rxa->outbuff);
RESAMPLE::setInRate_resample (rxa->rsmpout, rxa->dsp_rate); rxa->rsmpout->setInRate(rxa->dsp_rate);
ResCheck (*rxa); ResCheck (*rxa);
} }
@ -823,11 +823,11 @@ void RXA::setDSPBuffsize (RXA *rxa, int dsp_size)
rxa->nob->setBuffers(rxa->inbuff, rxa->inbuff); rxa->nob->setBuffers(rxa->inbuff, rxa->inbuff);
rxa->nob->setSize(rxa->dsp_insize); rxa->nob->setSize(rxa->dsp_insize);
// shift // shift
SHIFT::setBuffers_shift (rxa->shift, rxa->inbuff, rxa->inbuff); rxa->shift->setBuffers(rxa->inbuff, rxa->inbuff);
SHIFT::setSize_shift (rxa->shift, rxa->dsp_insize); rxa->shift->setSize(rxa->dsp_insize);
// input resampler // input resampler
RESAMPLE::setBuffers_resample (rxa->rsmpin, rxa->inbuff, rxa->midbuff); rxa->rsmpin->setBuffers(rxa->inbuff, rxa->midbuff);
RESAMPLE::setSize_resample (rxa->rsmpin, rxa->dsp_insize); rxa->rsmpin->setSize(rxa->dsp_insize);
// dsp_size blocks // dsp_size blocks
GEN::setBuffers_gen (rxa->gen0, rxa->midbuff, rxa->midbuff); GEN::setBuffers_gen (rxa->gen0, rxa->midbuff, rxa->midbuff);
GEN::setSize_gen (rxa->gen0, rxa->dsp_size); 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::setBuffers_panel (rxa->panel, rxa->midbuff, rxa->midbuff);
PANEL::setSize_panel (rxa->panel, rxa->dsp_size); PANEL::setSize_panel (rxa->panel, rxa->dsp_size);
// output resampler // output resampler
RESAMPLE::setBuffers_resample (rxa->rsmpout, rxa->midbuff, rxa->outbuff); rxa->rsmpout->setBuffers(rxa->midbuff, rxa->outbuff);
RESAMPLE::setSize_resample (rxa->rsmpout, rxa->dsp_size); rxa->rsmpout->setSize(rxa->dsp_size);
} }
void RXA::setSpectrumProbe(BufferProbe *spectrumProbe) void RXA::setSpectrumProbe(BufferProbe *spectrumProbe)

View File

@ -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->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->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 0, // run - will be turned on below if needed
txa->dsp_insize, // input buffer size txa->dsp_insize, // input buffer size
txa->inbuff, // pointer to input buffer txa->inbuff, // pointer to input buffer
@ -486,7 +486,7 @@ TXA* TXA::create_txa (
0.0, // raised-cosine transition width 0.0, // raised-cosine transition width
0); // window type 0); // window type
txa->rsmpout.p = RESAMPLE::create_resample ( txa->rsmpout.p = new RESAMPLE(
0, // run - will be turned ON below if needed 0, // run - will be turned ON below if needed
txa->dsp_size, // input size txa->dsp_size, // input size
txa->midbuff, // pointer to input buffer txa->midbuff, // pointer to input buffer
@ -520,7 +520,7 @@ void TXA::destroy_txa (TXA *txa)
{ {
// in reverse order, free each item we created // in reverse order, free each item we created
METER::destroy_meter (txa->outmeter.p); METER::destroy_meter (txa->outmeter.p);
RESAMPLE::destroy_resample (txa->rsmpout.p); delete (txa->rsmpout.p);
CFIR::destroy_cfir(txa->cfir.p); CFIR::destroy_cfir(txa->cfir.p);
// destroy_calcc (txa->calcc.p); // destroy_calcc (txa->calcc.p);
IQC::destroy_iqc (txa->iqc.p0); IQC::destroy_iqc (txa->iqc.p0);
@ -549,7 +549,7 @@ void TXA::destroy_txa (TXA *txa)
PHROT::destroy_phrot (txa->phrot.p); PHROT::destroy_phrot (txa->phrot.p);
PANEL::destroy_panel (txa->panel.p); PANEL::destroy_panel (txa->panel.p);
GEN::destroy_gen (txa->gen0.p); GEN::destroy_gen (txa->gen0.p);
RESAMPLE::destroy_resample (txa->rsmpin.p); delete (txa->rsmpin.p);
delete[] (txa->midbuff); delete[] (txa->midbuff);
delete[] (txa->outbuff); delete[] (txa->outbuff);
delete[] (txa->inbuff); 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->inbuff, txa->inbuff + 1 * txa->dsp_insize * 2, 0);
std::fill(txa->outbuff, txa->outbuff + 1 * txa->dsp_outsize * 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); 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); GEN::flush_gen (txa->gen0.p);
PANEL::flush_panel (txa->panel.p); PANEL::flush_panel (txa->panel.p);
PHROT::flush_phrot (txa->phrot.p); PHROT::flush_phrot (txa->phrot.p);
@ -589,13 +589,13 @@ void TXA::flush_txa (TXA* txa)
SIPHON::flush_siphon (txa->sip1.p); SIPHON::flush_siphon (txa->sip1.p);
IQC::flush_iqc (txa->iqc.p0); IQC::flush_iqc (txa->iqc.p0);
CFIR::flush_cfir(txa->cfir.p); CFIR::flush_cfir(txa->cfir.p);
RESAMPLE::flush_resample (txa->rsmpout.p); txa->rsmpout.p->flush();
METER::flush_meter (txa->outmeter.p); METER::flush_meter (txa->outmeter.p);
} }
void xtxa (TXA* txa) 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 GEN::xgen (txa->gen0.p); // input signal generator
PANEL::xpanel (txa->panel.p); // includes MIC gain PANEL::xpanel (txa->panel.p); // includes MIC gain
PHROT::xphrot (txa->phrot.p); // phase rotator 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 SIPHON::xsiphon (txa->sip1.p, 0); // siphon data for display
IQC::xiqc (txa->iqc.p0); // PureSignal correction IQC::xiqc (txa->iqc.p0); // PureSignal correction
CFIR::xcfir(txa->cfir.p); // compensating FIR filter (used Protocol_2 only) 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 METER::xmeter (txa->outmeter.p); // output meter
// print_peak_env ("env_exception.txt", txa->dsp_outsize, txa->outbuff, 0.7); // 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); delete[] (txa->inbuff);
txa->inbuff = new float[1 * txa->dsp_insize * 2]; //(float *)malloc0(1 * txa->dsp_insize * sizeof(complex)); txa->inbuff = new float[1 * txa->dsp_insize * 2]; //(float *)malloc0(1 * txa->dsp_insize * sizeof(complex));
// input resampler // input resampler
RESAMPLE::setBuffers_resample (txa->rsmpin.p, txa->inbuff, txa->midbuff); txa->rsmpin.p->setBuffers(txa->inbuff, txa->midbuff);
RESAMPLE::setSize_resample (txa->rsmpin.p, txa->dsp_insize); txa->rsmpin.p->setSize(txa->dsp_insize);
RESAMPLE::setInRate_resample (txa->rsmpin.p, txa->in_rate); txa->rsmpin.p->setInRate(txa->in_rate);
ResCheck (*txa); ResCheck (*txa);
} }
@ -662,8 +662,8 @@ void TXA::setOutputSamplerate (TXA* txa, int out_rate)
// cfir - needs to know input rate of firmware CIC // cfir - needs to know input rate of firmware CIC
CFIR::setOutRate_cfir (txa->cfir.p, txa->out_rate); CFIR::setOutRate_cfir (txa->cfir.p, txa->out_rate);
// output resampler // output resampler
RESAMPLE::setBuffers_resample (txa->rsmpout.p, txa->midbuff, txa->outbuff); txa->rsmpout.p->setBuffers(txa->midbuff, txa->outbuff);
RESAMPLE::setOutRate_resample (txa->rsmpout.p, txa->out_rate); txa->rsmpout.p->setOutRate(txa->out_rate);
ResCheck (*txa); ResCheck (*txa);
// output meter // output meter
METER::setBuffers_meter (txa->outmeter.p, txa->outbuff); METER::setBuffers_meter (txa->outmeter.p, txa->outbuff);
@ -690,9 +690,9 @@ void TXA::setDSPSamplerate (TXA *txa, int dsp_rate)
delete[] (txa->outbuff); delete[] (txa->outbuff);
txa->outbuff = new float[1 * txa->dsp_outsize * 2]; // (float *)malloc0(1 * txa->dsp_outsize * sizeof(complex)); txa->outbuff = new float[1 * txa->dsp_outsize * 2]; // (float *)malloc0(1 * txa->dsp_outsize * sizeof(complex));
// input resampler // input resampler
RESAMPLE::setBuffers_resample (txa->rsmpin.p, txa->inbuff, txa->midbuff); txa->rsmpin.p->setBuffers(txa->inbuff, txa->midbuff);
RESAMPLE::setSize_resample (txa->rsmpin.p, txa->dsp_insize); txa->rsmpin.p->setSize(txa->dsp_insize);
RESAMPLE::setOutRate_resample (txa->rsmpin.p, txa->dsp_rate); txa->rsmpin.p->setOutRate(txa->dsp_rate);
// dsp_rate blocks // dsp_rate blocks
GEN::setSamplerate_gen (txa->gen0.p, txa->dsp_rate); GEN::setSamplerate_gen (txa->gen0.p, txa->dsp_rate);
PANEL::setSamplerate_panel (txa->panel.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); IQC::setSamplerate_iqc (txa->iqc.p0, txa->dsp_rate);
CFIR::setSamplerate_cfir (txa->cfir.p, txa->dsp_rate); CFIR::setSamplerate_cfir (txa->cfir.p, txa->dsp_rate);
// output resampler // output resampler
RESAMPLE::setBuffers_resample (txa->rsmpout.p, txa->midbuff, txa->outbuff); txa->rsmpout.p->setBuffers(txa->midbuff, txa->outbuff);
RESAMPLE::setInRate_resample (txa->rsmpout.p, txa->dsp_rate); txa->rsmpout.p->setInRate(txa->dsp_rate);
ResCheck (*txa); ResCheck (*txa);
// output meter // output meter
METER::setBuffers_meter (txa->outmeter.p, txa->outbuff); METER::setBuffers_meter (txa->outmeter.p, txa->outbuff);
@ -751,8 +751,8 @@ void TXA::setDSPBuffsize (TXA *txa, int dsp_size)
delete[] (txa->outbuff); delete[] (txa->outbuff);
txa->outbuff = new float[1 * txa->dsp_outsize * 2]; // (float *)malloc0(1 * txa->dsp_outsize * sizeof(complex)); txa->outbuff = new float[1 * txa->dsp_outsize * 2]; // (float *)malloc0(1 * txa->dsp_outsize * sizeof(complex));
// input resampler // input resampler
RESAMPLE::setBuffers_resample (txa->rsmpin.p, txa->inbuff, txa->midbuff); txa->rsmpin.p->setBuffers(txa->inbuff, txa->midbuff);
RESAMPLE::setSize_resample (txa->rsmpin.p, txa->dsp_insize); txa->rsmpin.p->setSize(txa->dsp_insize);
// dsp_size blocks // dsp_size blocks
GEN::setBuffers_gen (txa->gen0.p, txa->midbuff, txa->midbuff); GEN::setBuffers_gen (txa->gen0.p, txa->midbuff, txa->midbuff);
GEN::setSize_gen (txa->gen0.p, txa->dsp_size); 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::setBuffers_cfir (txa->cfir.p, txa->midbuff, txa->midbuff);
CFIR::setSize_cfir (txa->cfir.p, txa->dsp_size); CFIR::setSize_cfir (txa->cfir.p, txa->dsp_size);
// output resampler // output resampler
RESAMPLE::setBuffers_resample (txa->rsmpout.p, txa->midbuff, txa->outbuff); txa->rsmpout.p->setBuffers(txa->midbuff, txa->outbuff);
RESAMPLE::setSize_resample (txa->rsmpout.p, txa->dsp_size); txa->rsmpout.p->setSize(txa->dsp_size);
// output meter // output meter
METER::setBuffers_meter (txa->outmeter.p, txa->outbuff); METER::setBuffers_meter (txa->outmeter.p, txa->outbuff);
METER::setSize_meter (txa->outmeter.p, txa->dsp_outsize); METER::setSize_meter (txa->outmeter.p, txa->dsp_outsize);

View File

@ -37,7 +37,7 @@ namespace WDSP {
* * * *
************************************************************************************************/ ************************************************************************************************/
void RESAMPLE::calc_resample (RESAMPLE *a) void RESAMPLE::calc_resample()
{ {
int x, y, z; int x, y, z;
int i, j, k; int i, j, k;
@ -45,10 +45,10 @@ void RESAMPLE::calc_resample (RESAMPLE *a)
double full_rate; double full_rate;
double fc_norm_high, fc_norm_low; double fc_norm_high, fc_norm_low;
float* impulse; float* impulse;
a->fc = a->fcin; fc = fcin;
a->ncoef = a->ncoefin; ncoef = ncoefin;
x = a->in_rate; x = in_rate;
y = a->out_rate; y = out_rate;
while (y != 0) while (y != 0)
{ {
@ -57,220 +57,214 @@ void RESAMPLE::calc_resample (RESAMPLE *a)
x = z; x = z;
} }
a->L = a->out_rate / x; L = out_rate / x;
a->M = a->in_rate / x; M = in_rate / x;
a->L = a->L <= 0 ? 1 : a->L; L = L <= 0 ? 1 : L;
a->M = a->M <= 0 ? 1 : a->M; M = M <= 0 ? 1 : M;
if (a->in_rate < a->out_rate) if (in_rate < out_rate)
min_rate = a->in_rate; min_rate = in_rate;
else else
min_rate = a->out_rate; min_rate = out_rate;
if (a->fc == 0.0) if (fc == 0.0)
a->fc = 0.45 * (float)min_rate; fc = 0.45 * (float)min_rate;
full_rate = (double) (a->in_rate * a->L); full_rate = (double) (in_rate * L);
fc_norm_high = a->fc / full_rate; fc_norm_high = fc / full_rate;
if (a->fc_low < 0.0) if (fc_low < 0.0)
fc_norm_low = - fc_norm_high; fc_norm_low = - fc_norm_high;
else else
fc_norm_low = a->fc_low / full_rate; fc_norm_low = fc_low / full_rate;
if (a->ncoef == 0) if (ncoef == 0)
a->ncoef = (int)(140.0 * full_rate / min_rate); ncoef = (int)(140.0 * full_rate / min_rate);
a->ncoef = (a->ncoef / a->L + 1) * a->L; ncoef = (ncoef / L + 1) * L;
a->cpp = a->ncoef / a->L; cpp = ncoef / L;
a->h = new double[a->ncoef]; // (float *)malloc0(a->ncoef * sizeof(float)); h = new double[ncoef]; // (float *)malloc0(ncoef * sizeof(float));
impulse = FIR::fir_bandpass(a->ncoef, fc_norm_low, fc_norm_high, 1.0, 1, 0, a->gain * (double)a->L); impulse = FIR::fir_bandpass(ncoef, fc_norm_low, fc_norm_high, 1.0, 1, 0, gain * (double)L);
i = 0; i = 0;
for (j = 0; j < a->L; j++) for (j = 0; j < L; j++)
{ {
for (k = 0; k < a->ncoef; k += a->L) for (k = 0; k < ncoef; k += L)
a->h[i++] = impulse[j + k]; h[i++] = impulse[j + k];
} }
a->ringsize = a->cpp; ringsize = cpp;
a->ring = new double[a->ringsize]; // (float *)malloc0(a->ringsize * sizeof(complex)); ring = new double[ringsize]; // (float *)malloc0(ringsize * sizeof(complex));
a->idx_in = a->ringsize - 1; idx_in = ringsize - 1;
a->phnum = 0; phnum = 0;
delete[] (impulse); delete[] (impulse);
} }
void RESAMPLE::decalc_resample (RESAMPLE *a) void RESAMPLE::decalc_resample()
{ {
delete[] (a->ring); delete[] ring;
delete[] (a->h); delete[] h;
} }
RESAMPLE* RESAMPLE::create_resample ( RESAMPLE::RESAMPLE (
int run, int _run,
int size, int _size,
float* in, float* _in,
float* out, float* _out,
int in_rate, int _in_rate,
int out_rate, int _out_rate,
double fc, double _fc,
int ncoef, int _ncoef,
double gain double _gain
) )
{ {
RESAMPLE *a = new RESAMPLE; run = _run;
size = _size;
a->run = run; in = _in;
a->size = size; out = _out;
a->in = in; in_rate = _in_rate;
a->out = out; out_rate = _out_rate;
a->in_rate = in_rate; fcin = _fc;
a->out_rate = out_rate; fc_low = -1.0; // could add to create_resample() parameters
a->fcin = fc; ncoefin = _ncoef;
a->fc_low = -1.0; // could add to create_resample() parameters gain = _gain;
a->ncoefin = ncoef; calc_resample();
a->gain = gain;
calc_resample (a);
return a;
} }
RESAMPLE::~RESAMPLE()
void RESAMPLE::destroy_resample (RESAMPLE *a)
{ {
decalc_resample (a); decalc_resample();
delete (a);
} }
void RESAMPLE::flush_resample (RESAMPLE *a) void RESAMPLE::flush()
{ {
std::fill(a->ring, a->ring + 2 * a->ringsize, 0); std::fill(ring, ring + 2 * ringsize, 0);
a->idx_in = a->ringsize - 1; idx_in = ringsize - 1;
a->phnum = 0; phnum = 0;
} }
int RESAMPLE::execute()
int RESAMPLE::xresample (RESAMPLE *a)
{ {
int outsamps = 0; int outsamps = 0;
if (a->run) if (run)
{ {
int i, j, n; int i, j, n;
int idx_out; int idx_out;
double I, Q; 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]; ring[2 * idx_in + 0] = in[2 * i + 0];
a->ring[2 * a->idx_in + 1] = a->in[2 * i + 1]; ring[2 * idx_in + 1] = in[2 * i + 1];
while (a->phnum < a->L) while (phnum < L)
{ {
I = 0.0; I = 0.0;
Q = 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) if ((idx_out = idx_in + j) >= ringsize)
idx_out -= a->ringsize; idx_out -= ringsize;
I += a->h[n + j] * a->ring[2 * idx_out + 0]; I += h[n + j] * ring[2 * idx_out + 0];
Q += a->h[n + j] * a->ring[2 * idx_out + 1]; Q += h[n + j] * ring[2 * idx_out + 1];
} }
a->out[2 * outsamps + 0] = I; out[2 * outsamps + 0] = I;
a->out[2 * outsamps + 1] = Q; out[2 * outsamps + 1] = Q;
outsamps++; outsamps++;
a->phnum += a->M; phnum += M;
} }
a->phnum -= a->L; phnum -= L;
if (--a->idx_in < 0) if (--idx_in < 0)
a->idx_in = a->ringsize - 1; 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; return outsamps;
} }
void RESAMPLE::setBuffers_resample(RESAMPLE *a, float* in, float* out) void RESAMPLE::setBuffers(float* _in, float* _out)
{ {
a->in = in; in = _in;
a->out = out; out = _out;
} }
void RESAMPLE::setSize_resample(RESAMPLE *a, int size) void RESAMPLE::setSize(int _size)
{ {
a->size = size; size = _size;
flush_resample (a); flush();
} }
void RESAMPLE::setInRate_resample(RESAMPLE *a, int rate) void RESAMPLE::setInRate(int _rate)
{ {
decalc_resample (a); decalc_resample();
a->in_rate = rate; in_rate = _rate;
calc_resample (a); calc_resample();
} }
void RESAMPLE::setOutRate_resample(RESAMPLE *a, int rate) void RESAMPLE::setOutRate(int _rate)
{ {
decalc_resample (a); decalc_resample();
a->out_rate = rate; out_rate = _rate;
calc_resample (a); 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); decalc_resample();
a->fc_low = fc_low; fc_low = _fc_low;
calc_resample (a); 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); decalc_resample();
a->fc_low = fc_low; fc_low = _fc_low;
a->fcin = fc_high; fcin = _fc_high;
calc_resample (a); calc_resample();
} }
} }
// exported calls // 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; RESAMPLE *a = (RESAMPLE*) ptr;
a->in = input; a->in = input;
a->out = output; a->out = output;
a->size = numsamps; 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 } // namespace WDSP

View File

@ -62,7 +62,7 @@ public:
int cpp; // coefficients of the phase int cpp; // coefficients of the phase
int phnum; // phase number int phnum; // phase number
static RESAMPLE* create_resample ( RESAMPLE (
int run, int run,
int size, int size,
float* in, float* in,
@ -73,23 +73,24 @@ public:
int ncoef, int ncoef,
double gain double gain
); );
static void destroy_resample (RESAMPLE *a); ~RESAMPLE();
static void flush_resample (RESAMPLE *a);
static int xresample (RESAMPLE *a); void flush();
static void setBuffers_resample (RESAMPLE *a, float* in, float* out); int execute();
static void setSize_resample(RESAMPLE *a, int size); void setBuffers(float* in, float* out);
static void setInRate_resample(RESAMPLE *a, int rate); void setSize(int size);
static void setOutRate_resample(RESAMPLE *a, int rate); void setInRate(int rate);
static void setFCLow_resample (RESAMPLE *a, double fc_low); void setOutRate(int rate);
static void setBandwidth_resample (RESAMPLE *a, double fc_low, double fc_high); void setFCLow(double fc_low);
void setBandwidth(double fc_low, double fc_high);
// Exported calls // Exported calls
static void* create_resampleV (int in_rate, int out_rate); static void* createV (int in_rate, int out_rate);
static void xresampleV (float* input, float* output, int numsamps, int* outsamps, void* ptr); static void executeV (float* input, float* output, int numsamps, int* outsamps, void* ptr);
static void destroy_resampleV (void* ptr); static void destroyV (void* ptr);
private: private:
static void calc_resample (RESAMPLE *a); void calc_resample();
static void decalc_resample (RESAMPLE *a); void decalc_resample();
}; };
} // namespace WDSP } // namespace WDSP

View File

@ -31,105 +31,98 @@ warren@wpratt.com
namespace WDSP { namespace WDSP {
void SHIFT::calc_shift (SHIFT *a) void SHIFT::calc_shift()
{ {
a->delta = TWOPI * a->shift / a->rate; delta = TWOPI * shift / rate;
a->cos_delta = cos (a->delta); cos_delta = cos (delta);
a->sin_delta = sin (a->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; run = _run;
a->run = run; size = _size;
a->size = size; in = _in;
a->in = in; out = _out;
a->out = out; rate = (double) _rate;
a->rate = (double) rate; shift = _fshift;
a->shift = fshift; phase = 0.0;
a->phase = 0.0; calc_shift();
calc_shift (a);
return a;
} }
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; if (run)
}
void SHIFT::xshift (SHIFT *a)
{
if (a->run)
{ {
int i; int i;
double I1, Q1, t1, t2; double I1, Q1, t1, t2;
double cos_phase = cos (a->phase); double cos_phase = cos (phase);
double sin_phase = sin (a->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]; I1 = in[2 * i + 0];
Q1 = a->in[2 * i + 1]; Q1 = in[2 * i + 1];
a->out[2 * i + 0] = I1 * cos_phase - Q1 * sin_phase; out[2 * i + 0] = I1 * cos_phase - Q1 * sin_phase;
a->out[2 * i + 1] = I1 * sin_phase + Q1 * cos_phase; out[2 * i + 1] = I1 * sin_phase + Q1 * cos_phase;
t1 = cos_phase; t1 = cos_phase;
t2 = sin_phase; t2 = sin_phase;
cos_phase = t1 * a->cos_delta - t2 * a->sin_delta; cos_phase = t1 * cos_delta - t2 * sin_delta;
sin_phase = t1 * a->sin_delta + t2 * a->cos_delta; sin_phase = t1 * sin_delta + t2 * cos_delta;
a->phase += a->delta; phase += delta;
if (a->phase >= TWOPI) if (phase >= TWOPI)
a->phase -= TWOPI; phase -= TWOPI;
if (a->phase < 0.0 ) if (phase < 0.0 )
a->phase += TWOPI; 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; in = _in;
a->out = out; out = _out;
} }
void SHIFT::setSamplerate_shift (SHIFT *a, int rate) void SHIFT::setSamplerate(int _rate)
{ {
a->rate = rate; rate = _rate;
a->phase = 0.0; phase = 0.0;
calc_shift(a); calc_shift();
} }
void SHIFT::setSize_shift (SHIFT *a, int size) void SHIFT::setSize(int _size)
{ {
a->size = size; size = _size;
flush_shift (a); 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; shift = fshift;
calc_shift (rxa.shift); calc_shift();
} }
} // namespace WDSP } // namespace WDSP

View File

@ -48,19 +48,20 @@ public:
double cos_delta; double cos_delta;
double sin_delta; double sin_delta;
static SHIFT* create_shift (int run, int size, float* in, float* out, int rate, double fshift); SHIFT(int run, int size, float* in, float* out, int rate, double fshift);
static void destroy_shift (SHIFT *a); ~SHIFT() = default;
static void flush_shift (SHIFT *a);
static void xshift (SHIFT *a); void flush();
static void setBuffers_shift (SHIFT *a, float* in, float* out); void execute();
static void setSamplerate_shift (SHIFT *a, int rate); void setBuffers(float* in, float* out);
static void setSize_shift (SHIFT *a, int size); void setSamplerate(int rate);
// RXA Properties void setSize(int size);
static void SetShiftRun (RXA& rxa, int run); // Noin static
static void SetShiftFreq (RXA& rxa, double fshift); void SetRun (int run);
void SetFreq (double fshift);
private: private:
static void calc_shift (SHIFT *a); void calc_shift ();
}; };
} // namespace WDSP } // namespace WDSP

View File

@ -56,7 +56,7 @@ void SNBA::calc_snba (SNBA *d)
else else
d->resamprun = 0; d->resamprun = 0;
d->inresamp = RESAMPLE::create_resample ( d->inresamp = new RESAMPLE(
d->resamprun, d->resamprun,
d->bsize, d->bsize,
d->in, d->in,
@ -67,8 +67,8 @@ void SNBA::calc_snba (SNBA *d)
0, 0,
2.0 2.0
); );
RESAMPLE::setFCLow_resample (d->inresamp, 250.0); d->inresamp->setFCLow(250.0);
d->outresamp = RESAMPLE::create_resample ( d->outresamp = new RESAMPLE(
d->resamprun, d->resamprun,
d->isize, d->isize,
d->outbuff, d->outbuff,
@ -79,7 +79,7 @@ void SNBA::calc_snba (SNBA *d)
0, 0,
2.0 2.0
); );
RESAMPLE::setFCLow_resample (d->outresamp, 200.0); d->outresamp->setFCLow(200.0);
d->incr = d->xsize / d->ovrlp; d->incr = d->xsize / d->ovrlp;
if (d->incr > d->isize) if (d->incr > d->isize)
@ -182,8 +182,8 @@ SNBA* SNBA::create_snba (
void SNBA::decalc_snba (SNBA *d) void SNBA::decalc_snba (SNBA *d)
{ {
RESAMPLE::destroy_resample (d->outresamp); delete (d->outresamp);
RESAMPLE::destroy_resample (d->inresamp); delete (d->inresamp);
delete[] (d->outbuff); delete[] (d->outbuff);
delete[] (d->inbuff); delete[] (d->inbuff);
delete[] (d->outaccum); 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->inbuff, d->inbuff + d->isize * 2, 0);
std::fill(d->outbuff, d->outbuff + d->isize * 2, 0); std::fill(d->outbuff, d->outbuff + d->isize * 2, 0);
RESAMPLE::flush_resample (d->inresamp); d->inresamp->flush();
RESAMPLE::flush_resample (d->outresamp); d->outresamp->flush();
} }
void SNBA::setBuffers_snba (SNBA *a, float* in, float* out) void SNBA::setBuffers_snba (SNBA *a, float* in, float* out)
@ -675,7 +675,7 @@ void SNBA::xsnba (SNBA *d)
if (d->run) if (d->run)
{ {
int i; int i;
RESAMPLE::xresample (d->inresamp); d->inresamp->execute();
for (i = 0; i < 2 * d->isize; i += 2) 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; d->oaoutidx = (d->oaoutidx + 1) % d->oasize;
} }
RESAMPLE::xresample (d->outresamp); d->outresamp->execute();
} }
else if (d->out != d->in) 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); f_high = std::min (a->out_high_cut, absmax);
} }
RESAMPLE::setBandwidth_resample (d, f_low, f_high); d->setBandwidth(f_low, f_high);
} }
} // namespace } // namespace