| 
									
										
										
										
											2024-06-16 11:31:13 +02:00
										 |  |  | /*  fmsq.h
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | This file is part of a program that implements a Software-Defined Radio. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Copyright (C) 2013, 2016 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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef wdsp_fmsq_h
 | 
					
						
							|  |  |  | #define wdsp_fmsq_h
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-28 11:36:45 +02:00
										 |  |  | #include <array>
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-16 11:31:13 +02:00
										 |  |  | #include "export.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace WDSP { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class FIRCORE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class WDSP_API FMSQ | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2024-08-03 11:05:12 +02:00
										 |  |  |     enum class FMSQState | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MUTED, | 
					
						
							|  |  |  |         INCREASE, | 
					
						
							|  |  |  |         UNMUTED, | 
					
						
							|  |  |  |         TAIL, | 
					
						
							|  |  |  |         DECREASE | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-16 11:31:13 +02:00
										 |  |  |     int run;                            // 0 if squelch system is OFF; 1 if it's ON
 | 
					
						
							|  |  |  |     int size;                           // size of input/output buffers
 | 
					
						
							| 
									
										
										
										
											2024-06-25 03:50:48 +02:00
										 |  |  |     float* insig;                      // squelch input signal buffer
 | 
					
						
							|  |  |  |     float* outsig;                     // squelch output signal buffer
 | 
					
						
							|  |  |  |     float* trigger;                    // buffer used to trigger mute/unmute (may be same as input; matches timing of input buffer)
 | 
					
						
							| 
									
										
										
										
											2024-07-06 03:25:41 +02:00
										 |  |  |     double rate;                        // sample rate
 | 
					
						
							| 
									
										
										
										
											2024-07-28 11:36:45 +02:00
										 |  |  |     std::vector<float> noise; | 
					
						
							| 
									
										
										
										
											2024-07-06 03:25:41 +02:00
										 |  |  |     double fc;                          // corner frequency for sig / noise detection
 | 
					
						
							|  |  |  |     double* pllpole;                    // pointer to pole frequency of the fm demodulator pll
 | 
					
						
							| 
									
										
										
										
											2024-07-28 11:36:45 +02:00
										 |  |  |     std::array<float, 4> F; | 
					
						
							|  |  |  |     std::array<float, 4> G; | 
					
						
							| 
									
										
										
										
											2024-07-06 03:25:41 +02:00
										 |  |  |     double avtau;                       // time constant for averaging noise
 | 
					
						
							|  |  |  |     double avm; | 
					
						
							|  |  |  |     double onem_avm; | 
					
						
							|  |  |  |     double avnoise; | 
					
						
							|  |  |  |     double longtau;                     // time constant for long averaging
 | 
					
						
							|  |  |  |     double longavm; | 
					
						
							|  |  |  |     double onem_longavm; | 
					
						
							|  |  |  |     double longnoise; | 
					
						
							| 
									
										
										
										
											2024-08-03 11:05:12 +02:00
										 |  |  |     FMSQState state;                          // state machine control
 | 
					
						
							| 
									
										
										
										
											2024-06-16 11:31:13 +02:00
										 |  |  |     int count; | 
					
						
							| 
									
										
										
										
											2024-07-06 03:25:41 +02:00
										 |  |  |     double tup; | 
					
						
							|  |  |  |     double tdown; | 
					
						
							| 
									
										
										
										
											2024-06-16 11:31:13 +02:00
										 |  |  |     int ntup; | 
					
						
							|  |  |  |     int ntdown; | 
					
						
							| 
									
										
										
										
											2024-07-28 11:36:45 +02:00
										 |  |  |     std::vector<double> cup; | 
					
						
							|  |  |  |     std::vector<double> cdown; | 
					
						
							| 
									
										
										
										
											2024-07-06 03:25:41 +02:00
										 |  |  |     double tail_thresh; | 
					
						
							|  |  |  |     double unmute_thresh; | 
					
						
							|  |  |  |     double min_tail; | 
					
						
							|  |  |  |     double max_tail; | 
					
						
							| 
									
										
										
										
											2024-06-16 11:31:13 +02:00
										 |  |  |     int ready; | 
					
						
							| 
									
										
										
										
											2024-07-06 03:25:41 +02:00
										 |  |  |     double ramp; | 
					
						
							|  |  |  |     double rstep; | 
					
						
							|  |  |  |     double tdelay; | 
					
						
							| 
									
										
										
										
											2024-06-16 11:31:13 +02:00
										 |  |  |     int nc; | 
					
						
							|  |  |  |     int mp; | 
					
						
							|  |  |  |     FIRCORE *p; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-26 19:10:53 +02:00
										 |  |  |     FMSQ( | 
					
						
							|  |  |  |         int _run, | 
					
						
							|  |  |  |         int _size, | 
					
						
							|  |  |  |         float* _insig, | 
					
						
							|  |  |  |         float* _outsig, | 
					
						
							|  |  |  |         float* _trigger, | 
					
						
							|  |  |  |         int _rate, | 
					
						
							|  |  |  |         double _fc, | 
					
						
							|  |  |  |         double* _pllpole, | 
					
						
							|  |  |  |         double _tdelay, | 
					
						
							|  |  |  |         double _avtau, | 
					
						
							|  |  |  |         double _longtau, | 
					
						
							|  |  |  |         double _tup, | 
					
						
							|  |  |  |         double _tdown, | 
					
						
							|  |  |  |         double _tail_thresh, | 
					
						
							|  |  |  |         double _unmute_thresh, | 
					
						
							|  |  |  |         double _min_tail, | 
					
						
							|  |  |  |         double _max_tail, | 
					
						
							|  |  |  |         int _nc, | 
					
						
							|  |  |  |         int _mp | 
					
						
							| 
									
										
										
										
											2024-06-16 11:31:13 +02:00
										 |  |  |     ); | 
					
						
							| 
									
										
										
										
											2024-07-28 11:36:45 +02:00
										 |  |  |     FMSQ(const FMSQ&) = delete; | 
					
						
							| 
									
										
										
										
											2024-07-29 08:57:02 +02:00
										 |  |  |     FMSQ& operator=(const FMSQ& other) = delete; | 
					
						
							| 
									
										
										
										
											2024-07-26 19:10:53 +02:00
										 |  |  |     ~FMSQ(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void flush(); | 
					
						
							|  |  |  |     void execute(); | 
					
						
							|  |  |  |     void setBuffers(float* in, float* out, float* trig); | 
					
						
							|  |  |  |     void setSamplerate(int rate); | 
					
						
							|  |  |  |     void setSize(int size); | 
					
						
							|  |  |  |     // Public Properties
 | 
					
						
							|  |  |  |     void setRun(int run); | 
					
						
							|  |  |  |     void setThreshold(double threshold); | 
					
						
							|  |  |  |     void setNC(int nc); | 
					
						
							|  |  |  |     void setMP(int mp); | 
					
						
							| 
									
										
										
										
											2024-06-16 11:31:13 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2024-07-26 19:10:53 +02:00
										 |  |  |     void calc(); | 
					
						
							|  |  |  |     void decalc(); | 
					
						
							| 
									
										
										
										
											2024-06-16 11:31:13 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace WDSP
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 |