mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-10-31 13:00:26 -04:00 
			
		
		
		
	WDSP: RXA and TXA rework
This commit is contained in:
		
							parent
							
								
									d6159067a8
								
							
						
					
					
						commit
						de756413e8
					
				| @ -125,14 +125,14 @@ WDSPRxSink::WDSPRxSink() : | ||||
|     m_sPeak = 0.0; | ||||
|     m_sCount = m_wdspBufSize; | ||||
| 
 | ||||
|     m_rxa = WDSP::RXA::create_rxa( | ||||
|     m_rxa = new WDSP::RXA( | ||||
|         m_wdspSampleRate, // input samplerate
 | ||||
|         m_wdspSampleRate, // output samplerate
 | ||||
|         m_wdspSampleRate, // sample rate for mainstream dsp processing (dsp)
 | ||||
|         m_wdspBufSize     // number complex samples processed per buffer in mainstream dsp processing
 | ||||
|     ); | ||||
|     m_rxa->setSpectrumProbe(&m_spectrumProbe); | ||||
|     WDSP::RXA::SetPassband(*m_rxa, 0, m_Bandwidth); | ||||
|     m_rxa->setPassband(0, m_Bandwidth); | ||||
| 
 | ||||
|     applyChannelSettings(m_channelSampleRate, m_channelFrequencyOffset, true); | ||||
| 	applySettings(m_settings, true); | ||||
| @ -140,7 +140,7 @@ WDSPRxSink::WDSPRxSink() : | ||||
| 
 | ||||
| WDSPRxSink::~WDSPRxSink() | ||||
| { | ||||
|     WDSP::RXA::destroy_rxa(m_rxa); | ||||
|     delete m_rxa; | ||||
| } | ||||
| 
 | ||||
| void WDSPRxSink::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end) | ||||
| @ -189,7 +189,7 @@ void WDSPRxSink::processOneSample(Complex &ci) | ||||
| 
 | ||||
|     if (++m_inCount == m_rxa->get_insize()) | ||||
|     { | ||||
|         WDSP::RXA::xrxa(m_rxa); | ||||
|         m_rxa->execute(); | ||||
| 
 | ||||
|         m_sCount = m_wdspBufSize; | ||||
|         m_sAvg = m_rxa->smeter->getMeter(WDSP::RXA::RXA_S_AV); | ||||
| @ -306,7 +306,7 @@ void WDSPRxSink::applyAudioSampleRate(int sampleRate) | ||||
|     m_interpolatorDistanceRemain = 0; | ||||
|     m_interpolatorDistance = (Real) m_channelSampleRate / (Real) m_wdspSampleRate; | ||||
| 
 | ||||
|     WDSP::RXA::setOutputSamplerate(m_rxa, sampleRate); | ||||
|     m_rxa->setOutputSamplerate(sampleRate); | ||||
| 
 | ||||
|     m_audioFifo.setSize(sampleRate); | ||||
|     m_audioSampleRate = sampleRate; | ||||
| @ -446,24 +446,24 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force) | ||||
|         m_interpolatorDistanceRemain = 0; | ||||
|         m_interpolatorDistance = (Real) m_channelSampleRate / (Real) m_audioSampleRate; | ||||
| 
 | ||||
|         WDSP::RXA::SetPassband(*m_rxa, fLow, fHigh); | ||||
|         WDSP::RXA::NBPSetWindow(*m_rxa, m_settings.m_profiles[m_settings.m_profileIndex].m_fftWindow); | ||||
|         m_rxa->setPassband(fLow, fHigh); | ||||
|         m_rxa->nbpSetWindow(m_settings.m_profiles[m_settings.m_profileIndex].m_fftWindow); | ||||
| 
 | ||||
|         if (settings.m_demod == WDSPRxProfile::DemodSSB) | ||||
|         { | ||||
|             if (dsb) { | ||||
|                 WDSP::RXA::SetMode(*m_rxa, WDSP::RXA::RXA_DSB); | ||||
|                 m_rxa->setMode(WDSP::RXA::RXA_DSB); | ||||
|             } else { | ||||
|                 WDSP::RXA::SetMode(*m_rxa, usb ? WDSP::RXA::RXA_USB : WDSP::RXA::RXA_LSB); | ||||
|                 m_rxa->setMode(usb ? WDSP::RXA::RXA_USB : WDSP::RXA::RXA_LSB); | ||||
|             } | ||||
|         } | ||||
|         else if (settings.m_demod == WDSPRxProfile::DemodAM) | ||||
|         { | ||||
|             WDSP::RXA::SetMode(*m_rxa, WDSP::RXA::RXA_AM); | ||||
|             m_rxa->setMode(WDSP::RXA::RXA_AM); | ||||
|         } | ||||
|         else if (settings.m_demod == WDSPRxProfile::DemodSAM) | ||||
|         { | ||||
|             WDSP::RXA::SetMode(*m_rxa, WDSP::RXA::RXA_SAM); | ||||
|             m_rxa->setMode(WDSP::RXA::RXA_SAM); | ||||
| 
 | ||||
|             if (dsb) { | ||||
|                 m_rxa->amd->setSBMode(0); | ||||
| @ -473,7 +473,7 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force) | ||||
|         } | ||||
|         else if (settings.m_demod == WDSPRxProfile::DemodFMN) | ||||
|         { | ||||
|             WDSP::RXA::SetMode(*m_rxa, WDSP::RXA::RXA_FM); | ||||
|             m_rxa->setMode(WDSP::RXA::RXA_FM); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| @ -486,18 +486,18 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force) | ||||
|     if ((m_settings.m_dnr != settings.m_dnr) | ||||
|     || (m_settings.m_nrScheme != settings.m_nrScheme) || force) | ||||
|     { | ||||
|         WDSP::RXA::SetANRRun(*m_rxa, 0); | ||||
|         WDSP::RXA::SetEMNRRun(*m_rxa, 0); | ||||
|         m_rxa->setANRRun(0); | ||||
|         m_rxa->setEMNRRun(0); | ||||
| 
 | ||||
|         if (settings.m_dnr) | ||||
|         { | ||||
|             switch (settings.m_nrScheme) | ||||
|             { | ||||
|             case WDSPRxProfile::NRSchemeNR: | ||||
|                 WDSP::RXA::SetANRRun(*m_rxa, 1); | ||||
|                 m_rxa->setANRRun(1); | ||||
|                 break; | ||||
|             case WDSPRxProfile::NRSchemeNR2: | ||||
|                 WDSP::RXA::SetEMNRRun(*m_rxa, 1); | ||||
|                 m_rxa->setEMNRRun(1); | ||||
|                 break; | ||||
|             default: | ||||
|                 break; | ||||
| @ -510,12 +510,12 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force) | ||||
|         switch (settings.m_nrPosition) | ||||
|         { | ||||
|         case WDSPRxProfile::NRPositionPreAGC: | ||||
|             WDSP::RXA::SetANRPosition(*m_rxa, 0); | ||||
|             WDSP::RXA::SetEMNRPosition(*m_rxa, 0); | ||||
|             m_rxa->setANRPosition(0); | ||||
|             m_rxa->setEMNRPosition(0); | ||||
|             break; | ||||
|         case WDSPRxProfile::NRPositionPostAGC: | ||||
|             WDSP::RXA::SetANRPosition(*m_rxa, 1); | ||||
|             WDSP::RXA::SetEMNRPosition(*m_rxa, 1); | ||||
|             m_rxa->setANRPosition(1); | ||||
|             m_rxa->setEMNRPosition(1); | ||||
|             break; | ||||
|         default: | ||||
|             break; | ||||
| @ -560,12 +560,12 @@ void WDSPRxSink::applySettings(const WDSPRxSettings& settings, bool force) | ||||
|     } | ||||
| 
 | ||||
|     if ((m_settings.m_anf != settings.m_anf) || force) { | ||||
|         WDSP::RXA::SetANFRun(*m_rxa, settings.m_anf ? 1 : 0); | ||||
|         m_rxa->setANFRun(settings.m_anf ? 1 : 0); | ||||
|     } | ||||
| 
 | ||||
|     // Caution: Causes corruption
 | ||||
|     if ((m_settings.m_snb != settings.m_snb) || force) { | ||||
|         WDSP::RXA::SetSNBARun(*m_rxa, settings.m_snb ? 1 : 0); | ||||
|         m_rxa->setSNBARun(settings.m_snb ? 1 : 0); | ||||
|     } | ||||
| 
 | ||||
|     // CW Peaking
 | ||||
|  | ||||
| @ -62,6 +62,7 @@ set(wdsp_SOURCES | ||||
|     sphp.cpp | ||||
|     ssql.cpp | ||||
|     TXA.cpp | ||||
|     unit.cpp | ||||
|     varsamp.cpp | ||||
|     wcpAGC.cpp | ||||
| ) | ||||
| @ -129,6 +130,7 @@ set(wdsp_HEADERS | ||||
|     sphp.hpp | ||||
|     ssql.hpp | ||||
|     TXA.hpp | ||||
|     unit.hpp | ||||
|     varsamp.hpp | ||||
|     wcpAGC.hpp | ||||
| ) | ||||
|  | ||||
							
								
								
									
										1262
									
								
								wdsp/RXA.cpp
									
									
									
									
									
								
							
							
						
						
									
										1262
									
								
								wdsp/RXA.cpp
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										94
									
								
								wdsp/RXA.hpp
									
									
									
									
									
								
							
							
						
						
									
										94
									
								
								wdsp/RXA.hpp
									
									
									
									
									
								
							| @ -128,70 +128,68 @@ public: | ||||
|     PANEL *panel; | ||||
|     RESAMPLE *rsmpout; | ||||
| 
 | ||||
|     static RXA* create_rxa ( | ||||
|     RXA( | ||||
|         int in_rate,                // input samplerate
 | ||||
|         int out_rate,               // output samplerate
 | ||||
|         int dsp_rate,               // sample rate for mainstream dsp processing
 | ||||
|         int dsp_size                // number complex samples processed per buffer in mainstream dsp processing
 | ||||
|     ); | ||||
|     static void destroy_rxa (RXA *rxa); | ||||
|     static void flush_rxa (RXA *rxa); | ||||
|     static void xrxa (RXA *rxa); | ||||
|     int get_insize() const { return dsp_insize; } | ||||
|     int get_outsize() const { return dsp_outsize; } | ||||
|     float *get_inbuff() { return inbuff; } | ||||
|     float *get_outbuff() { return outbuff; } | ||||
|     RXA(const RXA&) = delete; | ||||
|     RXA& operator=(const RXA& other) = delete; | ||||
|     ~RXA(); | ||||
| 
 | ||||
|     void flush(); | ||||
|     void execute(); | ||||
|     void setInputSamplerate(int _in_rate); | ||||
|     void setOutputSamplerate(int _out_rate); | ||||
|     void setDSPSamplerate(int _dsp_rate); | ||||
|     void setDSPBuffsize(int _dsp_size); | ||||
|     int get_insize() const { return Unit::dsp_insize; } | ||||
|     int get_outsize() const { return Unit::dsp_outsize; } | ||||
|     float *get_inbuff() { return Unit::inbuff; } | ||||
|     float *get_outbuff() { return Unit::outbuff; } | ||||
|     void setSpectrumProbe(BufferProbe *_spectrumProbe); | ||||
|     static void setInputSamplerate (RXA *rxa, int in_rate); | ||||
|     static void setOutputSamplerate (RXA *rxa, int out_rate); | ||||
|     static void setDSPSamplerate (RXA *rxa, int dsp_rate); | ||||
|     static void setDSPBuffsize (RXA *rxa, int dsp_size); | ||||
| 
 | ||||
|     // RXA Properties
 | ||||
|     static void SetMode (RXA& rxa, int mode); | ||||
|     static void ResCheck (RXA& rxa); | ||||
|     static void bp1Check (RXA& rxa, int amd_run, int snba_run, int emnr_run, int anf_run, int anr_run); | ||||
|     static void bp1Set (RXA& rxa); | ||||
|     static void bpsnbaCheck (RXA& rxa, int mode, int notch_run); | ||||
|     static void bpsnbaSet (RXA& rxa); | ||||
|     void setMode (int mode); | ||||
|     void resCheck (); | ||||
|     void bp1Check (int amd_run, int snba_run, int emnr_run, int anf_run, int anr_run); | ||||
|     void bp1Set (); | ||||
|     void bpsnbaCheck (int mode, int notch_run); | ||||
|     void bpsnbaSet (); | ||||
|     // NOTCHDB, NBP, SNBA
 | ||||
|     static void UpdateNBPFiltersLightWeight (RXA& rxa); | ||||
|     static void UpdateNBPFilters(RXA& rxa); | ||||
|     static int NBPAddNotch (RXA& rxa, int notch, double fcenter, double fwidth, int active); | ||||
|     static int NBPGetNotch (RXA& rxa, int notch, double* fcenter, double* fwidth, int* active); | ||||
|     static int NBPDeleteNotch (RXA& rxa, int notch); | ||||
|     static int NBPEditNotch (RXA& rxa, int notch, double fcenter, double fwidth, int active); | ||||
|     static void NBPGetNumNotches (RXA& rxa, int* nnotches); | ||||
|     static void NBPSetTuneFrequency (RXA& rxa, double tunefreq); | ||||
|     static void NBPSetShiftFrequency (RXA& rxa, double shift); | ||||
|     static void NBPSetNotchesRun (RXA& rxa, int run); | ||||
|     static void NBPSetWindow (RXA& rxa, int wintype); | ||||
|     static void NBPSetAutoIncrease (RXA& rxa, int autoincr); | ||||
|     void updateNBPFiltersLightWeight(); | ||||
|     void updateNBPFilters(); | ||||
|     int nbpAddNotch(int notch, double fcenter, double fwidth, int active); | ||||
|     int nbpGetNotch(int notch, double* fcenter, double* fwidth, int* active); | ||||
|     int nbpDeleteNotch(int notch); | ||||
|     int nbpEditNotch(int notch, double fcenter, double fwidth, int active); | ||||
|     void nbpGetNumNotches(int* nnotches); | ||||
|     void nbpSetTuneFrequency(double tunefreq); | ||||
|     void nbpSetShiftFrequency(double shift); | ||||
|     void nbpSetNotchesRun(int run); | ||||
|     void nbpSetWindow(int wintype); | ||||
|     void nbpSetAutoIncrease(int autoincr); | ||||
|     // AMD
 | ||||
|     static void SetAMDRun(RXA& rxa, int run); | ||||
|     void setAMDRun(int run); | ||||
|     // SNBA
 | ||||
|     static void SetSNBARun (RXA& rxa, int run); | ||||
|     void setSNBARun(int run); | ||||
|     // ANF
 | ||||
|     static void SetANFRun (RXA& rxa, int run); | ||||
|     static void SetANFPosition (RXA& rxa, int position); | ||||
|     void setANFRun(int run); | ||||
|     void setANFPosition(int position); | ||||
|     // ANR
 | ||||
|     static void SetANRRun (RXA& rxa, int run); | ||||
|     static void SetANRPosition (RXA& rxa, int position); | ||||
|     void setANRRun(int run); | ||||
|     void setANRPosition(int position); | ||||
|     // EMNR
 | ||||
|     static void SetEMNRRun (RXA& rxa, int run); | ||||
|     static void SetEMNRPosition (RXA& rxa, int position); | ||||
|     void setEMNRRun(int run); | ||||
|     void setEMNRPosition(int position); | ||||
|     // WCPAGC
 | ||||
|     static void SetAGCThresh(RXA& rxa, double thresh, double size, double rate); | ||||
|     static void GetAGCThresh(RXA& rxa, double *thresh, double size, double rate); | ||||
|     void setAGCThresh(double thresh, double size, double rate); | ||||
|     void getAGCThresh(double *thresh, double size, double rate); | ||||
|     // Collectives
 | ||||
|     static void SetPassband (RXA& rxa, float f_low, float f_high); | ||||
|     static void SetNC (RXA& rxa, int nc); | ||||
|     static void SetMP (RXA& rxa, int mp); | ||||
| 
 | ||||
| private: | ||||
|     float* inbuff; | ||||
|     float* midbuff; | ||||
|     float* outbuff; | ||||
|     void setPassband(float f_low, float f_high); | ||||
|     void setNC(int nc); | ||||
|     void setMP(int mp); | ||||
| }; | ||||
| 
 | ||||
| } // namespace WDSP
 | ||||
|  | ||||
							
								
								
									
										1116
									
								
								wdsp/TXA.cpp
									
									
									
									
									
								
							
							
						
						
									
										1116
									
								
								wdsp/TXA.cpp
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										55
									
								
								wdsp/TXA.hpp
									
									
									
									
									
								
							
							
						
						
									
										55
									
								
								wdsp/TXA.hpp
									
									
									
									
									
								
							| @ -157,11 +157,6 @@ public: | ||||
|     GEN *gen0; | ||||
|     GEN *gen1; | ||||
|     USLEW *uslew; | ||||
|     // struct
 | ||||
|     // {
 | ||||
|     //     CALCC *p;
 | ||||
|     //     CRITICAL_SECTION cs_update;
 | ||||
|     // } calcc;
 | ||||
|     struct | ||||
|     { | ||||
|         IQC *p0, *p1; | ||||
| @ -169,42 +164,42 @@ public: | ||||
|     } iqc; | ||||
|     CFIR *cfir; | ||||
| 
 | ||||
|     static TXA* create_txa ( | ||||
|     TXA( | ||||
|         int in_rate,                // input samplerate
 | ||||
|         int out_rate,               // output samplerate
 | ||||
|         int dsp_rate,               // sample rate for mainstream dsp processing
 | ||||
|         int dsp_size                // number complex samples processed per buffer in mainstream dsp processing
 | ||||
|     ); | ||||
|     static void destroy_txa (TXA *txa); | ||||
|     static void flush_txa (TXA *txa); | ||||
|     static void xtxa (TXA *txa); | ||||
|     int get_insize() const { return dsp_insize; } | ||||
|     int get_outsize() const { return dsp_outsize; } | ||||
|     float *get_inbuff() { return inbuff; } | ||||
|     float *get_outbuff() { return outbuff; } | ||||
|     static void setInputSamplerate (TXA *txa, int in_rate); | ||||
|     static void setOutputSamplerate (TXA *txa, int out_rate); | ||||
|     static void setDSPSamplerate (TXA *txa, int dsp_rate); | ||||
|     static void setDSPBuffsize (TXA *txa, int dsp_size); | ||||
|     TXA(const TXA&) = delete; | ||||
|     TXA& operator=(const TXA& other) = delete; | ||||
|     ~TXA(); | ||||
| 
 | ||||
|     void flush(); | ||||
|     void execute(); | ||||
|     void setInputSamplerate(int _in_rate); | ||||
|     void setOutputSamplerate(int _out_rate); | ||||
|     void setDSPSamplerate(int _dsp_rate); | ||||
|     void setDSPBuffsize(int _dsp_size); | ||||
|     int get_insize() const { return Unit::dsp_insize; } | ||||
|     int get_outsize() const { return Unit::dsp_outsize; } | ||||
|     float *get_inbuff() { return Unit::inbuff; } | ||||
|     float *get_outbuff() { return Unit::outbuff; } | ||||
| 
 | ||||
|     // TXA Properties
 | ||||
|     static void SetMode (TXA& txa, int mode); | ||||
|     static void SetBandpassFreqs (TXA& txa, float f_low, float f_high); | ||||
|     static void SetBandpassNC (TXA& txa, int nc); | ||||
|     static void SetBandpassMP (TXA& txa, int mp); | ||||
|     void setMode(int mode); | ||||
|     void setBandpassFreqs(float f_low, float f_high); | ||||
|     void setBandpassNC(int nc); | ||||
|     void setBandpassMP(int mp); | ||||
| 
 | ||||
|     // Collectives
 | ||||
|     static void SetNC (TXA& txa, int nc); | ||||
|     static void SetMP (TXA& txa, int mp); | ||||
|     static void SetFMAFFilter (TXA& txa, float low, float high); | ||||
|     static void SetupBPFilters (TXA& txa); | ||||
|     static int UslewCheck (TXA& txa); | ||||
|     void setNC(int nc); | ||||
|     void setMP(int mp); | ||||
|     void setFMAFFilter(float low, float high); | ||||
|     void setupBPFilters(); | ||||
|     int uslewCheck(); | ||||
| 
 | ||||
| private: | ||||
|     static void ResCheck (TXA& txa); | ||||
|     float* inbuff; | ||||
|     float* midbuff; | ||||
|     float* outbuff; | ||||
|     void resCheck(); | ||||
| }; | ||||
| 
 | ||||
| } // namespace WDSP
 | ||||
|  | ||||
| @ -103,7 +103,7 @@ void COMPRESSOR::SetCompressorRun (TXA& txa, int run) | ||||
|     if (txa.compressor->run != run) | ||||
|     { | ||||
|         txa.compressor->run = run; | ||||
|         TXA::SetupBPFilters (txa); | ||||
|         txa.setupBPFilters(); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -149,7 +149,7 @@ void OSCTRL::SetosctrlRun (TXA& txa, int run) | ||||
|     if (txa.osctrl->run != run) | ||||
|     { | ||||
|         txa.osctrl->run = run; | ||||
|         TXA::SetupBPFilters (txa); | ||||
|         txa.setupBPFilters(); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -103,7 +103,7 @@ void USLEW::flush_uslew (USLEW *a) | ||||
| 
 | ||||
| void USLEW::xuslew (USLEW *a) | ||||
| { | ||||
|     if (!a->runmode && TXA::UslewCheck (*a->txa)) | ||||
|     if (!a->runmode && a->txa->uslewCheck()) | ||||
|         a->runmode = 1; | ||||
| 
 | ||||
|     long upslew = *a->ch_upslew; | ||||
|  | ||||
							
								
								
									
										148
									
								
								wdsp/unit.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										148
									
								
								wdsp/unit.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,148 @@ | ||||
| /*  unit.hpp
 | ||||
| 
 | ||||
| This file is part of a program that implements a Software-Defined Radio. | ||||
| 
 | ||||
| Copyright (C) 2013 Warren Pratt, NR0V | ||||
| Copyright (C) 2024 Edouard Griffiths, F4EXB Adapted to SDRangel | ||||
| 
 | ||||
| This program is free software; you can redistribute it and/or | ||||
| modify it under the terms of the GNU General Public License | ||||
| as published by the Free Software Foundation; either version 2 | ||||
| of the License, or (at your option) any later version. | ||||
| 
 | ||||
| This program is distributed in the hope that it will be useful, | ||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| GNU General Public License for more details. | ||||
| 
 | ||||
| You should have received a copy of the GNU General Public License | ||||
| along with this program; if not, write to the Free Software | ||||
| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | ||||
| 
 | ||||
| The author can be reached by email at | ||||
| 
 | ||||
| warren@wpratt.com | ||||
| 
 | ||||
| */ | ||||
| 
 | ||||
| #include <algorithm> | ||||
| 
 | ||||
| #include "unit.hpp" | ||||
| 
 | ||||
| namespace WDSP { | ||||
| 
 | ||||
| Unit::Unit( | ||||
|     int _in_rate,                // input samplerate
 | ||||
|     int _out_rate,               // output samplerate
 | ||||
|     int _dsp_rate,               // sample rate for mainstream dsp processing
 | ||||
|     int _dsp_size                // number complex samples processed per buffer in mainstream dsp processing
 | ||||
| ) : | ||||
|     in_rate{_in_rate}, | ||||
|     out_rate(_out_rate), | ||||
|     dsp_rate(_dsp_rate), | ||||
|     dsp_size(_dsp_size) | ||||
| { | ||||
|     if (_in_rate  >= _dsp_rate) | ||||
|         dsp_insize  = _dsp_size * (_in_rate  / _dsp_rate); | ||||
|     else | ||||
|         dsp_insize  = _dsp_size / (_dsp_rate /  _in_rate); | ||||
| 
 | ||||
|     if (_out_rate >= _dsp_rate) | ||||
|         dsp_outsize = _dsp_size * (_out_rate / _dsp_rate); | ||||
|     else | ||||
|         dsp_outsize = _dsp_size / (_dsp_rate / _out_rate); | ||||
| 
 | ||||
|     // buffers
 | ||||
|     inbuff  = new float[1 * dsp_insize  * 2]; | ||||
|     outbuff = new float[1 * dsp_outsize  * 2]; | ||||
|     midbuff = new float[2 * dsp_size  * 2]; | ||||
| } | ||||
| 
 | ||||
| Unit::~Unit() | ||||
| { | ||||
|     delete[] inbuff; | ||||
|     delete[] outbuff; | ||||
|     delete[] midbuff; | ||||
| } | ||||
| 
 | ||||
| void Unit::flushBuffers() | ||||
| { | ||||
|     std::fill(inbuff,  inbuff  + 1 * dsp_insize  * 2, 0); | ||||
|     std::fill(outbuff, outbuff + 1 * dsp_outsize * 2, 0); | ||||
|     std::fill(midbuff, midbuff + 2 * dsp_size    * 2, 0); | ||||
| } | ||||
| 
 | ||||
| void Unit::setBuffersInputSamplerate(int _in_rate) | ||||
| { | ||||
|     if (_in_rate  >= dsp_rate) | ||||
|         dsp_insize  = dsp_size * (_in_rate  / dsp_rate); | ||||
|     else | ||||
|         dsp_insize  = dsp_size / (dsp_rate /  _in_rate); | ||||
| 
 | ||||
|     in_rate = _in_rate; | ||||
| 
 | ||||
|     // buffers
 | ||||
|     delete[] (inbuff); | ||||
|     inbuff = new float[1 * dsp_insize  * 2]; | ||||
| } | ||||
| 
 | ||||
| void Unit::setBuffersOutputSamplerate(int _out_rate) | ||||
| { | ||||
|     if (_out_rate >= dsp_rate) | ||||
|         dsp_outsize = dsp_size * (_out_rate / dsp_rate); | ||||
|     else | ||||
|         dsp_outsize = dsp_size / (dsp_rate / _out_rate); | ||||
| 
 | ||||
|     out_rate = _out_rate; | ||||
| 
 | ||||
|     // buffers
 | ||||
|     delete[] outbuff; | ||||
|     outbuff = new float[1 * dsp_outsize * 2]; | ||||
| } | ||||
| 
 | ||||
| void Unit::setBuffersDSPSamplerate(int _dsp_rate) | ||||
| { | ||||
|     if (in_rate  >= _dsp_rate) | ||||
|         dsp_insize  = dsp_size * (in_rate  / _dsp_rate); | ||||
|     else | ||||
|         dsp_insize  = dsp_size / (_dsp_rate /  in_rate); | ||||
| 
 | ||||
|     if (out_rate >= _dsp_rate) | ||||
|         dsp_outsize = dsp_size * (out_rate / _dsp_rate); | ||||
|     else | ||||
|         dsp_outsize = dsp_size / (_dsp_rate / out_rate); | ||||
| 
 | ||||
|     dsp_rate = _dsp_rate; | ||||
| 
 | ||||
|     // buffers
 | ||||
|     delete[] inbuff; | ||||
|     inbuff = new float[1 * dsp_insize  * 2]; | ||||
|     delete[] outbuff; | ||||
|     outbuff = new float[1 * dsp_outsize * 2]; | ||||
| } | ||||
| 
 | ||||
| void Unit::setBuffersDSPBuffsize(int _dsp_size) | ||||
| { | ||||
|     if (in_rate  >= dsp_rate) | ||||
|         dsp_insize  = _dsp_size * (in_rate  / dsp_rate); | ||||
|     else | ||||
|         dsp_insize  = _dsp_size / (dsp_rate /  in_rate); | ||||
| 
 | ||||
|     if (out_rate >= dsp_rate) | ||||
|         dsp_outsize = _dsp_size * (out_rate / dsp_rate); | ||||
|     else | ||||
|         dsp_outsize = _dsp_size / (dsp_rate / out_rate); | ||||
| 
 | ||||
|     dsp_size = _dsp_size; | ||||
| 
 | ||||
|     // buffers
 | ||||
|     delete[]inbuff; | ||||
|     inbuff = new float[1 * dsp_insize  * 2]; | ||||
|     delete[] midbuff; | ||||
|     midbuff = new float[2 * dsp_size * 2]; | ||||
|     delete[] outbuff; | ||||
|     outbuff = new float[1 * dsp_outsize * 2]; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| } // namespace
 | ||||
| @ -42,6 +42,25 @@ public: | ||||
|     int dsp_insize;             // size (complex samples) of the input buffer
 | ||||
|     int dsp_outsize;            // size (complex samples) of the output buffer
 | ||||
|     int state;                  // 0 for unit OFF; 1 for unit ON
 | ||||
| 
 | ||||
|     Unit( | ||||
|         int _in_rate,                // input samplerate
 | ||||
|         int _out_rate,               // output samplerate
 | ||||
|         int _dsp_rate,               // sample rate for mainstream dsp processing
 | ||||
|         int _dsp_size                // number complex samples processed per buffer in mainstream dsp processing
 | ||||
|     ); | ||||
|     ~Unit(); | ||||
| 
 | ||||
|     void flushBuffers(); | ||||
|     void setBuffersInputSamplerate(int _in_rate); | ||||
|     void setBuffersOutputSamplerate(int _out_rate); | ||||
|     void setBuffersDSPSamplerate(int _dsp_rate); | ||||
|     void setBuffersDSPBuffsize(int _dsp_size); | ||||
| 
 | ||||
| protected: | ||||
|     float* inbuff; | ||||
|     float* midbuff; | ||||
|     float* outbuff; | ||||
| }; | ||||
| 
 | ||||
| } // namespace WDSP
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user