mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-11-03 13:11:20 -05:00 
			
		
		
		
	WDSP: rework former IIR classes
This commit is contained in:
		
							parent
							
								
									b9e3b10a6b
								
							
						
					
					
						commit
						71fe079ee3
					
				@ -571,19 +571,19 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force)
 | 
				
			|||||||
    // CW Peaking
 | 
					    // CW Peaking
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ((m_settings.m_cwPeaking != settings.m_cwPeaking) || force) {
 | 
					    if ((m_settings.m_cwPeaking != settings.m_cwPeaking) || force) {
 | 
				
			||||||
        WDSP::SPEAK::SetSPCWRun(*m_rxa, settings.m_cwPeaking ? 1 : 0);
 | 
					        m_rxa->speak->setRun(settings.m_cwPeaking ? 1 : 0);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ((m_settings.m_cwPeakFrequency != settings.m_cwPeakFrequency) || force) {
 | 
					    if ((m_settings.m_cwPeakFrequency != settings.m_cwPeakFrequency) || force) {
 | 
				
			||||||
        WDSP::SPEAK::SetSPCWFreq(*m_rxa, settings.m_cwPeakFrequency);
 | 
					        m_rxa->speak->setFreq(settings.m_cwPeakFrequency);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ((m_settings.m_cwBandwidth != settings.m_cwBandwidth) || force) {
 | 
					    if ((m_settings.m_cwBandwidth != settings.m_cwBandwidth) || force) {
 | 
				
			||||||
        WDSP::SPEAK::SetSPCWBandwidth(*m_rxa, settings.m_cwBandwidth);
 | 
					        m_rxa->speak->setBandwidth(settings.m_cwBandwidth);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ((m_settings.m_cwGain != settings.m_cwGain) || force) {
 | 
					    if ((m_settings.m_cwGain != settings.m_cwGain) || force) {
 | 
				
			||||||
        WDSP::SPEAK::SetSPCWGain(*m_rxa, settings.m_cwGain);
 | 
					        m_rxa->speak->setGain(settings.m_cwGain);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Noise Blanker
 | 
					    // Noise Blanker
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										28
									
								
								wdsp/RXA.cpp
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								wdsp/RXA.cpp
									
									
									
									
									
								
							@ -482,7 +482,7 @@ RXA* RXA::create_rxa (
 | 
				
			|||||||
        0.02);                                  // tau
 | 
					        0.02);                                  // tau
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // CW peaking filter
 | 
					    // CW peaking filter
 | 
				
			||||||
    rxa->speak = SPEAK::create_speak (
 | 
					    rxa->speak = new SPEAK(
 | 
				
			||||||
        0,                                      // run
 | 
					        0,                                      // run
 | 
				
			||||||
        rxa->dsp_size,                          // buffer size,
 | 
					        rxa->dsp_size,                          // buffer size,
 | 
				
			||||||
        rxa->midbuff,                           // pointer to input buffer
 | 
					        rxa->midbuff,                           // pointer to input buffer
 | 
				
			||||||
@ -500,7 +500,7 @@ RXA* RXA::create_rxa (
 | 
				
			|||||||
        double def_freq[2] = {2125.0, 2295.0};
 | 
					        double def_freq[2] = {2125.0, 2295.0};
 | 
				
			||||||
        double def_bw[2] = {75.0, 75.0};
 | 
					        double def_bw[2] = {75.0, 75.0};
 | 
				
			||||||
        double def_gain[2] = {1.0, 1.0};
 | 
					        double def_gain[2] = {1.0, 1.0};
 | 
				
			||||||
        rxa->mpeak = MPEAK::create_mpeak (
 | 
					        rxa->mpeak = new MPEAK(
 | 
				
			||||||
            0,                                  // run
 | 
					            0,                                  // run
 | 
				
			||||||
            rxa->dsp_size,                      // size
 | 
					            rxa->dsp_size,                      // size
 | 
				
			||||||
            rxa->midbuff,                       // pointer to input buffer
 | 
					            rxa->midbuff,                       // pointer to input buffer
 | 
				
			||||||
@ -567,8 +567,8 @@ void RXA::destroy_rxa (RXA *rxa)
 | 
				
			|||||||
    delete (rxa->rsmpout);
 | 
					    delete (rxa->rsmpout);
 | 
				
			||||||
    PANEL::destroy_panel (rxa->panel);
 | 
					    PANEL::destroy_panel (rxa->panel);
 | 
				
			||||||
    SSQL::destroy_ssql (rxa->ssql);
 | 
					    SSQL::destroy_ssql (rxa->ssql);
 | 
				
			||||||
    MPEAK::destroy_mpeak (rxa->mpeak);
 | 
					    delete (rxa->mpeak);
 | 
				
			||||||
    SPEAK::destroy_speak (rxa->speak);
 | 
					    delete (rxa->speak);
 | 
				
			||||||
    delete (rxa->cbl);
 | 
					    delete (rxa->cbl);
 | 
				
			||||||
    delete (rxa->sip1);
 | 
					    delete (rxa->sip1);
 | 
				
			||||||
    delete (rxa->bp1);
 | 
					    delete (rxa->bp1);
 | 
				
			||||||
@ -627,8 +627,8 @@ void RXA::flush_rxa (RXA *rxa)
 | 
				
			|||||||
    rxa->bp1->flush();
 | 
					    rxa->bp1->flush();
 | 
				
			||||||
    rxa->sip1->flush();
 | 
					    rxa->sip1->flush();
 | 
				
			||||||
    rxa->cbl->flush();
 | 
					    rxa->cbl->flush();
 | 
				
			||||||
    SPEAK::flush_speak (rxa->speak);
 | 
					    rxa->speak->flush();
 | 
				
			||||||
    MPEAK::flush_mpeak (rxa->mpeak);
 | 
					    rxa->mpeak->flush();
 | 
				
			||||||
    SSQL::flush_ssql (rxa->ssql);
 | 
					    SSQL::flush_ssql (rxa->ssql);
 | 
				
			||||||
    PANEL::flush_panel (rxa->panel);
 | 
					    PANEL::flush_panel (rxa->panel);
 | 
				
			||||||
    rxa->rsmpout->flush();
 | 
					    rxa->rsmpout->flush();
 | 
				
			||||||
@ -666,8 +666,8 @@ void RXA::xrxa (RXA *rxa)
 | 
				
			|||||||
    rxa->agcmeter->execute();
 | 
					    rxa->agcmeter->execute();
 | 
				
			||||||
    rxa->sip1->execute(0);
 | 
					    rxa->sip1->execute(0);
 | 
				
			||||||
    rxa->cbl->execute();
 | 
					    rxa->cbl->execute();
 | 
				
			||||||
    SPEAK::xspeak (rxa->speak);
 | 
					    rxa->speak->execute();
 | 
				
			||||||
    MPEAK::xmpeak (rxa->mpeak);
 | 
					    rxa->mpeak->execute();
 | 
				
			||||||
    SSQL::xssql (rxa->ssql);
 | 
					    SSQL::xssql (rxa->ssql);
 | 
				
			||||||
    PANEL::xpanel (rxa->panel);
 | 
					    PANEL::xpanel (rxa->panel);
 | 
				
			||||||
    rxa->amsq->execute();
 | 
					    rxa->amsq->execute();
 | 
				
			||||||
@ -773,8 +773,8 @@ void RXA::setDSPSamplerate (RXA *rxa, int dsp_rate)
 | 
				
			|||||||
    rxa->agcmeter->setSamplerate(rxa->dsp_rate);
 | 
					    rxa->agcmeter->setSamplerate(rxa->dsp_rate);
 | 
				
			||||||
    rxa->sip1->setSamplerate(rxa->dsp_rate);
 | 
					    rxa->sip1->setSamplerate(rxa->dsp_rate);
 | 
				
			||||||
    rxa->cbl->setSamplerate(rxa->dsp_rate);
 | 
					    rxa->cbl->setSamplerate(rxa->dsp_rate);
 | 
				
			||||||
    SPEAK::setSamplerate_speak (rxa->speak, rxa->dsp_rate);
 | 
					    rxa->speak->setSamplerate(rxa->dsp_rate);
 | 
				
			||||||
    MPEAK::setSamplerate_mpeak (rxa->mpeak, rxa->dsp_rate);
 | 
					    rxa->mpeak->setSamplerate(rxa->dsp_rate);
 | 
				
			||||||
    SSQL::setSamplerate_ssql (rxa->ssql, rxa->dsp_rate);
 | 
					    SSQL::setSamplerate_ssql (rxa->ssql, rxa->dsp_rate);
 | 
				
			||||||
    PANEL::setSamplerate_panel (rxa->panel, rxa->dsp_rate);
 | 
					    PANEL::setSamplerate_panel (rxa->panel, rxa->dsp_rate);
 | 
				
			||||||
    // output resampler
 | 
					    // output resampler
 | 
				
			||||||
@ -854,10 +854,10 @@ void RXA::setDSPBuffsize (RXA *rxa, int dsp_size)
 | 
				
			|||||||
    rxa->sip1->setSize(rxa->dsp_size);
 | 
					    rxa->sip1->setSize(rxa->dsp_size);
 | 
				
			||||||
    rxa->cbl->setBuffers(rxa->midbuff, rxa->midbuff);
 | 
					    rxa->cbl->setBuffers(rxa->midbuff, rxa->midbuff);
 | 
				
			||||||
    rxa->cbl->setSize(rxa->dsp_size);
 | 
					    rxa->cbl->setSize(rxa->dsp_size);
 | 
				
			||||||
    SPEAK::setBuffers_speak (rxa->speak, rxa->midbuff, rxa->midbuff);
 | 
					    rxa->speak->setBuffers(rxa->midbuff, rxa->midbuff);
 | 
				
			||||||
    SPEAK::setSize_speak (rxa->speak, rxa->dsp_size);
 | 
					    rxa->speak->setSize(rxa->dsp_size);
 | 
				
			||||||
    MPEAK::setBuffers_mpeak (rxa->mpeak, rxa->midbuff, rxa->midbuff);
 | 
					    rxa->mpeak->setBuffers(rxa->midbuff, rxa->midbuff);
 | 
				
			||||||
    MPEAK::setSize_mpeak (rxa->mpeak, rxa->dsp_size);
 | 
					    rxa->mpeak->setSize(rxa->dsp_size);
 | 
				
			||||||
    SSQL::setBuffers_ssql (rxa->ssql, rxa->midbuff, rxa->midbuff);
 | 
					    SSQL::setBuffers_ssql (rxa->ssql, rxa->midbuff, rxa->midbuff);
 | 
				
			||||||
    SSQL::setSize_ssql (rxa->ssql, rxa->dsp_size);
 | 
					    SSQL::setSize_ssql (rxa->ssql, rxa->dsp_size);
 | 
				
			||||||
    PANEL::setBuffers_panel (rxa->panel, rxa->midbuff, rxa->midbuff);
 | 
					    PANEL::setBuffers_panel (rxa->panel, rxa->midbuff, rxa->midbuff);
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										14
									
								
								wdsp/TXA.cpp
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								wdsp/TXA.cpp
									
									
									
									
									
								
							@ -114,7 +114,7 @@ TXA* TXA::create_txa (
 | 
				
			|||||||
        2,                                          // 1 to use Q, 2 to use I for input
 | 
					        2,                                          // 1 to use Q, 2 to use I for input
 | 
				
			||||||
        0);                                         // 0, no copy
 | 
					        0);                                         // 0, no copy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    txa->phrot = PHROT::create_phrot (
 | 
					    txa->phrot = new PHROT(
 | 
				
			||||||
        0,                                          // run
 | 
					        0,                                          // run
 | 
				
			||||||
        txa->dsp_size,                       // size
 | 
					        txa->dsp_size,                       // size
 | 
				
			||||||
        txa->midbuff,                       // input buffer
 | 
					        txa->midbuff,                       // input buffer
 | 
				
			||||||
@ -548,7 +548,7 @@ void TXA::destroy_txa (TXA *txa)
 | 
				
			|||||||
    delete (txa->eqp);
 | 
					    delete (txa->eqp);
 | 
				
			||||||
    delete (txa->amsq);
 | 
					    delete (txa->amsq);
 | 
				
			||||||
    delete (txa->micmeter);
 | 
					    delete (txa->micmeter);
 | 
				
			||||||
    PHROT::destroy_phrot (txa->phrot);
 | 
					    delete (txa->phrot);
 | 
				
			||||||
    PANEL::destroy_panel (txa->panel);
 | 
					    PANEL::destroy_panel (txa->panel);
 | 
				
			||||||
    delete (txa->gen0);
 | 
					    delete (txa->gen0);
 | 
				
			||||||
    delete (txa->rsmpin);
 | 
					    delete (txa->rsmpin);
 | 
				
			||||||
@ -566,7 +566,7 @@ void TXA::flush_txa (TXA* txa)
 | 
				
			|||||||
    txa->rsmpin->flush();
 | 
					    txa->rsmpin->flush();
 | 
				
			||||||
    txa->gen0->flush();
 | 
					    txa->gen0->flush();
 | 
				
			||||||
    PANEL::flush_panel (txa->panel);
 | 
					    PANEL::flush_panel (txa->panel);
 | 
				
			||||||
    PHROT::flush_phrot (txa->phrot);
 | 
					    txa->phrot->flush();
 | 
				
			||||||
    txa->micmeter->flush ();
 | 
					    txa->micmeter->flush ();
 | 
				
			||||||
    txa->amsq->flush ();
 | 
					    txa->amsq->flush ();
 | 
				
			||||||
    txa->eqp->flush();
 | 
					    txa->eqp->flush();
 | 
				
			||||||
@ -600,7 +600,7 @@ void xtxa (TXA* txa)
 | 
				
			|||||||
    txa->rsmpin->execute();              // input resampler
 | 
					    txa->rsmpin->execute();              // input resampler
 | 
				
			||||||
    txa->gen0->execute();                     // input signal generator
 | 
					    txa->gen0->execute();                     // input signal generator
 | 
				
			||||||
    PANEL::xpanel (txa->panel);                  // includes MIC gain
 | 
					    PANEL::xpanel (txa->panel);                  // includes MIC gain
 | 
				
			||||||
    PHROT::xphrot (txa->phrot);                  // phase rotator
 | 
					    txa->phrot->execute();                  // phase rotator
 | 
				
			||||||
    txa->micmeter->execute ();               // MIC meter
 | 
					    txa->micmeter->execute ();               // MIC meter
 | 
				
			||||||
    txa->amsq->xcap ();                 // downward expander capture
 | 
					    txa->amsq->xcap ();                 // downward expander capture
 | 
				
			||||||
    txa->amsq->execute ();                    // downward expander action
 | 
					    txa->amsq->execute ();                    // downward expander action
 | 
				
			||||||
@ -698,7 +698,7 @@ void TXA::setDSPSamplerate (TXA *txa, int dsp_rate)
 | 
				
			|||||||
    // dsp_rate blocks
 | 
					    // dsp_rate blocks
 | 
				
			||||||
    txa->gen0->setSamplerate(txa->dsp_rate);
 | 
					    txa->gen0->setSamplerate(txa->dsp_rate);
 | 
				
			||||||
    PANEL::setSamplerate_panel (txa->panel, txa->dsp_rate);
 | 
					    PANEL::setSamplerate_panel (txa->panel, txa->dsp_rate);
 | 
				
			||||||
    PHROT::setSamplerate_phrot (txa->phrot, txa->dsp_rate);
 | 
					    txa->phrot->setSamplerate(txa->dsp_rate);
 | 
				
			||||||
    txa->micmeter->setSamplerate (txa->dsp_rate);
 | 
					    txa->micmeter->setSamplerate (txa->dsp_rate);
 | 
				
			||||||
    txa->amsq->setSamplerate (txa->dsp_rate);
 | 
					    txa->amsq->setSamplerate (txa->dsp_rate);
 | 
				
			||||||
    txa->eqp->setSamplerate (txa->dsp_rate);
 | 
					    txa->eqp->setSamplerate (txa->dsp_rate);
 | 
				
			||||||
@ -760,8 +760,8 @@ void TXA::setDSPBuffsize (TXA *txa, int dsp_size)
 | 
				
			|||||||
    txa->gen0->setSize(txa->dsp_size);
 | 
					    txa->gen0->setSize(txa->dsp_size);
 | 
				
			||||||
    PANEL::setBuffers_panel (txa->panel, txa->midbuff, txa->midbuff);
 | 
					    PANEL::setBuffers_panel (txa->panel, txa->midbuff, txa->midbuff);
 | 
				
			||||||
    PANEL::setSize_panel (txa->panel, txa->dsp_size);
 | 
					    PANEL::setSize_panel (txa->panel, txa->dsp_size);
 | 
				
			||||||
    PHROT::setBuffers_phrot (txa->phrot, txa->midbuff, txa->midbuff);
 | 
					    txa->phrot->setBuffers(txa->midbuff, txa->midbuff);
 | 
				
			||||||
    PHROT::setSize_phrot (txa->phrot, txa->dsp_size);
 | 
					    txa->phrot->setSize(txa->dsp_size);
 | 
				
			||||||
    txa->micmeter->setBuffers (txa->midbuff);
 | 
					    txa->micmeter->setBuffers (txa->midbuff);
 | 
				
			||||||
    txa->micmeter->setSize (txa->dsp_size);
 | 
					    txa->micmeter->setSize (txa->dsp_size);
 | 
				
			||||||
    txa->amsq->setBuffers (txa->midbuff, txa->midbuff, txa->midbuff);
 | 
					    txa->amsq->setBuffers (txa->midbuff, txa->midbuff, txa->midbuff);
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										143
									
								
								wdsp/bqbp.cpp
									
									
									
									
									
								
							
							
						
						
									
										143
									
								
								wdsp/bqbp.cpp
									
									
									
									
									
								
							@ -27,8 +27,6 @@ warren@wpratt.com
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "comm.hpp"
 | 
					#include "comm.hpp"
 | 
				
			||||||
#include "bqbp.hpp"
 | 
					#include "bqbp.hpp"
 | 
				
			||||||
#include "RXA.hpp"
 | 
					 | 
				
			||||||
#include "TXA.hpp"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace WDSP {
 | 
					namespace WDSP {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -38,122 +36,119 @@ namespace WDSP {
 | 
				
			|||||||
*                                                                                                       *
 | 
					*                                                                                                       *
 | 
				
			||||||
********************************************************************************************************/
 | 
					********************************************************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BQBP::calc_bqbp(BQBP *a)
 | 
					void BQBP::calc()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    double f0, w0, bw, q, sn, cs, c, den;
 | 
					    double f0, w0, bw, q, sn, cs, c, den;
 | 
				
			||||||
    bw = a->f_high - a->f_low;
 | 
					
 | 
				
			||||||
    f0 = (a->f_high + a->f_low) / 2.0;
 | 
					    bw = f_high - f_low;
 | 
				
			||||||
 | 
					    f0 = (f_high + f_low) / 2.0;
 | 
				
			||||||
    q = f0 / bw;
 | 
					    q = f0 / bw;
 | 
				
			||||||
    w0 = TWOPI * f0 / a->rate;
 | 
					    w0 = TWOPI * f0 / rate;
 | 
				
			||||||
    sn = sin(w0);
 | 
					    sn = sin(w0);
 | 
				
			||||||
    cs = cos(w0);
 | 
					    cs = cos(w0);
 | 
				
			||||||
    c = sn / (2.0 * q);
 | 
					    c = sn / (2.0 * q);
 | 
				
			||||||
    den = 1.0 + c;
 | 
					    den = 1.0 + c;
 | 
				
			||||||
    a->a0 = +c / den;
 | 
					    a0 = +c / den;
 | 
				
			||||||
    a->a1 = 0.0;
 | 
					    a1 = 0.0;
 | 
				
			||||||
    a->a2 = -c / den;
 | 
					    a2 = -c / den;
 | 
				
			||||||
    a->b1 = 2.0 * cs / den;
 | 
					    b1 = 2.0 * cs / den;
 | 
				
			||||||
    a->b2 = (c - 1.0) / den;
 | 
					    b2 = (c - 1.0) / den;
 | 
				
			||||||
    flush_bqbp(a);
 | 
					    flush();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
BQBP* BQBP::create_bqbp(int run, int size, float* in, float* out, double rate, double f_low, double f_high, double gain, int nstages)
 | 
					BQBP::BQBP(
 | 
				
			||||||
 | 
					    int _run,
 | 
				
			||||||
 | 
					    int _size,
 | 
				
			||||||
 | 
					    float* _in,
 | 
				
			||||||
 | 
					    float* _out,
 | 
				
			||||||
 | 
					    double _rate,
 | 
				
			||||||
 | 
					    double _f_low,
 | 
				
			||||||
 | 
					    double _f_high,
 | 
				
			||||||
 | 
					    double _gain,
 | 
				
			||||||
 | 
					    int _nstages
 | 
				
			||||||
 | 
					) :
 | 
				
			||||||
 | 
					    run(_run),
 | 
				
			||||||
 | 
					    size(_size),
 | 
				
			||||||
 | 
					    in(_in),
 | 
				
			||||||
 | 
					    out(_out),
 | 
				
			||||||
 | 
					    rate(_rate),
 | 
				
			||||||
 | 
					    f_low(_f_low),
 | 
				
			||||||
 | 
					    f_high(_f_high),
 | 
				
			||||||
 | 
					    gain(_gain),
 | 
				
			||||||
 | 
					    nstages(_nstages)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    BQBP *a = new BQBP;
 | 
					    x0.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
 | 
				
			||||||
    a->run = run;
 | 
					    x1.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
 | 
				
			||||||
    a->size = size;
 | 
					    x2.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
 | 
				
			||||||
    a->in = in;
 | 
					    y0.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
 | 
				
			||||||
    a->out = out;
 | 
					    y1.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
 | 
				
			||||||
    a->rate = rate;
 | 
					    y2.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
 | 
				
			||||||
    a->f_low = f_low;
 | 
					    calc();
 | 
				
			||||||
    a->f_high = f_high;
 | 
					 | 
				
			||||||
    a->gain = gain;
 | 
					 | 
				
			||||||
    a->nstages = nstages;
 | 
					 | 
				
			||||||
    a->x0 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
 | 
					 | 
				
			||||||
    a->x1 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
 | 
					 | 
				
			||||||
    a->x2 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
 | 
					 | 
				
			||||||
    a->y0 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
 | 
					 | 
				
			||||||
    a->y1 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
 | 
					 | 
				
			||||||
    a->y2 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
 | 
					 | 
				
			||||||
    calc_bqbp(a);
 | 
					 | 
				
			||||||
    return a;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BQBP::destroy_bqbp(BQBP *a)
 | 
					void BQBP::flush()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    delete[](a->y2);
 | 
					    for (int i = 0; i < nstages; i++)
 | 
				
			||||||
    delete[](a->y1);
 | 
					 | 
				
			||||||
    delete[](a->y0);
 | 
					 | 
				
			||||||
    delete[](a->x2);
 | 
					 | 
				
			||||||
    delete[](a->x1);
 | 
					 | 
				
			||||||
    delete[](a->x0);
 | 
					 | 
				
			||||||
    delete(a);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void BQBP::flush_bqbp(BQBP *a)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    int i;
 | 
					 | 
				
			||||||
    for (i = 0; i < a->nstages; i++)
 | 
					 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        a->x1[2 * i + 0] = a->x2[2 * i + 0] = a->y1[2 * i + 0] = a->y2[2 * i + 0] = 0.0;
 | 
					        x1[2 * i + 0] = x2[2 * i + 0] = y1[2 * i + 0] = y2[2 * i + 0] = 0.0;
 | 
				
			||||||
        a->x1[2 * i + 1] = a->x2[2 * i + 1] = a->y1[2 * i + 1] = a->y2[2 * i + 1] = 0.0;
 | 
					        x1[2 * i + 1] = x2[2 * i + 1] = y1[2 * i + 1] = y2[2 * i + 1] = 0.0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BQBP::xbqbp(BQBP *a)
 | 
					void BQBP::execute()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (a->run)
 | 
					    if (run)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        int i, j, n;
 | 
					        int i, j, n;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (i = 0; i < a->size; i++)
 | 
					        for (i = 0; i < size; i++)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            for (j = 0; j < 2; j++)
 | 
					            for (j = 0; j < 2; j++)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                a->x0[j] = a->gain * a->in[2 * i + j];
 | 
					                x0[j] = gain * in[2 * i + j];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                for (n = 0; n < a->nstages; n++)
 | 
					                for (n = 0; n < nstages; n++)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    if (n > 0)
 | 
					                    if (n > 0)
 | 
				
			||||||
                        a->x0[2 * n + j] = a->y0[2 * (n - 1) + j];
 | 
					                        x0[2 * n + j] = y0[2 * (n - 1) + j];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    a->y0[2 * n + j] = a->a0 * a->x0[2 * n + j]
 | 
					                    y0[2 * n + j] = a0 * x0[2 * n + j]
 | 
				
			||||||
                        + a->a1 * a->x1[2 * n + j]
 | 
					                        + a1 * x1[2 * n + j]
 | 
				
			||||||
                        + a->a2 * a->x2[2 * n + j]
 | 
					                        + a2 * x2[2 * n + j]
 | 
				
			||||||
                        + a->b1 * a->y1[2 * n + j]
 | 
					                        + b1 * y1[2 * n + j]
 | 
				
			||||||
                        + a->b2 * a->y2[2 * n + j];
 | 
					                        + b2 * y2[2 * n + j];
 | 
				
			||||||
                    a->y2[2 * n + j] = a->y1[2 * n + j];
 | 
					                    y2[2 * n + j] = y1[2 * n + j];
 | 
				
			||||||
                    a->y1[2 * n + j] = a->y0[2 * n + j];
 | 
					                    y1[2 * n + j] = y0[2 * n + j];
 | 
				
			||||||
                    a->x2[2 * n + j] = a->x1[2 * n + j];
 | 
					                    x2[2 * n + j] = x1[2 * n + j];
 | 
				
			||||||
                    a->x1[2 * n + j] = a->x0[2 * n + j];
 | 
					                    x1[2 * n + j] = x0[2 * n + j];
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                a->out[2 * i + j] = a->y0[2 * (a->nstages - 1) + j];
 | 
					                out[2 * i + j] = y0[2 * (nstages - 1) + j];
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (a->out != a->in)
 | 
					    else if (out != in)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        std::copy(a->in, a->in + a->size * 2, a->out);
 | 
					        std::copy(in, in + size * 2, out);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BQBP::setBuffers_bqbp(BQBP *a, float* in, float* out)
 | 
					void BQBP::setBuffers(float* _in, float* _out)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->in = in;
 | 
					    in = _in;
 | 
				
			||||||
    a->out = out;
 | 
					    out = _out;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BQBP::setSamplerate_bqbp(BQBP *a, int rate)
 | 
					void BQBP::setSamplerate( int _rate)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->rate = rate;
 | 
					    rate = _rate;
 | 
				
			||||||
    calc_bqbp(a);
 | 
					    calc();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BQBP::setSize_bqbp(BQBP *a, int size)
 | 
					void BQBP::setSize(int _size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->size = size;
 | 
					    size = _size;
 | 
				
			||||||
    flush_bqbp(a);
 | 
					    flush();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace WDSP
 | 
					} // namespace WDSP
 | 
				
			||||||
 | 
				
			|||||||
@ -34,6 +34,8 @@ warren@wpratt.com
 | 
				
			|||||||
#ifndef wdsp_bqbp_h
 | 
					#ifndef wdsp_bqbp_h
 | 
				
			||||||
#define wdsp_bqbp_h
 | 
					#define wdsp_bqbp_h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "export.h"
 | 
					#include "export.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace WDSP {
 | 
					namespace WDSP {
 | 
				
			||||||
@ -51,18 +53,31 @@ public:
 | 
				
			|||||||
    double gain;
 | 
					    double gain;
 | 
				
			||||||
    int nstages;
 | 
					    int nstages;
 | 
				
			||||||
    double a0, a1, a2, b1, b2;
 | 
					    double a0, a1, a2, b1, b2;
 | 
				
			||||||
    double* x0, * x1, * x2, * y0, * y1, * y2;
 | 
					    std::vector<double> x0, x1, x2, y0, y1, y2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static BQBP* create_bqbp(int run, int size, float* in, float* out, double rate, double f_low, double f_high, double gain, int nstages);
 | 
					    BQBP(
 | 
				
			||||||
    static void destroy_bqbp(BQBP *a);
 | 
					        int run,
 | 
				
			||||||
    static void flush_bqbp(BQBP *a);
 | 
					        int size,
 | 
				
			||||||
    static void xbqbp(BQBP *a);
 | 
					        float* in,
 | 
				
			||||||
    static void setBuffers_bqbp(BQBP *a, float* in, float* out);
 | 
					        float* out,
 | 
				
			||||||
    static void setSamplerate_bqbp(BQBP *a, int rate);
 | 
					        double rate,
 | 
				
			||||||
    static void setSize_bqbp(BQBP *a, int size);
 | 
					        double f_low,
 | 
				
			||||||
 | 
					        double f_high,
 | 
				
			||||||
 | 
					        double gain,
 | 
				
			||||||
 | 
					        int nstages
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    BQBP(const BQBP&) = delete;
 | 
				
			||||||
 | 
					    BQBP& operator=(BQBP& other) = delete;
 | 
				
			||||||
 | 
					    ~BQBP() = default;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void flush();
 | 
				
			||||||
 | 
					    void execute();
 | 
				
			||||||
 | 
					    void setBuffers(float* in, float* out);
 | 
				
			||||||
 | 
					    void setSamplerate(int rate);
 | 
				
			||||||
 | 
					    void setSize(int size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    static void calc_bqbp(BQBP *a);
 | 
					    void calc();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace WDSP
 | 
					} // namespace WDSP
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										142
									
								
								wdsp/bqlp.cpp
									
									
									
									
									
								
							
							
						
						
									
										142
									
								
								wdsp/bqlp.cpp
									
									
									
									
									
								
							@ -27,8 +27,6 @@ warren@wpratt.com
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "comm.hpp"
 | 
					#include "comm.hpp"
 | 
				
			||||||
#include "bqlp.hpp"
 | 
					#include "bqlp.hpp"
 | 
				
			||||||
#include "RXA.hpp"
 | 
					 | 
				
			||||||
#include "TXA.hpp"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace WDSP {
 | 
					namespace WDSP {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -38,118 +36,114 @@ namespace WDSP {
 | 
				
			|||||||
*                                                                                                       *
 | 
					*                                                                                                       *
 | 
				
			||||||
********************************************************************************************************/
 | 
					********************************************************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BQLP::calc_bqlp(BQLP *a)
 | 
					void BQLP::calc()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    double w0, cs, c, den;
 | 
					    double w0, cs, c, den;
 | 
				
			||||||
    w0 = TWOPI * a->fc / (double)a->rate;
 | 
					
 | 
				
			||||||
 | 
					    w0 = TWOPI * fc / (double)rate;
 | 
				
			||||||
    cs = cos(w0);
 | 
					    cs = cos(w0);
 | 
				
			||||||
    c = sin(w0) / (2.0 * a->Q);
 | 
					    c = sin(w0) / (2.0 * Q);
 | 
				
			||||||
    den = 1.0 + c;
 | 
					    den = 1.0 + c;
 | 
				
			||||||
    a->a0 = 0.5 * (1.0 - cs) / den;
 | 
					    a0 = 0.5 * (1.0 - cs) / den;
 | 
				
			||||||
    a->a1 = (1.0 - cs) / den;
 | 
					    a1 = (1.0 - cs) / den;
 | 
				
			||||||
    a->a2 = 0.5 * (1.0 - cs) / den;
 | 
					    a2 = 0.5 * (1.0 - cs) / den;
 | 
				
			||||||
    a->b1 = 2.0 * cs / den;
 | 
					    b1 = 2.0 * cs / den;
 | 
				
			||||||
    a->b2 = (c - 1.0) / den;
 | 
					    b2 = (c - 1.0) / den;
 | 
				
			||||||
    flush_bqlp(a);
 | 
					    flush();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
BQLP* BQLP::create_bqlp(int run, int size, float* in, float* out, double rate, double fc, double Q, double gain, int nstages)
 | 
					BQLP::BQLP(
 | 
				
			||||||
 | 
					    int _run,
 | 
				
			||||||
 | 
					    int _size,
 | 
				
			||||||
 | 
					    float* _in,
 | 
				
			||||||
 | 
					    float* _out,
 | 
				
			||||||
 | 
					    double _rate,
 | 
				
			||||||
 | 
					    double _fc,
 | 
				
			||||||
 | 
					    double _Q,
 | 
				
			||||||
 | 
					    double _gain,
 | 
				
			||||||
 | 
					    int _nstages
 | 
				
			||||||
 | 
					) :
 | 
				
			||||||
 | 
					    run(_run),
 | 
				
			||||||
 | 
					    size(_size),
 | 
				
			||||||
 | 
					    in(_in),
 | 
				
			||||||
 | 
					    out(_out),
 | 
				
			||||||
 | 
					    rate(_rate),
 | 
				
			||||||
 | 
					    fc(_fc),
 | 
				
			||||||
 | 
					    Q(_Q),
 | 
				
			||||||
 | 
					    gain(_gain),
 | 
				
			||||||
 | 
					    nstages(_nstages)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    BQLP *a = new BQLP;
 | 
					    x0.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
 | 
				
			||||||
    a->run = run;
 | 
					    x1.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
 | 
				
			||||||
    a->size = size;
 | 
					    x2.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
 | 
				
			||||||
    a->in = in;
 | 
					    y0.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
 | 
				
			||||||
    a->out = out;
 | 
					    y1.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
 | 
				
			||||||
    a->rate = rate;
 | 
					    y2.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
 | 
				
			||||||
    a->fc = fc;
 | 
					    calc();
 | 
				
			||||||
    a->Q = Q;
 | 
					 | 
				
			||||||
    a->gain = gain;
 | 
					 | 
				
			||||||
    a->nstages = nstages;
 | 
					 | 
				
			||||||
    a->x0 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
 | 
					 | 
				
			||||||
    a->x1 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
 | 
					 | 
				
			||||||
    a->x2 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
 | 
					 | 
				
			||||||
    a->y0 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
 | 
					 | 
				
			||||||
    a->y1 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
 | 
					 | 
				
			||||||
    a->y2 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
 | 
					 | 
				
			||||||
    calc_bqlp(a);
 | 
					 | 
				
			||||||
    return a;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BQLP::destroy_bqlp(BQLP *a)
 | 
					void BQLP::flush()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    delete[](a->y2);
 | 
					    for (int i = 0; i < nstages; i++)
 | 
				
			||||||
    delete[](a->y1);
 | 
					 | 
				
			||||||
    delete[](a->y0);
 | 
					 | 
				
			||||||
    delete[](a->x2);
 | 
					 | 
				
			||||||
    delete[](a->x1);
 | 
					 | 
				
			||||||
    delete[](a->x0);
 | 
					 | 
				
			||||||
    delete(a);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void BQLP::flush_bqlp(BQLP *a)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    int i;
 | 
					 | 
				
			||||||
    for (i = 0; i < a->nstages; i++)
 | 
					 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        a->x1[2 * i + 0] = a->x2[2 * i + 0] = a->y1[2 * i + 0] = a->y2[2 * i + 0] = 0.0;
 | 
					        x1[2 * i + 0] = x2[2 * i + 0] = y1[2 * i + 0] = y2[2 * i + 0] = 0.0;
 | 
				
			||||||
        a->x1[2 * i + 1] = a->x2[2 * i + 1] = a->y1[2 * i + 1] = a->y2[2 * i + 1] = 0.0;
 | 
					        x1[2 * i + 1] = x2[2 * i + 1] = y1[2 * i + 1] = y2[2 * i + 1] = 0.0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BQLP::xbqlp(BQLP *a)
 | 
					void BQLP::execute()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (a->run)
 | 
					    if (run)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        int i, j, n;
 | 
					        int i, j, n;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (i = 0; i < a->size; i++)
 | 
					        for (i = 0; i < size; i++)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            for (j = 0; j < 2; j++)
 | 
					            for (j = 0; j < 2; j++)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                a->x0[j] = a->gain * a->in[2 * i + j];
 | 
					                x0[j] = gain * in[2 * i + j];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                for (n = 0; n < a->nstages; n++)
 | 
					                for (n = 0; n < nstages; n++)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    if (n > 0)
 | 
					                    if (n > 0)
 | 
				
			||||||
                        a->x0[2 * n + j] = a->y0[2 * (n - 1) + j];
 | 
					                        x0[2 * n + j] = y0[2 * (n - 1) + j];
 | 
				
			||||||
                    a->y0[2 * n + j] = a->a0 * a->x0[2 * n + j]
 | 
					                    y0[2 * n + j] = a0 * x0[2 * n + j]
 | 
				
			||||||
                        + a->a1 * a->x1[2 * n + j]
 | 
					                        + a1 * x1[2 * n + j]
 | 
				
			||||||
                        + a->a2 * a->x2[2 * n + j]
 | 
					                        + a2 * x2[2 * n + j]
 | 
				
			||||||
                        + a->b1 * a->y1[2 * n + j]
 | 
					                        + b1 * y1[2 * n + j]
 | 
				
			||||||
                        + a->b2 * a->y2[2 * n + j];
 | 
					                        + b2 * y2[2 * n + j];
 | 
				
			||||||
                    a->y2[2 * n + j] = a->y1[2 * n + j];
 | 
					                    y2[2 * n + j] = y1[2 * n + j];
 | 
				
			||||||
                    a->y1[2 * n + j] = a->y0[2 * n + j];
 | 
					                    y1[2 * n + j] = y0[2 * n + j];
 | 
				
			||||||
                    a->x2[2 * n + j] = a->x1[2 * n + j];
 | 
					                    x2[2 * n + j] = x1[2 * n + j];
 | 
				
			||||||
                    a->x1[2 * n + j] = a->x0[2 * n + j];
 | 
					                    x1[2 * n + j] = x0[2 * n + j];
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                a->out[2 * i + j] = a->y0[2 * (a->nstages - 1) + j];
 | 
					                out[2 * i + j] = y0[2 * (nstages - 1) + j];
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (a->out != a->in)
 | 
					    else if (out != in)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        std::copy(a->in, a->in + a->size * 2, a->out);
 | 
					        std::copy(in, in + size * 2, out);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BQLP::setBuffers_bqlp(BQLP *a, float* in, float* out)
 | 
					void BQLP::setBuffers(float* _in, float* _out)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->in = in;
 | 
					    in = _in;
 | 
				
			||||||
    a->out = out;
 | 
					    out = _out;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BQLP::setSamplerate_bqlp(BQLP *a, int rate)
 | 
					void BQLP::setSamplerate(int _rate)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->rate = rate;
 | 
					    rate = _rate;
 | 
				
			||||||
    calc_bqlp(a);
 | 
					    calc();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BQLP::setSize_bqlp(BQLP *a, int size)
 | 
					void BQLP::setSize(int _size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->size = size;
 | 
					    size = _size;
 | 
				
			||||||
    flush_bqlp(a);
 | 
					    flush();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
} // namespace WDSP
 | 
					} // namespace WDSP
 | 
				
			||||||
 | 
				
			|||||||
@ -34,6 +34,8 @@ warren@wpratt.com
 | 
				
			|||||||
#ifndef wdsp_bqlp_h
 | 
					#ifndef wdsp_bqlp_h
 | 
				
			||||||
#define wdsp_bqlp_h
 | 
					#define wdsp_bqlp_h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "export.h"
 | 
					#include "export.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace WDSP {
 | 
					namespace WDSP {
 | 
				
			||||||
@ -51,18 +53,31 @@ public:
 | 
				
			|||||||
    double gain;
 | 
					    double gain;
 | 
				
			||||||
    int nstages;
 | 
					    int nstages;
 | 
				
			||||||
    double a0, a1, a2, b1, b2;
 | 
					    double a0, a1, a2, b1, b2;
 | 
				
			||||||
    double* x0, * x1, * x2, * y0, * y1, * y2;
 | 
					    std::vector<double> x0, x1, x2, y0, y1, y2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static BQLP* create_bqlp(int run, int size, float* in, float* out, double rate, double fc, double Q, double gain, int nstages);
 | 
					    BQLP(
 | 
				
			||||||
    static void destroy_bqlp(BQLP *a);
 | 
					        int run,
 | 
				
			||||||
    static void flush_bqlp(BQLP *a);
 | 
					        int size,
 | 
				
			||||||
    static void xbqlp(BQLP *a);
 | 
					        float* in,
 | 
				
			||||||
    static void setBuffers_bqlp(BQLP *a, float* in, float* out);
 | 
					        float* out,
 | 
				
			||||||
    static void setSamplerate_bqlp(BQLP *a, int rate);
 | 
					        double rate,
 | 
				
			||||||
    static void setSize_bqlp(BQLP *a, int size);
 | 
					        double fc,
 | 
				
			||||||
 | 
					        double Q,
 | 
				
			||||||
 | 
					        double gain,
 | 
				
			||||||
 | 
					        int nstages
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    BQLP(const BQLP&) = delete;
 | 
				
			||||||
 | 
					    BQLP& operator=(BQLP& other) = delete;
 | 
				
			||||||
 | 
					    ~BQLP() = default;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void flush();
 | 
				
			||||||
 | 
					    void execute();
 | 
				
			||||||
 | 
					    void setBuffers(float* in, float* out);
 | 
				
			||||||
 | 
					    void setSamplerate(int rate);
 | 
				
			||||||
 | 
					    void setSize(int size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    static void calc_bqlp(BQLP *a);
 | 
					    void calc();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace WDSP
 | 
					} // namespace WDSP
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										141
									
								
								wdsp/dbqbp.cpp
									
									
									
									
									
								
							
							
						
						
									
										141
									
								
								wdsp/dbqbp.cpp
									
									
									
									
									
								
							@ -27,8 +27,6 @@ warren@wpratt.com
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "comm.hpp"
 | 
					#include "comm.hpp"
 | 
				
			||||||
#include "dbqbp.hpp"
 | 
					#include "dbqbp.hpp"
 | 
				
			||||||
#include "RXA.hpp"
 | 
					 | 
				
			||||||
#include "TXA.hpp"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace WDSP {
 | 
					namespace WDSP {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -38,118 +36,115 @@ namespace WDSP {
 | 
				
			|||||||
*                                                                                                       *
 | 
					*                                                                                                       *
 | 
				
			||||||
********************************************************************************************************/
 | 
					********************************************************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DBQBP::calc_dbqbp(DBQBP *a)
 | 
					void DBQBP::calc()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    double f0, w0, bw, q, sn, cs, c, den;
 | 
					    double f0, w0, bw, q, sn, cs, c, den;
 | 
				
			||||||
    bw = a->f_high - a->f_low;
 | 
					
 | 
				
			||||||
    f0 = (a->f_high + a->f_low) / 2.0;
 | 
					    bw = f_high - f_low;
 | 
				
			||||||
 | 
					    f0 = (f_high + f_low) / 2.0;
 | 
				
			||||||
    q = f0 / bw;
 | 
					    q = f0 / bw;
 | 
				
			||||||
    w0 = TWOPI * f0 / a->rate;
 | 
					    w0 = TWOPI * f0 / rate;
 | 
				
			||||||
    sn = sin(w0);
 | 
					    sn = sin(w0);
 | 
				
			||||||
    cs = cos(w0);
 | 
					    cs = cos(w0);
 | 
				
			||||||
    c = sn / (2.0 * q);
 | 
					    c = sn / (2.0 * q);
 | 
				
			||||||
    den = 1.0 + c;
 | 
					    den = 1.0 + c;
 | 
				
			||||||
    a->a0 = +c / den;
 | 
					    a0 = +c / den;
 | 
				
			||||||
    a->a1 = 0.0;
 | 
					    a1 = 0.0;
 | 
				
			||||||
    a->a2 = -c / den;
 | 
					    a2 = -c / den;
 | 
				
			||||||
    a->b1 = 2.0 * cs / den;
 | 
					    b1 = 2.0 * cs / den;
 | 
				
			||||||
    a->b2 = (c - 1.0) / den;
 | 
					    b2 = (c - 1.0) / den;
 | 
				
			||||||
    flush_dbqbp(a);
 | 
					    flush();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DBQBP* DBQBP::create_dbqbp(int run, int size, float* in, float* out, double rate, double f_low, double f_high, double gain, int nstages)
 | 
					DBQBP::DBQBP(
 | 
				
			||||||
 | 
					    int _run,
 | 
				
			||||||
 | 
					    int _size,
 | 
				
			||||||
 | 
					    float* _in,
 | 
				
			||||||
 | 
					    float* _out,
 | 
				
			||||||
 | 
					    double _rate,
 | 
				
			||||||
 | 
					    double _f_low,
 | 
				
			||||||
 | 
					    double _f_high,
 | 
				
			||||||
 | 
					    double _gain,
 | 
				
			||||||
 | 
					    int _nstages
 | 
				
			||||||
 | 
					) :
 | 
				
			||||||
 | 
					    run(_run),
 | 
				
			||||||
 | 
					    size(_size),
 | 
				
			||||||
 | 
					    in(_in),
 | 
				
			||||||
 | 
					    out(_out),
 | 
				
			||||||
 | 
					    rate(_rate),
 | 
				
			||||||
 | 
					    f_low(_f_low),
 | 
				
			||||||
 | 
					    f_high(_f_high),
 | 
				
			||||||
 | 
					    gain(_gain),
 | 
				
			||||||
 | 
					    nstages(_nstages)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    DBQBP *a = new DBQBP;
 | 
					    x0.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
 | 
				
			||||||
    a->run = run;
 | 
					    x1.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
 | 
				
			||||||
    a->size = size;
 | 
					    x2.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
 | 
				
			||||||
    a->in = in;
 | 
					    y0.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
 | 
				
			||||||
    a->out = out;
 | 
					    y1.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
 | 
				
			||||||
    a->rate = rate;
 | 
					    y2.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
 | 
				
			||||||
    a->f_low = f_low;
 | 
					    calc();
 | 
				
			||||||
    a->f_high = f_high;
 | 
					 | 
				
			||||||
    a->gain = gain;
 | 
					 | 
				
			||||||
    a->nstages = nstages;
 | 
					 | 
				
			||||||
    a->x0 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
 | 
					 | 
				
			||||||
    a->x1 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
 | 
					 | 
				
			||||||
    a->x2 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
 | 
					 | 
				
			||||||
    a->y0 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
 | 
					 | 
				
			||||||
    a->y1 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
 | 
					 | 
				
			||||||
    a->y2 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
 | 
					 | 
				
			||||||
    calc_dbqbp(a);
 | 
					 | 
				
			||||||
    return a;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DBQBP::destroy_dbqbp(DBQBP *a)
 | 
					void DBQBP::flush()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    delete[](a->y2);
 | 
					    for (int i = 0; i < nstages; i++)
 | 
				
			||||||
    delete[](a->y1);
 | 
					 | 
				
			||||||
    delete[](a->y0);
 | 
					 | 
				
			||||||
    delete[](a->x2);
 | 
					 | 
				
			||||||
    delete[](a->x1);
 | 
					 | 
				
			||||||
    delete[](a->x0);
 | 
					 | 
				
			||||||
    delete(a);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void DBQBP::flush_dbqbp(DBQBP *a)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    int i;
 | 
					 | 
				
			||||||
    for (i = 0; i < a->nstages; i++)
 | 
					 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        a->x1[i] = a->x2[i] = a->y1[i] = a->y2[i] = 0.0;
 | 
					        x1[i] = x2[i] = y1[i] = y2[i] = 0.0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DBQBP::xdbqbp(DBQBP *a)
 | 
					void DBQBP::execute()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (a->run)
 | 
					    if (run)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        int i, n;
 | 
					        int i, n;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (i = 0; i < a->size; i++)
 | 
					        for (i = 0; i < size; i++)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            a->x0[0] = a->gain * a->in[i];
 | 
					            x0[0] = gain * in[i];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for (n = 0; n < a->nstages; n++)
 | 
					            for (n = 0; n < nstages; n++)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                if (n > 0)
 | 
					                if (n > 0)
 | 
				
			||||||
                    a->x0[n] = a->y0[n - 1];
 | 
					                    x0[n] = y0[n - 1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                a->y0[n] = a->a0 * a->x0[n]
 | 
					                y0[n] = a0 * x0[n]
 | 
				
			||||||
                    + a->a1 * a->x1[n]
 | 
					                    + a1 * x1[n]
 | 
				
			||||||
                    + a->a2 * a->x2[n]
 | 
					                    + a2 * x2[n]
 | 
				
			||||||
                    + a->b1 * a->y1[n]
 | 
					                    + b1 * y1[n]
 | 
				
			||||||
                    + a->b2 * a->y2[n];
 | 
					                    + b2 * y2[n];
 | 
				
			||||||
                a->y2[n] = a->y1[n];
 | 
					                y2[n] = y1[n];
 | 
				
			||||||
                a->y1[n] = a->y0[n];
 | 
					                y1[n] = y0[n];
 | 
				
			||||||
                a->x2[n] = a->x1[n];
 | 
					                x2[n] = x1[n];
 | 
				
			||||||
                a->x1[n] = a->x0[n];
 | 
					                x1[n] = x0[n];
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            a->out[i] = a->y0[a->nstages - 1];
 | 
					            out[i] = y0[nstages - 1];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (a->out != a->in)
 | 
					    else if (out != in)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        memcpy(a->out, a->in, a->size * sizeof(float));
 | 
					        std::copy(in, in + size, out);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DBQBP::setBuffers_dbqbp(DBQBP *a, float* in, float* out)
 | 
					void DBQBP::setBuffers(float* _in, float* _out)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->in = in;
 | 
					    in = _in;
 | 
				
			||||||
    a->out = out;
 | 
					    out = _out;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DBQBP::setSamplerate_dbqbp(DBQBP *a, int rate)
 | 
					void DBQBP::setSamplerate(int _rate)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->rate = rate;
 | 
					    rate = _rate;
 | 
				
			||||||
    calc_dbqbp(a);
 | 
					    calc();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DBQBP::setSize_dbqbp(DBQBP *a, int size)
 | 
					void DBQBP::setSize(int _size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->size = size;
 | 
					    size = _size;
 | 
				
			||||||
    flush_dbqbp(a);
 | 
					    flush();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace WDSP
 | 
					} // namespace WDSP
 | 
				
			||||||
 | 
				
			|||||||
@ -34,6 +34,8 @@ warren@wpratt.com
 | 
				
			|||||||
#ifndef wdsp_dbqbp_h
 | 
					#ifndef wdsp_dbqbp_h
 | 
				
			||||||
#define wdsp_dbqbp_h
 | 
					#define wdsp_dbqbp_h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "export.h"
 | 
					#include "export.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace WDSP {
 | 
					namespace WDSP {
 | 
				
			||||||
@ -51,19 +53,32 @@ public:
 | 
				
			|||||||
    double gain;
 | 
					    double gain;
 | 
				
			||||||
    int nstages;
 | 
					    int nstages;
 | 
				
			||||||
    double a0, a1, a2, b1, b2;
 | 
					    double a0, a1, a2, b1, b2;
 | 
				
			||||||
    double* x0, * x1, * x2, * y0, * y1, * y2;
 | 
					    std::vector<double> x0, x1, x2, y0, y1, y2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Double Bi-Quad Band-Pass
 | 
					    // Double Bi-Quad Band-Pass
 | 
				
			||||||
    static DBQBP* create_dbqbp(int run, int size, float* in, float* out, double rate, double f_low, double f_high, double gain, int nstages);
 | 
					    DBQBP(
 | 
				
			||||||
    static void destroy_dbqbp(DBQBP *a);
 | 
					        int run,
 | 
				
			||||||
    static void flush_dbqbp(DBQBP *a);
 | 
					        int size,
 | 
				
			||||||
    static void xdbqbp(DBQBP *a);
 | 
					        float* in,
 | 
				
			||||||
    static void setBuffers_dbqbp(DBQBP *a, float* in, float* out);
 | 
					        float* out,
 | 
				
			||||||
    static void setSamplerate_dbqbp(DBQBP *a, int rate);
 | 
					        double rate,
 | 
				
			||||||
    static void setSize_dbqbp(DBQBP *a, int size);
 | 
					        double f_low,
 | 
				
			||||||
 | 
					        double f_high,
 | 
				
			||||||
 | 
					        double gain,
 | 
				
			||||||
 | 
					        int nstages
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    DBQBP(const DBQBP&) = delete;
 | 
				
			||||||
 | 
					    DBQBP& operator=(DBQBP& other) = delete;
 | 
				
			||||||
 | 
					    ~DBQBP() = default;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void flush();
 | 
				
			||||||
 | 
					    void execute();
 | 
				
			||||||
 | 
					    void setBuffers(float* in, float* out);
 | 
				
			||||||
 | 
					    void setSamplerate(int rate);
 | 
				
			||||||
 | 
					    void setSize(int size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    static void calc_dbqbp(DBQBP *a);
 | 
					    void calc();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace WDSP
 | 
					} // namespace WDSP
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										139
									
								
								wdsp/dbqlp.cpp
									
									
									
									
									
								
							
							
						
						
									
										139
									
								
								wdsp/dbqlp.cpp
									
									
									
									
									
								
							@ -27,8 +27,6 @@ warren@wpratt.com
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "comm.hpp"
 | 
					#include "comm.hpp"
 | 
				
			||||||
#include "dbqlp.hpp"
 | 
					#include "dbqlp.hpp"
 | 
				
			||||||
#include "RXA.hpp"
 | 
					 | 
				
			||||||
#include "TXA.hpp"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace WDSP {
 | 
					namespace WDSP {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -38,114 +36,111 @@ namespace WDSP {
 | 
				
			|||||||
*                                                                                                       *
 | 
					*                                                                                                       *
 | 
				
			||||||
********************************************************************************************************/
 | 
					********************************************************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DBQLP::calc_dbqlp(DBQLP *a)
 | 
					void DBQLP::calc()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    float w0, cs, c, den;
 | 
					    float w0, cs, c, den;
 | 
				
			||||||
    w0 = TWOPI * a->fc / (float)a->rate;
 | 
					
 | 
				
			||||||
 | 
					    w0 = TWOPI * fc / (float)rate;
 | 
				
			||||||
    cs = cos(w0);
 | 
					    cs = cos(w0);
 | 
				
			||||||
    c = sin(w0) / (2.0 * a->Q);
 | 
					    c = sin(w0) / (2.0 * Q);
 | 
				
			||||||
    den = 1.0 + c;
 | 
					    den = 1.0 + c;
 | 
				
			||||||
    a->a0 = 0.5 * (1.0 - cs) / den;
 | 
					    a0 = 0.5 * (1.0 - cs) / den;
 | 
				
			||||||
    a->a1 = (1.0 - cs) / den;
 | 
					    a1 = (1.0 - cs) / den;
 | 
				
			||||||
    a->a2 = 0.5 * (1.0 - cs) / den;
 | 
					    a2 = 0.5 * (1.0 - cs) / den;
 | 
				
			||||||
    a->b1 = 2.0 * cs / den;
 | 
					    b1 = 2.0 * cs / den;
 | 
				
			||||||
    a->b2 = (c - 1.0) / den;
 | 
					    b2 = (c - 1.0) / den;
 | 
				
			||||||
    flush_dbqlp(a);
 | 
					    flush();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DBQLP* DBQLP::create_dbqlp(int run, int size, float* in, float* out, double rate, double fc, double Q, double gain, int nstages)
 | 
					DBQLP::DBQLP(
 | 
				
			||||||
 | 
					    int _run,
 | 
				
			||||||
 | 
					    int _size,
 | 
				
			||||||
 | 
					    float* _in,
 | 
				
			||||||
 | 
					    float* _out,
 | 
				
			||||||
 | 
					    double _rate,
 | 
				
			||||||
 | 
					    double _fc,
 | 
				
			||||||
 | 
					    double _Q,
 | 
				
			||||||
 | 
					    double _gain,
 | 
				
			||||||
 | 
					    int _nstages
 | 
				
			||||||
 | 
					) :
 | 
				
			||||||
 | 
					    run(_run),
 | 
				
			||||||
 | 
					    size(_size),
 | 
				
			||||||
 | 
					    in(_in),
 | 
				
			||||||
 | 
					    out(_out),
 | 
				
			||||||
 | 
					    rate(_rate),
 | 
				
			||||||
 | 
					    fc(_fc),
 | 
				
			||||||
 | 
					    Q(_Q),
 | 
				
			||||||
 | 
					    gain(_gain),
 | 
				
			||||||
 | 
					    nstages(_nstages)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    DBQLP *a = new DBQLP;
 | 
					    x0.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
 | 
				
			||||||
    a->run = run;
 | 
					    x1.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
 | 
				
			||||||
    a->size = size;
 | 
					    x2.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
 | 
				
			||||||
    a->in = in;
 | 
					    y0.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
 | 
				
			||||||
    a->out = out;
 | 
					    y1.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
 | 
				
			||||||
    a->rate = rate;
 | 
					    y2.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
 | 
				
			||||||
    a->fc = fc;
 | 
					    calc();
 | 
				
			||||||
    a->Q = Q;
 | 
					 | 
				
			||||||
    a->gain = gain;
 | 
					 | 
				
			||||||
    a->nstages = nstages;
 | 
					 | 
				
			||||||
    a->x0 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
 | 
					 | 
				
			||||||
    a->x1 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
 | 
					 | 
				
			||||||
    a->x2 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
 | 
					 | 
				
			||||||
    a->y0 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
 | 
					 | 
				
			||||||
    a->y1 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
 | 
					 | 
				
			||||||
    a->y2 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
 | 
					 | 
				
			||||||
    calc_dbqlp(a);
 | 
					 | 
				
			||||||
    return a;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DBQLP::destroy_dbqlp(DBQLP *a)
 | 
					void DBQLP::flush()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    delete[](a->y2);
 | 
					    for (int i = 0; i < nstages; i++)
 | 
				
			||||||
    delete[](a->y1);
 | 
					 | 
				
			||||||
    delete[](a->y0);
 | 
					 | 
				
			||||||
    delete[](a->x2);
 | 
					 | 
				
			||||||
    delete[](a->x1);
 | 
					 | 
				
			||||||
    delete[](a->x0);
 | 
					 | 
				
			||||||
    delete(a);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void DBQLP::flush_dbqlp(DBQLP *a)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    int i;
 | 
					 | 
				
			||||||
    for (i = 0; i < a->nstages; i++)
 | 
					 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        a->x1[i] = a->x2[i] = a->y1[i] = a->y2[i] = 0.0;
 | 
					        x1[i] = x2[i] = y1[i] = y2[i] = 0.0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DBQLP::xdbqlp(DBQLP *a)
 | 
					void DBQLP::execute()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (a->run)
 | 
					    if (run)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        int i, n;
 | 
					        int i, n;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (i = 0; i < a->size; i++)
 | 
					        for (i = 0; i < size; i++)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            a->x0[0] = a->gain * a->in[i];
 | 
					            x0[0] = gain * in[i];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for (n = 0; n < a->nstages; n++)
 | 
					            for (n = 0; n < nstages; n++)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                if (n > 0)
 | 
					                if (n > 0)
 | 
				
			||||||
                    a->x0[n] = a->y0[n - 1];
 | 
					                    x0[n] = y0[n - 1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                a->y0[n] = a->a0 * a->x0[n]
 | 
					                y0[n] = a0 * x0[n]
 | 
				
			||||||
                    + a->a1 * a->x1[n]
 | 
					                    + a1 * x1[n]
 | 
				
			||||||
                    + a->a2 * a->x2[n]
 | 
					                    + a2 * x2[n]
 | 
				
			||||||
                    + a->b1 * a->y1[n]
 | 
					                    + b1 * y1[n]
 | 
				
			||||||
                    + a->b2 * a->y2[n];
 | 
					                    + b2 * y2[n];
 | 
				
			||||||
                a->y2[n] = a->y1[n];
 | 
					                y2[n] = y1[n];
 | 
				
			||||||
                a->y1[n] = a->y0[n];
 | 
					                y1[n] = y0[n];
 | 
				
			||||||
                a->x2[n] = a->x1[n];
 | 
					                x2[n] = x1[n];
 | 
				
			||||||
                a->x1[n] = a->x0[n];
 | 
					                x1[n] = x0[n];
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            a->out[i] = a->y0[a->nstages - 1];
 | 
					            out[i] = y0[nstages - 1];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (a->out != a->in)
 | 
					    else if (out != in)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        memcpy(a->out, a->in, a->size * sizeof(float));
 | 
					        std::copy(in, in + size, out);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DBQLP::setBuffers_dbqlp(DBQLP *a, float* in, float* out)
 | 
					void DBQLP::setBuffers(float* _in, float* _out)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->in = in;
 | 
					    in = _in;
 | 
				
			||||||
    a->out = out;
 | 
					    out = _out;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DBQLP::setSamplerate_dbqlp(DBQLP *a, int rate)
 | 
					void DBQLP::setSamplerate(int _rate)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->rate = rate;
 | 
					    rate = _rate;
 | 
				
			||||||
    calc_dbqlp(a);
 | 
					    calc();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DBQLP::setSize_dbqlp(DBQLP *a, int size)
 | 
					void DBQLP::setSize(int _size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->size = size;
 | 
					    size = _size;
 | 
				
			||||||
    flush_dbqlp(a);
 | 
					    flush();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace WDSP
 | 
					} // namespace WDSP
 | 
				
			||||||
 | 
				
			|||||||
@ -34,6 +34,8 @@ warren@wpratt.com
 | 
				
			|||||||
#ifndef wdsp_dbqlp_h
 | 
					#ifndef wdsp_dbqlp_h
 | 
				
			||||||
#define wdsp_dbqlp_h
 | 
					#define wdsp_dbqlp_h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "export.h"
 | 
					#include "export.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace WDSP {
 | 
					namespace WDSP {
 | 
				
			||||||
@ -51,18 +53,31 @@ public:
 | 
				
			|||||||
    double gain;
 | 
					    double gain;
 | 
				
			||||||
    int nstages;
 | 
					    int nstages;
 | 
				
			||||||
    double a0, a1, a2, b1, b2;
 | 
					    double a0, a1, a2, b1, b2;
 | 
				
			||||||
    double* x0, * x1, * x2, * y0, * y1, * y2;
 | 
					    std::vector<double> x0, x1, x2, y0, y1, y2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static DBQLP* create_dbqlp(int run, int size, float* in, float* out, double rate, double fc, double Q, double gain, int nstages);
 | 
					    DBQLP(
 | 
				
			||||||
    static void destroy_dbqlp(DBQLP *a);
 | 
					        int run,
 | 
				
			||||||
    static void flush_dbqlp(DBQLP *a);
 | 
					        int size,
 | 
				
			||||||
    static void xdbqlp(DBQLP *a);
 | 
					        float* in,
 | 
				
			||||||
    static void setBuffers_dbqlp(DBQLP *a, float* in, float* out);
 | 
					        float* out,
 | 
				
			||||||
    static void setSamplerate_dbqlp(DBQLP *a, int rate);
 | 
					        double rate,
 | 
				
			||||||
    static void setSize_dbqlp(DBQLP *a, int size);
 | 
					        double fc,
 | 
				
			||||||
 | 
					        double Q,
 | 
				
			||||||
 | 
					        double gain,
 | 
				
			||||||
 | 
					        int nstages
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    DBQLP(const DBQLP&) = delete;
 | 
				
			||||||
 | 
					    DBQLP& operator=(DBQLP& other) = delete;
 | 
				
			||||||
 | 
					    ~DBQLP() = default;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void flush();
 | 
				
			||||||
 | 
					    void execute();
 | 
				
			||||||
 | 
					    void setBuffers(float* in, float* out);
 | 
				
			||||||
 | 
					    void setSamplerate(int rate);
 | 
				
			||||||
 | 
					    void setSize(int size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    static void calc_dbqlp(DBQLP *a);
 | 
					    void calc();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace WDSP
 | 
					} // namespace WDSP
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										118
									
								
								wdsp/dsphp.cpp
									
									
									
									
									
								
							
							
						
						
									
										118
									
								
								wdsp/dsphp.cpp
									
									
									
									
									
								
							@ -38,103 +38,91 @@ namespace WDSP {
 | 
				
			|||||||
*                                                                                                       *
 | 
					*                                                                                                       *
 | 
				
			||||||
********************************************************************************************************/
 | 
					********************************************************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DSPHP::calc_dsphp(DSPHP *a)
 | 
					void DSPHP::calc()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    double g;
 | 
					    double g;
 | 
				
			||||||
    a->x0 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
 | 
					    x0.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
 | 
				
			||||||
    a->x1 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
 | 
					    x1.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
 | 
				
			||||||
    a->y0 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
 | 
					    y0.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
 | 
				
			||||||
    a->y1 = new double[a->nstages]; // (float*)malloc0(a->nstages * sizeof(float));
 | 
					    y1.resize(nstages); // (float*)malloc0(nstages * sizeof(float));
 | 
				
			||||||
    g = exp(-TWOPI * a->fc / a->rate);
 | 
					    g = exp(-TWOPI * fc / rate);
 | 
				
			||||||
    a->b0 = +0.5 * (1.0 + g);
 | 
					    b0 = +0.5 * (1.0 + g);
 | 
				
			||||||
    a->b1 = -0.5 * (1.0 + g);
 | 
					    b1 = -0.5 * (1.0 + g);
 | 
				
			||||||
    a->a1 = -g;
 | 
					    a1 = -g;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DSPHP* DSPHP::create_dsphp(int run, int size, float* in, float* out, double rate, double fc, int nstages)
 | 
					DSPHP::DSPHP(
 | 
				
			||||||
 | 
					    int _run,
 | 
				
			||||||
 | 
					    int _size,
 | 
				
			||||||
 | 
					    float* _in,
 | 
				
			||||||
 | 
					    float* _out,
 | 
				
			||||||
 | 
					    double _rate,
 | 
				
			||||||
 | 
					    double _fc,
 | 
				
			||||||
 | 
					    int _nstages
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    DSPHP *a = new DSPHP;
 | 
					    run = _run;
 | 
				
			||||||
    a->run = run;
 | 
					    size = _size;
 | 
				
			||||||
    a->size = size;
 | 
					    in = _in;
 | 
				
			||||||
    a->in = in;
 | 
					    out = _out;
 | 
				
			||||||
    a->out = out;
 | 
					    rate = _rate;
 | 
				
			||||||
    a->rate = rate;
 | 
					    fc = _fc;
 | 
				
			||||||
    a->fc = fc;
 | 
					    nstages = _nstages;
 | 
				
			||||||
    a->nstages = nstages;
 | 
					    calc();
 | 
				
			||||||
    calc_dsphp(a);
 | 
					 | 
				
			||||||
    return a;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DSPHP::decalc_dsphp(DSPHP *a)
 | 
					void DSPHP::flush()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    delete[](a->y1);
 | 
					    std::fill(x0.begin(), x0.end(), 0);
 | 
				
			||||||
    delete[](a->y0);
 | 
					    std::fill(x1.begin(), x1.end(), 0);
 | 
				
			||||||
    delete[](a->x1);
 | 
					    std::fill(y0.begin(), y0.end(), 0);
 | 
				
			||||||
    delete[](a->x0);
 | 
					    std::fill(y1.begin(), y1.end(), 0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DSPHP::destroy_dsphp(DSPHP *a)
 | 
					void DSPHP::execute()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    decalc_dsphp(a);
 | 
					    if (run)
 | 
				
			||||||
    delete(a);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void DSPHP::flush_dsphp(DSPHP *a)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    memset(a->x0, 0, a->nstages * sizeof(float));
 | 
					 | 
				
			||||||
    memset(a->x1, 0, a->nstages * sizeof(float));
 | 
					 | 
				
			||||||
    memset(a->y0, 0, a->nstages * sizeof(float));
 | 
					 | 
				
			||||||
    memset(a->y1, 0, a->nstages * sizeof(float));
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void DSPHP::xdsphp(DSPHP *a)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    if (a->run)
 | 
					 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        int i, n;
 | 
					        for (int i = 0; i < size; i++)
 | 
				
			||||||
 | 
					 | 
				
			||||||
        for (i = 0; i < a->size; i++)
 | 
					 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            a->x0[0] = a->in[i];
 | 
					            x0[0] = in[i];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for (n = 0; n < a->nstages; n++)
 | 
					            for (int n = 0; n < nstages; n++)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                if (n > 0)
 | 
					                if (n > 0)
 | 
				
			||||||
                    a->x0[n] = a->y0[n - 1];
 | 
					                    x0[n] = y0[n - 1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                a->y0[n] = a->b0 * a->x0[n]
 | 
					                y0[n] = b0 * x0[n]
 | 
				
			||||||
                    + a->b1 * a->x1[n]
 | 
					                    + b1 * x1[n]
 | 
				
			||||||
                    - a->a1 * a->y1[n];
 | 
					                    - a1 * y1[n];
 | 
				
			||||||
                a->y1[n] = a->y0[n];
 | 
					                y1[n] = y0[n];
 | 
				
			||||||
                a->x1[n] = a->x0[n];
 | 
					                x1[n] = x0[n];
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            a->out[i] = a->y0[a->nstages - 1];
 | 
					            out[i] = y0[nstages - 1];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (a->out != a->in)
 | 
					    else if (out != in)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        memcpy(a->out, a->in, a->size * sizeof(float));
 | 
					        std::copy(in, in + size, out);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DSPHP::setBuffers_dsphp(DSPHP *a, float* in, float* out)
 | 
					void DSPHP::setBuffers(float* _in, float* _out)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->in = in;
 | 
					    in = _in;
 | 
				
			||||||
    a->out = out;
 | 
					    out = _out;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DSPHP::setSamplerate_dsphp(DSPHP *a, int rate)
 | 
					void DSPHP::setSamplerate(int _rate)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    decalc_dsphp(a);
 | 
					    rate = _rate;
 | 
				
			||||||
    a->rate = rate;
 | 
					    calc();
 | 
				
			||||||
    calc_dsphp(a);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DSPHP::setSize_dsphp(DSPHP *a, int size)
 | 
					void DSPHP::setSize(int _size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->size = size;
 | 
					    size = _size;
 | 
				
			||||||
    flush_dsphp(a);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace WDSP
 | 
					} // namespace WDSP
 | 
				
			||||||
 | 
				
			|||||||
@ -34,6 +34,8 @@ warren@wpratt.com
 | 
				
			|||||||
#ifndef wdsp_dsphp_h
 | 
					#ifndef wdsp_dsphp_h
 | 
				
			||||||
#define wdsp_dsphp_h
 | 
					#define wdsp_dsphp_h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "export.h"
 | 
					#include "export.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace WDSP {
 | 
					namespace WDSP {
 | 
				
			||||||
@ -49,19 +51,31 @@ public:
 | 
				
			|||||||
    double fc;
 | 
					    double fc;
 | 
				
			||||||
    int nstages;
 | 
					    int nstages;
 | 
				
			||||||
    double a1, b0, b1;
 | 
					    double a1, b0, b1;
 | 
				
			||||||
    double* x0, * x1, * y0, * y1;
 | 
					    std::vector<double> x0, x1, y0, y1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static DSPHP* create_dsphp(int run, int size, float* in, float* out, double rate, double fc, int nstages);
 | 
					    DSPHP(
 | 
				
			||||||
    static void destroy_dsphp(DSPHP *a);
 | 
					        int run,
 | 
				
			||||||
    static void flush_dsphp(DSPHP *a);
 | 
					        int size,
 | 
				
			||||||
    static void xdsphp(DSPHP *a);
 | 
					        float* in,
 | 
				
			||||||
    static void setBuffers_dsphp(DSPHP *a, float* in, float* out);
 | 
					        float* out,
 | 
				
			||||||
    static void setSamplerate_dsphp(DSPHP *a, int rate);
 | 
					        double rate,
 | 
				
			||||||
    static void setSize_dsphp(DSPHP *a, int size);
 | 
					        double fc,
 | 
				
			||||||
 | 
					        int nstages
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    DSPHP(const DSPHP&) = delete;
 | 
				
			||||||
 | 
					    DSPHP& operator=(DSPHP& other) = delete;
 | 
				
			||||||
 | 
					    ~DSPHP() = default;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void destroy();
 | 
				
			||||||
 | 
					    void flush();
 | 
				
			||||||
 | 
					    void execute();
 | 
				
			||||||
 | 
					    void setBuffers(float* in, float* out);
 | 
				
			||||||
 | 
					    void setSamplerate(int rate);
 | 
				
			||||||
 | 
					    void setSize(int size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    static void calc_dsphp(DSPHP *a);
 | 
					    void calc();
 | 
				
			||||||
    static void decalc_dsphp(DSPHP *a);
 | 
					    void decalc();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace WDSP
 | 
					} // namespace WDSP
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										20
									
								
								wdsp/fmd.cpp
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								wdsp/fmd.cpp
									
									
									
									
									
								
							@ -53,7 +53,15 @@ void FMD::calc()
 | 
				
			|||||||
    // pll audio gain
 | 
					    // pll audio gain
 | 
				
			||||||
    again = rate / (deviation * TWOPI);
 | 
					    again = rate / (deviation * TWOPI);
 | 
				
			||||||
    // CTCSS Removal
 | 
					    // CTCSS Removal
 | 
				
			||||||
    sntch = SNOTCH::create_snotch(1, size, out, out, (int)rate, ctcss_freq, 0.0002);
 | 
					    sntch = new SNOTCH(
 | 
				
			||||||
 | 
					        1,
 | 
				
			||||||
 | 
					        size,
 | 
				
			||||||
 | 
					        out,
 | 
				
			||||||
 | 
					        out,
 | 
				
			||||||
 | 
					        (int) rate,
 | 
				
			||||||
 | 
					        ctcss_freq,
 | 
				
			||||||
 | 
					        0.0002)
 | 
				
			||||||
 | 
					    ;
 | 
				
			||||||
    // detector limiter
 | 
					    // detector limiter
 | 
				
			||||||
    plim = new WCPAGC(
 | 
					    plim = new WCPAGC(
 | 
				
			||||||
        1,                                          // run - always ON
 | 
					        1,                                          // run - always ON
 | 
				
			||||||
@ -84,7 +92,7 @@ void FMD::calc()
 | 
				
			|||||||
void FMD::decalc()
 | 
					void FMD::decalc()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    delete (plim);
 | 
					    delete (plim);
 | 
				
			||||||
    SNOTCH::destroy_snotch(sntch);
 | 
					    delete (sntch);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FMD::FMD(
 | 
					FMD::FMD(
 | 
				
			||||||
@ -162,7 +170,7 @@ void FMD::flush()
 | 
				
			|||||||
    fil_out = 0.0;
 | 
					    fil_out = 0.0;
 | 
				
			||||||
    omega = 0.0;
 | 
					    omega = 0.0;
 | 
				
			||||||
    fmdc = 0.0;
 | 
					    fmdc = 0.0;
 | 
				
			||||||
    SNOTCH::flush_snotch (sntch);
 | 
					    sntch->flush();
 | 
				
			||||||
    plim->flush();
 | 
					    plim->flush();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -200,7 +208,7 @@ void FMD::execute()
 | 
				
			|||||||
        // audio filter
 | 
					        // audio filter
 | 
				
			||||||
        FIRCORE::xfircore (paud);
 | 
					        FIRCORE::xfircore (paud);
 | 
				
			||||||
        // CTCSS Removal
 | 
					        // CTCSS Removal
 | 
				
			||||||
        SNOTCH::xsnotch (sntch);
 | 
					        sntch->execute();
 | 
				
			||||||
        if (lim_run)
 | 
					        if (lim_run)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            for (i = 0; i < 2 * size; i++)
 | 
					            for (i = 0; i < 2 * size; i++)
 | 
				
			||||||
@ -275,13 +283,13 @@ void FMD::setDeviation(double _deviation)
 | 
				
			|||||||
void FMD::setCTCSSFreq(double freq)
 | 
					void FMD::setCTCSSFreq(double freq)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ctcss_freq = freq;
 | 
					    ctcss_freq = freq;
 | 
				
			||||||
    SNOTCH::SetSNCTCSSFreq (sntch, ctcss_freq);
 | 
					    sntch->setFreq(ctcss_freq);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void FMD::setCTCSSRun(int run)
 | 
					void FMD::setCTCSSRun(int run)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    sntch_run = run;
 | 
					    sntch_run = run;
 | 
				
			||||||
    SNOTCH::SetSNCTCSSRun (sntch, sntch_run);
 | 
					    sntch->setRun(sntch_run);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void FMD::setNCde(int nc)
 | 
					void FMD::setNCde(int nc)
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										204
									
								
								wdsp/mpeak.cpp
									
									
									
									
									
								
							
							
						
						
									
										204
									
								
								wdsp/mpeak.cpp
									
									
									
									
									
								
							@ -39,135 +39,121 @@ namespace WDSP {
 | 
				
			|||||||
*                                                                                                       *
 | 
					*                                                                                                       *
 | 
				
			||||||
********************************************************************************************************/
 | 
					********************************************************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MPEAK::calc_mpeak (MPEAK *a)
 | 
					void MPEAK::calc()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int i;
 | 
					    tmp.resize(size * 2); // (float *) malloc0 (size * sizeof (complex));
 | 
				
			||||||
    a->tmp = new float[a->size * 2]; // (float *) malloc0 (a->size * sizeof (complex));
 | 
					    mix.resize(size * 2); // (float *) malloc0 (size * sizeof (complex));
 | 
				
			||||||
    a->mix = new float[a->size * 2]; // (float *) malloc0 (a->size * sizeof (complex));
 | 
					    for (int i = 0; i < npeaks; i++)
 | 
				
			||||||
    for (i = 0; i < a->npeaks; i++)
 | 
					 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        a->pfil[i] = SPEAK::create_speak (
 | 
					        pfil[i] = new SPEAK(
 | 
				
			||||||
            1,
 | 
					            1,
 | 
				
			||||||
            a->size,
 | 
					            size,
 | 
				
			||||||
            a->in,
 | 
					            in,
 | 
				
			||||||
            a->tmp,
 | 
					            tmp.data(),
 | 
				
			||||||
            a->rate,
 | 
					            rate,
 | 
				
			||||||
            a->f[i],
 | 
					            f[i],
 | 
				
			||||||
            a->bw[i],
 | 
					            bw[i],
 | 
				
			||||||
            a->gain[i],
 | 
					            gain[i],
 | 
				
			||||||
            a->nstages,
 | 
					            nstages,
 | 
				
			||||||
            1
 | 
					            1
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MPEAK::decalc_mpeak (MPEAK *a)
 | 
					void MPEAK::decalc()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int i;
 | 
					    for (int i = 0; i < npeaks; i++)
 | 
				
			||||||
    for (i = 0; i < a->npeaks; i++)
 | 
					        delete (pfil[i]);
 | 
				
			||||||
        SPEAK::destroy_speak (a->pfil[i]);
 | 
					 | 
				
			||||||
    delete[] (a->mix);
 | 
					 | 
				
			||||||
    delete[] (a->tmp);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
MPEAK* MPEAK::create_mpeak (
 | 
					MPEAK::MPEAK(
 | 
				
			||||||
    int run,
 | 
					    int _run,
 | 
				
			||||||
    int size,
 | 
					    int _size,
 | 
				
			||||||
    float* in,
 | 
					    float* _in,
 | 
				
			||||||
    float* out,
 | 
					    float* _out,
 | 
				
			||||||
    int rate,
 | 
					    int _rate,
 | 
				
			||||||
    int npeaks,
 | 
					    int _npeaks,
 | 
				
			||||||
    int* enable,
 | 
					    int* _enable,
 | 
				
			||||||
    double* f,
 | 
					    double* _f,
 | 
				
			||||||
    double* bw,
 | 
					    double* _bw,
 | 
				
			||||||
    double* gain,
 | 
					    double* _gain,
 | 
				
			||||||
    int nstages
 | 
					    int _nstages
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    MPEAK *a = new MPEAK;
 | 
					    run = _run;
 | 
				
			||||||
    a->run = run;
 | 
					    size = _size;
 | 
				
			||||||
    a->size = size;
 | 
					    in = _in;
 | 
				
			||||||
    a->in = in;
 | 
					    out = _out;
 | 
				
			||||||
    a->out = out;
 | 
					    rate = _rate;
 | 
				
			||||||
    a->rate = rate;
 | 
					    npeaks = _npeaks;
 | 
				
			||||||
    a->npeaks = npeaks;
 | 
					    nstages = _nstages;
 | 
				
			||||||
    a->nstages = nstages;
 | 
					    enable.resize(npeaks); // (int *) malloc0 (npeaks * sizeof (int));
 | 
				
			||||||
    a->enable = new int[a->npeaks]; // (int *) malloc0 (a->npeaks * sizeof (int));
 | 
					    f.resize(npeaks); // (float *) malloc0 (npeaks * sizeof (float));
 | 
				
			||||||
    a->f    = new double[a->npeaks]; // (float *) malloc0 (a->npeaks * sizeof (float));
 | 
					    bw.resize(npeaks); // (float *) malloc0 (npeaks * sizeof (float));
 | 
				
			||||||
    a->bw   = new double[a->npeaks]; // (float *) malloc0 (a->npeaks * sizeof (float));
 | 
					    gain.resize(npeaks); // (float *) malloc0 (npeaks * sizeof (float));
 | 
				
			||||||
    a->gain = new double[a->npeaks]; // (float *) malloc0 (a->npeaks * sizeof (float));
 | 
					    std::copy(_enable, _enable + npeaks, enable.begin());
 | 
				
			||||||
    memcpy (a->enable, enable, a->npeaks * sizeof (int));
 | 
					    std::copy(_f, _f + npeaks, f.begin());
 | 
				
			||||||
    memcpy (a->f, f, a->npeaks * sizeof (double));
 | 
					    std::copy(_bw, _bw + npeaks, bw.begin());
 | 
				
			||||||
    memcpy (a->bw, bw, a->npeaks * sizeof (double));
 | 
					    std::copy(_gain, _gain + npeaks, gain.begin());
 | 
				
			||||||
    memcpy (a->gain, gain, a->npeaks * sizeof (double));
 | 
					    pfil.resize(npeaks); // (SPEAK *) malloc0 (npeaks * sizeof (SPEAK));
 | 
				
			||||||
    a->pfil = new SPEAK*[a->npeaks]; // (SPEAK *) malloc0 (a->npeaks * sizeof (SPEAK));
 | 
					    calc();
 | 
				
			||||||
    calc_mpeak (a);
 | 
					 | 
				
			||||||
    return a;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MPEAK::destroy_mpeak (MPEAK *a)
 | 
					MPEAK::~MPEAK()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    decalc_mpeak (a);
 | 
					    decalc();
 | 
				
			||||||
    delete[] (a->pfil);
 | 
					 | 
				
			||||||
    delete[] (a->gain);
 | 
					 | 
				
			||||||
    delete[] (a->bw);
 | 
					 | 
				
			||||||
    delete[] (a->f);
 | 
					 | 
				
			||||||
    delete[] (a->enable);
 | 
					 | 
				
			||||||
    delete (a);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MPEAK::flush_mpeak (MPEAK *a)
 | 
					void MPEAK::flush()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int i;
 | 
					    for (int i = 0; i < npeaks; i++)
 | 
				
			||||||
    for (i = 0; i < a->npeaks; i++)
 | 
					        pfil[i]->flush();
 | 
				
			||||||
        SPEAK::flush_speak (a->pfil[i]);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MPEAK::xmpeak (MPEAK *a)
 | 
					void MPEAK::execute()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (a->run)
 | 
					    if (run)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        int i, j;
 | 
					        std::fill(mix.begin(), mix.end(), 0);
 | 
				
			||||||
        std::fill(a->mix, a->mix + a->size * 2, 0);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (i = 0; i < a->npeaks; i++)
 | 
					        for (int i = 0; i < npeaks; i++)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (a->enable[i])
 | 
					            if (enable[i])
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                SPEAK::xspeak (a->pfil[i]);
 | 
					                pfil[i]->execute();
 | 
				
			||||||
                for (j = 0; j < 2 * a->size; j++)
 | 
					                for (int j = 0; j < 2 * size; j++)
 | 
				
			||||||
                    a->mix[j] += a->tmp[j];
 | 
					                    mix[j] += tmp[j];
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        std::copy(a->mix, a->mix + a->size * 2, a->out);
 | 
					        std::copy(mix.begin(), mix.end(), out);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (a->in != a->out)
 | 
					    else if (in != out)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        std::copy( a->in,  a->in + a->size * 2, a->out);
 | 
					        std::copy( in,  in + size * 2, out);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MPEAK::setBuffers_mpeak (MPEAK *a, float* in, float* out)
 | 
					void MPEAK::setBuffers(float* _in, float* _out)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    decalc_mpeak (a);
 | 
					    decalc();
 | 
				
			||||||
    a->in = in;
 | 
					    in = _in;
 | 
				
			||||||
    a->out = out;
 | 
					    out = _out;
 | 
				
			||||||
    calc_mpeak (a);
 | 
					    calc();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MPEAK::setSamplerate_mpeak (MPEAK *a, int rate)
 | 
					void MPEAK::setSamplerate(int _rate)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    decalc_mpeak (a);
 | 
					    decalc();
 | 
				
			||||||
    a->rate = rate;
 | 
					    rate = _rate;
 | 
				
			||||||
    calc_mpeak (a);
 | 
					    calc();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MPEAK::setSize_mpeak (MPEAK *a, int size)
 | 
					void MPEAK::setSize(int _size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    decalc_mpeak (a);
 | 
					    decalc();
 | 
				
			||||||
    a->size = size;
 | 
					    size = _size;
 | 
				
			||||||
    calc_mpeak (a);
 | 
					    calc();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/********************************************************************************************************
 | 
					/********************************************************************************************************
 | 
				
			||||||
@ -176,46 +162,40 @@ void MPEAK::setSize_mpeak (MPEAK *a, int size)
 | 
				
			|||||||
*                                                                                                       *
 | 
					*                                                                                                       *
 | 
				
			||||||
********************************************************************************************************/
 | 
					********************************************************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MPEAK::SetmpeakRun (RXA& rxa, int run)
 | 
					void MPEAK::setRun(int _run)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    MPEAK *a = rxa.mpeak;
 | 
					    run = _run;
 | 
				
			||||||
    a->run = run;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MPEAK::SetmpeakNpeaks (RXA& rxa, int npeaks)
 | 
					void MPEAK::setNpeaks(int _npeaks)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    MPEAK *a = rxa.mpeak;
 | 
					    npeaks = _npeaks;
 | 
				
			||||||
    a->npeaks = npeaks;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MPEAK::SetmpeakFilEnable (RXA& rxa, int fil, int enable)
 | 
					void MPEAK::setFilEnable(int _fil, int _enable)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    MPEAK *a = rxa.mpeak;
 | 
					    enable[_fil] = _enable;
 | 
				
			||||||
    a->enable[fil] = enable;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MPEAK::SetmpeakFilFreq (RXA& rxa, int fil, double freq)
 | 
					void MPEAK::setFilFreq(int _fil, double _freq)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    MPEAK *a = rxa.mpeak;
 | 
					    f[_fil] = _freq;
 | 
				
			||||||
    a->f[fil] = freq;
 | 
					    pfil[_fil]->f = _freq;
 | 
				
			||||||
    a->pfil[fil]->f = freq;
 | 
					    pfil[_fil]->calc();
 | 
				
			||||||
    SPEAK::calc_speak(a->pfil[fil]);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MPEAK::SetmpeakFilBw (RXA& rxa, int fil, double bw)
 | 
					void MPEAK::setFilBw(int _fil, double _bw)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    MPEAK *a = rxa.mpeak;
 | 
					    bw[_fil] = _bw;
 | 
				
			||||||
    a->bw[fil] = bw;
 | 
					    pfil[_fil]->bw = _bw;
 | 
				
			||||||
    a->pfil[fil]->bw = bw;
 | 
					    pfil[_fil]->calc();
 | 
				
			||||||
    SPEAK::calc_speak(a->pfil[fil]);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MPEAK::SetmpeakFilGain (RXA& rxa, int fil, double gain)
 | 
					void MPEAK::setFilGain(int _fil, double _gain)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    MPEAK *a = rxa.mpeak;
 | 
					    gain[_fil] = _gain;
 | 
				
			||||||
    a->gain[fil] = gain;
 | 
					    pfil[_fil]->gain = _gain;
 | 
				
			||||||
    a->pfil[fil]->gain = gain;
 | 
					    pfil[_fil]->calc();
 | 
				
			||||||
    SPEAK::calc_speak(a->pfil[fil]);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace WDSP
 | 
					} // namespace WDSP
 | 
				
			||||||
 | 
				
			|||||||
@ -34,11 +34,12 @@ warren@wpratt.com
 | 
				
			|||||||
#ifndef _mpeak_h
 | 
					#ifndef _mpeak_h
 | 
				
			||||||
#define _mpeak_h
 | 
					#define _mpeak_h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "export.h"
 | 
					#include "export.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace WDSP {
 | 
					namespace WDSP {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class RXA;
 | 
					 | 
				
			||||||
class SPEAK;
 | 
					class SPEAK;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class WDSP_API MPEAK
 | 
					class WDSP_API MPEAK
 | 
				
			||||||
@ -50,16 +51,16 @@ public:
 | 
				
			|||||||
    float* out;
 | 
					    float* out;
 | 
				
			||||||
    int rate;
 | 
					    int rate;
 | 
				
			||||||
    int npeaks;
 | 
					    int npeaks;
 | 
				
			||||||
    int* enable;
 | 
					    std::vector<int> enable;
 | 
				
			||||||
    double* f;
 | 
					    std::vector<double> f;
 | 
				
			||||||
    double* bw;
 | 
					    std::vector<double> bw;
 | 
				
			||||||
    double* gain;
 | 
					    std::vector<double> gain;
 | 
				
			||||||
    int nstages;
 | 
					    int nstages;
 | 
				
			||||||
    SPEAK** pfil;
 | 
					    std::vector<SPEAK*> pfil;
 | 
				
			||||||
    float* tmp;
 | 
					    std::vector<float> tmp;
 | 
				
			||||||
    float* mix;
 | 
					    std::vector<float> mix;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static MPEAK* create_mpeak (
 | 
					    MPEAK(
 | 
				
			||||||
        int run,
 | 
					        int run,
 | 
				
			||||||
        int size,
 | 
					        int size,
 | 
				
			||||||
        float* in,
 | 
					        float* in,
 | 
				
			||||||
@ -72,23 +73,26 @@ public:
 | 
				
			|||||||
        double* gain,
 | 
					        double* gain,
 | 
				
			||||||
        int nstages
 | 
					        int nstages
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
    static void destroy_mpeak (MPEAK *a);
 | 
					    MPEAK(const MPEAK&) = delete;
 | 
				
			||||||
    static void flush_mpeak (MPEAK *a);
 | 
					    MPEAK& operator=(const MPEAK& other) = delete;
 | 
				
			||||||
    static void xmpeak (MPEAK *a);
 | 
					    ~MPEAK();
 | 
				
			||||||
    static void setBuffers_mpeak (MPEAK *a, float* in, float* out);
 | 
					
 | 
				
			||||||
    static void setSamplerate_mpeak (MPEAK *a, int rate);
 | 
					    void flush();
 | 
				
			||||||
    static void setSize_mpeak (MPEAK *a, int size);
 | 
					    void execute();
 | 
				
			||||||
 | 
					    void setBuffers(float* in, float* out);
 | 
				
			||||||
 | 
					    void setSamplerate(int rate);
 | 
				
			||||||
 | 
					    void setSize(int size);
 | 
				
			||||||
    // RXA
 | 
					    // RXA
 | 
				
			||||||
    static void SetmpeakRun (RXA& rxa, int run);
 | 
					    void setRun(int run);
 | 
				
			||||||
    static void SetmpeakNpeaks (RXA& rxa, int npeaks);
 | 
					    void setNpeaks(int npeaks);
 | 
				
			||||||
    static void SetmpeakFilEnable (RXA& rxa, int fil, int enable);
 | 
					    void setFilEnable(int fil, int enable);
 | 
				
			||||||
    static void SetmpeakFilFreq (RXA& rxa, int fil, double freq);
 | 
					    void setFilFreq(int fil, double freq);
 | 
				
			||||||
    static void SetmpeakFilBw (RXA& rxa, int fil, double bw);
 | 
					    void setFilBw(int fil, double bw);
 | 
				
			||||||
    static void SetmpeakFilGain (RXA& rxa, int fil, double gain);
 | 
					    void setFilGain(int fil, double gain);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    static void calc_mpeak (MPEAK *a);
 | 
					    void calc();
 | 
				
			||||||
    static void decalc_mpeak (MPEAK *a);
 | 
					    void decalc();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace WDSP
 | 
					} // namespace WDSP
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										157
									
								
								wdsp/phrot.cpp
									
									
									
									
									
								
							
							
						
						
									
										157
									
								
								wdsp/phrot.cpp
									
									
									
									
									
								
							@ -38,108 +38,97 @@ namespace WDSP {
 | 
				
			|||||||
*                                                                                                       *
 | 
					*                                                                                                       *
 | 
				
			||||||
********************************************************************************************************/
 | 
					********************************************************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void PHROT::calc_phrot (PHROT *a)
 | 
					void PHROT::calc()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    double g;
 | 
					    double g;
 | 
				
			||||||
    a->x0 = new double[a->nstages]; // (float *) malloc0 (a->nstages * sizeof (float));
 | 
					    x0.resize(nstages); // (float *) malloc0 (nstages * sizeof (float));
 | 
				
			||||||
    a->x1 = new double[a->nstages]; // (float *) malloc0 (a->nstages * sizeof (float));
 | 
					    x1.resize(nstages); // (float *) malloc0 (nstages * sizeof (float));
 | 
				
			||||||
    a->y0 = new double[a->nstages]; // (float *) malloc0 (a->nstages * sizeof (float));
 | 
					    y0.resize(nstages); // (float *) malloc0 (nstages * sizeof (float));
 | 
				
			||||||
    a->y1 = new double[a->nstages]; // (float *) malloc0 (a->nstages * sizeof (float));
 | 
					    y1.resize(nstages); // (float *) malloc0 (nstages * sizeof (float));
 | 
				
			||||||
    g = tan (PI * a->fc / (float)a->rate);
 | 
					    g = tan (PI * fc / (float)rate);
 | 
				
			||||||
    a->b0 = (g - 1.0) / (g + 1.0);
 | 
					    b0 = (g - 1.0) / (g + 1.0);
 | 
				
			||||||
    a->b1 = 1.0;
 | 
					    b1 = 1.0;
 | 
				
			||||||
    a->a1 = a->b0;
 | 
					    a1 = b0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void PHROT::decalc_phrot (PHROT *a)
 | 
					PHROT::PHROT(
 | 
				
			||||||
 | 
					    int _run,
 | 
				
			||||||
 | 
					    int _size,
 | 
				
			||||||
 | 
					    float* _in,
 | 
				
			||||||
 | 
					    float* _out,
 | 
				
			||||||
 | 
					    int _rate,
 | 
				
			||||||
 | 
					    double _fc,
 | 
				
			||||||
 | 
					    int _nstages
 | 
				
			||||||
 | 
					) :
 | 
				
			||||||
 | 
					    reverse(0),
 | 
				
			||||||
 | 
					    run(_run),
 | 
				
			||||||
 | 
					    size(_size),
 | 
				
			||||||
 | 
					    in(_in),
 | 
				
			||||||
 | 
					    out(_out),
 | 
				
			||||||
 | 
					    rate(_rate),
 | 
				
			||||||
 | 
					    fc(_fc),
 | 
				
			||||||
 | 
					    nstages(_nstages)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    delete[] (a->y1);
 | 
					    calc();
 | 
				
			||||||
    delete[] (a->y0);
 | 
					 | 
				
			||||||
    delete[] (a->x1);
 | 
					 | 
				
			||||||
    delete[] (a->x0);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PHROT* PHROT::create_phrot (int run, int size, float* in, float* out, int rate, double fc, int nstages)
 | 
					void PHROT::flush()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    PHROT *a = new PHROT;
 | 
					    std::fill (x0.begin(), x0.end(), 0);
 | 
				
			||||||
    a->reverse = 0;
 | 
					    std::fill (x1.begin(), x1.end(), 0);
 | 
				
			||||||
    a->run = run;
 | 
					    std::fill (y0.begin(), y0.end(), 0);
 | 
				
			||||||
    a->size = size;
 | 
					    std::fill (y1.begin(), y1.end(), 0);
 | 
				
			||||||
    a->in = in;
 | 
					 | 
				
			||||||
    a->out = out;
 | 
					 | 
				
			||||||
    a->rate = rate;
 | 
					 | 
				
			||||||
    a->fc = fc;
 | 
					 | 
				
			||||||
    a->nstages = nstages;
 | 
					 | 
				
			||||||
    calc_phrot (a);
 | 
					 | 
				
			||||||
    return a;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void PHROT::destroy_phrot (PHROT *a)
 | 
					void PHROT::execute()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    decalc_phrot (a);
 | 
					    if (reverse)
 | 
				
			||||||
    delete (a);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void PHROT::flush_phrot (PHROT *a)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    memset (a->x0, 0, a->nstages * sizeof (double));
 | 
					 | 
				
			||||||
    memset (a->x1, 0, a->nstages * sizeof (double));
 | 
					 | 
				
			||||||
    memset (a->y0, 0, a->nstages * sizeof (double));
 | 
					 | 
				
			||||||
    memset (a->y1, 0, a->nstages * sizeof (double));
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void PHROT::xphrot (PHROT *a)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    if (a->reverse)
 | 
					 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        for (int i = 0; i < a->size; i++)
 | 
					        for (int i = 0; i < size; i++)
 | 
				
			||||||
            a->in[2 * i + 0] = -a->in[2 * i + 0];
 | 
					            in[2 * i + 0] = -in[2 * i + 0];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (a->run)
 | 
					    if (run)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        int i, n;
 | 
					        for (int i = 0; i < size; i++)
 | 
				
			||||||
 | 
					 | 
				
			||||||
        for (i = 0; i < a->size; i++)
 | 
					 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            a->x0[0] = a->in[2 * i + 0];
 | 
					            x0[0] = in[2 * i + 0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for (n = 0; n < a->nstages; n++)
 | 
					            for (int n = 0; n < nstages; n++)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                if (n > 0) a->x0[n] = a->y0[n - 1];
 | 
					                if (n > 0) x0[n] = y0[n - 1];
 | 
				
			||||||
                a->y0[n] = a->b0 * a->x0[n]
 | 
					                y0[n] = b0 * x0[n]
 | 
				
			||||||
                    + a->b1 * a->x1[n]
 | 
					                    + b1 * x1[n]
 | 
				
			||||||
                    - a->a1 * a->y1[n];
 | 
					                    - a1 * y1[n];
 | 
				
			||||||
                a->y1[n] = a->y0[n];
 | 
					                y1[n] = y0[n];
 | 
				
			||||||
                a->x1[n] = a->x0[n];
 | 
					                x1[n] = x0[n];
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            a->out[2 * i + 0] = a->y0[a->nstages - 1];
 | 
					            out[2 * i + 0] = y0[nstages - 1];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (a->out != a->in)
 | 
					    else if (out != in)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        std::copy( a->in,  a->in + a->size * 2, a->out);
 | 
					        std::copy( in,  in + size * 2, out);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void PHROT::setBuffers_phrot (PHROT *a, float* in, float* out)
 | 
					void PHROT::setBuffers(float* _in, float* _out)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->in = in;
 | 
					    in = _in;
 | 
				
			||||||
    a->out = out;
 | 
					    out = _out;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void PHROT::setSamplerate_phrot (PHROT *a, int rate)
 | 
					void PHROT::setSamplerate(int _rate)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    decalc_phrot (a);
 | 
					    rate = _rate;
 | 
				
			||||||
    a->rate = rate;
 | 
					    calc();
 | 
				
			||||||
    calc_phrot (a);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void PHROT::setSize_phrot (PHROT *a, int size)
 | 
					void PHROT::setSize(int _size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->size = size;
 | 
					    size = _size;
 | 
				
			||||||
    flush_phrot (a);
 | 
					    flush();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/********************************************************************************************************
 | 
					/********************************************************************************************************
 | 
				
			||||||
@ -148,35 +137,29 @@ void PHROT::setSize_phrot (PHROT *a, int size)
 | 
				
			|||||||
*                                                                                                       *
 | 
					*                                                                                                       *
 | 
				
			||||||
********************************************************************************************************/
 | 
					********************************************************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void PHROT::SetPHROTRun (TXA& txa, int run)
 | 
					void PHROT::setRun(int run)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    PHROT *a = txa.phrot;
 | 
					    run = run;
 | 
				
			||||||
    a->run = run;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (a->run)
 | 
					    if (run)
 | 
				
			||||||
        flush_phrot (a);
 | 
					        flush();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void PHROT::SetPHROTCorner (TXA& txa, double corner)
 | 
					void PHROT::setCorner(double corner)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    PHROT *a = txa.phrot;
 | 
					    fc = corner;
 | 
				
			||||||
    decalc_phrot (a);
 | 
					    calc();
 | 
				
			||||||
    a->fc = corner;
 | 
					 | 
				
			||||||
    calc_phrot (a);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void PHROT::SetPHROTNstages (TXA& txa, int nstages)
 | 
					void PHROT::setNstages(int _nstages)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    PHROT *a = txa.phrot;
 | 
					    nstages = _nstages;
 | 
				
			||||||
    decalc_phrot (a);
 | 
					    calc();
 | 
				
			||||||
    a->nstages = nstages;
 | 
					 | 
				
			||||||
    calc_phrot (a);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void PHROT::SetPHROTReverse (TXA& txa, int reverse)
 | 
					void PHROT::setReverse(int _reverse)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    PHROT *a = txa.phrot;
 | 
					    reverse = _reverse;
 | 
				
			||||||
    a->reverse = reverse;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace WDSP
 | 
					} // namespace WDSP
 | 
				
			||||||
 | 
				
			|||||||
@ -34,6 +34,8 @@ warren@wpratt.com
 | 
				
			|||||||
#ifndef wdsp_phrot_h
 | 
					#ifndef wdsp_phrot_h
 | 
				
			||||||
#define wdsp_phrot_h
 | 
					#define wdsp_phrot_h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "export.h"
 | 
					#include "export.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace WDSP {
 | 
					namespace WDSP {
 | 
				
			||||||
@ -53,24 +55,35 @@ public:
 | 
				
			|||||||
    int nstages;
 | 
					    int nstages;
 | 
				
			||||||
    // normalized such that a0 = 1
 | 
					    // normalized such that a0 = 1
 | 
				
			||||||
    double a1, b0, b1;
 | 
					    double a1, b0, b1;
 | 
				
			||||||
    double *x0, *x1, *y0, *y1;
 | 
					    std::vector<double> x0, x1, y0, y1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static PHROT* create_phrot (int run, int size, float* in, float* out, int rate, double fc, int nstages);
 | 
					    PHROT(
 | 
				
			||||||
    static void destroy_phrot (PHROT *a);
 | 
					        int run,
 | 
				
			||||||
    static void flush_phrot (PHROT *a);
 | 
					        int size,
 | 
				
			||||||
    static void xphrot (PHROT *a);
 | 
					        float* in,
 | 
				
			||||||
    static void setBuffers_phrot (PHROT *a, float* in, float* out);
 | 
					        float* out,
 | 
				
			||||||
    static void setSamplerate_phrot (PHROT *a, int rate);
 | 
					        int rate,
 | 
				
			||||||
    static void setSize_phrot (PHROT *a, int size);
 | 
					        double fc,
 | 
				
			||||||
 | 
					        int nstages
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    PHROT(const PHROT&) = delete;
 | 
				
			||||||
 | 
					    PHROT& operator=(const PHROT& other) = delete;
 | 
				
			||||||
 | 
					    ~PHROT() = default;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void destroy();
 | 
				
			||||||
 | 
					    void flush();
 | 
				
			||||||
 | 
					    void execute();
 | 
				
			||||||
 | 
					    void setBuffers(float* in, float* out);
 | 
				
			||||||
 | 
					    void setSamplerate(int rate);
 | 
				
			||||||
 | 
					    void setSize(int size);
 | 
				
			||||||
    // TXA Properties
 | 
					    // TXA Properties
 | 
				
			||||||
    static void SetPHROTRun (TXA& txa, int run);
 | 
					    void setRun(int run);
 | 
				
			||||||
    static void SetPHROTCorner (TXA& txa, double corner);
 | 
					    void setCorner(double corner);
 | 
				
			||||||
    static void SetPHROTNstages (TXA& txa, int nstages);
 | 
					    void setNstages(int nstages);
 | 
				
			||||||
    static void SetPHROTReverse (TXA& txa, int reverse);
 | 
					    void setReverse(int reverse);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    static void calc_phrot (PHROT *a);
 | 
					    void calc();
 | 
				
			||||||
    static void decalc_phrot (PHROT *a);
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace WDSP
 | 
					} // namespace WDSP
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										105
									
								
								wdsp/snotch.cpp
									
									
									
									
									
								
							
							
						
						
									
										105
									
								
								wdsp/snotch.cpp
									
									
									
									
									
								
							@ -38,82 +38,83 @@ namespace WDSP {
 | 
				
			|||||||
*                                                                                                       *
 | 
					*                                                                                                       *
 | 
				
			||||||
********************************************************************************************************/
 | 
					********************************************************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SNOTCH::calc_snotch (SNOTCH *a)
 | 
					void SNOTCH::calc()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    double fn, qk, qr, csn;
 | 
					    double fn, qk, qr, csn;
 | 
				
			||||||
    fn = a->f / (float)a->rate;
 | 
					    fn = f / (double) rate;
 | 
				
			||||||
    csn = cos (TWOPI * fn);
 | 
					    csn = cos (TWOPI * fn);
 | 
				
			||||||
    qr = 1.0 - 3.0 * a->bw;
 | 
					    qr = 1.0 - 3.0 * bw;
 | 
				
			||||||
    qk = (1.0 - 2.0 * qr * csn + qr * qr) / (2.0 * (1.0 - csn));
 | 
					    qk = (1.0 - 2.0 * qr * csn + qr * qr) / (2.0 * (1.0 - csn));
 | 
				
			||||||
    a->a0 = + qk;
 | 
					    a0 = + qk;
 | 
				
			||||||
    a->a1 = - 2.0 * qk * csn;
 | 
					    a1 = - 2.0 * qk * csn;
 | 
				
			||||||
    a->a2 = + qk;
 | 
					    a2 = + qk;
 | 
				
			||||||
    a->b1 = + 2.0 * qr * csn;
 | 
					    b1 = + 2.0 * qr * csn;
 | 
				
			||||||
    a->b2 = - qr * qr;
 | 
					    b2 = - qr * qr;
 | 
				
			||||||
    flush_snotch (a);
 | 
					    flush();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SNOTCH* SNOTCH::create_snotch (int run, int size, float* in, float* out, int rate, double f, double bw)
 | 
					SNOTCH::SNOTCH(
 | 
				
			||||||
 | 
					    int _run,
 | 
				
			||||||
 | 
					    int _size,
 | 
				
			||||||
 | 
					    float* _in,
 | 
				
			||||||
 | 
					    float* _out,
 | 
				
			||||||
 | 
					    int _rate,
 | 
				
			||||||
 | 
					    double _f,
 | 
				
			||||||
 | 
					    double _bw
 | 
				
			||||||
 | 
					) :
 | 
				
			||||||
 | 
					    run(_run),
 | 
				
			||||||
 | 
					    size(_size),
 | 
				
			||||||
 | 
					    in(_in),
 | 
				
			||||||
 | 
					    out(_out),
 | 
				
			||||||
 | 
					    rate(_rate),
 | 
				
			||||||
 | 
					    f(_f),
 | 
				
			||||||
 | 
					    bw(_bw)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    SNOTCH *a = new SNOTCH;
 | 
					    calc();
 | 
				
			||||||
    a->run = run;
 | 
					 | 
				
			||||||
    a->size = size;
 | 
					 | 
				
			||||||
    a->in = in;
 | 
					 | 
				
			||||||
    a->out = out;
 | 
					 | 
				
			||||||
    a->rate = rate;
 | 
					 | 
				
			||||||
    a->f = f;
 | 
					 | 
				
			||||||
    a->bw = bw;
 | 
					 | 
				
			||||||
    calc_snotch (a);
 | 
					 | 
				
			||||||
    return a;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SNOTCH::destroy_snotch (SNOTCH *a)
 | 
					void SNOTCH::flush()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    delete (a);
 | 
					    x1 = x2 = y1 = y2 = 0.0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SNOTCH::flush_snotch (SNOTCH *a)
 | 
					void SNOTCH::execute()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->x1 = a->x2 = a->y1 = a->y2 = 0.0;
 | 
					    if (run)
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void SNOTCH::xsnotch (SNOTCH *a)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    if (a->run)
 | 
					 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        int i;
 | 
					        int i;
 | 
				
			||||||
        for (i = 0; i < a->size; i++)
 | 
					        for (i = 0; i < size; i++)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            a->x0 = a->in[2 * i + 0];
 | 
					            x0 = in[2 * i + 0];
 | 
				
			||||||
            a->out[2 * i + 0] = a->a0 * a->x0 + a->a1 * a->x1 + a->a2 * a->x2 + a->b1 * a->y1 + a->b2 * a->y2;
 | 
					            out[2 * i + 0] = a0 * x0 + a1 * x1 + a2 * x2 + b1 * y1 + b2 * y2;
 | 
				
			||||||
            a->y2 = a->y1;
 | 
					            y2 = y1;
 | 
				
			||||||
            a->y1 = a->out[2 * i + 0];
 | 
					            y1 = out[2 * i + 0];
 | 
				
			||||||
            a->x2 = a->x1;
 | 
					            x2 = x1;
 | 
				
			||||||
            a->x1 = a->x0;
 | 
					            x1 = x0;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (a->out != a->in)
 | 
					    else if (out != in)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        std::copy( a->in,  a->in + a->size * 2, a->out);
 | 
					        std::copy( in,  in + size * 2, out);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SNOTCH::setBuffers_snotch (SNOTCH *a, float* in, float* out)
 | 
					void SNOTCH::setBuffers(float* _in, float* _out)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->in = in;
 | 
					    in = _in;
 | 
				
			||||||
    a->out = out;
 | 
					    out = _out;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SNOTCH::setSamplerate_snotch (SNOTCH *a, int rate)
 | 
					void SNOTCH::setSamplerate(int _rate)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->rate = rate;
 | 
					    rate = _rate;
 | 
				
			||||||
    calc_snotch (a);
 | 
					    calc();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SNOTCH::setSize_snotch (SNOTCH *a, int size)
 | 
					void SNOTCH::setSize(int _size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->size = size;
 | 
					    size = _size;
 | 
				
			||||||
    flush_snotch (a);
 | 
					    flush();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/********************************************************************************************************
 | 
					/********************************************************************************************************
 | 
				
			||||||
@ -122,15 +123,15 @@ void SNOTCH::setSize_snotch (SNOTCH *a, int size)
 | 
				
			|||||||
*                                                                                                       *
 | 
					*                                                                                                       *
 | 
				
			||||||
********************************************************************************************************/
 | 
					********************************************************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SNOTCH::SetSNCTCSSFreq (SNOTCH *a, double freq)
 | 
					void SNOTCH::setFreq(double _freq)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->f = freq;
 | 
					    f = _freq;
 | 
				
			||||||
    calc_snotch (a);
 | 
					    calc();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SNOTCH::SetSNCTCSSRun (SNOTCH *a, int run)
 | 
					void SNOTCH::setRun(int _run)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->run = run;
 | 
					    run = _run;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace WDSP
 | 
					} // namespace WDSP
 | 
				
			||||||
 | 
				
			|||||||
@ -51,18 +51,29 @@ public:
 | 
				
			|||||||
    double a0, a1, a2, b1, b2;
 | 
					    double a0, a1, a2, b1, b2;
 | 
				
			||||||
    double x0, x1, x2, y1, y2;
 | 
					    double x0, x1, x2, y1, y2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static SNOTCH* create_snotch (int run, int size, float* in, float* out, int rate, double f, double bw);
 | 
					    SNOTCH(
 | 
				
			||||||
    static void destroy_snotch (SNOTCH *a);
 | 
					        int run,
 | 
				
			||||||
    static void flush_snotch (SNOTCH *a);
 | 
					        int size,
 | 
				
			||||||
    static void xsnotch (SNOTCH *a);
 | 
					        float* in,
 | 
				
			||||||
    static void setBuffers_snotch (SNOTCH *a, float* in, float* out);
 | 
					        float* out,
 | 
				
			||||||
    static void setSamplerate_snotch (SNOTCH *a, int rate);
 | 
					        int rate,
 | 
				
			||||||
    static void setSize_snotch (SNOTCH *a, int size);
 | 
					        double f,
 | 
				
			||||||
    static void SetSNCTCSSFreq (SNOTCH *a, double freq);
 | 
					        double bw
 | 
				
			||||||
    static void SetSNCTCSSRun (SNOTCH *a, int run);
 | 
					    );
 | 
				
			||||||
 | 
					    SNOTCH(const SNOTCH&) = delete;
 | 
				
			||||||
 | 
					    SNOTCH& operator=(SNOTCH& other) = delete;
 | 
				
			||||||
 | 
					    ~SNOTCH() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void flush();
 | 
				
			||||||
 | 
					    void execute();
 | 
				
			||||||
 | 
					    void setBuffers(float* in, float* out);
 | 
				
			||||||
 | 
					    void setSamplerate(int rate);
 | 
				
			||||||
 | 
					    void setSize(int size);
 | 
				
			||||||
 | 
					    void setFreq(double freq);
 | 
				
			||||||
 | 
					    void setRun(int run);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    static void calc_snotch (SNOTCH *a);
 | 
					    void calc();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace WDSP
 | 
					} // namespace WDSP
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										216
									
								
								wdsp/speak.cpp
									
									
									
									
									
								
							
							
						
						
									
										216
									
								
								wdsp/speak.cpp
									
									
									
									
									
								
							@ -38,16 +38,16 @@ namespace WDSP {
 | 
				
			|||||||
*                                                                                                       *
 | 
					*                                                                                                       *
 | 
				
			||||||
********************************************************************************************************/
 | 
					********************************************************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SPEAK::calc_speak (SPEAK *a)
 | 
					void SPEAK::calc()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    double ratio;
 | 
					    double ratio;
 | 
				
			||||||
    double f_corr, g_corr, bw_corr, bw_parm, A, f_min;
 | 
					    double f_corr, g_corr, bw_corr, bw_parm, A, f_min;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    switch (a->design)
 | 
					    switch (design)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    case 0:
 | 
					    case 0:
 | 
				
			||||||
        ratio = a->bw / a->f;
 | 
					        ratio = bw / f;
 | 
				
			||||||
        switch (a->nstages)
 | 
					        switch (nstages)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
        case 4:
 | 
					        case 4:
 | 
				
			||||||
            bw_parm = 2.4;
 | 
					            bw_parm = 2.4;
 | 
				
			||||||
@ -62,23 +62,23 @@ void SPEAK::calc_speak (SPEAK *a)
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            double fn, qk, qr, csn;
 | 
					            double fn, qk, qr, csn;
 | 
				
			||||||
            a->fgain = a->gain / g_corr;
 | 
					            fgain = gain / g_corr;
 | 
				
			||||||
            fn = a->f / (double)a->rate / f_corr;
 | 
					            fn = f / (double)rate / f_corr;
 | 
				
			||||||
            csn = cos (TWOPI * fn);
 | 
					            csn = cos (TWOPI * fn);
 | 
				
			||||||
            qr = 1.0 - 3.0 * a->bw / (double)a->rate * bw_parm;
 | 
					            qr = 1.0 - 3.0 * bw / (double)rate * bw_parm;
 | 
				
			||||||
            qk = (1.0 - 2.0 * qr * csn + qr * qr) / (2.0 * (1.0 - csn));
 | 
					            qk = (1.0 - 2.0 * qr * csn + qr * qr) / (2.0 * (1.0 - csn));
 | 
				
			||||||
            a->a0 = 1.0 - qk;
 | 
					            a0 = 1.0 - qk;
 | 
				
			||||||
            a->a1 = 2.0 * (qk - qr) * csn;
 | 
					            a1 = 2.0 * (qk - qr) * csn;
 | 
				
			||||||
            a->a2 = qr * qr - qk;
 | 
					            a2 = qr * qr - qk;
 | 
				
			||||||
            a->b1 = 2.0 * qr * csn;
 | 
					            b1 = 2.0 * qr * csn;
 | 
				
			||||||
            a->b2 = - qr * qr;
 | 
					            b2 = - qr * qr;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    case 1:
 | 
					    case 1:
 | 
				
			||||||
        if (a->f < 200.0) a->f = 200.0;
 | 
					        if (f < 200.0) f = 200.0;
 | 
				
			||||||
        ratio = a->bw / a->f;
 | 
					        ratio = bw / f;
 | 
				
			||||||
        switch (a->nstages)
 | 
					        switch (nstages)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
        case 4:
 | 
					        case 4:
 | 
				
			||||||
            bw_parm = 5.0;
 | 
					            bw_parm = 5.0;
 | 
				
			||||||
@ -96,132 +96,116 @@ void SPEAK::calc_speak (SPEAK *a)
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            double w0, sn, c, den;
 | 
					            double w0, sn, c, den;
 | 
				
			||||||
            if (a->f < f_min) a->f = f_min;
 | 
					            if (f < f_min) f = f_min;
 | 
				
			||||||
            w0 = TWOPI * a->f / (double)a->rate;
 | 
					            w0 = TWOPI * f / (double)rate;
 | 
				
			||||||
            sn = sin (w0);
 | 
					            sn = sin (w0);
 | 
				
			||||||
            a->cbw = bw_corr * a->f;
 | 
					            cbw = bw_corr * f;
 | 
				
			||||||
            c = sn * sinh(0.5 * log((a->f + 0.5 * a->cbw * bw_parm) / (a->f - 0.5 * a->cbw * bw_parm)) * w0 / sn);
 | 
					            c = sn * sinh(0.5 * log((f + 0.5 * cbw * bw_parm) / (f - 0.5 * cbw * bw_parm)) * w0 / sn);
 | 
				
			||||||
            den = 1.0 + c / A;
 | 
					            den = 1.0 + c / A;
 | 
				
			||||||
            a->a0 = (1.0 + c * A) / den;
 | 
					            a0 = (1.0 + c * A) / den;
 | 
				
			||||||
            a->a1 = - 2.0 * cos (w0) / den;
 | 
					            a1 = - 2.0 * cos (w0) / den;
 | 
				
			||||||
            a->a2 = (1 - c * A) / den;
 | 
					            a2 = (1 - c * A) / den;
 | 
				
			||||||
            a->b1 = - a->a1;
 | 
					            b1 = - a1;
 | 
				
			||||||
            a->b2 = - (1 - c / A ) / den;
 | 
					            b2 = - (1 - c / A ) / den;
 | 
				
			||||||
            a->fgain = a->gain / pow (A * A, (double)a->nstages);
 | 
					            fgain = gain / pow (A * A, (double)nstages);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    flush_speak (a);
 | 
					    flush();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SPEAK* SPEAK::create_speak (
 | 
					SPEAK::SPEAK(
 | 
				
			||||||
    int run,
 | 
					    int _run,
 | 
				
			||||||
    int size,
 | 
					    int _size,
 | 
				
			||||||
    float* in,
 | 
					    float* _in,
 | 
				
			||||||
    float* out,
 | 
					    float* _out,
 | 
				
			||||||
    int rate,
 | 
					    int _rate,
 | 
				
			||||||
    double f,
 | 
					    double _f,
 | 
				
			||||||
    double bw,
 | 
					    double _bw,
 | 
				
			||||||
    double gain,
 | 
					    double _gain,
 | 
				
			||||||
    int nstages,
 | 
					    int _nstages,
 | 
				
			||||||
    int design
 | 
					    int _design
 | 
				
			||||||
)
 | 
					) :
 | 
				
			||||||
 | 
					    run(_run),
 | 
				
			||||||
 | 
					    size(_size),
 | 
				
			||||||
 | 
					    in(_in),
 | 
				
			||||||
 | 
					    out(_out),
 | 
				
			||||||
 | 
					    rate(_rate),
 | 
				
			||||||
 | 
					    f(_f),
 | 
				
			||||||
 | 
					    bw(_bw),
 | 
				
			||||||
 | 
					    gain(_gain),
 | 
				
			||||||
 | 
					    nstages(_nstages),
 | 
				
			||||||
 | 
					    design(_design)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    SPEAK *a = new SPEAK;
 | 
					    x0.resize(nstages * 2); // (float *) malloc0 (nstages * sizeof (complex));
 | 
				
			||||||
    a->run = run;
 | 
					    x1.resize(nstages * 2); // (float *) malloc0 (nstages * sizeof (complex));
 | 
				
			||||||
    a->size = size;
 | 
					    x2.resize(nstages * 2); //(float *) malloc0 (nstages * sizeof (complex));
 | 
				
			||||||
    a->in = in;
 | 
					    y0.resize(nstages * 2); // (float *) malloc0 (nstages * sizeof (complex));
 | 
				
			||||||
    a->out = out;
 | 
					    y1.resize(nstages * 2); // (float *) malloc0 (nstages * sizeof (complex));
 | 
				
			||||||
    a->rate = rate;
 | 
					    y2.resize(nstages * 2); // (float *) malloc0 (nstages * sizeof (complex));
 | 
				
			||||||
    a->f = f;
 | 
					    calc();
 | 
				
			||||||
    a->bw = bw;
 | 
					 | 
				
			||||||
    a->gain = gain;
 | 
					 | 
				
			||||||
    a->nstages = nstages;
 | 
					 | 
				
			||||||
    a->design = design;
 | 
					 | 
				
			||||||
    a->x0 = new double[a->nstages * 2]; // (float *) malloc0 (a->nstages * sizeof (complex));
 | 
					 | 
				
			||||||
    a->x1 = new double[a->nstages * 2]; // (float *) malloc0 (a->nstages * sizeof (complex));
 | 
					 | 
				
			||||||
    a->x2 = new double[a->nstages * 2]; //(float *) malloc0 (a->nstages * sizeof (complex));
 | 
					 | 
				
			||||||
    a->y0 = new double[a->nstages * 2]; // (float *) malloc0 (a->nstages * sizeof (complex));
 | 
					 | 
				
			||||||
    a->y1 = new double[a->nstages * 2]; // (float *) malloc0 (a->nstages * sizeof (complex));
 | 
					 | 
				
			||||||
    a->y2 = new double[a->nstages * 2]; // (float *) malloc0 (a->nstages * sizeof (complex));
 | 
					 | 
				
			||||||
    calc_speak (a);
 | 
					 | 
				
			||||||
    return a;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SPEAK::destroy_speak (SPEAK *a)
 | 
					void SPEAK::flush()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    delete[] (a->y2);
 | 
					    for (int i = 0; i < nstages; i++)
 | 
				
			||||||
    delete[] (a->y1);
 | 
					 | 
				
			||||||
    delete[] (a->y0);
 | 
					 | 
				
			||||||
    delete[] (a->x2);
 | 
					 | 
				
			||||||
    delete[] (a->x1);
 | 
					 | 
				
			||||||
    delete[] (a->x0);
 | 
					 | 
				
			||||||
    delete (a);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void SPEAK::flush_speak (SPEAK *a)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    int i;
 | 
					 | 
				
			||||||
    for (i = 0; i < a->nstages; i++)
 | 
					 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        a->x1[2 * i + 0] = a->x2[2 * i + 0] = a->y1[2 * i + 0] = a->y2[2 * i + 0] = 0.0;
 | 
					        x1[2 * i + 0] = x2[2 * i + 0] = y1[2 * i + 0] = y2[2 * i + 0] = 0.0;
 | 
				
			||||||
        a->x1[2 * i + 1] = a->x2[2 * i + 1] = a->y1[2 * i + 1] = a->y2[2 * i + 1] = 0.0;
 | 
					        x1[2 * i + 1] = x2[2 * i + 1] = y1[2 * i + 1] = y2[2 * i + 1] = 0.0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SPEAK::xspeak (SPEAK *a)
 | 
					void SPEAK::execute()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (a->run)
 | 
					    if (run)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        int i, j, n;
 | 
					        for (int i = 0; i < size; i++)
 | 
				
			||||||
 | 
					 | 
				
			||||||
        for (i = 0; i < a->size; i++)
 | 
					 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            for (j = 0; j < 2; j++)
 | 
					            for (int j = 0; j < 2; j++)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                a->x0[j] = a->fgain * a->in[2 * i + j];
 | 
					                x0[j] = fgain * in[2 * i + j];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                for (n = 0; n < a->nstages; n++)
 | 
					                for (int n = 0; n < nstages; n++)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    if (n > 0)
 | 
					                    if (n > 0)
 | 
				
			||||||
                        a->x0[2 * n + j] = a->y0[2 * (n - 1) + j];
 | 
					                        x0[2 * n + j] = y0[2 * (n - 1) + j];
 | 
				
			||||||
                    a->y0[2 * n + j] = a->a0 * a->x0[2 * n + j]
 | 
					                    y0[2 * n + j] = a0 * x0[2 * n + j]
 | 
				
			||||||
                        + a->a1 * a->x1[2 * n + j]
 | 
					                        + a1 * x1[2 * n + j]
 | 
				
			||||||
                        + a->a2 * a->x2[2 * n + j]
 | 
					                        + a2 * x2[2 * n + j]
 | 
				
			||||||
                        + a->b1 * a->y1[2 * n + j]
 | 
					                        + b1 * y1[2 * n + j]
 | 
				
			||||||
                        + a->b2 * a->y2[2 * n + j];
 | 
					                        + b2 * y2[2 * n + j];
 | 
				
			||||||
                    a->y2[2 * n + j] = a->y1[2 * n + j];
 | 
					                    y2[2 * n + j] = y1[2 * n + j];
 | 
				
			||||||
                    a->y1[2 * n + j] = a->y0[2 * n + j];
 | 
					                    y1[2 * n + j] = y0[2 * n + j];
 | 
				
			||||||
                    a->x2[2 * n + j] = a->x1[2 * n + j];
 | 
					                    x2[2 * n + j] = x1[2 * n + j];
 | 
				
			||||||
                    a->x1[2 * n + j] = a->x0[2 * n + j];
 | 
					                    x1[2 * n + j] = x0[2 * n + j];
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                a->out[2 * i + j] = a->y0[2 * (a->nstages - 1) + j];
 | 
					                out[2 * i + j] = y0[2 * (nstages - 1) + j];
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (a->out != a->in)
 | 
					    else if (out != in)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        std::copy( a->in,  a->in + a->size * 2, a->out);
 | 
					        std::copy( in,  in + size * 2, out);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SPEAK::setBuffers_speak (SPEAK *a, float* in, float* out)
 | 
					void SPEAK::setBuffers(float* _in, float* _out)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->in = in;
 | 
					    in = _in;
 | 
				
			||||||
    a->out = out;
 | 
					    out = _out;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SPEAK::setSamplerate_speak (SPEAK *a, int rate)
 | 
					void SPEAK::setSamplerate(int _rate)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->rate = rate;
 | 
					    rate = _rate;
 | 
				
			||||||
    calc_speak (a);
 | 
					    calc();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SPEAK::setSize_speak (SPEAK *a, int size)
 | 
					void SPEAK::setSize(int _size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->size = size;
 | 
					    size = _size;
 | 
				
			||||||
    flush_speak (a);
 | 
					    flush();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/********************************************************************************************************
 | 
					/********************************************************************************************************
 | 
				
			||||||
@ -230,31 +214,27 @@ void SPEAK::setSize_speak (SPEAK *a, int size)
 | 
				
			|||||||
*                                                                                                       *
 | 
					*                                                                                                       *
 | 
				
			||||||
********************************************************************************************************/
 | 
					********************************************************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SPEAK::SetSPCWRun (RXA& rxa, int run)
 | 
					void SPEAK::setRun(int _run)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    SPEAK *a = rxa.speak;
 | 
					    run = _run;
 | 
				
			||||||
    a->run = run;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SPEAK::SetSPCWFreq (RXA& rxa, double freq)
 | 
					void SPEAK::setFreq(double _freq)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    SPEAK *a = rxa.speak;
 | 
					    f = _freq;
 | 
				
			||||||
    a->f = freq;
 | 
					    calc();
 | 
				
			||||||
    calc_speak (a);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SPEAK::SetSPCWBandwidth (RXA& rxa, double bw)
 | 
					void SPEAK::setBandwidth(double _bw)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    SPEAK *a = rxa.speak;
 | 
					    bw = _bw;
 | 
				
			||||||
    a->bw = bw;
 | 
					    calc();
 | 
				
			||||||
    calc_speak (a);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SPEAK::SetSPCWGain (RXA& rxa, double gain)
 | 
					void SPEAK::setGain(double _gain)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    SPEAK *a = rxa.speak;
 | 
					    gain = _gain;
 | 
				
			||||||
    a->gain = gain;
 | 
					    calc();
 | 
				
			||||||
    calc_speak (a);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace WDSP
 | 
					} // namespace WDSP
 | 
				
			||||||
 | 
				
			|||||||
@ -34,6 +34,8 @@ warren@wpratt.com
 | 
				
			|||||||
#ifndef wdsp_speak_h
 | 
					#ifndef wdsp_speak_h
 | 
				
			||||||
#define wdsp_speak_h
 | 
					#define wdsp_speak_h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "export.h"
 | 
					#include "export.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace WDSP {
 | 
					namespace WDSP {
 | 
				
			||||||
@ -56,9 +58,9 @@ public:
 | 
				
			|||||||
    int nstages;
 | 
					    int nstages;
 | 
				
			||||||
    int design;
 | 
					    int design;
 | 
				
			||||||
    double a0, a1, a2, b1, b2;
 | 
					    double a0, a1, a2, b1, b2;
 | 
				
			||||||
    double *x0, *x1, *x2, *y0, *y1, *y2;
 | 
					    std::vector<double> x0, x1, x2, y0, y1, y2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static SPEAK* create_speak (
 | 
					    SPEAK(
 | 
				
			||||||
        int run,
 | 
					        int run,
 | 
				
			||||||
        int size,
 | 
					        int size,
 | 
				
			||||||
        float* in,
 | 
					        float* in,
 | 
				
			||||||
@ -70,18 +72,21 @@ public:
 | 
				
			|||||||
        int nstages,
 | 
					        int nstages,
 | 
				
			||||||
        int design
 | 
					        int design
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
    static void destroy_speak (SPEAK *a);
 | 
					    SPEAK(const SPEAK&) = delete;
 | 
				
			||||||
    static void flush_speak (SPEAK *a);
 | 
					    SPEAK& operator=(const SPEAK& other) = delete;
 | 
				
			||||||
    static void xspeak (SPEAK *a);
 | 
					    ~SPEAK() {}
 | 
				
			||||||
    static void setBuffers_speak (SPEAK *a, float* in, float* out);
 | 
					
 | 
				
			||||||
    static void setSamplerate_speak (SPEAK *a, int rate);
 | 
					    void flush();
 | 
				
			||||||
    static void setSize_speak (SPEAK *a, int size);
 | 
					    void execute();
 | 
				
			||||||
 | 
					    void setBuffers(float* in, float* out);
 | 
				
			||||||
 | 
					    void setSamplerate(int rate);
 | 
				
			||||||
 | 
					    void setSize(int size);
 | 
				
			||||||
    // RXA
 | 
					    // RXA
 | 
				
			||||||
    static void SetSPCWRun (RXA& rxa, int run);
 | 
					    void setRun(int run);
 | 
				
			||||||
    static void SetSPCWFreq (RXA& rxa, double freq);
 | 
					    void setFreq(double freq);
 | 
				
			||||||
    static void SetSPCWBandwidth (RXA& rxa, double bw);
 | 
					    void setBandwidth(double bw);
 | 
				
			||||||
    static void SetSPCWGain (RXA& rxa, double gain);
 | 
					    void setGain(double gain);
 | 
				
			||||||
    static void calc_speak (SPEAK *a);
 | 
					    void calc();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace WDSP
 | 
					} // namespace WDSP
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										117
									
								
								wdsp/sphp.cpp
									
									
									
									
									
								
							
							
						
						
									
										117
									
								
								wdsp/sphp.cpp
									
									
									
									
									
								
							@ -37,105 +37,96 @@ namespace WDSP {
 | 
				
			|||||||
*                                                                                                       *
 | 
					*                                                                                                       *
 | 
				
			||||||
********************************************************************************************************/
 | 
					********************************************************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SPHP::calc_sphp(SPHP *a)
 | 
					void SPHP::calc()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    double g;
 | 
					    double g;
 | 
				
			||||||
    a->x0 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
 | 
					    x0.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
 | 
				
			||||||
    a->x1 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
 | 
					    x1.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
 | 
				
			||||||
    a->y0 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
 | 
					    y0.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
 | 
				
			||||||
    a->y1 = new double[a->nstages * 2]; // (float*)malloc0(a->nstages * sizeof(complex));
 | 
					    y1.resize(nstages * 2); // (float*)malloc0(nstages * sizeof(complex));
 | 
				
			||||||
    g = exp(-TWOPI * a->fc / a->rate);
 | 
					    g = exp(-TWOPI * fc / rate);
 | 
				
			||||||
    a->b0 = +0.5 * (1.0 + g);
 | 
					    b0 = +0.5 * (1.0 + g);
 | 
				
			||||||
    a->b1 = -0.5 * (1.0 + g);
 | 
					    b1 = -0.5 * (1.0 + g);
 | 
				
			||||||
    a->a1 = -g;
 | 
					    a1 = -g;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SPHP* SPHP::create_sphp(int run, int size, float* in, float* out, double rate, double fc, int nstages)
 | 
					SPHP::SPHP(
 | 
				
			||||||
 | 
					    int _run,
 | 
				
			||||||
 | 
					    int _size,
 | 
				
			||||||
 | 
					    float* _in,
 | 
				
			||||||
 | 
					    float* _out,
 | 
				
			||||||
 | 
					    double _rate,
 | 
				
			||||||
 | 
					    double _fc,
 | 
				
			||||||
 | 
					    int _nstages
 | 
				
			||||||
 | 
					) :
 | 
				
			||||||
 | 
					    run(_run),
 | 
				
			||||||
 | 
					    size(_size),
 | 
				
			||||||
 | 
					    in(_in),
 | 
				
			||||||
 | 
					    out(_out),
 | 
				
			||||||
 | 
					    rate(_rate),
 | 
				
			||||||
 | 
					    fc(_fc),
 | 
				
			||||||
 | 
					    nstages(_nstages)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    SPHP *a = new SPHP;
 | 
					    calc();
 | 
				
			||||||
    a->run = run;
 | 
					 | 
				
			||||||
    a->size = size;
 | 
					 | 
				
			||||||
    a->in = in;
 | 
					 | 
				
			||||||
    a->out = out;
 | 
					 | 
				
			||||||
    a->rate = rate;
 | 
					 | 
				
			||||||
    a->fc = fc;
 | 
					 | 
				
			||||||
    a->nstages = nstages;
 | 
					 | 
				
			||||||
    calc_sphp(a);
 | 
					 | 
				
			||||||
    return a;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SPHP::decalc_sphp(SPHP *a)
 | 
					void SPHP::flush()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    delete[](a->y1);
 | 
					    std::fill(x0.begin(), x0.end(), 0);
 | 
				
			||||||
    delete[](a->y0);
 | 
					    std::fill(x1.begin(), x0.end(), 0);
 | 
				
			||||||
    delete[](a->x1);
 | 
					    std::fill(y0.begin(), x0.end(), 0);
 | 
				
			||||||
    delete[](a->x0);
 | 
					    std::fill(y1.begin(), x0.end(), 0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SPHP::destroy_sphp(SPHP *a)
 | 
					void SPHP::execute()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    decalc_sphp(a);
 | 
					    if (run)
 | 
				
			||||||
    delete(a);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void SPHP::flush_sphp(SPHP *a)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    std::fill(a->x0, a->x0 + a->nstages * 2, 0);
 | 
					 | 
				
			||||||
    std::fill(a->x1, a->x0 + a->nstages * 2, 0);
 | 
					 | 
				
			||||||
    std::fill(a->y0, a->x0 + a->nstages * 2, 0);
 | 
					 | 
				
			||||||
    std::fill(a->y1, a->x0 + a->nstages * 2, 0);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void SPHP::xsphp(SPHP *a)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    if (a->run)
 | 
					 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        int i, j, n;
 | 
					        int i, j, n;
 | 
				
			||||||
        for (i = 0; i < a->size; i++)
 | 
					        for (i = 0; i < size; i++)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            for (j = 0; j < 2; j++)
 | 
					            for (j = 0; j < 2; j++)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                a->x0[j] = a->in[2 * i + j];
 | 
					                x0[j] = in[2 * i + j];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                for (n = 0; n < a->nstages; n++)
 | 
					                for (n = 0; n < nstages; n++)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    if (n > 0)
 | 
					                    if (n > 0)
 | 
				
			||||||
                        a->x0[2 * n + j] = a->y0[2 * (n - 1) + j];
 | 
					                        x0[2 * n + j] = y0[2 * (n - 1) + j];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    a->y0[2 * n + j] = a->b0 * a->x0[2 * n + j]
 | 
					                    y0[2 * n + j] = b0 * x0[2 * n + j]
 | 
				
			||||||
                        + a->b1 * a->x1[2 * n + j]
 | 
					                        + b1 * x1[2 * n + j]
 | 
				
			||||||
                        - a->a1 * a->y1[2 * n + j];
 | 
					                        - a1 * y1[2 * n + j];
 | 
				
			||||||
                    a->y1[2 * n + j] = a->y0[2 * n + j];
 | 
					                    y1[2 * n + j] = y0[2 * n + j];
 | 
				
			||||||
                    a->x1[2 * n + j] = a->x0[2 * n + j];
 | 
					                    x1[2 * n + j] = x0[2 * n + j];
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                a->out[2 * i + j] = a->y0[2 * (a->nstages - 1) + j];
 | 
					                out[2 * i + j] = y0[2 * (nstages - 1) + j];
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (a->out != a->in)
 | 
					    else if (out != in)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        std::copy(a->in, a->in + a->size * 2, a->out);
 | 
					        std::copy(in, in + size * 2, out);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SPHP::setBuffers_sphp(SPHP *a, float* in, float* out)
 | 
					void SPHP::setBuffers(float* _in, float* _out)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->in = in;
 | 
					    in = _in;
 | 
				
			||||||
    a->out = out;
 | 
					    out = _out;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SPHP::setSamplerate_sphp(SPHP *a, int rate)
 | 
					void SPHP::setSamplerate(int _rate)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    decalc_sphp(a);
 | 
					    rate = _rate;
 | 
				
			||||||
    a->rate = rate;
 | 
					    calc();
 | 
				
			||||||
    calc_sphp(a);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SPHP::setSize_sphp(SPHP *a, int size)
 | 
					void SPHP::setSize(int _size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    a->size = size;
 | 
					    size = _size;
 | 
				
			||||||
    flush_sphp(a);
 | 
					    flush();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace WDSP
 | 
					} // namespace WDSP
 | 
				
			||||||
 | 
				
			|||||||
@ -34,6 +34,8 @@ warren@wpratt.com
 | 
				
			|||||||
#ifndef wdsp_sphp_h
 | 
					#ifndef wdsp_sphp_h
 | 
				
			||||||
#define wdsp_sphp_h
 | 
					#define wdsp_sphp_h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "export.h"
 | 
					#include "export.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace WDSP {
 | 
					namespace WDSP {
 | 
				
			||||||
@ -49,20 +51,31 @@ public:
 | 
				
			|||||||
    double fc;
 | 
					    double fc;
 | 
				
			||||||
    int nstages;
 | 
					    int nstages;
 | 
				
			||||||
    double a1, b0, b1;
 | 
					    double a1, b0, b1;
 | 
				
			||||||
    double* x0, * x1, * y0, * y1;
 | 
					    std::vector<double> x0, x1, y0, y1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Complex Single-Pole High-Pass
 | 
					    // Complex Single-Pole High-Pass
 | 
				
			||||||
    static SPHP* create_sphp(int run, int size, float* in, float* out, double rate, double fc, int nstages);
 | 
					    SPHP(
 | 
				
			||||||
    static void destroy_sphp(SPHP *a);
 | 
					        int run,
 | 
				
			||||||
    static void flush_sphp(SPHP *a);
 | 
					        int size,
 | 
				
			||||||
    static void xsphp(SPHP *a);
 | 
					        float* in,
 | 
				
			||||||
    static void setBuffers_sphp(SPHP *a, float* in, float* out);
 | 
					        float* out,
 | 
				
			||||||
    static void setSamplerate_sphp(SPHP *a, int rate);
 | 
					        double rate,
 | 
				
			||||||
    static void setSize_sphp(SPHP *a, int size);
 | 
					        double fc,
 | 
				
			||||||
 | 
					        int nstages
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    SPHP(const SPHP&) = delete;
 | 
				
			||||||
 | 
					    SPHP& operator=(const SPHP& other) = delete;
 | 
				
			||||||
 | 
					    ~SPHP() = default;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void destroy();
 | 
				
			||||||
 | 
					    void flush();
 | 
				
			||||||
 | 
					    void execute();
 | 
				
			||||||
 | 
					    void setBuffers(float* in, float* out);
 | 
				
			||||||
 | 
					    void setSamplerate(int rate);
 | 
				
			||||||
 | 
					    void setSize(int size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    static void calc_sphp(SPHP *a);
 | 
					    void calc();
 | 
				
			||||||
    static void decalc_sphp(SPHP *a);
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace WDSP
 | 
					} // namespace WDSP
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										114
									
								
								wdsp/ssql.cpp
									
									
									
									
									
								
							
							
						
						
									
										114
									
								
								wdsp/ssql.cpp
									
									
									
									
									
								
							@ -39,76 +39,76 @@ namespace WDSP {
 | 
				
			|||||||
*                                                                                                       *
 | 
					*                                                                                                       *
 | 
				
			||||||
********************************************************************************************************/
 | 
					********************************************************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FTOV* FTOV::create_ftov (int run, int size, int rate, int rsize, double fmax, float* in, float* out)
 | 
					FTOV::FTOV(
 | 
				
			||||||
 | 
					    int _run,
 | 
				
			||||||
 | 
					    int _size,
 | 
				
			||||||
 | 
					    int _rate,
 | 
				
			||||||
 | 
					    int _rsize,
 | 
				
			||||||
 | 
					    double _fmax,
 | 
				
			||||||
 | 
					    float* _in,
 | 
				
			||||||
 | 
					    float* _out
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    FTOV *a = new FTOV;
 | 
					    run = _run;
 | 
				
			||||||
    a->run = run;
 | 
					    size = _size;
 | 
				
			||||||
    a->size = size;
 | 
					    rate = _rate;
 | 
				
			||||||
    a->rate = rate;
 | 
					    rsize = _rsize;
 | 
				
			||||||
    a->rsize = rsize;
 | 
					    fmax = _fmax;
 | 
				
			||||||
    a->fmax = fmax;
 | 
					    in = _in;
 | 
				
			||||||
    a->in = in;
 | 
					    out = _out;
 | 
				
			||||||
    a->out = out;
 | 
					    eps = 0.01;
 | 
				
			||||||
    a->eps = 0.01;
 | 
					    ring.resize(rsize); // (int*) malloc0 (rsize * sizeof (int));
 | 
				
			||||||
    a->ring = new int[a->rsize]; // (int*) malloc0 (a->rsize * sizeof (int));
 | 
					    rptr = 0;
 | 
				
			||||||
    a->rptr = 0;
 | 
					    inlast = 0.0;
 | 
				
			||||||
    a->inlast = 0.0;
 | 
					    rcount = 0;
 | 
				
			||||||
    a->rcount = 0;
 | 
					    div = fmax * 2.0 * rsize / rate;                // fmax * 2 = zero-crossings/sec
 | 
				
			||||||
    a->div = a->fmax * 2.0 * a->rsize / a->rate;                // fmax * 2 = zero-crossings/sec
 | 
					 | 
				
			||||||
                                                                // rsize / rate = sec of data in ring
 | 
					                                                                // rsize / rate = sec of data in ring
 | 
				
			||||||
                                                                // product is # zero-crossings in ring at fmax
 | 
					                                                                // product is # zero-crossings in ring at fmax
 | 
				
			||||||
    return a;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void FTOV::destroy_ftov (FTOV *a)
 | 
					void FTOV::flush()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    delete[] (a->ring);
 | 
					    std::fill(ring.begin(), ring.end(), 0);
 | 
				
			||||||
    delete (a);
 | 
					    rptr = 0;
 | 
				
			||||||
 | 
					    rcount = 0;
 | 
				
			||||||
 | 
					    inlast = 0.0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void FTOV::flush_ftov (FTOV *a)
 | 
					void FTOV::execute()
 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    memset (a->ring, 0, a->rsize * sizeof (int));
 | 
					 | 
				
			||||||
    a->rptr = 0;
 | 
					 | 
				
			||||||
    a->rcount = 0;
 | 
					 | 
				
			||||||
    a->inlast = 0.0;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void FTOV::xftov (FTOV *a)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    // 'ftov' does frequency to voltage conversion looking only at zero crossings of an
 | 
					    // 'ftov' does frequency to voltage conversion looking only at zero crossings of an
 | 
				
			||||||
    //     AC (DC blocked) signal, i.e., ignoring signal amplitude.
 | 
					    //     AC (DC blocked) signal, i.e., ignoring signal amplitude.
 | 
				
			||||||
    if (a->run)
 | 
					    if (run)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (a->ring[a->rptr] == 1)                              // if current ring location is a '1' ...
 | 
					        if (ring[rptr] == 1)                              // if current ring location is a '1' ...
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            a->rcount--;                                        // decrement the count
 | 
					            rcount--;                                        // decrement the count
 | 
				
			||||||
            a->ring[a->rptr] = 0;                               // set the location to '0'
 | 
					            ring[rptr] = 0;                               // set the location to '0'
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if ((a->inlast * a->in[0] < 0.0) &&                     // different signs mean zero-crossing
 | 
					        if ((inlast * in[0] < 0.0) &&                     // different signs mean zero-crossing
 | 
				
			||||||
            (fabs (a->inlast - a->in[0]) > a->eps))
 | 
					            (fabs (inlast - in[0]) > eps))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            a->ring[a->rptr] = 1;                               // set the ring location to '1'
 | 
					            ring[rptr] = 1;                               // set the ring location to '1'
 | 
				
			||||||
            a->rcount++;                                        // increment the count
 | 
					            rcount++;                                        // increment the count
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (++a->rptr == a->rsize) a->rptr = 0;                 // increment and wrap the pointer as needed
 | 
					        if (++rptr == rsize) rptr = 0;                 // increment and wrap the pointer as needed
 | 
				
			||||||
        a->out[0] = std::min (1.0, (double)a->rcount / a->div);      // calculate the output sample
 | 
					        out[0] = std::min (1.0, (double)rcount / div);      // calculate the output sample
 | 
				
			||||||
        a->inlast = a->in[a->size - 1];                         // save the last input sample for next buffer
 | 
					        inlast = in[size - 1];                         // save the last input sample for next buffer
 | 
				
			||||||
        for (int i = 1; i < a->size; i++)
 | 
					        for (int i = 1; i < size; i++)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (a->ring[a->rptr] == 1)                          // if current ring location is '1' ...
 | 
					            if (ring[rptr] == 1)                          // if current ring location is '1' ...
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                a->rcount--;                                    // decrement the count
 | 
					                rcount--;                                    // decrement the count
 | 
				
			||||||
                a->ring[a->rptr] = 0;                           // set the location to '0'
 | 
					                ring[rptr] = 0;                           // set the location to '0'
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if ((a->in[i - 1] * a->in[i] < 0.0) &&              // different signs mean zero-crossing
 | 
					            if ((in[i - 1] * in[i] < 0.0) &&              // different signs mean zero-crossing
 | 
				
			||||||
                (fabs (a->in[i - 1] - a->in[i]) > a->eps))
 | 
					                (fabs (in[i - 1] - in[i]) > eps))
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                a->ring[a->rptr] = 1;                           // set the ring location to '1'
 | 
					                ring[rptr] = 1;                           // set the ring location to '1'
 | 
				
			||||||
                a->rcount++;                                    // increment the count
 | 
					                rcount++;                                    // increment the count
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (++a->rptr == a->rsize) a->rptr = 0;             // increment and wrap the pointer as needed
 | 
					            if (++rptr == rsize) rptr = 0;             // increment and wrap the pointer as needed
 | 
				
			||||||
            a->out[i] = std::min(1.0, (double)a->rcount / a->div);   // calculate the output sample
 | 
					            out[i] = std::min(1.0, (double)rcount / div);   // calculate the output sample
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -143,9 +143,9 @@ void SSQL::calc_ssql (SSQL *a)
 | 
				
			|||||||
    a->dcbl = new CBL(1, a->size, a->in, a->b1, 0, a->rate, 0.02);
 | 
					    a->dcbl = new CBL(1, a->size, a->in, a->b1, 0, a->rate, 0.02);
 | 
				
			||||||
    a->ibuff = new float[a->size]; // (float*) malloc0 (a->size * sizeof (float));
 | 
					    a->ibuff = new float[a->size]; // (float*) malloc0 (a->size * sizeof (float));
 | 
				
			||||||
    a->ftovbuff = new float[a->size]; // (float*) malloc0(a->size * sizeof (float));
 | 
					    a->ftovbuff = new float[a->size]; // (float*) malloc0(a->size * sizeof (float));
 | 
				
			||||||
    a->cvtr = FTOV::create_ftov (1, a->size, a->rate, a->ftov_rsize, a->ftov_fmax, a->ibuff, a->ftovbuff);
 | 
					    a->cvtr = new FTOV(1, a->size, a->rate, a->ftov_rsize, a->ftov_fmax, a->ibuff, a->ftovbuff);
 | 
				
			||||||
    a->lpbuff = new float[a->size]; // (float*) malloc0 (a->size * sizeof (float));
 | 
					    a->lpbuff = new float[a->size]; // (float*) malloc0 (a->size * sizeof (float));
 | 
				
			||||||
    a->filt = DBQLP::create_dbqlp (1, a->size, a->ftovbuff, a->lpbuff, a->rate, 11.3, 1.0, 1.0, 1);
 | 
					    a->filt = new DBQLP(1, a->size, a->ftovbuff, a->lpbuff, a->rate, 11.3, 1.0, 1.0, 1);
 | 
				
			||||||
    a->wdbuff = new int[a->size]; // (int*) malloc0 (a->size * sizeof (int));
 | 
					    a->wdbuff = new int[a->size]; // (int*) malloc0 (a->size * sizeof (int));
 | 
				
			||||||
    a->tr_signal = new int[a->size]; // (int*) malloc0 (a->size * sizeof (int));
 | 
					    a->tr_signal = new int[a->size]; // (int*) malloc0 (a->size * sizeof (int));
 | 
				
			||||||
    // window detector
 | 
					    // window detector
 | 
				
			||||||
@ -170,9 +170,9 @@ void SSQL::decalc_ssql (SSQL *a)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    delete[] (a->tr_signal);
 | 
					    delete[] (a->tr_signal);
 | 
				
			||||||
    delete[] (a->wdbuff);
 | 
					    delete[] (a->wdbuff);
 | 
				
			||||||
    DBQLP::destroy_dbqlp (a->filt);
 | 
					    delete (a->filt);
 | 
				
			||||||
    delete[] (a->lpbuff);
 | 
					    delete[] (a->lpbuff);
 | 
				
			||||||
    FTOV::destroy_ftov (a->cvtr);
 | 
					    delete (a->cvtr);
 | 
				
			||||||
    delete[] (a->ftovbuff);
 | 
					    delete[] (a->ftovbuff);
 | 
				
			||||||
    delete[] (a->ibuff);
 | 
					    delete[] (a->ibuff);
 | 
				
			||||||
    delete (a->dcbl);
 | 
					    delete (a->dcbl);
 | 
				
			||||||
@ -233,9 +233,9 @@ void SSQL::flush_ssql (SSQL *a)
 | 
				
			|||||||
    a->dcbl->flush();
 | 
					    a->dcbl->flush();
 | 
				
			||||||
    memset (a->ibuff, 0, a->size * sizeof (float));
 | 
					    memset (a->ibuff, 0, a->size * sizeof (float));
 | 
				
			||||||
    memset (a->ftovbuff, 0, a->size * sizeof (float));
 | 
					    memset (a->ftovbuff, 0, a->size * sizeof (float));
 | 
				
			||||||
    FTOV::flush_ftov (a->cvtr);
 | 
					    a->cvtr->flush();
 | 
				
			||||||
    memset (a->lpbuff, 0, a->size * sizeof (float));
 | 
					    memset (a->lpbuff, 0, a->size * sizeof (float));
 | 
				
			||||||
    DBQLP::flush_dbqlp (a->filt);
 | 
					    a->filt->flush();
 | 
				
			||||||
    memset (a->wdbuff, 0, a->size * sizeof (int));
 | 
					    memset (a->wdbuff, 0, a->size * sizeof (int));
 | 
				
			||||||
    memset (a->tr_signal, 0, a->size * sizeof (int));
 | 
					    memset (a->tr_signal, 0, a->size * sizeof (int));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -255,9 +255,9 @@ void SSQL::xssql (SSQL *a)
 | 
				
			|||||||
        a->dcbl->execute();                                         // dc block the input signal
 | 
					        a->dcbl->execute();                                         // dc block the input signal
 | 
				
			||||||
        for (int i = 0; i < a->size; i++)                       // extract 'I' component
 | 
					        for (int i = 0; i < a->size; i++)                       // extract 'I' component
 | 
				
			||||||
            a->ibuff[i] = a->b1[2 * i];
 | 
					            a->ibuff[i] = a->b1[2 * i];
 | 
				
			||||||
        FTOV::xftov (a->cvtr);                                        // convert frequency to voltage, ignoring amplitude
 | 
					        a->cvtr->execute();                                        // convert frequency to voltage, ignoring amplitude
 | 
				
			||||||
        // WriteAudioWDSP(20.0, a->rate, a->size, a->ftovbuff, 4, 0.99);
 | 
					        // WriteAudioWDSP(20.0, a->rate, a->size, a->ftovbuff, 4, 0.99);
 | 
				
			||||||
        DBQLP::xdbqlp (a->filt);                                       // low-pass filter
 | 
					        a->filt->execute();                                       // low-pass filter
 | 
				
			||||||
        // WriteAudioWDSP(20.0, a->rate, a->size, a->lpbuff, 4, 0.99);
 | 
					        // WriteAudioWDSP(20.0, a->rate, a->size, a->lpbuff, 4, 0.99);
 | 
				
			||||||
        // calculate the output of the window detector for each sample
 | 
					        // calculate the output of the window detector for each sample
 | 
				
			||||||
        for (int i = 0; i < a->size; i++)
 | 
					        for (int i = 0; i < a->size; i++)
 | 
				
			||||||
 | 
				
			|||||||
@ -28,6 +28,8 @@ warren@pratt.one
 | 
				
			|||||||
#ifndef wdsp_ssql_h
 | 
					#ifndef wdsp_ssql_h
 | 
				
			||||||
#define wdsp_ssql_h
 | 
					#define wdsp_ssql_h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "export.h"
 | 
					#include "export.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace WDSP {
 | 
					namespace WDSP {
 | 
				
			||||||
@ -40,19 +42,30 @@ public:
 | 
				
			|||||||
    int rate;                           // sample-rate
 | 
					    int rate;                           // sample-rate
 | 
				
			||||||
    int rsize;                          // rate * time_to_fill_ring, e.g., 48K/s * 50ms = 2400
 | 
					    int rsize;                          // rate * time_to_fill_ring, e.g., 48K/s * 50ms = 2400
 | 
				
			||||||
    double fmax;                        // frequency (Hz) for full output, e.g., 2000 (Hz)
 | 
					    double fmax;                        // frequency (Hz) for full output, e.g., 2000 (Hz)
 | 
				
			||||||
    float* in;                         // pointer to the intput buffer for ftov
 | 
					    float* in;                          // pointer to the intput buffer for ftov
 | 
				
			||||||
    float* out;                        // pointer to the output buffer for ftov
 | 
					    float* out;                         // pointer to the output buffer for ftov
 | 
				
			||||||
    int* ring;                          // pointer to the base of the ring
 | 
					    std::vector<int> ring;              // the ring
 | 
				
			||||||
    int rptr;                           // index into the ring
 | 
					    int rptr;                           // index into the ring
 | 
				
			||||||
    double inlast;                      // holds last sample from previous buffer
 | 
					    double inlast;                      // holds last sample from previous buffer
 | 
				
			||||||
    int rcount;                         // count of zero-crossings currently in the ring
 | 
					    int rcount;                         // count of zero-crossings currently in the ring
 | 
				
			||||||
    double div;                         // divisor for 'rcount' to produce output of 1.0 at 'fmax'
 | 
					    double div;                         // divisor for 'rcount' to produce output of 1.0 at 'fmax'
 | 
				
			||||||
    double eps;                         // minimum input change to count as a signal edge transition
 | 
					    double eps;                         // minimum input change to count as a signal edge transition
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static FTOV* create_ftov (int run, int size, int rate, int rsize, double fmax, float* in, float* out);
 | 
					    FTOV(
 | 
				
			||||||
    static void destroy_ftov (FTOV *a);
 | 
					        int run,
 | 
				
			||||||
    static void flush_ftov (FTOV *a);
 | 
					        int size,
 | 
				
			||||||
    static void xftov (FTOV *a);
 | 
					        int rate,
 | 
				
			||||||
 | 
					        int rsize,
 | 
				
			||||||
 | 
					        double fmax,
 | 
				
			||||||
 | 
					        float* in,
 | 
				
			||||||
 | 
					        float* out
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    FTOV(const FTOV&) = delete;
 | 
				
			||||||
 | 
					    FTOV& operator=(FTOV& other) = delete;
 | 
				
			||||||
 | 
					    ~FTOV() = default;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void flush();
 | 
				
			||||||
 | 
					    void execute();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CBL;
 | 
					class CBL;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user