diff --git a/plugins/channelrx/wdsprx/wdsprxsink.cpp b/plugins/channelrx/wdsprx/wdsprxsink.cpp index 0114558dc..3ba83b5ff 100644 --- a/plugins/channelrx/wdsprx/wdsprxsink.cpp +++ b/plugins/channelrx/wdsprx/wdsprxsink.cpp @@ -125,14 +125,14 @@ WDSPRxSink::WDSPRxSink() : m_sPeak = 0.0; m_sCount = m_wdspBufSize; - m_rxa = WDSP::RXA::create_rxa( + m_rxa = new WDSP::RXA( m_wdspSampleRate, // input samplerate m_wdspSampleRate, // output samplerate m_wdspSampleRate, // sample rate for mainstream dsp processing (dsp) m_wdspBufSize // number complex samples processed per buffer in mainstream dsp processing ); m_rxa->setSpectrumProbe(&m_spectrumProbe); - WDSP::RXA::SetPassband(*m_rxa, 0, m_Bandwidth); + m_rxa->setPassband(0, m_Bandwidth); applyChannelSettings(m_channelSampleRate, m_channelFrequencyOffset, true); applySettings(m_settings, true); @@ -140,7 +140,7 @@ WDSPRxSink::WDSPRxSink() : WDSPRxSink::~WDSPRxSink() { - WDSP::RXA::destroy_rxa(m_rxa); + delete m_rxa; } void WDSPRxSink::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end) @@ -189,7 +189,7 @@ void WDSPRxSink::processOneSample(Complex &ci) if (++m_inCount == m_rxa->get_insize()) { - WDSP::RXA::xrxa(m_rxa); + m_rxa->execute(); m_sCount = m_wdspBufSize; m_sAvg = m_rxa->smeter->getMeter(WDSP::RXA::RXA_S_AV); @@ -306,7 +306,7 @@ void WDSPRxSink::applyAudioSampleRate(int sampleRate) m_interpolatorDistanceRemain = 0; m_interpolatorDistance = (Real) m_channelSampleRate / (Real) m_wdspSampleRate; - WDSP::RXA::setOutputSamplerate(m_rxa, sampleRate); + m_rxa->setOutputSamplerate(sampleRate); m_audioFifo.setSize(sampleRate); m_audioSampleRate = sampleRate; @@ -446,24 +446,24 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force) m_interpolatorDistanceRemain = 0; m_interpolatorDistance = (Real) m_channelSampleRate / (Real) m_audioSampleRate; - WDSP::RXA::SetPassband(*m_rxa, fLow, fHigh); - WDSP::RXA::NBPSetWindow(*m_rxa, m_settings.m_profiles[m_settings.m_profileIndex].m_fftWindow); + m_rxa->setPassband(fLow, fHigh); + m_rxa->nbpSetWindow(m_settings.m_profiles[m_settings.m_profileIndex].m_fftWindow); if (settings.m_demod == WDSPRxProfile::DemodSSB) { if (dsb) { - WDSP::RXA::SetMode(*m_rxa, WDSP::RXA::RXA_DSB); + m_rxa->setMode(WDSP::RXA::RXA_DSB); } else { - WDSP::RXA::SetMode(*m_rxa, usb ? WDSP::RXA::RXA_USB : WDSP::RXA::RXA_LSB); + m_rxa->setMode(usb ? WDSP::RXA::RXA_USB : WDSP::RXA::RXA_LSB); } } else if (settings.m_demod == WDSPRxProfile::DemodAM) { - WDSP::RXA::SetMode(*m_rxa, WDSP::RXA::RXA_AM); + m_rxa->setMode(WDSP::RXA::RXA_AM); } else if (settings.m_demod == WDSPRxProfile::DemodSAM) { - WDSP::RXA::SetMode(*m_rxa, WDSP::RXA::RXA_SAM); + m_rxa->setMode(WDSP::RXA::RXA_SAM); if (dsb) { m_rxa->amd->setSBMode(0); @@ -473,7 +473,7 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force) } else if (settings.m_demod == WDSPRxProfile::DemodFMN) { - WDSP::RXA::SetMode(*m_rxa, WDSP::RXA::RXA_FM); + m_rxa->setMode(WDSP::RXA::RXA_FM); } } @@ -486,18 +486,18 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force) if ((m_settings.m_dnr != settings.m_dnr) || (m_settings.m_nrScheme != settings.m_nrScheme) || force) { - WDSP::RXA::SetANRRun(*m_rxa, 0); - WDSP::RXA::SetEMNRRun(*m_rxa, 0); + m_rxa->setANRRun(0); + m_rxa->setEMNRRun(0); if (settings.m_dnr) { switch (settings.m_nrScheme) { case WDSPRxProfile::NRSchemeNR: - WDSP::RXA::SetANRRun(*m_rxa, 1); + m_rxa->setANRRun(1); break; case WDSPRxProfile::NRSchemeNR2: - WDSP::RXA::SetEMNRRun(*m_rxa, 1); + m_rxa->setEMNRRun(1); break; default: break; @@ -510,12 +510,12 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force) switch (settings.m_nrPosition) { case WDSPRxProfile::NRPositionPreAGC: - WDSP::RXA::SetANRPosition(*m_rxa, 0); - WDSP::RXA::SetEMNRPosition(*m_rxa, 0); + m_rxa->setANRPosition(0); + m_rxa->setEMNRPosition(0); break; case WDSPRxProfile::NRPositionPostAGC: - WDSP::RXA::SetANRPosition(*m_rxa, 1); - WDSP::RXA::SetEMNRPosition(*m_rxa, 1); + m_rxa->setANRPosition(1); + m_rxa->setEMNRPosition(1); break; default: break; @@ -560,12 +560,12 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force) } if ((m_settings.m_anf != settings.m_anf) || force) { - WDSP::RXA::SetANFRun(*m_rxa, settings.m_anf ? 1 : 0); + m_rxa->setANFRun(settings.m_anf ? 1 : 0); } // Caution: Causes corruption if ((m_settings.m_snb != settings.m_snb) || force) { - WDSP::RXA::SetSNBARun(*m_rxa, settings.m_snb ? 1 : 0); + m_rxa->setSNBARun(settings.m_snb ? 1 : 0); } // CW Peaking diff --git a/wdsp/CMakeLists.txt b/wdsp/CMakeLists.txt index fea3b3a1c..59f76a89b 100644 --- a/wdsp/CMakeLists.txt +++ b/wdsp/CMakeLists.txt @@ -62,6 +62,7 @@ set(wdsp_SOURCES sphp.cpp ssql.cpp TXA.cpp + unit.cpp varsamp.cpp wcpAGC.cpp ) @@ -129,6 +130,7 @@ set(wdsp_HEADERS sphp.hpp ssql.hpp TXA.hpp + unit.hpp varsamp.hpp wcpAGC.hpp ) diff --git a/wdsp/RXA.cpp b/wdsp/RXA.cpp index 8053b8f98..940911ea3 100644 --- a/wdsp/RXA.cpp +++ b/wdsp/RXA.cpp @@ -58,43 +58,28 @@ warren@wpratt.com namespace WDSP { -RXA* RXA::create_rxa ( - int in_rate, // input samplerate - int out_rate, // output samplerate - int dsp_rate, // sample rate for mainstream dsp processing - int dsp_size // number complex samples processed per buffer in mainstream dsp processing +RXA::RXA( + int _in_rate, // input samplerate + int _out_rate, // output samplerate + int _dsp_rate, // sample rate for mainstream dsp processing + int _dsp_size // number complex samples processed per buffer in mainstream dsp processing +) : Unit( + _in_rate, + _out_rate, + _dsp_rate, + _dsp_size ) { - RXA* rxa = new RXA; - - rxa->in_rate = in_rate; - rxa->out_rate = out_rate; - rxa->dsp_rate = dsp_rate; - rxa->dsp_size = dsp_size; - - if (in_rate >= dsp_rate) - rxa->dsp_insize = dsp_size * (in_rate / dsp_rate); - else - rxa->dsp_insize = dsp_size / (dsp_rate / in_rate); - - if (out_rate >= dsp_rate) - rxa->dsp_outsize = dsp_size * (out_rate / dsp_rate); - else - rxa->dsp_outsize = dsp_size / (dsp_rate / out_rate); - - rxa->mode = RXA_LSB; - rxa->inbuff = new float[1 * rxa->dsp_insize * 2]; // (float *) malloc0 (1 * ch.dsp_insize * sizeof (complex)); - rxa->outbuff = new float[1 * rxa->dsp_outsize * 2]; // (float *) malloc0 (1 * ch.dsp_outsize * sizeof (complex)); - rxa->midbuff = new float[2 * rxa->dsp_size * 2]; // (float *) malloc0 (2 * ch.dsp_size * sizeof (complex)); - std::fill(rxa->meter, rxa->meter + RXA_METERTYPE_LAST, 0); + mode = RXA::RXA_LSB; + std::fill(meter, meter + RXA::RXA_METERTYPE_LAST, 0); // Noise blanker (ANB or "NB") - rxa->anb = new ANB( + anb = new ANB( 0, // run - rxa->dsp_insize, // input buffer size - rxa->inbuff, // pointer to input buffer - rxa->inbuff, // pointer to output buffer - rxa->in_rate, // samplerate + dsp_insize, // input buffer size + inbuff, // pointer to input buffer + inbuff, // pointer to output buffer + in_rate, // samplerate 0.0001, // tau 0.0001, // hang time 0.0001, // advance time @@ -102,12 +87,12 @@ RXA* RXA::create_rxa ( 30 // thershold ); // Noise blanker (NOB or "NB2") - rxa->nob = new NOB( + nob = new NOB( 0, // run - rxa->dsp_insize, // input buffer size - rxa->inbuff, // pointer to input buffer - rxa->inbuff, // pointer to output buffer - rxa->in_rate, // samplerate + dsp_insize, // input buffer size + inbuff, // pointer to input buffer + inbuff, // pointer to output buffer + in_rate, // samplerate 0, // mode (zero) 0.0001, // advance slew time 0.0001, // advance time @@ -119,36 +104,36 @@ RXA* RXA::create_rxa ( ); // Ftequency shifter - shift to select a slice of spectrum - rxa->shift = new SHIFT( + shift = new SHIFT( 0, // run - rxa->dsp_insize, // input buffer size - rxa->inbuff, // pointer to input buffer - rxa->inbuff, // pointer to output buffer - rxa->in_rate, // samplerate + dsp_insize, // input buffer size + inbuff, // pointer to input buffer + inbuff, // pointer to output buffer + in_rate, // samplerate 0.0); // amount to shift (Hz) // Input resampler - resample to dsp rate for main processing - rxa->rsmpin = new RESAMPLE( + rsmpin = new RESAMPLE( 0, // run - will be turned ON below if needed - rxa->dsp_insize, // input buffer size - rxa->inbuff, // pointer to input buffer - rxa->midbuff, // pointer to output buffer - rxa->in_rate, // input samplerate - rxa->dsp_rate, // output samplerate + dsp_insize, // input buffer size + inbuff, // pointer to input buffer + midbuff, // pointer to output buffer + in_rate, // input samplerate + dsp_rate, // output samplerate 0.0, // select cutoff automatically 0, // select ncoef automatically 1.0); // gain // Input meter - ADC - rxa->adcmeter = new METER( + adcmeter = new METER( 0, // run 0, // optional pointer to another 'run' - rxa->dsp_size, // size - rxa->midbuff, // pointer to buffer - rxa->dsp_rate, // samplerate + dsp_size, // size + midbuff, // pointer to buffer + dsp_rate, // samplerate 0.100, // averaging time constant 0.100, // peak decay time constant - rxa->meter, // result vector + meter, // result vector RXA_ADC_AV, // index for average value RXA_ADC_PK, // index for peak value -1, // index for gain value - disabled @@ -157,40 +142,40 @@ RXA* RXA::create_rxa ( // Notched bandpass section // notch database - rxa->ndb = new NOTCHDB ( + ndb = new NOTCHDB ( 0, // master run for all nbp's 1024); // max number of notches // notched bandpass - rxa->nbp0 = new NBP ( + nbp0 = new NBP ( 1, // run, always runs 0, // run the notches 0, // position - rxa->dsp_size, // buffer size - std::max(2048, rxa->dsp_size), // number of coefficients + dsp_size, // buffer size + std::max(2048, dsp_size), // number of coefficients 0, // minimum phase flag - rxa->midbuff, // pointer to input buffer - rxa->midbuff, // pointer to output buffer + midbuff, // pointer to input buffer + midbuff, // pointer to output buffer -4150.0, // lower filter frequency -150.0, // upper filter frequency - rxa->dsp_rate, // sample rate + dsp_rate, // sample rate 0, // wintype 1.0, // gain 1, // auto-increase notch width 1025, // max number of passbands - rxa->ndb); // addr of database pointer + ndb); // addr of database pointer // bandpass for snba - rxa->bpsnba = new BPSNBA ( + bpsnba = new BPSNBA ( 0, // bpsnba run flag 0, // run the notches 0, // position - rxa->dsp_size, // size - std::max(2048, rxa->dsp_size), // number of filter coefficients + dsp_size, // size + std::max(2048, dsp_size), // number of filter coefficients 0, // minimum phase flag - rxa->midbuff, // input buffer - rxa->midbuff, // output buffer - rxa->dsp_rate, // samplerate + midbuff, // input buffer + midbuff, // output buffer + dsp_rate, // samplerate + 250.0, // abs value of cutoff nearest zero + 5700.0, // abs value of cutoff farthest zero - 5700.0, // current low frequency @@ -199,42 +184,42 @@ RXA* RXA::create_rxa ( 1.0, // gain 1, // auto-increase notch width 1025, // max number of passbands - rxa->ndb); // addr of database pointer + ndb); // addr of database pointer // Post filter display send - send spectrum display (after S-meter in the block diagram) - rxa->sender = new SENDER ( + sender = new SENDER ( 0, // run 0, // flag 0, // mode - rxa->dsp_size, // size - rxa->midbuff // pointer to input buffer + dsp_size, // size + midbuff // pointer to input buffer ); // End notched bandpass section // S-meter - rxa->smeter = new METER( + smeter = new METER( 1, // run 0, // optional pointer to another 'run' - rxa->dsp_size, // size - rxa->midbuff, // pointer to buffer - rxa->dsp_rate, // samplerate + dsp_size, // size + midbuff, // pointer to buffer + dsp_rate, // samplerate 0.100, // averaging time constant 0.100, // peak decay time constant - rxa->meter, // result vector + meter, // result vector RXA_S_AV, // index for average value RXA_S_PK, // index for peak value -1, // index for gain value - disabled 0); // pointer for gain computation // AM squelch capture (for other modes than FM) - rxa->amsq = new AMSQ( + amsq = new AMSQ( 0, // run - rxa->dsp_size, // buffer size - rxa->midbuff, // pointer to signal input buffer used by xamsq - rxa->midbuff, // pointer to signal output buffer used by xamsq - rxa->midbuff, // pointer to trigger buffer that xamsqcap will capture - rxa->dsp_rate, // sample rate + dsp_size, // buffer size + midbuff, // pointer to signal input buffer used by xamsq + midbuff, // pointer to signal output buffer used by xamsq + midbuff, // pointer to trigger buffer that xamsqcap will capture + dsp_rate, // sample rate 0.010, // time constant for averaging signal level 0.070, // signal up transition time 0.070, // signal down transition time @@ -245,15 +230,15 @@ RXA* RXA::create_rxa ( 0.0); // muted gain // AM/SAM demodulator - rxa->amd = new AMD( + amd = new AMD( 0, // run - OFF by default - rxa->dsp_size, // buffer size - rxa->midbuff, // pointer to input buffer - rxa->midbuff, // pointer to output buffer + dsp_size, // buffer size + midbuff, // pointer to input buffer + midbuff, // pointer to output buffer 0, // mode: 0->AM, 1->SAM 1, // levelfade: 0->OFF, 1->ON 0, // sideband mode: 0->OFF - rxa->dsp_rate, // sample rate + dsp_rate, // sample rate -2000.0, // minimum lock frequency +2000.0, // maximum lock frequency 1.0, // zeta @@ -262,12 +247,12 @@ RXA* RXA::create_rxa ( 1.4); // tauI // FM demodulator - rxa->fmd = new FMD( + fmd = new FMD( 0, // run - rxa->dsp_size, // buffer size - rxa->midbuff, // pointer to input buffer - rxa->midbuff, // pointer to output buffer - rxa->dsp_rate, // sample rate + dsp_size, // buffer size + midbuff, // pointer to input buffer + midbuff, // pointer to output buffer + dsp_rate, // sample rate 5000.0, // deviation 300.0, // f_low 3000.0, // f_high @@ -279,21 +264,21 @@ RXA* RXA::create_rxa ( 0.5, // audio gain 1, // run tone filter 254.1, // ctcss frequency - std::max(2048, rxa->dsp_size), // # coefs for de-emphasis filter + std::max(2048, dsp_size), // # coefs for de-emphasis filter 0, // min phase flag for de-emphasis filter - std::max(2048, rxa->dsp_size), // # coefs for audio cutoff filter + std::max(2048, dsp_size), // # coefs for audio cutoff filter 0); // min phase flag for audio cutoff filter // FM squelch apply - rxa->fmsq = new FMSQ( + fmsq = new FMSQ( 0, // run - rxa->dsp_size, // buffer size - rxa->midbuff, // pointer to input signal buffer - rxa->midbuff, // pointer to output signal buffer - rxa->fmd->audio.data(), // pointer to trigger buffer - rxa->dsp_rate, // sample rate + dsp_size, // buffer size + midbuff, // pointer to input signal buffer + midbuff, // pointer to output signal buffer + fmd->audio.data(), // pointer to trigger buffer + dsp_rate, // sample rate 5000.0, // cutoff freq for noise filter (Hz) - &rxa->fmd->pllpole, // pointer to pole frequency of the fmd pll (Hz) + &fmd->pllpole, // pointer to pole frequency of the fmd pll (Hz) 0.100, // delay time after channel flush 0.001, // tau for noise averaging 0.100, // tau for long noise averaging @@ -303,17 +288,17 @@ RXA* RXA::create_rxa ( 0.562, // noise level to initiate unmute 0.000, // minimum tail time 0.100, // maximum tail time - std::max(2048, rxa->dsp_size), // number of coefficients for noise filter + std::max(2048, dsp_size), // number of coefficients for noise filter 0); // minimum phase flag // Spectral noise blanker (SNB) - rxa->snba = new SNBA( + snba = new SNBA( 0, // run - rxa->midbuff, // input buffer - rxa->midbuff, // output buffer - rxa->dsp_rate, // input / output sample rate + midbuff, // input buffer + midbuff, // output buffer + dsp_rate, // input / output sample rate 12000, // internal processing sample rate - rxa->dsp_size, // buffer size + dsp_size, // buffer size 4, // overlap factor to use 256, // frame size to use; sized for 12K rate 64, // asize @@ -329,31 +314,30 @@ RXA* RXA::create_rxa ( // Equalizer { - float default_F[11] = {0.0, 32.0, 63.0, 125.0, 250.0, 500.0, 1000.0, 2000.0, 4000.0, 8000.0, 16000.0}; - //float default_G[11] = {0.0, -12.0, -12.0, -12.0, -1.0, +1.0, +4.0, +9.0, +12.0, -10.0, -10.0}; - float default_G[11] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; - rxa->eqp = new EQP( + std::array default_F = {0.0, 32.0, 63.0, 125.0, 250.0, 500.0, 1000.0, 2000.0, 4000.0, 8000.0, 16000.0}; + std::array default_G = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; + eqp = new EQP( 0, // run - OFF by default - rxa->dsp_size, // buffer size - std::max(2048, rxa->dsp_size), // number of filter coefficients + dsp_size, // buffer size + std::max(2048, dsp_size), // number of filter coefficients 0, // minimum phase flag - rxa->midbuff, // pointer to input buffer - rxa->midbuff, // pointer to output buffer + midbuff, // pointer to input buffer + midbuff, // pointer to output buffer 10, // number of frequencies - default_F, // frequency vector - default_G, // gain vector + default_F.data(), // frequency vector + default_G.data(), // gain vector 0, // cutoff mode 0, // wintype - rxa->dsp_rate); // sample rate + dsp_rate); // sample rate } // Auto notch filter - rxa->anf = new ANF( + anf = new ANF( 0, // run - OFF by default 0, // position - rxa->dsp_size, // buffer size - rxa->midbuff, // pointer to input buffer - rxa->midbuff, // pointer to output buffer + dsp_size, // buffer size + midbuff, // pointer to input buffer + midbuff, // pointer to output buffer ANF::ANF_DLINE_SIZE, // dline_size 64, // taps 16, // delay @@ -368,12 +352,12 @@ RXA* RXA::create_rxa ( 3.0); // ldecr // LMS noise reduction (ANR or "NR") - rxa->anr = new ANR( + anr = new ANR( 0, // run - OFF by default 0, // position - rxa->dsp_size, // buffer size - rxa->midbuff, // pointer to input buffer - rxa->midbuff, // pointer to output buffer + dsp_size, // buffer size + midbuff, // pointer to input buffer + midbuff, // pointer to output buffer ANR::ANR_DLINE_SIZE, // dline_size 64, // taps 16, // delay @@ -388,15 +372,15 @@ RXA* RXA::create_rxa ( 3.0); // ldecr // Spectral noise reduyction (EMNR or "NR2") - rxa->emnr = new EMNR( + emnr = new EMNR( 0, // run 0, // position - rxa->dsp_size, // buffer size - rxa->midbuff, // input buffer - rxa->midbuff, // output buffer + dsp_size, // buffer size + midbuff, // input buffer + midbuff, // output buffer 4096, // FFT size 4, // overlap - rxa->dsp_rate, // samplerate + dsp_rate, // samplerate 0, // window type 1.0, // gain 2, // gain method @@ -404,14 +388,14 @@ RXA* RXA::create_rxa ( 1); // ae_run // AGC - rxa->agc = new WCPAGC( + agc = new WCPAGC( 1, // run 3, // mode 1, // peakmode = envelope - rxa->midbuff, // pointer to input buffer - rxa->midbuff, // pointer to output buffer - rxa->dsp_size, // buffer size - rxa->dsp_rate, // sample rate + midbuff, // pointer to input buffer + midbuff, // pointer to output buffer + dsp_size, // buffer size + dsp_rate, // sample rate 0.001, // tau_attack 0.250, // tau_decay 4, // n_tau @@ -430,64 +414,64 @@ RXA* RXA::create_rxa ( 0.100); // tau_hang_decay // AGC meter - rxa->agcmeter = new METER( + agcmeter = new METER( 0, // run 0, // optional pointer to another 'run' - rxa->dsp_size, // size - rxa->midbuff, // pointer to buffer - rxa->dsp_rate, // samplerate + dsp_size, // size + midbuff, // pointer to buffer + dsp_rate, // samplerate 0.100, // averaging time constant 0.100, // peak decay time constant - rxa->meter, // result vector + meter, // result vector RXA_AGC_AV, // index for average value RXA_AGC_PK, // index for peak value RXA_AGC_GAIN, // index for gain value - &rxa->agc->gain); // pointer for gain computation + &agc->gain); // pointer for gain computation // Bandpass filter - After spectral noise reduction in the block diagram - rxa->bp1 = new BANDPASS ( + bp1 = new BANDPASS ( 1, // run - used only with ( AM || ANF || ANR || EMNR) 0, // position - rxa->dsp_size, // buffer size - std::max(2048, rxa->dsp_size), // number of coefficients + dsp_size, // buffer size + std::max(2048, dsp_size), // number of coefficients 0, // flag for minimum phase - rxa->midbuff, // pointer to input buffer - rxa->midbuff, // pointer to output buffer + midbuff, // pointer to input buffer + midbuff, // pointer to output buffer -4150.0, // lower filter frequency -150.0, // upper filter frequency - rxa->dsp_rate, // sample rate + dsp_rate, // sample rate 1, // wintype 1.0); // gain // Scope/phase display send - pull phase & scope display data - rxa->sip1 = new SIPHON( + sip1 = new SIPHON( 0, // run - needed only for phase display 0, // position 0, // mode 0, // disp - rxa->dsp_size, // size of input buffer - rxa->midbuff, // input buffer + dsp_size, // size of input buffer + midbuff, // input buffer 4096, // number of samples to store 4096, // fft size for spectrum 0); // specmode // AM carrier block - rxa->cbl = new CBL( + cbl = new CBL( 0, // run - needed only if set to ON - rxa->dsp_size, // buffer size - rxa->midbuff, // pointer to input buffer - rxa->midbuff, // pointer to output buffer + dsp_size, // buffer size + midbuff, // pointer to input buffer + midbuff, // pointer to output buffer 0, // mode - rxa->dsp_rate, // sample rate + dsp_rate, // sample rate 0.02); // tau // CW peaking filter - rxa->speak = new SPEAK( + speak = new SPEAK( 0, // run - rxa->dsp_size, // buffer size, - rxa->midbuff, // pointer to input buffer - rxa->midbuff, // pointer to output buffer - rxa->dsp_rate, // sample rate + dsp_size, // buffer size, + midbuff, // pointer to input buffer + midbuff, // pointer to output buffer + dsp_rate, // sample rate 600.0, // center frequency 100.0, // bandwidth 2.0, // gain @@ -496,31 +480,31 @@ RXA* RXA::create_rxa ( // Dolly filter (multiple peak filter) - default is 2 for RTTY { - int def_enable[2] = {1, 1}; - double def_freq[2] = {2125.0, 2295.0}; - double def_bw[2] = {75.0, 75.0}; - double def_gain[2] = {1.0, 1.0}; - rxa->mpeak = new MPEAK( + std::array def_enable = { 1, 1}; + std::array def_freq = {2125.0, 2295.0}; + std::array def_bw = { 75.0, 75.0}; + std::array def_gain = { 1.0, 1.0}; + mpeak = new MPEAK( 0, // run - rxa->dsp_size, // size - rxa->midbuff, // pointer to input buffer - rxa->midbuff, // pointer to output buffer - rxa->dsp_rate, // sample rate + dsp_size, // size + midbuff, // pointer to input buffer + midbuff, // pointer to output buffer + dsp_rate, // sample rate 2, // number of peaking filters - def_enable, // enable vector - def_freq, // frequency vector - def_bw, // bandwidth vector - def_gain, // gain vector + def_enable.data(), // enable vector + def_freq.data(), // frequency vector + def_bw.data(), // bandwidth vector + def_gain.data(), // gain vector 4 ); // number of stages } // Syllabic squelch (Voice suelch) - Not in the block diagram - rxa->ssql = new SSQL( + ssql = new SSQL( 0, // run - rxa->dsp_size, // size - rxa->midbuff, // pointer to input buffer - rxa->midbuff, // pointer to output buffer - rxa->dsp_rate, // sample rate + dsp_size, // size + midbuff, // pointer to input buffer + midbuff, // pointer to output buffer + dsp_rate, // sample rate 0.070, // signal up transition time 0.070, // signal down transition time 0.0, // muted gain @@ -532,11 +516,11 @@ RXA* RXA::create_rxa ( 2000.0); // max freq for f_to_v converter // PatchPanel - rxa->panel = new PANEL( + panel = new PANEL( 1, // run - rxa->dsp_size, // size - rxa->midbuff, // pointer to input buffer - rxa->midbuff, // pointer to output buffer + dsp_size, // size + midbuff, // pointer to input buffer + midbuff, // pointer to output buffer 4.0, // gain1 1.0, // gain2I 1.0, // gain2Q @@ -546,325 +530,270 @@ RXA* RXA::create_rxa ( // AM squelch apply - absent but in the block diagram // Output resampler - rxa->rsmpout = new RESAMPLE( + rsmpout = new RESAMPLE( 0, // run - will be turned ON below if needed - rxa->dsp_size, // input buffer size - rxa->midbuff, // pointer to input buffer - rxa->outbuff, // pointer to output buffer - rxa->dsp_rate, // input sample rate - rxa->out_rate, // output sample rate + dsp_size, // input buffer size + midbuff, // pointer to input buffer + outbuff, // pointer to output buffer + dsp_rate, // input sample rate + out_rate, // output sample rate 0.0, // select cutoff automatically 0, // select ncoef automatically 1.0); // gain // turn OFF / ON resamplers as needed - ResCheck (*rxa); - return rxa; + resCheck(); } -void RXA::destroy_rxa (RXA *rxa) +RXA::~RXA() { - delete (rxa->rsmpout); - delete (rxa->panel); - delete (rxa->ssql); - delete (rxa->mpeak); - delete (rxa->speak); - delete (rxa->cbl); - delete (rxa->sip1); - delete (rxa->bp1); - delete (rxa->agcmeter); - delete (rxa->agc); - delete (rxa->emnr); - delete (rxa->anr); - delete (rxa->anf); - delete (rxa->eqp); - delete (rxa->snba); - delete (rxa->fmsq); - delete (rxa->fmd); - delete (rxa->amd); - delete (rxa->amsq); - delete (rxa->smeter); - delete (rxa->sender); - delete (rxa->bpsnba); - delete (rxa->nbp0); - delete (rxa->ndb); - delete (rxa->adcmeter); - delete (rxa->rsmpin); - delete (rxa->shift); - delete (rxa->nob); - delete (rxa->anb); - delete[] (rxa->midbuff); - delete[] (rxa->outbuff); - delete[] (rxa->inbuff); - delete rxa; + delete rsmpout; + delete panel; + delete ssql; + delete mpeak; + delete speak; + delete cbl; + delete sip1; + delete bp1; + delete agcmeter; + delete agc; + delete emnr; + delete anr; + delete anf; + delete eqp; + delete snba; + delete fmsq; + delete fmd; + delete amd; + delete amsq; + delete smeter; + delete sender; + delete bpsnba; + delete nbp0; + delete ndb; + delete adcmeter; + delete rsmpin; + delete shift; + delete nob; + delete anb; } -void RXA::flush_rxa (RXA *rxa) +void RXA::flush() { - std::fill(rxa->inbuff, rxa->inbuff + 1 * rxa->dsp_insize * 2, 0); - std::fill(rxa->outbuff, rxa->outbuff + 1 * rxa->dsp_outsize * 2, 0); - std::fill(rxa->midbuff, rxa->midbuff + 2 * rxa->dsp_size * 2, 0); - rxa->anb->flush(); - rxa->nob->flush(); - rxa->shift->flush(); - rxa->rsmpin->flush(); - rxa->adcmeter->flush(); - rxa->nbp0->flush(); - rxa->bpsnba->flush(); - rxa->sender->flush(); - rxa->smeter->flush(); - rxa->amsq->flush(); - rxa->amd->flush(); - rxa->fmd->flush(); - rxa->fmsq->flush(); - rxa->snba->flush(); - rxa->eqp->flush(); - rxa->anf->flush(); - rxa->anr->flush(); - rxa->emnr->flush(); - rxa->agc->flush(); - rxa->agcmeter->flush(); - rxa->bp1->flush(); - rxa->sip1->flush(); - rxa->cbl->flush(); - rxa->speak->flush(); - rxa->mpeak->flush(); - rxa->ssql->flush(); - rxa->panel->flush(); - rxa->rsmpout->flush(); + Unit::flushBuffers(); + anb->flush(); + nob->flush(); + shift->flush(); + rsmpin->flush(); + adcmeter->flush(); + nbp0->flush(); + bpsnba->flush(); + sender->flush(); + smeter->flush(); + amsq->flush(); + amd->flush(); + fmd->flush(); + fmsq->flush(); + snba->flush(); + eqp->flush(); + anf->flush(); + anr->flush(); + emnr->flush(); + agc->flush(); + agcmeter->flush(); + bp1->flush(); + sip1->flush(); + cbl->flush(); + speak->flush(); + mpeak->flush(); + ssql->flush(); + panel->flush(); + rsmpout->flush(); } -void RXA::xrxa (RXA *rxa) +void RXA::execute() { - rxa->anb->execute(); - rxa->nob->execute(); - rxa->shift->execute(); - rxa->rsmpin->execute(); - rxa->adcmeter->execute(); - rxa->bpsnba->exec_in(0); - rxa->nbp0->execute(0); - rxa->smeter->execute(); - rxa->sender->execute(); - rxa->amsq->xcap(); - rxa->bpsnba->exec_out(0); - rxa->amd->execute(); - rxa->fmd->execute(); - rxa->fmsq->execute(); - rxa->bpsnba->exec_in(1); - rxa->bpsnba->exec_out(1); - rxa->snba->execute(); - rxa->eqp->execute(); - rxa->anf->execute(0); - rxa->anr->ANR::execute(0); - rxa->emnr->execute(0); - rxa->bp1->BANDPASS::execute(0); - rxa->agc->execute(); - rxa->anf->execute(1); - rxa->anr->execute(1); - rxa->emnr->execute(1); - rxa->bp1->execute(1); - rxa->agcmeter->execute(); - rxa->sip1->execute(0); - rxa->cbl->execute(); - rxa->speak->execute(); - rxa->mpeak->execute(); - rxa->ssql->execute(); - rxa->panel->execute(); - rxa->amsq->execute(); - rxa->rsmpout->execute(); + anb->execute(); + nob->execute(); + shift->execute(); + rsmpin->execute(); + adcmeter->execute(); + bpsnba->exec_in(0); + nbp0->execute(0); + smeter->execute(); + sender->execute(); + amsq->xcap(); + bpsnba->exec_out(0); + amd->execute(); + fmd->execute(); + fmsq->execute(); + bpsnba->exec_in(1); + bpsnba->exec_out(1); + snba->execute(); + eqp->execute(); + anf->execute(0); + anr->ANR::execute(0); + emnr->execute(0); + bp1->BANDPASS::execute(0); + agc->execute(); + anf->execute(1); + anr->execute(1); + emnr->execute(1); + bp1->execute(1); + agcmeter->execute(); + sip1->execute(0); + cbl->execute(); + speak->execute(); + mpeak->execute(); + ssql->execute(); + panel->execute(); + amsq->execute(); + rsmpout->execute(); } -void RXA::setInputSamplerate (RXA *rxa, int in_rate) +void RXA::setInputSamplerate(int _in_rate) { - if (in_rate >= rxa->dsp_rate) - rxa->dsp_insize = rxa->dsp_size * (in_rate / rxa->dsp_rate); - else - rxa->dsp_insize = rxa->dsp_size / (rxa->dsp_rate / in_rate); - - rxa->in_rate = in_rate; - // buffers - delete[] (rxa->inbuff); - rxa->inbuff = new float[1 * rxa->dsp_insize * 2]; // (float *)malloc0(1 * ch.dsp_insize * sizeof(complex)); + Unit::setBuffersInputSamplerate(_in_rate); // anb - rxa->anb->setBuffers(rxa->inbuff, rxa->inbuff); - rxa->anb->setSize(rxa->dsp_insize); - rxa->anb->setSamplerate(rxa->in_rate); + anb->setBuffers(inbuff, inbuff); + anb->setSize(dsp_insize); + anb->setSamplerate(in_rate); // nob - rxa->nob->setBuffers(rxa->inbuff, rxa->inbuff); - rxa->nob->setSize(rxa->dsp_insize); - rxa->nob->setSamplerate(rxa->in_rate); + nob->setBuffers(inbuff, inbuff); + nob->setSize(dsp_insize); + nob->setSamplerate(in_rate); // shift - rxa->shift->setBuffers(rxa->inbuff, rxa->inbuff); - rxa->shift->setSize(rxa->dsp_insize); - rxa->shift->setSamplerate(rxa->in_rate); + shift->setBuffers(inbuff, inbuff); + shift->setSize(dsp_insize); + shift->setSamplerate(in_rate); // input resampler - rxa->rsmpin->setBuffers(rxa->inbuff, rxa->midbuff); - rxa->rsmpin->setSize(rxa->dsp_insize); - rxa->rsmpin->setInRate(rxa->in_rate); - ResCheck (*rxa); + rsmpin->setBuffers(inbuff, midbuff); + rsmpin->setSize(dsp_insize); + rsmpin->setInRate(in_rate); + resCheck(); } -void RXA::setOutputSamplerate (RXA *rxa, int out_rate) +void RXA::setOutputSamplerate(int _out_rate) { - if (out_rate >= rxa->dsp_rate) - rxa->dsp_outsize = rxa->dsp_size * (out_rate / rxa->dsp_rate); - else - rxa->dsp_outsize = rxa->dsp_size / (rxa->dsp_rate / out_rate); - - rxa->out_rate = out_rate; - // buffers - delete[] (rxa->outbuff); - rxa->outbuff = new float[1 * rxa->dsp_outsize * 2]; // (float *)malloc0(1 * ch.dsp_outsize * sizeof(complex)); + Unit::setBuffersOutputSamplerate(_out_rate); // output resampler - rxa->rsmpout->setBuffers(rxa->midbuff, rxa->outbuff); - rxa->rsmpout->setOutRate(rxa->out_rate); - ResCheck (*rxa); + rsmpout->setBuffers(midbuff, outbuff); + rsmpout->setOutRate(out_rate); + resCheck(); } -void RXA::setDSPSamplerate (RXA *rxa, int dsp_rate) +void RXA::setDSPSamplerate(int _dsp_rate) { - if (rxa->in_rate >= dsp_rate) - rxa->dsp_insize = rxa->dsp_size * (rxa->in_rate / dsp_rate); - else - rxa->dsp_insize = rxa->dsp_size / (dsp_rate / rxa->in_rate); - - if (rxa->out_rate >= dsp_rate) - rxa->dsp_outsize = rxa->dsp_size * (rxa->out_rate / dsp_rate); - else - rxa->dsp_outsize = rxa->dsp_size / (dsp_rate / rxa->out_rate); - - rxa->dsp_rate = dsp_rate; - // buffers - delete[] (rxa->inbuff); - rxa->inbuff = new float[1 * rxa->dsp_insize * 2]; // (float *)malloc0(1 * rxa->dsp_insize * sizeof(complex)); - delete[] (rxa->outbuff); - rxa->outbuff = new float[1 * rxa->dsp_outsize * 2]; // (float *)malloc0(1 * rxa->dsp_outsize * sizeof(complex)); + Unit::setBuffersDSPSamplerate(_dsp_rate); // anb - rxa->anb->setBuffers(rxa->inbuff, rxa->inbuff); - rxa->anb->setSize(rxa->dsp_insize); + anb->setBuffers(inbuff, inbuff); + anb->setSize(dsp_insize); // nob - rxa->nob->setBuffers(rxa->inbuff, rxa->inbuff); - rxa->nob->setSize(rxa->dsp_insize); + nob->setBuffers(inbuff, inbuff); + nob->setSize(dsp_insize); // shift - rxa->shift->setBuffers(rxa->inbuff, rxa->inbuff); - rxa->shift->setSize(rxa->dsp_insize); + shift->setBuffers(inbuff, inbuff); + shift->setSize(dsp_insize); // input resampler - rxa->rsmpin->setBuffers(rxa->inbuff, rxa->midbuff); - rxa->rsmpin->setSize(rxa->dsp_insize); - rxa->rsmpin->setOutRate(rxa->dsp_rate); + rsmpin->setBuffers(inbuff, midbuff); + rsmpin->setSize(dsp_insize); + rsmpin->setOutRate(dsp_rate); // dsp_rate blocks - rxa->adcmeter->setSamplerate(rxa->dsp_rate); - rxa->nbp0->setSamplerate(rxa->dsp_rate); - rxa->bpsnba->setSamplerate(rxa->dsp_rate); - rxa->smeter->setSamplerate(rxa->dsp_rate); - rxa->sender->setSamplerate(rxa->dsp_rate); - rxa->amsq->setSamplerate(rxa->dsp_rate); - rxa->amd->setSamplerate(rxa->dsp_rate); - rxa->fmd->setSamplerate(rxa->dsp_rate); - rxa->fmsq->setBuffers(rxa->midbuff, rxa->midbuff, rxa->fmd->audio.data()); - rxa->fmsq->setSamplerate(rxa->dsp_rate); - // rxa->snba->setSamplerate(rxa->dsp_rate); SMBA removed - rxa->eqp->setSamplerate(rxa->dsp_rate); - rxa->anf->setSamplerate(rxa->dsp_rate); - rxa->anr->setSamplerate(rxa->dsp_rate); - rxa->emnr->setSamplerate(rxa->dsp_rate); - rxa->bp1->setSamplerate(rxa->dsp_rate); - rxa->agc->setSamplerate(rxa->dsp_rate); - rxa->agcmeter->setSamplerate(rxa->dsp_rate); - rxa->sip1->setSamplerate(rxa->dsp_rate); - rxa->cbl->setSamplerate(rxa->dsp_rate); - rxa->speak->setSamplerate(rxa->dsp_rate); - rxa->mpeak->setSamplerate(rxa->dsp_rate); - rxa->ssql->setSamplerate(rxa->dsp_rate); - rxa->panel->setSamplerate(rxa->dsp_rate); + adcmeter->setSamplerate(dsp_rate); + nbp0->setSamplerate(dsp_rate); + bpsnba->setSamplerate(dsp_rate); + smeter->setSamplerate(dsp_rate); + sender->setSamplerate(dsp_rate); + amsq->setSamplerate(dsp_rate); + amd->setSamplerate(dsp_rate); + fmd->setSamplerate(dsp_rate); + fmsq->setBuffers(midbuff, midbuff, fmd->audio.data()); + fmsq->setSamplerate(dsp_rate); + // snba->setSamplerate(dsp_rate); SMBA removed + eqp->setSamplerate(dsp_rate); + anf->setSamplerate(dsp_rate); + anr->setSamplerate(dsp_rate); + emnr->setSamplerate(dsp_rate); + bp1->setSamplerate(dsp_rate); + agc->setSamplerate(dsp_rate); + agcmeter->setSamplerate(dsp_rate); + sip1->setSamplerate(dsp_rate); + cbl->setSamplerate(dsp_rate); + speak->setSamplerate(dsp_rate); + mpeak->setSamplerate(dsp_rate); + ssql->setSamplerate(dsp_rate); + panel->setSamplerate(dsp_rate); // output resampler - rxa->rsmpout->setBuffers(rxa->midbuff, rxa->outbuff); - rxa->rsmpout->setInRate(rxa->dsp_rate); - ResCheck (*rxa); + rsmpout->setBuffers(midbuff, outbuff); + rsmpout->setInRate(dsp_rate); + resCheck(); } -void RXA::setDSPBuffsize (RXA *rxa, int dsp_size) +void RXA::setDSPBuffsize(int _dsp_size) { - if (rxa->in_rate >= rxa->dsp_rate) - rxa->dsp_insize = dsp_size * (rxa->in_rate / rxa->dsp_rate); - else - rxa->dsp_insize = dsp_size / (rxa->dsp_rate / rxa->in_rate); - - if (rxa->out_rate >= rxa->dsp_rate) - rxa->dsp_outsize = dsp_size * (rxa->out_rate / rxa->dsp_rate); - else - rxa->dsp_outsize = dsp_size / (rxa->dsp_rate / rxa->out_rate); - - rxa->dsp_size = dsp_size; - // buffers - delete[](rxa->inbuff); - rxa->inbuff = new float[1 * rxa->dsp_insize * 2]; // (float *)malloc0(1 * rxa->dsp_insize * sizeof(complex)); - delete[] (rxa->midbuff); - rxa->midbuff = new float[2 * rxa->dsp_size * 2]; // (float *)malloc0(2 * rxa->dsp_size * sizeof(complex)); - delete[] (rxa->outbuff); - rxa->outbuff = new float[1 * rxa->dsp_outsize * 2]; // (float *)malloc0(1 * rxa->dsp_outsize * sizeof(complex)); + Unit::setBuffersDSPBuffsize(_dsp_size); // anb - rxa->anb->setBuffers(rxa->inbuff, rxa->inbuff); - rxa->anb->setSize(rxa->dsp_insize); + anb->setBuffers(inbuff, inbuff); + anb->setSize(dsp_insize); // nob - rxa->nob->setBuffers(rxa->inbuff, rxa->inbuff); - rxa->nob->setSize(rxa->dsp_insize); + nob->setBuffers(inbuff, inbuff); + nob->setSize(dsp_insize); // shift - rxa->shift->setBuffers(rxa->inbuff, rxa->inbuff); - rxa->shift->setSize(rxa->dsp_insize); + shift->setBuffers(inbuff, inbuff); + shift->setSize(dsp_insize); // input resampler - rxa->rsmpin->setBuffers(rxa->inbuff, rxa->midbuff); - rxa->rsmpin->setSize(rxa->dsp_insize); + rsmpin->setBuffers(inbuff, midbuff); + rsmpin->setSize(dsp_insize); // dsp_size blocks - rxa->adcmeter->setBuffers(rxa->midbuff); - rxa->adcmeter->setSize(rxa->dsp_size); - rxa->nbp0->setBuffers(rxa->midbuff, rxa->midbuff); - rxa->nbp0->setSize(rxa->dsp_size); - rxa->bpsnba->setBuffers(rxa->midbuff, rxa->midbuff); - rxa->bpsnba->setSize(rxa->dsp_size); - rxa->smeter->setBuffers(rxa->midbuff); - rxa->smeter->setSize(rxa->dsp_size); - rxa->sender->setBuffers(rxa->midbuff); - rxa->sender->setSize(rxa->dsp_size); - rxa->amsq->setBuffers(rxa->midbuff, rxa->midbuff, rxa->midbuff); - rxa->amsq->setSize(rxa->dsp_size); - rxa->amd->setBuffers(rxa->midbuff, rxa->midbuff); - rxa->amd->setSize(rxa->dsp_size); - rxa->fmd->setBuffers(rxa->midbuff, rxa->midbuff); - rxa->fmd->setSize(rxa->dsp_size); - rxa->fmsq->setBuffers(rxa->midbuff, rxa->midbuff, rxa->fmd->audio.data()); - rxa->fmsq->setSize(rxa->dsp_size); - rxa->snba->setBuffers(rxa->midbuff, rxa->midbuff); - rxa->snba->setSize(rxa->dsp_size); - rxa->eqp->setBuffers(rxa->midbuff, rxa->midbuff); - rxa->eqp->setSize(rxa->dsp_size); - rxa->anf->setBuffers(rxa->midbuff, rxa->midbuff); - rxa->anf->setSize(rxa->dsp_size); - rxa->anr->setBuffers(rxa->midbuff, rxa->midbuff); - rxa->anr->setSize(rxa->dsp_size); - rxa->emnr->setBuffers(rxa->midbuff, rxa->midbuff); - rxa->emnr->setSize(rxa->dsp_size); - rxa->bp1->setBuffers(rxa->midbuff, rxa->midbuff); - rxa->bp1->setSize(rxa->dsp_size); - rxa->agc->setBuffers(rxa->midbuff, rxa->midbuff); - rxa->agc->setSize(rxa->dsp_size); - rxa->agcmeter->setBuffers(rxa->midbuff); - rxa->agcmeter->setSize(rxa->dsp_size); - rxa->sip1->setBuffers(rxa->midbuff); - rxa->sip1->setSize(rxa->dsp_size); - rxa->cbl->setBuffers(rxa->midbuff, rxa->midbuff); - rxa->cbl->setSize(rxa->dsp_size); - rxa->speak->setBuffers(rxa->midbuff, rxa->midbuff); - rxa->speak->setSize(rxa->dsp_size); - rxa->mpeak->setBuffers(rxa->midbuff, rxa->midbuff); - rxa->mpeak->setSize(rxa->dsp_size); - rxa->ssql->setBuffers(rxa->midbuff, rxa->midbuff); - rxa->ssql->setSize(rxa->dsp_size); - rxa->panel->setBuffers(rxa->midbuff, rxa->midbuff); - rxa->panel->setSize(rxa->dsp_size); + adcmeter->setBuffers(midbuff); + adcmeter->setSize(dsp_size); + nbp0->setBuffers(midbuff, midbuff); + nbp0->setSize(dsp_size); + bpsnba->setBuffers(midbuff, midbuff); + bpsnba->setSize(dsp_size); + smeter->setBuffers(midbuff); + smeter->setSize(dsp_size); + sender->setBuffers(midbuff); + sender->setSize(dsp_size); + amsq->setBuffers(midbuff, midbuff, midbuff); + amsq->setSize(dsp_size); + amd->setBuffers(midbuff, midbuff); + amd->setSize(dsp_size); + fmd->setBuffers(midbuff, midbuff); + fmd->setSize(dsp_size); + fmsq->setBuffers(midbuff, midbuff, fmd->audio.data()); + fmsq->setSize(dsp_size); + snba->setBuffers(midbuff, midbuff); + snba->setSize(dsp_size); + eqp->setBuffers(midbuff, midbuff); + eqp->setSize(dsp_size); + anf->setBuffers(midbuff, midbuff); + anf->setSize(dsp_size); + anr->setBuffers(midbuff, midbuff); + anr->setSize(dsp_size); + emnr->setBuffers(midbuff, midbuff); + emnr->setSize(dsp_size); + bp1->setBuffers(midbuff, midbuff); + bp1->setSize(dsp_size); + agc->setBuffers(midbuff, midbuff); + agc->setSize(dsp_size); + agcmeter->setBuffers(midbuff); + agcmeter->setSize(dsp_size); + sip1->setBuffers(midbuff); + sip1->setSize(dsp_size); + cbl->setBuffers(midbuff, midbuff); + cbl->setSize(dsp_size); + speak->setBuffers(midbuff, midbuff); + speak->setSize(dsp_size); + mpeak->setBuffers(midbuff, midbuff); + mpeak->setSize(dsp_size); + ssql->setBuffers(midbuff, midbuff); + ssql->setSize(dsp_size); + panel->setBuffers(midbuff, midbuff); + panel->setSize(dsp_size); // output resampler - rxa->rsmpout->setBuffers(rxa->midbuff, rxa->outbuff); - rxa->rsmpout->setSize(rxa->dsp_size); + rsmpout->setBuffers(midbuff, outbuff); + rsmpout->setSize(dsp_size); } void RXA::setSpectrumProbe(BufferProbe *spectrumProbe) @@ -879,66 +808,64 @@ void RXA::setSpectrumProbe(BufferProbe *spectrumProbe) * * ********************************************************************************************************/ -void RXA::SetMode (RXA& rxa, int mode) +void RXA::setMode(int _mode) { - if (rxa.mode != mode) + if (mode != _mode) { - int amd_run = (mode == RXA_AM) || (mode == RXA_SAM); - bpsnbaCheck (rxa, mode, rxa.ndb->master_run); + int amd_run = (_mode == RXA_AM) || (_mode == RXA_SAM); + bpsnbaCheck (_mode, ndb->master_run); bp1Check ( - rxa, amd_run, - rxa.snba->run, - rxa.emnr->run, - rxa.anf->run, - rxa.anr->run + snba->run, + emnr->run, + anf->run, + anr->run ); - rxa.mode = mode; - rxa.amd->run = 0; - rxa.fmd->run = 0; + mode = _mode; + amd->run = 0; + fmd->run = 0; - switch (mode) + switch (_mode) { case RXA_AM: - rxa.amd->run = 1; - rxa.amd->mode = 0; + amd->run = 1; + amd->mode = 0; break; case RXA_SAM: - rxa.amd->run = 1; - rxa.amd->mode = 1; + amd->run = 1; + amd->mode = 1; break; case RXA_DSB: break; case RXA_FM: - rxa.fmd->run = 1; + fmd->run = 1; break; default: break; } - bp1Set (rxa); - bpsnbaSet (rxa); // update variables + bp1Set(); + bpsnbaSet(); // update variables } } -void RXA::ResCheck (RXA& rxa) +void RXA::resCheck() { // turn OFF/ON resamplers depending upon whether they're needed - RESAMPLE *a = rxa.rsmpin; - if (rxa.in_rate != rxa.dsp_rate) + RESAMPLE *a = rsmpin; + if (in_rate != dsp_rate) a->run = 1; else a->run = 0; - a = rxa.rsmpout; - if (rxa.dsp_rate != rxa.out_rate) + a = rsmpout; + if (dsp_rate != out_rate) a->run = 1; else a->run = 0; } void RXA::bp1Check ( - RXA& rxa, int amd_run, int snba_run, int emnr_run, @@ -946,7 +873,7 @@ void RXA::bp1Check ( int anr_run ) { - BANDPASS *a = rxa.bp1; + BANDPASS *a = bp1; float gain; if (amd_run || snba_run || @@ -961,15 +888,15 @@ void RXA::bp1Check ( a->setGain(gain, 0); } -void RXA::bp1Set (RXA& rxa) +void RXA::bp1Set () { - BANDPASS *a = rxa.bp1; + BANDPASS *a = bp1; int old = a->run; - if ((rxa.amd->run == 1) || - (rxa.snba->run == 1) || - (rxa.emnr->run == 1) || - (rxa.anf->run == 1) || - (rxa.anr->run == 1) + if ((amd->run == 1) || + (snba->run == 1) || + (emnr->run == 1) || + (anf->run == 1) || + (anr->run == 1) ) a->run = 1; else @@ -979,36 +906,33 @@ void RXA::bp1Set (RXA& rxa) FIRCORE::setUpdate_fircore (a->fircore); } -void RXA::bpsnbaCheck (RXA& rxa, int mode, int notch_run) +void RXA::bpsnbaCheck(int _mode, int _notch_run) { // for BPSNBA: set run, position, freqs, run_notches // call this upon change in RXA_mode, snba_run, notch_master_run - BPSNBA *a = rxa.bpsnba; - float f_low = 0.0, f_high = 0.0; + BPSNBA *a = bpsnba; + double f_low = 0.0; + double f_high = 0.0; int run_notches = 0; - switch (mode) + switch (_mode) { case RXA_LSB: case RXA_CWL: case RXA_DIGL: f_low = -a->abs_high_freq; f_high = -a->abs_low_freq; - run_notches = notch_run; + run_notches = _notch_run; break; case RXA_USB: case RXA_CWU: case RXA_DIGU: f_low = +a->abs_low_freq; f_high = +a->abs_high_freq; - run_notches = notch_run; + run_notches = _notch_run; break; case RXA_AM: case RXA_SAM: case RXA_DSB: - f_low = +a->abs_low_freq; - f_high = +a->abs_high_freq; - run_notches = 0; - break; case RXA_FM: f_low = +a->abs_low_freq; f_high = +a->abs_high_freq; @@ -1016,7 +940,8 @@ void RXA::bpsnbaCheck (RXA& rxa, int mode, int notch_run) break; case RXA_DRM: case RXA_SPEC: - + break; + default: break; } // 'run' and 'position' are examined at run time; no filter changes required. @@ -1029,57 +954,53 @@ void RXA::bpsnbaCheck (RXA& rxa, int mode, int notch_run) a->f_high = f_high; a->run_notches = run_notches; // f_low, f_high, run_notches are needed for the filter recalculation - rxa.bpsnba->recalc_bpsnba_filter(0); + bpsnba->recalc_bpsnba_filter(0); } } -void RXA::bpsnbaSet (RXA& rxa) +void RXA::bpsnbaSet() { // for BPSNBA: set run, position, freqs, run_notches // call this upon change in RXA_mode, snba_run, notch_master_run - BPSNBA *a = rxa.bpsnba; - switch (rxa.mode) + BPSNBA *a = bpsnba; + switch (mode) { case RXA_LSB: case RXA_CWL: case RXA_DIGL: - a->run = rxa.snba->run; - a->position = 0; - break; case RXA_USB: case RXA_CWU: case RXA_DIGU: - a->run = rxa.snba->run; + a->run = snba->run; a->position = 0; break; - case RXA_AM: - case RXA_SAM: case RXA_DSB: - a->run = rxa.snba->run; - a->position = 1; - break; + case RXA_AM: case RXA_FM: - a->run = rxa.snba->run; + a->run = snba->run; a->position = 1; break; + case RXA_SAM: case RXA_DRM: case RXA_SPEC: a->run = 0; break; + default: + break; } FIRCORE::setUpdate_fircore (a->bpsnba->fircore); } -void RXA::UpdateNBPFiltersLightWeight (RXA& rxa) +void RXA::updateNBPFiltersLightWeight() { // called when setting tune freq or shift freq - rxa.nbp0->calc_lightweight(); - rxa.bpsnba->bpsnba->calc_lightweight(); + nbp0->calc_lightweight(); + bpsnba->bpsnba->calc_lightweight(); } -void RXA::UpdateNBPFilters(RXA& rxa) +void RXA::updateNBPFilters() { - NBP *a = rxa.nbp0; - BPSNBA *b = rxa.bpsnba; + NBP *a = nbp0; + BPSNBA *b = bpsnba; if (a->fnfrun) { a->calc_impulse(); @@ -1092,273 +1013,268 @@ void RXA::UpdateNBPFilters(RXA& rxa) } } -int RXA::NBPAddNotch (RXA& rxa, int notch, double fcenter, double fwidth, int active) +int RXA::nbpAddNotch(int _notch, double _fcenter, double _fwidth, int _active) { - NOTCHDB *b = rxa.ndb; - int rval = b->addNotch(notch, fcenter, fwidth, active); + NOTCHDB *b = ndb; + int rval = b->addNotch(_notch, _fcenter, _fwidth, _active); if (rval == 0) { - RXA::UpdateNBPFilters (rxa); + updateNBPFilters(); } return rval; } -int RXA::NBPGetNotch (RXA& rxa, int notch, double* fcenter, double* fwidth, int* active) +int RXA::nbpGetNotch(int _notch, double* _fcenter, double* _fwidth, int* _active) { - NOTCHDB *a = rxa.ndb; - int rval = a->getNotch(notch, fcenter, fwidth, active); + NOTCHDB *a = ndb; + int rval = a->getNotch(_notch, _fcenter, _fwidth, _active); return rval; } -int RXA::NBPDeleteNotch (RXA& rxa, int notch) +int RXA::nbpDeleteNotch(int _notch) { - NOTCHDB *a = rxa.ndb; - int rval = a->deleteNotch(notch); + NOTCHDB *a = ndb; + int rval = a->deleteNotch(_notch); if (rval == 0) { - RXA::UpdateNBPFilters (rxa); + updateNBPFilters(); } return rval; } -int RXA::NBPEditNotch (RXA& rxa, int notch, double fcenter, double fwidth, int active) +int RXA::nbpEditNotch(int _notch, double _fcenter, double _fwidth, int _active) { - NOTCHDB *a = rxa.ndb; - int rval = a->editNotch(notch, fcenter, fwidth, active); + NOTCHDB *a = ndb; + int rval = a->editNotch(_notch, _fcenter, _fwidth, _active); if (rval == 0) { - RXA::UpdateNBPFilters (rxa); + updateNBPFilters(); } return rval; } -void RXA::NBPGetNumNotches (RXA& rxa, int* nnotches) +void RXA::nbpGetNumNotches(int* _nnotches) { - NOTCHDB *a = rxa.ndb; - a->getNumNotches(nnotches); + const NOTCHDB *a = ndb; + a->getNumNotches(_nnotches); } -void RXA::NBPSetTuneFrequency (RXA& rxa, double tunefreq) +void RXA::nbpSetTuneFrequency(double _tunefreq) { NOTCHDB *a; - a = rxa.ndb; + a = ndb; - if (tunefreq != a->tunefreq) + if (_tunefreq != a->tunefreq) { - a->tunefreq = tunefreq; - RXA::UpdateNBPFiltersLightWeight (rxa); + a->tunefreq = _tunefreq; + updateNBPFiltersLightWeight(); } } -void RXA::NBPSetShiftFrequency (RXA& rxa, double shift) +void RXA::nbpSetShiftFrequency(double _shift) { NOTCHDB *a; - a = rxa.ndb; - if (shift != a->shift) + a = ndb; + if (_shift != a->shift) { - a->shift = shift; - RXA::UpdateNBPFiltersLightWeight (rxa); + a->shift = _shift; + updateNBPFiltersLightWeight(); } } -void RXA::NBPSetNotchesRun (RXA& rxa, int run) +void RXA::nbpSetNotchesRun(int _run) { - NOTCHDB *a = rxa.ndb; - NBP *b = rxa.nbp0; + NOTCHDB *a = ndb; + NBP *b = nbp0; - if ( run != a->master_run) + if ( _run != a->master_run) { - a->master_run = run; // update variables + a->master_run = _run; // update variables b->fnfrun = a->master_run; - RXA::bpsnbaCheck (rxa, rxa.mode, run); + bpsnbaCheck(mode, _run); b->calc_impulse(); // recalc nbp impulse response FIRCORE::setImpulse_fircore (b->fircore, b->impulse, 0); // calculate new filter masks delete[] (b->impulse); - RXA::bpsnbaSet (rxa); + bpsnbaSet(); FIRCORE::setUpdate_fircore (b->fircore); // apply new filter masks } } -void RXA::NBPSetWindow (RXA& rxa, int wintype) +void RXA::nbpSetWindow(int _wintype) { NBP *a; BPSNBA *b; - a = rxa.nbp0; - b = rxa.bpsnba; + a = nbp0; + b = bpsnba; - if ((a->wintype != wintype)) + if ((a->wintype != _wintype)) { - a->wintype = wintype; + a->wintype = _wintype; a->calc_impulse(); FIRCORE::setImpulse_fircore (a->fircore, a->impulse, 1); delete[] (a->impulse); } - if ((b->wintype != wintype)) + if ((b->wintype != _wintype)) { - b->wintype = wintype; + b->wintype = _wintype; b->recalc_bpsnba_filter(1); } } -void RXA::NBPSetAutoIncrease (RXA& rxa, int autoincr) +void RXA::nbpSetAutoIncrease(int _autoincr) { NBP *a; BPSNBA *b; - a = rxa.nbp0; - b = rxa.bpsnba; + a = nbp0; + b = bpsnba; - if ((a->autoincr != autoincr)) + if ((a->autoincr != _autoincr)) { - a->autoincr = autoincr; + a->autoincr = _autoincr; a->calc_impulse(); FIRCORE::setImpulse_fircore (a->fircore, a->impulse, 1); delete[] (a->impulse); } - if ((b->autoincr != autoincr)) + if ((b->autoincr != _autoincr)) { - b->autoincr = autoincr; + b->autoincr = _autoincr; b->recalc_bpsnba_filter(1); } } -void RXA::SetAMDRun(RXA& rxa, int run) +void RXA::setAMDRun(int _run) { - if (rxa.amd->run != run) + if (amd->run != _run) { - RXA::bp1Check ( - rxa, - run, - rxa.snba->run, - rxa.emnr->run, - rxa.anf->run, - rxa.anr->run + bp1Check ( + _run, + snba->run, + emnr->run, + anf->run, + anr->run ); - rxa.amd->run = run; - RXA::bp1Set (rxa); + amd->run = _run; + bp1Set(); } } -void RXA::SetSNBARun (RXA& rxa, int run) +void RXA::setSNBARun(int _run) { - SNBA *a = rxa.snba; + SNBA *a = snba; - if (a->run != run) + if (a->run != _run) { - RXA::bpsnbaCheck (rxa, rxa.mode, rxa.ndb->master_run); - RXA::bp1Check ( - rxa, - rxa.amd->run, - run, - rxa.emnr->run, - rxa.anf->run, - rxa.anr->run + bpsnbaCheck(mode, ndb->master_run); + bp1Check( + amd->run, + _run, + emnr->run, + anf->run, + anr->run ); - a->run = run; - RXA::bp1Set (rxa); - RXA::bpsnbaSet (rxa); + a->run = _run; + bp1Set(); + bpsnbaSet(); } } -void RXA::SetANFRun (RXA& rxa, int run) +void RXA::setANFRun(int _run) { - ANF *a = rxa.anf; + ANF *a = anf; - if (a->run != run) + if (a->run != _run) { - RXA::bp1Check ( - rxa, - rxa.amd->run, - rxa.snba->run, - rxa.emnr->run, - run, - rxa.anr->run + bp1Check ( + amd->run, + snba->run, + emnr->run, + _run, + anr->run ); - a->run = run; - RXA::bp1Set (rxa); + a->run = _run; + bp1Set(); a->flush(); } } -void RXA::SetANFPosition (RXA& rxa, int position) +void RXA::setANFPosition(int _position) { - rxa.anf->position = position; - rxa.bp1->position = position; - rxa.anf->flush(); + anf->position = _position; + bp1->position = _position; + anf->flush(); } -void RXA::SetANRRun (RXA& rxa, int run) +void RXA::setANRRun(int _run) { - ANR *a = rxa.anr; + ANR *a = anr; - if (a->run != run) + if (a->run != _run) { - RXA::bp1Check ( - rxa, - rxa.amd->run, - rxa.snba->run, - rxa.emnr->run, - rxa.anf->run, - run + bp1Check ( + amd->run, + snba->run, + emnr->run, + anf->run, + _run ); - a->run = run; - RXA::bp1Set (rxa); + a->run = _run; + bp1Set(); a->flush(); } } -void RXA::SetANRPosition (RXA& rxa, int position) +void RXA::setANRPosition(int _position) { - rxa.anr->position = position; - rxa.bp1->position = position; - rxa.anr->flush(); + anr->position = _position; + bp1->position = _position; + anr->flush(); } -void RXA::SetEMNRRun (RXA& rxa, int run) +void RXA::setEMNRRun(int _run) { - EMNR *a = rxa.emnr; + EMNR *a = emnr; - if (a->run != run) + if (a->run != _run) { - RXA::bp1Check ( - rxa, - rxa.amd->run, - rxa.snba->run, - run, - rxa.anf->run, - rxa.anr->run + bp1Check ( + amd->run, + snba->run, + _run, + anf->run, + anr->run ); - a->run = run; - RXA::bp1Set (rxa); + a->run = _run; + bp1Set(); } } -void RXA::SetEMNRPosition (RXA& rxa, int position) +void RXA::setEMNRPosition(int _position) { - rxa.emnr->position = position; - rxa.bp1->position = position; + emnr->position = _position; + bp1->position = _position; } -void RXA::GetAGCThresh(RXA& rxa, double *thresh, double size, double rate) +void RXA::getAGCThresh(double *_thresh, double _size, double _rate) //for line on bandscope. { double noise_offset; - noise_offset = 10.0 * log10((rxa.nbp0->fhigh - rxa.nbp0->flow) * size / rate); - *thresh = 20.0 * log10( rxa.agc->min_volts ) - noise_offset; + noise_offset = 10.0 * log10((nbp0->fhigh - nbp0->flow) * _size / _rate); + *_thresh = 20.0 * log10( agc->min_volts ) - noise_offset; } -void RXA::SetAGCThresh(RXA& rxa, double thresh, double size, double rate) +void RXA::setAGCThresh(double _thresh, double _size, double _rate) //for line on bandscope { double noise_offset; - noise_offset = 10.0 * log10((rxa.nbp0->fhigh - rxa.nbp0->flow) * size / rate); - rxa.agc->max_gain = rxa.agc->out_target / (rxa.agc->var_gain * pow (10.0, (thresh + noise_offset) / 20.0)); - rxa.agc->loadWcpAGC(); + noise_offset = 10.0 * log10((nbp0->fhigh - nbp0->flow) * _size / _rate); + agc->max_gain = agc->out_target / (agc->var_gain * pow (10.0, (_thresh + noise_offset) / 20.0)); + agc->loadWcpAGC(); } /******************************************************************************************************** @@ -1367,35 +1283,35 @@ void RXA::SetAGCThresh(RXA& rxa, double thresh, double size, double rate) * * ********************************************************************************************************/ -void RXA::SetPassband (RXA& rxa, float f_low, float f_high) +void RXA::setPassband(float _f_low, float _f_high) { - rxa.bp1->setBandpassFreqs (f_low, f_high); // After spectral noise reduction ( AM || ANF || ANR || EMNR) - rxa.snba->setOutputBandwidth (f_low, f_high); // Spectral noise blanker (SNB) - rxa.nbp0->SetFreqs (f_low, f_high); // Notched bandpass + bp1->setBandpassFreqs (_f_low, _f_high); // After spectral noise reduction ( AM || ANF || ANR || EMNR) + snba->setOutputBandwidth (_f_low, _f_high); // Spectral noise blanker (SNB) + nbp0->SetFreqs (_f_low, _f_high); // Notched bandpass } -void RXA::SetNC (RXA& rxa, int nc) +void RXA::setNC(int _nc) { - int oldstate = rxa.state; - rxa.nbp0->SetNC (nc); - rxa.bpsnba->SetNC (nc); - rxa.bp1->SetBandpassNC (nc); - rxa.eqp->setNC (nc); - rxa.fmsq->setNC (nc); - rxa.fmd->setNCde (nc); - rxa.fmd->setNCaud (nc); - rxa.state = oldstate; + int oldstate = state; + nbp0->SetNC (_nc); + bpsnba->SetNC (_nc); + bp1->SetBandpassNC (_nc); + eqp->setNC (_nc); + fmsq->setNC (_nc); + fmd->setNCde (_nc); + fmd->setNCaud (_nc); + state = oldstate; } -void RXA::SetMP (RXA& rxa, int mp) +void RXA::setMP(int _mp) { - rxa.nbp0->SetMP (mp); - rxa.bpsnba->SetMP (mp); - rxa.bp1->SetBandpassMP (mp); - rxa.eqp->setMP (mp); - rxa.fmsq->setMP (mp); - rxa.fmd->setMPde (mp); - rxa.fmd->setMPaud (mp); + nbp0->SetMP (_mp); + bpsnba->SetMP (_mp); + bp1->SetBandpassMP (_mp); + eqp->setMP (_mp); + fmsq->setMP (_mp); + fmd->setMPde (_mp); + fmd->setMPaud (_mp); } } // namespace WDSP diff --git a/wdsp/RXA.hpp b/wdsp/RXA.hpp index 629a9374e..1f1fc6b0a 100644 --- a/wdsp/RXA.hpp +++ b/wdsp/RXA.hpp @@ -128,70 +128,68 @@ public: PANEL *panel; RESAMPLE *rsmpout; - static RXA* create_rxa ( + RXA( int in_rate, // input samplerate int out_rate, // output samplerate int dsp_rate, // sample rate for mainstream dsp processing int dsp_size // number complex samples processed per buffer in mainstream dsp processing ); - static void destroy_rxa (RXA *rxa); - static void flush_rxa (RXA *rxa); - static void xrxa (RXA *rxa); - int get_insize() const { return dsp_insize; } - int get_outsize() const { return dsp_outsize; } - float *get_inbuff() { return inbuff; } - float *get_outbuff() { return outbuff; } + RXA(const RXA&) = delete; + RXA& operator=(const RXA& other) = delete; + ~RXA(); + + void flush(); + void execute(); + void setInputSamplerate(int _in_rate); + void setOutputSamplerate(int _out_rate); + void setDSPSamplerate(int _dsp_rate); + void setDSPBuffsize(int _dsp_size); + int get_insize() const { return Unit::dsp_insize; } + int get_outsize() const { return Unit::dsp_outsize; } + float *get_inbuff() { return Unit::inbuff; } + float *get_outbuff() { return Unit::outbuff; } void setSpectrumProbe(BufferProbe *_spectrumProbe); - static void setInputSamplerate (RXA *rxa, int in_rate); - static void setOutputSamplerate (RXA *rxa, int out_rate); - static void setDSPSamplerate (RXA *rxa, int dsp_rate); - static void setDSPBuffsize (RXA *rxa, int dsp_size); // RXA Properties - static void SetMode (RXA& rxa, int mode); - static void ResCheck (RXA& rxa); - static void bp1Check (RXA& rxa, int amd_run, int snba_run, int emnr_run, int anf_run, int anr_run); - static void bp1Set (RXA& rxa); - static void bpsnbaCheck (RXA& rxa, int mode, int notch_run); - static void bpsnbaSet (RXA& rxa); + void setMode (int mode); + void resCheck (); + void bp1Check (int amd_run, int snba_run, int emnr_run, int anf_run, int anr_run); + void bp1Set (); + void bpsnbaCheck (int mode, int notch_run); + void bpsnbaSet (); // NOTCHDB, NBP, SNBA - static void UpdateNBPFiltersLightWeight (RXA& rxa); - static void UpdateNBPFilters(RXA& rxa); - static int NBPAddNotch (RXA& rxa, int notch, double fcenter, double fwidth, int active); - static int NBPGetNotch (RXA& rxa, int notch, double* fcenter, double* fwidth, int* active); - static int NBPDeleteNotch (RXA& rxa, int notch); - static int NBPEditNotch (RXA& rxa, int notch, double fcenter, double fwidth, int active); - static void NBPGetNumNotches (RXA& rxa, int* nnotches); - static void NBPSetTuneFrequency (RXA& rxa, double tunefreq); - static void NBPSetShiftFrequency (RXA& rxa, double shift); - static void NBPSetNotchesRun (RXA& rxa, int run); - static void NBPSetWindow (RXA& rxa, int wintype); - static void NBPSetAutoIncrease (RXA& rxa, int autoincr); + void updateNBPFiltersLightWeight(); + void updateNBPFilters(); + int nbpAddNotch(int notch, double fcenter, double fwidth, int active); + int nbpGetNotch(int notch, double* fcenter, double* fwidth, int* active); + int nbpDeleteNotch(int notch); + int nbpEditNotch(int notch, double fcenter, double fwidth, int active); + void nbpGetNumNotches(int* nnotches); + void nbpSetTuneFrequency(double tunefreq); + void nbpSetShiftFrequency(double shift); + void nbpSetNotchesRun(int run); + void nbpSetWindow(int wintype); + void nbpSetAutoIncrease(int autoincr); // AMD - static void SetAMDRun(RXA& rxa, int run); + void setAMDRun(int run); // SNBA - static void SetSNBARun (RXA& rxa, int run); + void setSNBARun(int run); // ANF - static void SetANFRun (RXA& rxa, int run); - static void SetANFPosition (RXA& rxa, int position); + void setANFRun(int run); + void setANFPosition(int position); // ANR - static void SetANRRun (RXA& rxa, int run); - static void SetANRPosition (RXA& rxa, int position); + void setANRRun(int run); + void setANRPosition(int position); // EMNR - static void SetEMNRRun (RXA& rxa, int run); - static void SetEMNRPosition (RXA& rxa, int position); + void setEMNRRun(int run); + void setEMNRPosition(int position); // WCPAGC - static void SetAGCThresh(RXA& rxa, double thresh, double size, double rate); - static void GetAGCThresh(RXA& rxa, double *thresh, double size, double rate); + void setAGCThresh(double thresh, double size, double rate); + void getAGCThresh(double *thresh, double size, double rate); // Collectives - static void SetPassband (RXA& rxa, float f_low, float f_high); - static void SetNC (RXA& rxa, int nc); - static void SetMP (RXA& rxa, int mp); - -private: - float* inbuff; - float* midbuff; - float* outbuff; + void setPassband(float f_low, float f_high); + void setNC(int nc); + void setMP(int mp); }; } // namespace WDSP diff --git a/wdsp/TXA.cpp b/wdsp/TXA.cpp index ac8f9285b..8532a0c6f 100644 --- a/wdsp/TXA.cpp +++ b/wdsp/TXA.cpp @@ -53,97 +53,82 @@ warren@wpratt.com namespace WDSP { -TXA* TXA::create_txa ( - int in_rate, // input samplerate - int out_rate, // output samplerate - int dsp_rate, // sample rate for mainstream dsp processing - int dsp_size // number complex samples processed per buffer in mainstream dsp processing +TXA::TXA( + int _in_rate, // input samplerate + int _out_rate, // output samplerate + int _dsp_rate, // sample rate for mainstream dsp processing + int _dsp_size // number complex samples processed per buffer in mainstream dsp processing +) : Unit( + _in_rate, + _out_rate, + _dsp_rate, + _dsp_size ) { - TXA *txa = new TXA; + mode = TXA_LSB; + f_low = -5000.0; + f_high = - 100.0; - txa->in_rate = in_rate; - txa->out_rate = out_rate; - txa->dsp_rate = dsp_rate; - txa->dsp_size = dsp_size; - - if (in_rate >= dsp_rate) - txa->dsp_insize = dsp_size * (in_rate / dsp_rate); - else - txa->dsp_insize = dsp_size / (dsp_rate / in_rate); - - if (out_rate >= dsp_rate) - txa->dsp_outsize = dsp_size * (out_rate / dsp_rate); - else - txa->dsp_outsize = dsp_size / (dsp_rate / out_rate); - - txa->mode = TXA_LSB; - txa->f_low = -5000.0; - txa->f_high = - 100.0; - txa->inbuff = new float[1 * txa->dsp_insize * 2]; // (float *) malloc0 (1 * txa->dsp_insize * 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->rsmpin = new RESAMPLE( + rsmpin = new RESAMPLE( 0, // run - will be turned on below if needed - txa->dsp_insize, // input buffer size - txa->inbuff, // pointer to input buffer - txa->midbuff, // pointer to output buffer - txa->in_rate, // input sample rate - txa->dsp_rate, // output sample rate + dsp_insize, // input buffer size + inbuff, // pointer to input buffer + midbuff, // pointer to output buffer + in_rate, // input sample rate + dsp_rate, // output sample rate 0.0, // select cutoff automatically 0, // select ncoef automatically 1.0); // gain - txa->gen0 = new GEN( + gen0 = new GEN( 0, // run - txa->dsp_size, // buffer size - txa->midbuff, // input buffer - txa->midbuff, // output buffer - txa->dsp_rate, // sample rate + dsp_size, // buffer size + midbuff, // input buffer + midbuff, // output buffer + dsp_rate, // sample rate 2); // mode - txa->panel = new PANEL( + panel = new PANEL( 1, // run - txa->dsp_size, // size - txa->midbuff, // pointer to input buffer - txa->midbuff, // pointer to output buffer + dsp_size, // size + midbuff, // pointer to input buffer + midbuff, // pointer to output buffer 1.0, // gain1 1.0, // gain2I 1.0, // gain2Q 2, // 1 to use Q, 2 to use I for input 0); // 0, no copy - txa->phrot = new PHROT( + phrot = new PHROT( 0, // run - txa->dsp_size, // size - txa->midbuff, // input buffer - txa->midbuff, // output buffer - txa->dsp_rate, // samplerate + dsp_size, // size + midbuff, // input buffer + midbuff, // output buffer + dsp_rate, // samplerate 338.0, // 1/2 of phase frequency 8); // number of stages - txa->micmeter = new METER( + micmeter = new METER( 1, // run - 0, // optional pointer to another 'run' - txa->dsp_size, // size - txa->midbuff, // pointer to buffer - txa->dsp_rate, // samplerate + nullptr, // optional pointer to another 'run' + dsp_size, // size + midbuff, // pointer to buffer + dsp_rate, // samplerate 0.100, // averaging time constant 0.100, // peak decay time constant - txa->meter, // result vector + meter, // result vector TXA_MIC_AV, // index for average value TXA_MIC_PK, // index for peak value -1, // index for gain value - 0); // pointer for gain computation + nullptr); // pointer for gain computation - txa->amsq = new AMSQ( + amsq = new AMSQ( 0, // run - txa->dsp_size, // size - txa->midbuff, // input buffer - txa->midbuff, // output buffer - txa->midbuff, // trigger buffer - txa->dsp_rate, // sample rate + dsp_size, // size + midbuff, // input buffer + midbuff, // output buffer + midbuff, // trigger buffer + dsp_rate, // sample rate 0.010, // time constant for averaging signal 0.004, // up-slew time 0.004, // down-slew time @@ -154,59 +139,59 @@ TXA* TXA::create_txa ( 0.200); // muted gain { - float default_F[11] = {0.0, 32.0, 63.0, 125.0, 250.0, 500.0, 1000.0, 2000.0, 4000.0, 8000.0, 16000.0}; - float default_G[11] = {0.0, -12.0, -12.0, -12.0, -1.0, +1.0, +4.0, +9.0, +12.0, -10.0, -10.0}; + std::array default_F = {0.0, 32.0, 63.0, 125.0, 250.0, 500.0, 1000.0, 2000.0, 4000.0, 8000.0, 16000.0}; + std::array default_G = {0.0, -12.0, -12.0, -12.0, -1.0, +1.0, +4.0, +9.0, +12.0, -10.0, -10.0}; //float default_G[11] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; - txa->eqp = new EQP ( + eqp = new EQP ( 0, // run - OFF by default - txa->dsp_size, // size - std::max(2048, txa->dsp_size), // number of filter coefficients + dsp_size, // size + std::max(2048, dsp_size), // number of filter coefficients 0, // minimum phase flag - txa->midbuff, // pointer to input buffer - txa->midbuff, // pointer to output buffer + midbuff, // pointer to input buffer + midbuff, // pointer to output buffer 10, // nfreqs - default_F, // vector of frequencies - default_G, // vector of gain values + default_F.data(), // vector of frequencies + default_G.data(), // vector of gain values 0, // cutoff mode 0, // wintype - txa->dsp_rate); // samplerate + dsp_rate); // samplerate } - txa->eqmeter = new METER( + eqmeter = new METER( 1, // run - &(txa->eqp->run), // pointer to eqp 'run' - txa->dsp_size, // size - txa->midbuff, // pointer to buffer - txa->dsp_rate, // samplerate + &(eqp->run), // pointer to eqp 'run' + dsp_size, // size + midbuff, // pointer to buffer + dsp_rate, // samplerate 0.100, // averaging time constant 0.100, // peak decay time constant - txa->meter, // result vector + meter, // result vector TXA_EQ_AV, // index for average value TXA_EQ_PK, // index for peak value -1, // index for gain value - 0); // pointer for gain computation + nullptr); // pointer for gain computation - txa->preemph = EMPHP::create_emphp ( + preemph = EMPHP::create_emphp ( 0, // run 1, // position - txa->dsp_size, // size - std::max(2048, txa->dsp_size), // number of filter coefficients + dsp_size, // size + std::max(2048, dsp_size), // number of filter coefficients 0, // minimum phase flag - txa->midbuff, // input buffer - txa->midbuff, // output buffer, - txa->dsp_rate, // sample rate + midbuff, // input buffer + midbuff, // output buffer, + dsp_rate, // sample rate 0, // pre-emphasis type 300.0, // f_low 3000.0); // f_high - txa->leveler = new WCPAGC( + leveler = new WCPAGC( 0, // run - OFF by default 5, // mode 0, // 0 for max(I,Q), 1 for envelope - txa->midbuff, // input buff pointer - txa->midbuff, // output buff pointer - txa->dsp_size, // io_buffsize - txa->dsp_rate, // sample rate + midbuff, // input buff pointer + midbuff, // output buff pointer + dsp_size, // io_buffsize + dsp_rate, // sample rate 0.001, // tau_attack 0.500, // tau_decay 6, // n_tau @@ -224,139 +209,139 @@ TXA* TXA::create_txa ( 2.000, // hang_thresh 0.100); // tau_hang_decay - txa->lvlrmeter = new METER( + lvlrmeter = new METER( 1, // run - &(txa->leveler->run), // pointer to leveler 'run' - txa->dsp_size, // size - txa->midbuff, // pointer to buffer - txa->dsp_rate, // samplerate + &(leveler->run), // pointer to leveler 'run' + dsp_size, // size + midbuff, // pointer to buffer + dsp_rate, // samplerate 0.100, // averaging time constant 0.100, // peak decay time constant - txa->meter, // result vector + meter, // result vector TXA_LVLR_AV, // index for average value TXA_LVLR_PK, // index for peak value TXA_LVLR_GAIN, // index for gain value - &txa->leveler->gain); // pointer for gain computation + &leveler->gain); // pointer for gain computation { - float default_F[5] = {200.0, 1000.0, 2000.0, 3000.0, 4000.0}; - float default_G[5] = {0.0, 5.0, 10.0, 10.0, 5.0}; - float default_E[5] = {7.0, 7.0, 7.0, 7.0, 7.0}; - txa->cfcomp = CFCOMP::create_cfcomp( + std::array default_F = {200.0, 1000.0, 2000.0, 3000.0, 4000.0}; + std::array default_G = { 0.0, 5.0, 10.0, 10.0, 5.0}; + std::array default_E = { 7.0, 7.0, 7.0, 7.0, 7.0}; + cfcomp = CFCOMP::create_cfcomp( 0, // run 0, // position 0, // post-equalizer run - txa->dsp_size, // size - txa->midbuff, // input buffer - txa->midbuff, // output buffer + dsp_size, // size + midbuff, // input buffer + midbuff, // output buffer 2048, // fft size 4, // overlap - txa->dsp_rate, // samplerate + dsp_rate, // samplerate 1, // window type 0, // compression method 5, // nfreqs 0.0, // pre-compression 0.0, // pre-postequalization - default_F, // frequency array - default_G, // compression array - default_E, // eq array + default_F.data(), // frequency array + default_G.data(), // compression array + default_E.data(), // eq array 0.25, // metering time constant 0.50); // display time constant } - txa->cfcmeter = new METER( + cfcmeter = new METER( 1, // run - &(txa->cfcomp->run), // pointer to eqp 'run' - txa->dsp_size, // size - txa->midbuff, // pointer to buffer - txa->dsp_rate, // samplerate + &(cfcomp->run), // pointer to eqp 'run' + dsp_size, // size + midbuff, // pointer to buffer + dsp_rate, // samplerate 0.100, // averaging time constant 0.100, // peak decay time constant - txa->meter, // result vector + meter, // result vector TXA_CFC_AV, // index for average value TXA_CFC_PK, // index for peak value TXA_CFC_GAIN, // index for gain value - (double*) &txa->cfcomp->gain); // pointer for gain computation + (double*) &cfcomp->gain); // pointer for gain computation - txa->bp0 = new BANDPASS( + bp0 = new BANDPASS( 1, // always runs 0, // position - txa->dsp_size, // size - std::max(2048, txa->dsp_size), // number of coefficients + dsp_size, // size + std::max(2048, dsp_size), // number of coefficients 0, // flag for minimum phase - txa->midbuff, // pointer to input buffer - txa->midbuff, // pointer to output buffer - txa->f_low, // low freq cutoff - txa->f_high, // high freq cutoff - txa->dsp_rate, // samplerate + midbuff, // pointer to input buffer + midbuff, // pointer to output buffer + f_low, // low freq cutoff + f_high, // high freq cutoff + dsp_rate, // samplerate 1, // wintype 2.0); // gain - txa->compressor = COMPRESSOR::create_compressor ( + compressor = COMPRESSOR::create_compressor ( 0, // run - OFF by default - txa->dsp_size, // size - txa->midbuff, // pointer to input buffer - txa->midbuff, // pointer to output buffer + dsp_size, // size + midbuff, // pointer to input buffer + midbuff, // pointer to output buffer 3.0); // gain - txa->bp1 = new BANDPASS( + bp1 = new BANDPASS( 0, // ONLY RUNS WHEN COMPRESSOR IS USED 0, // position - txa->dsp_size, // size - std::max(2048, txa->dsp_size), // number of coefficients + dsp_size, // size + std::max(2048, dsp_size), // number of coefficients 0, // flag for minimum phase - txa->midbuff, // pointer to input buffer - txa->midbuff, // pointer to output buffer - txa->f_low, // low freq cutoff - txa->f_high, // high freq cutoff - txa->dsp_rate, // samplerate + midbuff, // pointer to input buffer + midbuff, // pointer to output buffer + f_low, // low freq cutoff + f_high, // high freq cutoff + dsp_rate, // samplerate 1, // wintype 2.0); // gain - txa->osctrl = OSCTRL::create_osctrl ( + osctrl = OSCTRL::create_osctrl ( 0, // run - txa->dsp_size, // size - txa->midbuff, // input buffer - txa->midbuff, // output buffer - txa->dsp_rate, // sample rate - 1.95); // gain for clippings + dsp_size, // size + midbuff, // input buffer + midbuff, // output buffer + dsp_rate, // sample rate + 1.95f); // gain for clippings - txa->bp2 = new BANDPASS( + bp2 = new BANDPASS( 0, // ONLY RUNS WHEN COMPRESSOR IS USED 0, // position - txa->dsp_size, // size - std::max(2048, txa->dsp_size), // number of coefficients + dsp_size, // size + std::max(2048, dsp_size), // number of coefficients 0, // flag for minimum phase - txa->midbuff, // pointer to input buffer - txa->midbuff, // pointer to output buffer - txa->f_low, // low freq cutoff - txa->f_high, // high freq cutoff - txa->dsp_rate, // samplerate + midbuff, // pointer to input buffer + midbuff, // pointer to output buffer + f_low, // low freq cutoff + f_high, // high freq cutoff + dsp_rate, // samplerate 1, // wintype 1.0); // gain - txa->compmeter = new METER( + compmeter = new METER( 1, // run - &(txa->compressor->run), // pointer to compressor 'run' - txa->dsp_size, // size - txa->midbuff, // pointer to buffer - txa->dsp_rate, // samplerate + &(compressor->run), // pointer to compressor 'run' + dsp_size, // size + midbuff, // pointer to buffer + dsp_rate, // samplerate 0.100, // averaging time constant 0.100, // peak decay time constant - txa->meter, // result vector + meter, // result vector TXA_COMP_AV, // index for average value TXA_COMP_PK, // index for peak value -1, // index for gain value - 0); // pointer for gain computation + nullptr); // pointer for gain computation - txa->alc = new WCPAGC( + alc = new WCPAGC( 1, // run - always ON 5, // mode 1, // 0 for max(I,Q), 1 for envelope - txa->midbuff, // input buff pointer - txa->midbuff, // output buff pointer - txa->dsp_size, // io_buffsize - txa->dsp_rate, // sample rate + midbuff, // input buff pointer + midbuff, // output buff pointer + dsp_size, // io_buffsize + dsp_rate, // sample rate 0.001, // tau_attack 0.010, // tau_decay 6, // n_tau @@ -374,70 +359,70 @@ TXA* TXA::create_txa ( 2.000, // hang_thresh 0.100); // tau_hang_decay - txa->ammod = AMMOD::create_ammod ( + ammod = AMMOD::create_ammod ( 0, // run - OFF by default 0, // mode: 0=>AM, 1=>DSB - txa->dsp_size, // size - txa->midbuff, // pointer to input buffer - txa->midbuff, // pointer to output buffer + dsp_size, // size + midbuff, // pointer to input buffer + midbuff, // pointer to output buffer 0.5); // carrier level - txa->fmmod = FMMOD::create_fmmod ( + fmmod = FMMOD::create_fmmod ( 0, // run - OFF by default - txa->dsp_size, // size - txa->midbuff, // pointer to input buffer - txa->midbuff, // pointer to input buffer - txa->dsp_rate, // samplerate + dsp_size, // size + midbuff, // pointer to input buffer + midbuff, // pointer to input buffer + dsp_rate, // samplerate 5000.0, // deviation 300.0, // low cutoff frequency 3000.0, // high cutoff frequency 1, // ctcss run control - 0.10, // ctcss level + 0.10f, // ctcss level 100.0, // ctcss frequency 1, // run bandpass filter - std::max(2048, txa->dsp_size), // number coefficients for bandpass filter + std::max(2048, dsp_size), // number coefficients for bandpass filter 0); // minimum phase flag - txa->gen1 = new GEN( + gen1 = new GEN( 0, // run - txa->dsp_size, // buffer size - txa->midbuff, // input buffer - txa->midbuff, // output buffer - txa->dsp_rate, // sample rate + dsp_size, // buffer size + midbuff, // input buffer + midbuff, // output buffer + dsp_rate, // sample rate 0); // mode - txa->uslew = USLEW::create_uslew ( - txa, - &(txa->upslew), // pointer to channel upslew flag - txa->dsp_size, // buffer size - txa->midbuff, // input buffer - txa->midbuff, // output buffer - txa->dsp_rate, // sample rate + uslew = USLEW::create_uslew ( + this, + &upslew, // pointer to channel upslew flag + dsp_size, // buffer size + midbuff, // input buffer + midbuff, // output buffer + (float) dsp_rate, // sample rate 0.000, // delay time - 0.005); // upslew time + 0.005f); // upslew time - txa->alcmeter = new METER( + alcmeter = new METER( 1, // run - 0, // optional pointer to a 'run' - txa->dsp_size, // size - txa->midbuff, // pointer to buffer - txa->dsp_rate, // samplerate + nullptr, // optional pointer to a 'run' + dsp_size, // size + midbuff, // pointer to buffer + dsp_rate, // samplerate 0.100, // averaging time constant 0.100, // peak decay time constant - txa->meter, // result vector + meter, // result vector TXA_ALC_AV, // index for average value TXA_ALC_PK, // index for peak value TXA_ALC_GAIN, // index for gain value - &txa->alc->gain); // pointer for gain computation + &alc->gain); // pointer for gain computation - txa->sip1 = new SIPHON( + sip1 = new SIPHON( 1, // run 0, // position 0, // mode 0, // disp - txa->dsp_size, // input buffer size - txa->midbuff, // input buffer + dsp_size, // input buffer size + midbuff, // input buffer 16384, // number of samples to buffer 16384, // fft size for spectrum 1); // specmode @@ -446,7 +431,7 @@ TXA* TXA::create_txa ( // channel, // channel number // 1, // run calibration // 1024, // input buffer size - // txa->in_rate, // samplerate + // in_rate, // samplerate // 16, // ints // 256, // spi // (1.0 / 0.4072), // hw_scale @@ -461,25 +446,25 @@ TXA* TXA::create_txa ( // 256, // pin samples // 0.9); // alpha - txa->iqc.p0 = txa->iqc.p1 = IQC::create_iqc ( + iqc.p0 = iqc.p1 = IQC::create_iqc ( 0, // run - txa->dsp_size, // size - txa->midbuff, // input buffer - txa->midbuff, // output buffer - (float)txa->dsp_rate, // sample rate + dsp_size, // size + midbuff, // input buffer + midbuff, // output buffer + (float)dsp_rate, // sample rate 16, // ints - 0.005, // changeover time + 0.005f, // changeover time 256); // spi - txa->cfir = CFIR::create_cfir( + cfir = CFIR::create_cfir( 0, // run - txa->dsp_size, // size - std::max(2048, txa->dsp_size), // number of filter coefficients + dsp_size, // size + std::max(2048, dsp_size), // number of filter coefficients 0, // minimum phase flag - txa->midbuff, // input buffer - txa->midbuff, // output buffer - txa->dsp_rate, // input sample rate - txa->out_rate, // CIC input sample rate + midbuff, // input buffer + midbuff, // output buffer + dsp_rate, // input sample rate + out_rate, // CIC input sample rate 1, // CIC differential delay 640, // CIC interpolation factor 5, // CIC integrator-comb pairs @@ -488,334 +473,277 @@ TXA* TXA::create_txa ( 0.0, // raised-cosine transition width 0); // window type - txa->rsmpout = new RESAMPLE( + rsmpout = new RESAMPLE( 0, // run - will be turned ON below if needed - txa->dsp_size, // input size - txa->midbuff, // pointer to input buffer - txa->outbuff, // pointer to output buffer - txa->dsp_rate, // input sample rate - txa->out_rate, // output sample rate + dsp_size, // input size + midbuff, // pointer to input buffer + outbuff, // pointer to output buffer + dsp_rate, // input sample rate + out_rate, // output sample rate 0.0, // select cutoff automatically 0, // select ncoef automatically 0.980); // gain - txa->outmeter = new METER( + outmeter = new METER( 1, // run - 0, // optional pointer to another 'run' - txa->dsp_outsize, // size - txa->outbuff, // pointer to buffer - txa->out_rate, // samplerate + nullptr, // optional pointer to another 'run' + dsp_outsize, // size + outbuff, // pointer to buffer + out_rate, // samplerate 0.100, // averaging time constant 0.100, // peak decay time constant - txa->meter, // result vector + meter, // result vector TXA_OUT_AV, // index for average value TXA_OUT_PK, // index for peak value -1, // index for gain value - 0); // pointer for gain computation + nullptr); // pointer for gain computation // turn OFF / ON resamplers as needed - ResCheck (*txa); - return txa; + resCheck(); } -void TXA::destroy_txa (TXA *txa) +TXA::~TXA() { // in reverse order, free each item we created - delete (txa->outmeter); - delete (txa->rsmpout); - CFIR::destroy_cfir(txa->cfir); - // destroy_calcc (txa->calcc); - IQC::destroy_iqc (txa->iqc.p0); - delete (txa->sip1); - delete (txa->alcmeter); - USLEW::destroy_uslew (txa->uslew); - delete (txa->gen1); - FMMOD::destroy_fmmod (txa->fmmod); - AMMOD::destroy_ammod (txa->ammod); - delete (txa->alc); - delete (txa->compmeter); - delete (txa->bp2); - OSCTRL::destroy_osctrl (txa->osctrl); - delete (txa->bp1); - COMPRESSOR::destroy_compressor (txa->compressor); - delete (txa->bp0); - delete (txa->cfcmeter); - CFCOMP::destroy_cfcomp (txa->cfcomp); - delete (txa->lvlrmeter); - delete (txa->leveler); - EMPHP::destroy_emphp (txa->preemph); - delete (txa->eqmeter); - delete (txa->eqp); - delete (txa->amsq); - delete (txa->micmeter); - delete (txa->phrot); - delete (txa->panel); - delete (txa->gen0); - delete (txa->rsmpin); - delete[] (txa->midbuff); - delete[] (txa->outbuff); - delete[] (txa->inbuff); - delete txa; + delete outmeter; + delete rsmpout; + CFIR::destroy_cfir(cfir); + IQC::destroy_iqc (iqc.p0); + delete sip1; + delete alcmeter; + USLEW::destroy_uslew (uslew); + delete gen1; + FMMOD::destroy_fmmod (fmmod); + AMMOD::destroy_ammod (ammod); + delete alc; + delete compmeter; + delete bp2; + OSCTRL::destroy_osctrl (osctrl); + delete bp1; + COMPRESSOR::destroy_compressor (compressor); + delete bp0; + delete cfcmeter; + CFCOMP::destroy_cfcomp (cfcomp); + delete lvlrmeter; + delete leveler; + EMPHP::destroy_emphp (preemph); + delete eqmeter; + delete eqp; + delete amsq; + delete micmeter; + delete phrot; + delete panel; + delete gen0; + delete rsmpin; } -void TXA::flush_txa (TXA* txa) +void TXA::flush() { - 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); - txa->rsmpin->flush(); - txa->gen0->flush(); - txa->panel->flush (); - txa->phrot->flush(); - txa->micmeter->flush (); - txa->amsq->flush (); - txa->eqp->flush(); - txa->eqmeter->flush (); - EMPHP::flush_emphp (txa->preemph); - txa->leveler->flush(); - txa->lvlrmeter->flush (); - CFCOMP::flush_cfcomp (txa->cfcomp); - txa->cfcmeter->flush (); - txa->bp0->flush (); - COMPRESSOR::flush_compressor (txa->compressor); - txa->bp1->flush (); - OSCTRL::flush_osctrl (txa->osctrl); - txa->bp2->flush (); - txa->compmeter->flush (); - txa->alc->flush (); - AMMOD::flush_ammod (txa->ammod); - FMMOD::flush_fmmod (txa->fmmod); - txa->gen1->flush(); - USLEW::flush_uslew (txa->uslew); - txa->alcmeter->flush (); - txa->sip1->flush(); - IQC::flush_iqc (txa->iqc.p0); - CFIR::flush_cfir(txa->cfir); - txa->rsmpout->flush(); - txa->outmeter->flush (); + Unit::flushBuffers(); + rsmpin->flush(); + gen0->flush(); + panel->flush (); + phrot->flush(); + micmeter->flush (); + amsq->flush (); + eqp->flush(); + eqmeter->flush (); + EMPHP::flush_emphp (preemph); + leveler->flush(); + lvlrmeter->flush (); + CFCOMP::flush_cfcomp (cfcomp); + cfcmeter->flush (); + bp0->flush (); + COMPRESSOR::flush_compressor (compressor); + bp1->flush (); + OSCTRL::flush_osctrl (osctrl); + bp2->flush (); + compmeter->flush (); + alc->flush (); + AMMOD::flush_ammod (ammod); + FMMOD::flush_fmmod (fmmod); + gen1->flush(); + USLEW::flush_uslew (uslew); + alcmeter->flush (); + sip1->flush(); + IQC::flush_iqc (iqc.p0); + CFIR::flush_cfir(cfir); + rsmpout->flush(); + outmeter->flush (); } -void xtxa (TXA* txa) +void TXA::execute() { - txa->rsmpin->execute(); // input resampler - txa->gen0->execute(); // input signal generator - txa->panel->execute(); // includes MIC gain - txa->phrot->execute(); // phase rotator - txa->micmeter->execute (); // MIC meter - txa->amsq->xcap (); // downward expander capture - txa->amsq->execute (); // downward expander action - txa->eqp->execute (); // pre-EQ - txa->eqmeter->execute (); // EQ meter - EMPHP::xemphp (txa->preemph, 0); // FM pre-emphasis (first option) - txa->leveler->execute (); // Leveler - txa->lvlrmeter->execute (); // Leveler Meter - CFCOMP::xcfcomp (txa->cfcomp, 0); // Continuous Frequency Compressor with post-EQ - txa->cfcmeter->execute (); // CFC+PostEQ Meter - txa->bp0->execute (0); // primary bandpass filter - COMPRESSOR::xcompressor (txa->compressor); // COMP compressor - txa->bp1->execute (0); // aux bandpass (runs if COMP) - OSCTRL::xosctrl (txa->osctrl); // CESSB Overshoot Control - txa->bp2->execute (0); // aux bandpass (runs if CESSB) - txa->compmeter->execute (); // COMP meter - txa->alc->execute (); // ALC - AMMOD::xammod (txa->ammod); // AM Modulator - EMPHP::xemphp (txa->preemph, 1); // FM pre-emphasis (second option) - FMMOD::xfmmod (txa->fmmod); // FM Modulator - txa->gen1->execute(); // output signal generator (TUN and Two-tone) - USLEW::xuslew (txa->uslew); // up-slew for AM, FM, and gens - txa->alcmeter->execute (); // ALC Meter - txa->sip1->execute(0); // siphon data for display - IQC::xiqc (txa->iqc.p0); // PureSignal correction - CFIR::xcfir(txa->cfir); // compensating FIR filter (used Protocol_2 only) - txa->rsmpout->execute(); // output resampler - txa->outmeter->execute (); // output meter - // print_peak_env ("env_exception.txt", txa->dsp_outsize, txa->outbuff, 0.7); + rsmpin->execute(); // input resampler + gen0->execute(); // input signal generator + panel->execute(); // includes MIC gain + phrot->execute(); // phase rotator + micmeter->execute (); // MIC meter + amsq->xcap (); // downward expander capture + amsq->execute (); // downward expander action + eqp->execute (); // pre-EQ + eqmeter->execute (); // EQ meter + EMPHP::xemphp (preemph, 0); // FM pre-emphasis (first option) + leveler->execute (); // Leveler + lvlrmeter->execute (); // Leveler Meter + CFCOMP::xcfcomp (cfcomp, 0); // Continuous Frequency Compressor with post-EQ + cfcmeter->execute (); // CFC+PostEQ Meter + bp0->execute (0); // primary bandpass filter + COMPRESSOR::xcompressor (compressor); // COMP compressor + bp1->execute (0); // aux bandpass (runs if COMP) + OSCTRL::xosctrl (osctrl); // CESSB Overshoot Control + bp2->execute (0); // aux bandpass (runs if CESSB) + compmeter->execute (); // COMP meter + alc->execute (); // ALC + AMMOD::xammod (ammod); // AM Modulator + EMPHP::xemphp (preemph, 1); // FM pre-emphasis (second option) + FMMOD::xfmmod (fmmod); // FM Modulator + gen1->execute(); // output signal generator (TUN and Two-tone) + USLEW::xuslew (uslew); // up-slew for AM, FM, and gens + alcmeter->execute (); // ALC Meter + sip1->execute(0); // siphon data for display + IQC::xiqc (iqc.p0); // PureSignal correction + CFIR::xcfir(cfir); // compensating FIR filter (used Protocol_2 only) + rsmpout->execute(); // output resampler + outmeter->execute (); // output meter } -void TXA::setInputSamplerate (TXA *txa, int in_rate) +void TXA::setInputSamplerate(int in_rate) { - if (in_rate >= txa->dsp_rate) - txa->dsp_insize = txa->dsp_size * (in_rate / txa->dsp_rate); - else - txa->dsp_insize = txa->dsp_size / (txa->dsp_rate / in_rate); - - txa->in_rate = in_rate; - // buffers - delete[] (txa->inbuff); - txa->inbuff = new float[1 * txa->dsp_insize * 2]; //(float *)malloc0(1 * txa->dsp_insize * sizeof(complex)); + Unit::setBuffersInputSamplerate(in_rate); // input resampler - txa->rsmpin->setBuffers(txa->inbuff, txa->midbuff); - txa->rsmpin->setSize(txa->dsp_insize); - txa->rsmpin->setInRate(txa->in_rate); - ResCheck (*txa); + rsmpin->setBuffers(inbuff, midbuff); + rsmpin->setSize(dsp_insize); + rsmpin->setInRate(in_rate); + resCheck(); } -void TXA::setOutputSamplerate (TXA* txa, int out_rate) +void TXA::setOutputSamplerate(int out_rate) { - if (out_rate >= txa->dsp_rate) - txa->dsp_outsize = txa->dsp_size * (out_rate / txa->dsp_rate); - else - txa->dsp_outsize = txa->dsp_size / (txa->dsp_rate / out_rate); - - txa->out_rate = out_rate; - // buffers - delete[] (txa->outbuff); - txa->outbuff = new float[1 * txa->dsp_outsize * 2]; // (float *)malloc0(1 * txa->dsp_outsize * sizeof(complex)); + Unit::setBuffersOutputSamplerate(out_rate); // cfir - needs to know input rate of firmware CIC - CFIR::setOutRate_cfir (txa->cfir, txa->out_rate); + CFIR::setOutRate_cfir (cfir, out_rate); // output resampler - txa->rsmpout->setBuffers(txa->midbuff, txa->outbuff); - txa->rsmpout->setOutRate(txa->out_rate); - ResCheck (*txa); + rsmpout->setBuffers(midbuff, outbuff); + rsmpout->setOutRate(out_rate); + resCheck(); // output meter - txa->outmeter->setBuffers(txa->outbuff); - txa->outmeter->setSize(txa->dsp_outsize); - txa->outmeter->setSamplerate (txa->out_rate); + outmeter->setBuffers(outbuff); + outmeter->setSize(dsp_outsize); + outmeter->setSamplerate (out_rate); } -void TXA::setDSPSamplerate (TXA *txa, int dsp_rate) +void TXA::setDSPSamplerate(int dsp_rate) { - if (txa->in_rate >= dsp_rate) - txa->dsp_insize = txa->dsp_size * (txa->in_rate / dsp_rate); - else - txa->dsp_insize = txa->dsp_size / (dsp_rate / txa->in_rate); - - if (txa->out_rate >= dsp_rate) - txa->dsp_outsize = txa->dsp_size * (txa->out_rate / dsp_rate); - else - txa->dsp_outsize = txa->dsp_size / (dsp_rate / txa->out_rate); - - txa->dsp_rate = dsp_rate; - // buffers - delete[] (txa->inbuff); - txa->inbuff = new float[1 * txa->dsp_insize * 2]; // (float *)malloc0(1 * txa->dsp_insize * sizeof(complex)); - delete[] (txa->outbuff); - txa->outbuff = new float[1 * txa->dsp_outsize * 2]; // (float *)malloc0(1 * txa->dsp_outsize * sizeof(complex)); + Unit::setBuffersDSPSamplerate(dsp_rate); // input resampler - txa->rsmpin->setBuffers(txa->inbuff, txa->midbuff); - txa->rsmpin->setSize(txa->dsp_insize); - txa->rsmpin->setOutRate(txa->dsp_rate); + rsmpin->setBuffers(inbuff, midbuff); + rsmpin->setSize(dsp_insize); + rsmpin->setOutRate(dsp_rate); // dsp_rate blocks - txa->gen0->setSamplerate(txa->dsp_rate); - txa->panel->setSamplerate(txa->dsp_rate); - txa->phrot->setSamplerate(txa->dsp_rate); - txa->micmeter->setSamplerate (txa->dsp_rate); - txa->amsq->setSamplerate (txa->dsp_rate); - txa->eqp->setSamplerate (txa->dsp_rate); - txa->eqmeter->setSamplerate (txa->dsp_rate); - EMPHP::setSamplerate_emphp (txa->preemph, txa->dsp_rate); - txa->leveler->setSamplerate (txa->dsp_rate); - txa->lvlrmeter->setSamplerate (txa->dsp_rate); - CFCOMP::setSamplerate_cfcomp (txa->cfcomp, txa->dsp_rate); - txa->cfcmeter->setSamplerate (txa->dsp_rate); - txa->bp0->setSamplerate (txa->dsp_rate); - COMPRESSOR::setSamplerate_compressor (txa->compressor, txa->dsp_rate); - txa->bp1->setSamplerate (txa->dsp_rate); - OSCTRL::setSamplerate_osctrl (txa->osctrl, txa->dsp_rate); - txa->bp2->setSamplerate (txa->dsp_rate); - txa->compmeter->setSamplerate (txa->dsp_rate); - txa->alc->setSamplerate (txa->dsp_rate); - AMMOD::setSamplerate_ammod (txa->ammod, txa->dsp_rate); - FMMOD::setSamplerate_fmmod (txa->fmmod, txa->dsp_rate); - txa->gen1->setSamplerate(txa->dsp_rate); - USLEW::setSamplerate_uslew (txa->uslew, txa->dsp_rate); - txa->alcmeter->setSamplerate (txa->dsp_rate); - txa->sip1->setSamplerate (txa->dsp_rate); - IQC::setSamplerate_iqc (txa->iqc.p0, txa->dsp_rate); - CFIR::setSamplerate_cfir (txa->cfir, txa->dsp_rate); + gen0->setSamplerate(dsp_rate); + panel->setSamplerate(dsp_rate); + phrot->setSamplerate(dsp_rate); + micmeter->setSamplerate (dsp_rate); + amsq->setSamplerate (dsp_rate); + eqp->setSamplerate (dsp_rate); + eqmeter->setSamplerate (dsp_rate); + EMPHP::setSamplerate_emphp (preemph, dsp_rate); + leveler->setSamplerate (dsp_rate); + lvlrmeter->setSamplerate (dsp_rate); + CFCOMP::setSamplerate_cfcomp (cfcomp, dsp_rate); + cfcmeter->setSamplerate (dsp_rate); + bp0->setSamplerate (dsp_rate); + COMPRESSOR::setSamplerate_compressor (compressor, dsp_rate); + bp1->setSamplerate (dsp_rate); + OSCTRL::setSamplerate_osctrl (osctrl, dsp_rate); + bp2->setSamplerate (dsp_rate); + compmeter->setSamplerate (dsp_rate); + alc->setSamplerate (dsp_rate); + AMMOD::setSamplerate_ammod (ammod, dsp_rate); + FMMOD::setSamplerate_fmmod (fmmod, dsp_rate); + gen1->setSamplerate(dsp_rate); + USLEW::setSamplerate_uslew (uslew, dsp_rate); + alcmeter->setSamplerate (dsp_rate); + sip1->setSamplerate (dsp_rate); + IQC::setSamplerate_iqc (iqc.p0, dsp_rate); + CFIR::setSamplerate_cfir (cfir, dsp_rate); // output resampler - txa->rsmpout->setBuffers(txa->midbuff, txa->outbuff); - txa->rsmpout->setInRate(txa->dsp_rate); - ResCheck (*txa); + rsmpout->setBuffers(midbuff, outbuff); + rsmpout->setInRate(dsp_rate); + resCheck(); // output meter - txa->outmeter->setBuffers(txa->outbuff); - txa->outmeter->setSize (txa->dsp_outsize); + outmeter->setBuffers(outbuff); + outmeter->setSize (dsp_outsize); } -void TXA::setDSPBuffsize (TXA *txa, int dsp_size) +void TXA::setDSPBuffsize(int dsp_size) { - if (txa->in_rate >= txa->dsp_rate) - txa->dsp_insize = dsp_size * (txa->in_rate / txa->dsp_rate); - else - txa->dsp_insize = dsp_size / (txa->dsp_rate / txa->in_rate); - - if (txa->out_rate >= txa->dsp_rate) - txa->dsp_outsize = dsp_size * (txa->out_rate / txa->dsp_rate); - else - txa->dsp_outsize = dsp_size / (txa->dsp_rate / txa->out_rate); - - txa->dsp_size = dsp_size; - // buffers - delete[] (txa->inbuff); - txa->inbuff = new float[1 * txa->dsp_insize * 2]; // (float *)malloc0(1 * txa->dsp_insize * sizeof(complex)); - delete[] (txa->midbuff); - txa->midbuff = new float[2 * txa->dsp_size * 2]; // (float *)malloc0(2 * txa->dsp_size * sizeof(complex)); - delete[] (txa->outbuff); - txa->outbuff = new float[1 * txa->dsp_outsize * 2]; // (float *)malloc0(1 * txa->dsp_outsize * sizeof(complex)); + Unit::setBuffersDSPBuffsize(dsp_size); // input resampler - txa->rsmpin->setBuffers(txa->inbuff, txa->midbuff); - txa->rsmpin->setSize(txa->dsp_insize); + rsmpin->setBuffers(inbuff, midbuff); + rsmpin->setSize(dsp_insize); // dsp_size blocks - txa->gen0->setBuffers(txa->midbuff, txa->midbuff); - txa->gen0->setSize(txa->dsp_size); - txa->panel->setBuffers(txa->midbuff, txa->midbuff); - txa->panel->setSize(txa->dsp_size); - txa->phrot->setBuffers(txa->midbuff, txa->midbuff); - txa->phrot->setSize(txa->dsp_size); - txa->micmeter->setBuffers (txa->midbuff); - txa->micmeter->setSize (txa->dsp_size); - txa->amsq->setBuffers (txa->midbuff, txa->midbuff, txa->midbuff); - txa->amsq->setSize (txa->dsp_size); - txa->eqp->setBuffers (txa->midbuff, txa->midbuff); - txa->eqp->setSize (txa->dsp_size); - txa->eqmeter->setBuffers (txa->midbuff); - txa->eqmeter->setSize (txa->dsp_size); - EMPHP::setBuffers_emphp (txa->preemph, txa->midbuff, txa->midbuff); - EMPHP::setSize_emphp (txa->preemph, txa->dsp_size); - txa->leveler->setBuffers(txa->midbuff, txa->midbuff); - txa->leveler->setSize(txa->dsp_size); - txa->lvlrmeter->setBuffers(txa->midbuff); - txa->lvlrmeter->setSize(txa->dsp_size); - CFCOMP::setBuffers_cfcomp (txa->cfcomp, txa->midbuff, txa->midbuff); - CFCOMP::setSize_cfcomp (txa->cfcomp, txa->dsp_size); - txa->cfcmeter->setBuffers(txa->midbuff); - txa->cfcmeter->setSize(txa->dsp_size); - txa->bp0->setBuffers (txa->midbuff, txa->midbuff); - txa->bp0->setSize (txa->dsp_size); - COMPRESSOR::setBuffers_compressor (txa->compressor, txa->midbuff, txa->midbuff); - COMPRESSOR::setSize_compressor (txa->compressor, txa->dsp_size); - txa->bp1->setBuffers (txa->midbuff, txa->midbuff); - txa->bp1->setSize (txa->dsp_size); - OSCTRL::setBuffers_osctrl (txa->osctrl, txa->midbuff, txa->midbuff); - OSCTRL::setSize_osctrl (txa->osctrl, txa->dsp_size); - txa->bp2->setBuffers (txa->midbuff, txa->midbuff); - txa->bp2->setSize (txa->dsp_size); - txa->compmeter->setBuffers(txa->midbuff); - txa->compmeter->setSize(txa->dsp_size); - txa->alc->setBuffers(txa->midbuff, txa->midbuff); - txa->alc->setSize( txa->dsp_size); - AMMOD::setBuffers_ammod (txa->ammod, txa->midbuff, txa->midbuff); - AMMOD::setSize_ammod (txa->ammod, txa->dsp_size); - FMMOD::setBuffers_fmmod (txa->fmmod, txa->midbuff, txa->midbuff); - FMMOD::setSize_fmmod (txa->fmmod, txa->dsp_size); - txa->gen1->setBuffers(txa->midbuff, txa->midbuff); - txa->gen1->setSize(txa->dsp_size); - USLEW::setBuffers_uslew (txa->uslew, txa->midbuff, txa->midbuff); - USLEW::setSize_uslew (txa->uslew, txa->dsp_size); - txa->alcmeter->setBuffers (txa->midbuff); - txa->alcmeter->setSize(txa->dsp_size); - txa->sip1->setBuffers (txa->midbuff); - txa->sip1->setSize (txa->dsp_size); - IQC::setBuffers_iqc (txa->iqc.p0, txa->midbuff, txa->midbuff); - IQC::setSize_iqc (txa->iqc.p0, txa->dsp_size); - CFIR::setBuffers_cfir (txa->cfir, txa->midbuff, txa->midbuff); - CFIR::setSize_cfir (txa->cfir, txa->dsp_size); + gen0->setBuffers(midbuff, midbuff); + gen0->setSize(dsp_size); + panel->setBuffers(midbuff, midbuff); + panel->setSize(dsp_size); + phrot->setBuffers(midbuff, midbuff); + phrot->setSize(dsp_size); + micmeter->setBuffers (midbuff); + micmeter->setSize (dsp_size); + amsq->setBuffers (midbuff, midbuff, midbuff); + amsq->setSize (dsp_size); + eqp->setBuffers (midbuff, midbuff); + eqp->setSize (dsp_size); + eqmeter->setBuffers (midbuff); + eqmeter->setSize (dsp_size); + EMPHP::setBuffers_emphp (preemph, midbuff, midbuff); + EMPHP::setSize_emphp (preemph, dsp_size); + leveler->setBuffers(midbuff, midbuff); + leveler->setSize(dsp_size); + lvlrmeter->setBuffers(midbuff); + lvlrmeter->setSize(dsp_size); + CFCOMP::setBuffers_cfcomp (cfcomp, midbuff, midbuff); + CFCOMP::setSize_cfcomp (cfcomp, dsp_size); + cfcmeter->setBuffers(midbuff); + cfcmeter->setSize(dsp_size); + bp0->setBuffers (midbuff, midbuff); + bp0->setSize (dsp_size); + COMPRESSOR::setBuffers_compressor (compressor, midbuff, midbuff); + COMPRESSOR::setSize_compressor (compressor, dsp_size); + bp1->setBuffers (midbuff, midbuff); + bp1->setSize (dsp_size); + OSCTRL::setBuffers_osctrl (osctrl, midbuff, midbuff); + OSCTRL::setSize_osctrl (osctrl, dsp_size); + bp2->setBuffers (midbuff, midbuff); + bp2->setSize (dsp_size); + compmeter->setBuffers(midbuff); + compmeter->setSize(dsp_size); + alc->setBuffers(midbuff, midbuff); + alc->setSize( dsp_size); + AMMOD::setBuffers_ammod (ammod, midbuff, midbuff); + AMMOD::setSize_ammod (ammod, dsp_size); + FMMOD::setBuffers_fmmod (fmmod, midbuff, midbuff); + FMMOD::setSize_fmmod (fmmod, dsp_size); + gen1->setBuffers(midbuff, midbuff); + gen1->setSize(dsp_size); + USLEW::setBuffers_uslew (uslew, midbuff, midbuff); + USLEW::setSize_uslew (uslew, dsp_size); + alcmeter->setBuffers (midbuff); + alcmeter->setSize(dsp_size); + sip1->setBuffers (midbuff); + sip1->setSize (dsp_size); + IQC::setBuffers_iqc (iqc.p0, midbuff, midbuff); + IQC::setSize_iqc (iqc.p0, dsp_size); + CFIR::setBuffers_cfir (cfir, midbuff, midbuff); + CFIR::setSize_cfir (cfir, dsp_size); // output resampler - txa->rsmpout->setBuffers(txa->midbuff, txa->outbuff); - txa->rsmpout->setSize(txa->dsp_size); + rsmpout->setBuffers(midbuff, outbuff); + rsmpout->setSize(dsp_size); // output meter - txa->outmeter->setBuffers(txa->outbuff); - txa->outmeter->setSize(txa->dsp_outsize); + outmeter->setBuffers(outbuff); + outmeter->setSize(dsp_outsize); } /******************************************************************************************************** @@ -824,51 +752,51 @@ void TXA::setDSPBuffsize (TXA *txa, int dsp_size) * * ********************************************************************************************************/ -void TXA::SetMode (TXA& txa, int mode) +void TXA::setMode(int _mode) { - if (txa.mode != mode) + if (mode != _mode) { - txa.mode = mode; - txa.ammod->run = 0; - txa.fmmod->run = 0; - txa.preemph->run = 0; + mode = _mode; + ammod->run = 0; + fmmod->run = 0; + preemph->run = 0; - switch (mode) + switch (_mode) { case TXA_AM: case TXA_SAM: - txa.ammod->run = 1; - txa.ammod->mode = 0; + ammod->run = 1; + ammod->mode = 0; break; case TXA_DSB: - txa.ammod->run = 1; - txa.ammod->mode = 1; + ammod->run = 1; + ammod->mode = 1; break; case TXA_AM_LSB: case TXA_AM_USB: - txa.ammod->run = 1; - txa.ammod->mode = 2; + ammod->run = 1; + ammod->mode = 2; break; case TXA_FM: - txa.fmmod->run = 1; - txa.preemph->run = 1; + fmmod->run = 1; + preemph->run = 1; break; default: break; } - SetupBPFilters (txa); + setupBPFilters(); } } -void TXA::SetBandpassFreqs (TXA& txa, float f_low, float f_high) +void TXA::setBandpassFreqs(float _f_low, float _f_high) { - if ((txa.f_low != f_low) || (txa.f_high != f_high)) + if ((f_low != _f_low) || (f_high != _f_high)) { - txa.f_low = f_low; - txa.f_high = f_high; - SetupBPFilters (txa); + f_low = _f_low; + f_high = _f_high; + setupBPFilters(); } } @@ -879,34 +807,34 @@ void TXA::SetBandpassFreqs (TXA& txa, float f_low, float f_high) * * ********************************************************************************************************/ -void TXA::ResCheck (TXA& txa) +void TXA::resCheck() { - RESAMPLE *a = txa.rsmpin; - if (txa.in_rate != txa.dsp_rate) + RESAMPLE *a = rsmpin; + if (in_rate != dsp_rate) a->run = 1; else a->run = 0; - a = txa.rsmpout; - if (txa.dsp_rate != txa.out_rate) + a = rsmpout; + if (dsp_rate != out_rate) a->run = 1; else a->run = 0; } -int TXA::UslewCheck (TXA& txa) +int TXA::uslewCheck() { - return (txa.ammod->run == 1) || - (txa.fmmod->run == 1) || - (txa.gen0->run == 1) || - (txa.gen1->run == 1); + return (ammod->run == 1) || + (fmmod->run == 1) || + (gen0->run == 1) || + (gen1->run == 1); } -void TXA::SetupBPFilters (TXA& txa) +void TXA::setupBPFilters() { - txa.bp0->run = 1; - txa.bp1->run = 0; - txa.bp2->run = 0; - switch (txa.mode) + bp0->run = 1; + bp1->run = 0; + bp2->run = 0; + switch (mode) { case TXA_LSB: case TXA_USB: @@ -916,15 +844,15 @@ void TXA::SetupBPFilters (TXA& txa) case TXA_DIGU: case TXA_SPEC: case TXA_DRM: - txa.bp0->calcBandpassFilter (txa.f_low, txa.f_high, 2.0); - if (txa.compressor->run) + bp0->calcBandpassFilter (f_low, f_high, 2.0); + if (compressor->run) { - txa.bp1->calcBandpassFilter (txa.f_low, txa.f_high, 2.0); - txa.bp1->run = 1; - if (txa.osctrl->run) + bp1->calcBandpassFilter (f_low, f_high, 2.0); + bp1->run = 1; + if (osctrl->run) { - txa.bp2->calcBandpassFilter (txa.f_low, txa.f_high, 1.0); - txa.bp2->run = 1; + bp2->calcBandpassFilter (f_low, f_high, 1.0); + bp2->run = 1; } } break; @@ -932,60 +860,62 @@ void TXA::SetupBPFilters (TXA& txa) case TXA_AM: case TXA_SAM: case TXA_FM: - if (txa.compressor->run) + if (compressor->run) { - txa.bp0->calcBandpassFilter (0.0, txa.f_high, 2.0); - txa.bp1->calcBandpassFilter (0.0, txa.f_high, 2.0); - txa.bp1->run = 1; - if (txa.osctrl->run) + bp0->calcBandpassFilter (0.0, f_high, 2.0); + bp1->calcBandpassFilter (0.0, f_high, 2.0); + bp1->run = 1; + if (osctrl->run) { - txa.bp2->calcBandpassFilter (0.0, txa.f_high, 1.0); - txa.bp2->run = 1; + bp2->calcBandpassFilter (0.0, f_high, 1.0); + bp2->run = 1; } } else { - txa.bp0->calcBandpassFilter (txa.f_low, txa.f_high, 1.0); + bp0->calcBandpassFilter (f_low, f_high, 1.0); } break; case TXA_AM_LSB: - txa.bp0->calcBandpassFilter (-txa.f_high, 0.0, 2.0); - if (txa.compressor->run) + bp0->calcBandpassFilter (-f_high, 0.0, 2.0); + if (compressor->run) { - txa.bp1->calcBandpassFilter (-txa.f_high, 0.0, 2.0); - txa.bp1->run = 1; - if (txa.osctrl->run) + bp1->calcBandpassFilter (-f_high, 0.0, 2.0); + bp1->run = 1; + if (osctrl->run) { - txa.bp2->calcBandpassFilter (-txa.f_high, 0.0, 1.0); - txa.bp2->run = 1; + bp2->calcBandpassFilter (-f_high, 0.0, 1.0); + bp2->run = 1; } } break; case TXA_AM_USB: - txa.bp0->calcBandpassFilter (0.0, txa.f_high, 2.0); - if (txa.compressor->run) + bp0->calcBandpassFilter (0.0, f_high, 2.0); + if (compressor->run) { - txa.bp1->calcBandpassFilter (0.0, txa.f_high, 2.0); - txa.bp1->run = 1; - if (txa.osctrl->run) + bp1->calcBandpassFilter (0.0, f_high, 2.0); + bp1->run = 1; + if (osctrl->run) { - txa.bp2->calcBandpassFilter(0.0, txa.f_high, 1.0); - txa.bp2->run = 1; + bp2->calcBandpassFilter(0.0, f_high, 1.0); + bp2->run = 1; } } break; + default: + break; } } -void TXA::SetBandpassNC (TXA& txa, int nc) +void TXA::setBandpassNC(int _nc) { // NOTE: 'nc' must be >= 'size' BANDPASS *a; - a = txa.bp0; + a = bp0; - if (a->nc != nc) + if (a->nc != _nc) { - a->nc = nc; + a->nc = _nc; float* impulse = FIR::fir_bandpass ( a->nc, a->f_low, @@ -996,14 +926,14 @@ void TXA::SetBandpassNC (TXA& txa, int nc) a->gain / (double)(2 * a->size) ); FIRCORE::setNc_fircore (a->fircore, a->nc, impulse); - delete[] (impulse); + delete[] impulse; } - a = txa.bp1; + a = bp1; - if (a->nc != nc) + if (a->nc != _nc) { - a->nc = nc; + a->nc = _nc; float* impulse = FIR::fir_bandpass ( a->nc, a->f_low, @@ -1014,14 +944,14 @@ void TXA::SetBandpassNC (TXA& txa, int nc) a->gain / (double)(2 * a->size) ); FIRCORE::setNc_fircore (a->fircore, a->nc, impulse); - delete[] (impulse); + delete[] impulse; } - a = txa.bp2; + a = bp2; - if (a->nc != nc) + if (a->nc != _nc) { - a->nc = nc; + a->nc = _nc; float* impulse = FIR::fir_bandpass ( a->nc, a->f_low, @@ -1032,34 +962,34 @@ void TXA::SetBandpassNC (TXA& txa, int nc) a->gain / (double)(2 * a->size) ); FIRCORE::setNc_fircore (a->fircore, a->nc, impulse); - delete[] (impulse); + delete[] impulse; } } -void TXA::SetBandpassMP (TXA& txa, int mp) +void TXA::setBandpassMP(int _mp) { BANDPASS *a; - a = txa.bp0; + a = bp0; - if (mp != a->mp) + if (_mp != a->mp) { - a->mp = mp; + a->mp = _mp; FIRCORE::setMp_fircore (a->fircore, a->mp); } - a = txa.bp1; + a = bp1; - if (mp != a->mp) + if (_mp != a->mp) { - a->mp = mp; + a->mp = _mp; FIRCORE::setMp_fircore (a->fircore, a->mp); } - a = txa.bp2; + a = bp2; - if (mp != a->mp) + if (_mp != a->mp) { - a->mp = mp; + a->mp = _mp; FIRCORE::setMp_fircore (a->fircore, a->mp); } } @@ -1070,30 +1000,30 @@ void TXA::SetBandpassMP (TXA& txa, int mp) * * ********************************************************************************************************/ -void TXA::SetNC (TXA& txa, int nc) +void TXA::setNC(int _nc) { - int oldstate = txa.state; + int oldstate = state; - SetBandpassNC (txa, nc); - EMPHP::SetFMEmphNC (txa, nc); - txa.eqp->setNC (nc); - FMMOD::SetFMNC (txa, nc); - CFIR::SetCFIRNC (txa, nc); - txa.state = oldstate; + setBandpassNC (_nc); + EMPHP::SetFMEmphNC (*this, _nc); + eqp->setNC (_nc); + FMMOD::SetFMNC (*this, _nc); + CFIR::SetCFIRNC (*this, _nc); + state = oldstate; } -void TXA::SetMP (TXA& txa, int mp) +void TXA::setMP(int _mp) { - SetBandpassMP (txa, mp); - EMPHP::SetFMEmphMP (txa, mp); - txa.eqp->setMP (mp); - FMMOD::SetFMMP (txa, mp); + setBandpassMP (_mp); + EMPHP::SetFMEmphMP (*this, _mp); + eqp->setMP (_mp); + FMMOD::SetFMMP (*this, _mp); } -void TXA::SetFMAFFilter (TXA& txa, float low, float high) +void TXA::setFMAFFilter(float _low, float _high) { - EMPHP::SetFMPreEmphFreqs (txa, low, high); - FMMOD::SetFMAFFreqs (txa, low, high); + EMPHP::SetFMPreEmphFreqs (*this, _low, _high); + FMMOD::SetFMAFFreqs (*this, _low, _high); } } // namespace WDSP diff --git a/wdsp/TXA.hpp b/wdsp/TXA.hpp index 284f2a643..19e5a5771 100644 --- a/wdsp/TXA.hpp +++ b/wdsp/TXA.hpp @@ -157,11 +157,6 @@ public: GEN *gen0; GEN *gen1; USLEW *uslew; - // struct - // { - // CALCC *p; - // CRITICAL_SECTION cs_update; - // } calcc; struct { IQC *p0, *p1; @@ -169,42 +164,42 @@ public: } iqc; CFIR *cfir; - static TXA* create_txa ( + TXA( int in_rate, // input samplerate int out_rate, // output samplerate int dsp_rate, // sample rate for mainstream dsp processing int dsp_size // number complex samples processed per buffer in mainstream dsp processing ); - static void destroy_txa (TXA *txa); - static void flush_txa (TXA *txa); - static void xtxa (TXA *txa); - int get_insize() const { return dsp_insize; } - int get_outsize() const { return dsp_outsize; } - float *get_inbuff() { return inbuff; } - float *get_outbuff() { return outbuff; } - static void setInputSamplerate (TXA *txa, int in_rate); - static void setOutputSamplerate (TXA *txa, int out_rate); - static void setDSPSamplerate (TXA *txa, int dsp_rate); - static void setDSPBuffsize (TXA *txa, int dsp_size); + TXA(const TXA&) = delete; + TXA& operator=(const TXA& other) = delete; + ~TXA(); + + void flush(); + void execute(); + void setInputSamplerate(int _in_rate); + void setOutputSamplerate(int _out_rate); + void setDSPSamplerate(int _dsp_rate); + void setDSPBuffsize(int _dsp_size); + int get_insize() const { return Unit::dsp_insize; } + int get_outsize() const { return Unit::dsp_outsize; } + float *get_inbuff() { return Unit::inbuff; } + float *get_outbuff() { return Unit::outbuff; } // TXA Properties - static void SetMode (TXA& txa, int mode); - static void SetBandpassFreqs (TXA& txa, float f_low, float f_high); - static void SetBandpassNC (TXA& txa, int nc); - static void SetBandpassMP (TXA& txa, int mp); + void setMode(int mode); + void setBandpassFreqs(float f_low, float f_high); + void setBandpassNC(int nc); + void setBandpassMP(int mp); // Collectives - static void SetNC (TXA& txa, int nc); - static void SetMP (TXA& txa, int mp); - static void SetFMAFFilter (TXA& txa, float low, float high); - static void SetupBPFilters (TXA& txa); - static int UslewCheck (TXA& txa); + void setNC(int nc); + void setMP(int mp); + void setFMAFFilter(float low, float high); + void setupBPFilters(); + int uslewCheck(); private: - static void ResCheck (TXA& txa); - float* inbuff; - float* midbuff; - float* outbuff; + void resCheck(); }; } // namespace WDSP diff --git a/wdsp/compress.cpp b/wdsp/compress.cpp index 949dcf854..5a8d2a556 100644 --- a/wdsp/compress.cpp +++ b/wdsp/compress.cpp @@ -103,7 +103,7 @@ void COMPRESSOR::SetCompressorRun (TXA& txa, int run) if (txa.compressor->run != run) { txa.compressor->run = run; - TXA::SetupBPFilters (txa); + txa.setupBPFilters(); } } diff --git a/wdsp/osctrl.cpp b/wdsp/osctrl.cpp index 30876fcd1..084f495f7 100644 --- a/wdsp/osctrl.cpp +++ b/wdsp/osctrl.cpp @@ -149,7 +149,7 @@ void OSCTRL::SetosctrlRun (TXA& txa, int run) if (txa.osctrl->run != run) { txa.osctrl->run = run; - TXA::SetupBPFilters (txa); + txa.setupBPFilters(); } } diff --git a/wdsp/slew.cpp b/wdsp/slew.cpp index 04b47eeda..50651bfd1 100644 --- a/wdsp/slew.cpp +++ b/wdsp/slew.cpp @@ -103,7 +103,7 @@ void USLEW::flush_uslew (USLEW *a) void USLEW::xuslew (USLEW *a) { - if (!a->runmode && TXA::UslewCheck (*a->txa)) + if (!a->runmode && a->txa->uslewCheck()) a->runmode = 1; long upslew = *a->ch_upslew; diff --git a/wdsp/unit.cpp b/wdsp/unit.cpp new file mode 100644 index 000000000..b6d33ad55 --- /dev/null +++ b/wdsp/unit.cpp @@ -0,0 +1,148 @@ +/* unit.hpp + +This file is part of a program that implements a Software-Defined Radio. + +Copyright (C) 2013 Warren Pratt, NR0V +Copyright (C) 2024 Edouard Griffiths, F4EXB Adapted to SDRangel + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +The author can be reached by email at + +warren@wpratt.com + +*/ + +#include + +#include "unit.hpp" + +namespace WDSP { + +Unit::Unit( + int _in_rate, // input samplerate + int _out_rate, // output samplerate + int _dsp_rate, // sample rate for mainstream dsp processing + int _dsp_size // number complex samples processed per buffer in mainstream dsp processing +) : + in_rate{_in_rate}, + out_rate(_out_rate), + dsp_rate(_dsp_rate), + dsp_size(_dsp_size) +{ + if (_in_rate >= _dsp_rate) + dsp_insize = _dsp_size * (_in_rate / _dsp_rate); + else + dsp_insize = _dsp_size / (_dsp_rate / _in_rate); + + if (_out_rate >= _dsp_rate) + dsp_outsize = _dsp_size * (_out_rate / _dsp_rate); + else + dsp_outsize = _dsp_size / (_dsp_rate / _out_rate); + + // buffers + inbuff = new float[1 * dsp_insize * 2]; + outbuff = new float[1 * dsp_outsize * 2]; + midbuff = new float[2 * dsp_size * 2]; +} + +Unit::~Unit() +{ + delete[] inbuff; + delete[] outbuff; + delete[] midbuff; +} + +void Unit::flushBuffers() +{ + std::fill(inbuff, inbuff + 1 * dsp_insize * 2, 0); + std::fill(outbuff, outbuff + 1 * dsp_outsize * 2, 0); + std::fill(midbuff, midbuff + 2 * dsp_size * 2, 0); +} + +void Unit::setBuffersInputSamplerate(int _in_rate) +{ + if (_in_rate >= dsp_rate) + dsp_insize = dsp_size * (_in_rate / dsp_rate); + else + dsp_insize = dsp_size / (dsp_rate / _in_rate); + + in_rate = _in_rate; + + // buffers + delete[] (inbuff); + inbuff = new float[1 * dsp_insize * 2]; +} + +void Unit::setBuffersOutputSamplerate(int _out_rate) +{ + if (_out_rate >= dsp_rate) + dsp_outsize = dsp_size * (_out_rate / dsp_rate); + else + dsp_outsize = dsp_size / (dsp_rate / _out_rate); + + out_rate = _out_rate; + + // buffers + delete[] outbuff; + outbuff = new float[1 * dsp_outsize * 2]; +} + +void Unit::setBuffersDSPSamplerate(int _dsp_rate) +{ + if (in_rate >= _dsp_rate) + dsp_insize = dsp_size * (in_rate / _dsp_rate); + else + dsp_insize = dsp_size / (_dsp_rate / in_rate); + + if (out_rate >= _dsp_rate) + dsp_outsize = dsp_size * (out_rate / _dsp_rate); + else + dsp_outsize = dsp_size / (_dsp_rate / out_rate); + + dsp_rate = _dsp_rate; + + // buffers + delete[] inbuff; + inbuff = new float[1 * dsp_insize * 2]; + delete[] outbuff; + outbuff = new float[1 * dsp_outsize * 2]; +} + +void Unit::setBuffersDSPBuffsize(int _dsp_size) +{ + if (in_rate >= dsp_rate) + dsp_insize = _dsp_size * (in_rate / dsp_rate); + else + dsp_insize = _dsp_size / (dsp_rate / in_rate); + + if (out_rate >= dsp_rate) + dsp_outsize = _dsp_size * (out_rate / dsp_rate); + else + dsp_outsize = _dsp_size / (dsp_rate / out_rate); + + dsp_size = _dsp_size; + + // buffers + delete[]inbuff; + inbuff = new float[1 * dsp_insize * 2]; + delete[] midbuff; + midbuff = new float[2 * dsp_size * 2]; + delete[] outbuff; + outbuff = new float[1 * dsp_outsize * 2]; +} + + +} // namespace diff --git a/wdsp/unit.hpp b/wdsp/unit.hpp index 09000f0c3..a60844ddc 100644 --- a/wdsp/unit.hpp +++ b/wdsp/unit.hpp @@ -42,6 +42,25 @@ public: int dsp_insize; // size (complex samples) of the input buffer int dsp_outsize; // size (complex samples) of the output buffer int state; // 0 for unit OFF; 1 for unit ON + + Unit( + int _in_rate, // input samplerate + int _out_rate, // output samplerate + int _dsp_rate, // sample rate for mainstream dsp processing + int _dsp_size // number complex samples processed per buffer in mainstream dsp processing + ); + ~Unit(); + + void flushBuffers(); + void setBuffersInputSamplerate(int _in_rate); + void setBuffersOutputSamplerate(int _out_rate); + void setBuffersDSPSamplerate(int _dsp_rate); + void setBuffersDSPBuffsize(int _dsp_size); + +protected: + float* inbuff; + float* midbuff; + float* outbuff; }; } // namespace WDSP