diff --git a/FMControl.cpp b/FMControl.cpp index 8cb7183..74943ac 100644 --- a/FMControl.cpp +++ b/FMControl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020,2021 by Jonathan Naylor G4KLX + * Copyright (C) 2020,2021,2024 by Jonathan Naylor G4KLX * * 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 @@ -48,13 +48,13 @@ m_filterStage3(NULL) assert(txAudioGain > 0.0F); assert(rxAudioGain > 0.0F); - m_preEmphasis = new CIIRDirectForm1Filter(8.315375384336983F, -7.03334621603483F,0.0F,1.0F, 0.282029168302153F,0.0F, PREEMPHASIS_GAIN_DB); - m_deEmphasis = new CIIRDirectForm1Filter(0.07708787090460224F, 0.07708787090460224F,0.0F, 1.0F, -0.8458242581907955F,0.0F, DEEMPHASIS_GAIN_DB); + m_preEmphasis = new CIIR(8.315375384336983F, -7.03334621603483F,0.0F, 1.0F, 0.282029168302153F, 0.0F, PREEMPHASIS_GAIN_DB); + m_deEmphasis = new CIIR(0.07708787090460224F, 0.07708787090460224F,0.0F, 1.0F, -0.8458242581907955F, 0.0F, DEEMPHASIS_GAIN_DB); // Chebyshev type 1 0.2dB cheby type 1 3rd order 300-2700Hz fs=8000 - m_filterStage1 = new CIIRDirectForm1Filter(0.29495028f, 0.0f, -0.29495028f, 1.0f, -0.61384624f, -0.057158668f, FILTER_GAIN_DB); - m_filterStage2 = new CIIRDirectForm1Filter(1.0f, 2.0f, 1.0f, 1.0f, 0.9946123f, 0.6050482f, FILTER_GAIN_DB); - m_filterStage3 = new CIIRDirectForm1Filter(1.0f, -2.0f, 1.0f, 1.0f, -1.8414584f, 0.8804949f, FILTER_GAIN_DB); + m_filterStage1 = new CIIR(0.29495028f, 0.0f, -0.29495028f, 1.0f, -0.61384624f, -0.057158668f, FILTER_GAIN_DB); + m_filterStage2 = new CIIR(1.0f, 2.0f, 1.0f, 1.0f, 0.9946123f, 0.6050482f, FILTER_GAIN_DB); + m_filterStage3 = new CIIR(1.0f, -2.0f, 1.0f, 1.0f, -1.8414584f, 0.8804949f, FILTER_GAIN_DB); } CFMControl::~CFMControl() diff --git a/FMControl.h b/FMControl.h index 9344f77..ea3d83d 100644 --- a/FMControl.h +++ b/FMControl.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020,2021 by Jonathan Naylor G4KLX + * Copyright (C) 2020,2021,2024 by Jonathan Naylor G4KLX * * 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 @@ -21,7 +21,7 @@ #include "FMNetwork.h" #include "Defines.h" -#include "IIRDirectForm1Filter.h" +#include "IIR.h" // Uncomment this to dump audio to a raw audio file // The file will be written in same folder as executable @@ -49,11 +49,11 @@ private: bool m_deEmphasisOn; bool m_enabled; CRingBuffer m_incomingRFAudio; - CIIRDirectForm1Filter* m_preEmphasis; - CIIRDirectForm1Filter* m_deEmphasis; - CIIRDirectForm1Filter* m_filterStage1; - CIIRDirectForm1Filter* m_filterStage2; - CIIRDirectForm1Filter* m_filterStage3; + CIIR* m_preEmphasis; + CIIR* m_deEmphasis; + CIIR* m_filterStage1; + CIIR* m_filterStage2; + CIIR* m_filterStage3; }; #endif diff --git a/IIRDirectForm1Filter.cpp b/IIR.cpp similarity index 57% rename from IIRDirectForm1Filter.cpp rename to IIR.cpp index 946acdd..ef46457 100644 --- a/IIRDirectForm1Filter.cpp +++ b/IIR.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2020 by Jonathan Naylor G4KLX + * Copyright (C) 2015-2020,2024 by Jonathan Naylor G4KLX * Copyright (C) 2020 by Geoffrey Merck - F4FXL KC3FRA * * This program is free software; you can redistribute it and/or modify @@ -17,10 +17,11 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "IIRDirectForm1Filter.h" -#include "math.h" +#include "IIR.h" -CIIRDirectForm1Filter::CIIRDirectForm1Filter(float b0, float b1, float b2, float , float a1, float a2, float addtionalGaindB) : +#include + +CIIR::CIIR(float b0, float b1, float b2, float , float a1, float a2, float addtionalGaindB) : m_x2(0.0F), m_y2(0.0F), m_x1(0.0F), @@ -32,29 +33,29 @@ m_a1(a1), m_a2(a2), m_additionalGainLin(0.0F) { - m_additionalGainLin = ::powf(10.0F, addtionalGaindB / 20.0F); + m_additionalGainLin = ::powf(10.0F, addtionalGaindB / 20.0F); } -float CIIRDirectForm1Filter::filter(float sample) +CIIR::~CIIR() { - float output = m_b0 * sample - + m_b1 * m_x1 - + m_b2 * m_x2 - - m_a1 * m_y1 - - m_a2 * m_y2; - - m_x2 = m_x1; - m_y2 = m_y1; - m_x1 = sample; - m_y1 = output; - - return output * m_additionalGainLin; } -void CIIRDirectForm1Filter::reset() +float CIIR::filter(float sample) { - m_x1 = 0.0f; - m_x2 = 0.0f; - m_y1 = 0.0f; - m_y2 = 0.0f; + float output = m_b0 * sample + m_b1 * m_x1 + m_b2 * m_x2 - m_a1 * m_y1 - m_a2 * m_y2; + + m_x2 = m_x1; + m_y2 = m_y1; + m_x1 = sample; + m_y1 = output; + + return output * m_additionalGainLin; +} + +void CIIR::reset() +{ + m_x1 = 0.0F; + m_x2 = 0.0F; + m_y1 = 0.0F; + m_y2 = 0.0F; } diff --git a/IIRDirectForm1Filter.h b/IIR.h similarity index 59% rename from IIRDirectForm1Filter.h rename to IIR.h index f575f7f..0e35577 100644 --- a/IIRDirectForm1Filter.h +++ b/IIR.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2020 by Jonathan Naylor G4KLX + * Copyright (C) 2015-2020,2024 by Jonathan Naylor G4KLX * Copyright (C) 2020 by Geoffrey Merck - F4FXL KC3FRA * * This program is free software; you can redistribute it and/or modify @@ -17,34 +17,33 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#if !defined(IIRDIRECTFORM1FILTER_H) -#define IIRDIRECTFORM1FILTER_H +#if !defined(IIR_H) +#define IIR_H -class CIIRDirectForm1Filter +class CIIR { public: - CIIRDirectForm1Filter(float b0, float b1, float b2, float, float a1, float a2, float additionalGaindB); - float filter(float sample); - void reset(); + CIIR(float b0, float b1, float b2, float, float a1, float a2, float additionalGaindB); + ~CIIR(); + + float filter(float sample); + + void reset(); private: -// delay line - float m_x2; // x[n-2] - float m_y2; // y[n-2] - float m_x1; // x[n-1] - float m_y1; // y[n-1] - - // coefficients - // FIR - float m_b0; - float m_b1; - float m_b2; - // IIR - float m_a1; - float m_a2; + // Delay line + float m_x2; // x[n-2] + float m_y2; // y[n-2] + float m_x1; // x[n-1] + float m_y1; // y[n-1] - float m_additionalGainLin; + // Coefficients + float m_b0; + float m_b1; + float m_b2; + float m_a1; + float m_a2; + float m_additionalGainLin; }; - -#endif \ No newline at end of file +#endif diff --git a/MMDVMHost.vcxproj b/MMDVMHost.vcxproj index 0b29f63..c83c2a6 100644 --- a/MMDVMHost.vcxproj +++ b/MMDVMHost.vcxproj @@ -204,7 +204,7 @@ - + @@ -315,7 +315,7 @@ - + diff --git a/MMDVMHost.vcxproj.filters b/MMDVMHost.vcxproj.filters index 3b74c31..71f0e8a 100644 --- a/MMDVMHost.vcxproj.filters +++ b/MMDVMHost.vcxproj.filters @@ -317,7 +317,7 @@ Header Files - + Header Files @@ -625,7 +625,7 @@ Source Files - + Source Files diff --git a/Version.h b/Version.h index 5478441..9823a94 100644 --- a/Version.h +++ b/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20240429"; +const char* VERSION = "20240430"; #endif