diff options
author | Jan Holthuis <jan.holthuis@ruhr-uni-bochum.de> | 2020-11-24 17:30:21 +0100 |
---|---|---|
committer | Jan Holthuis <jan.holthuis@ruhr-uni-bochum.de> | 2020-11-24 18:11:12 +0100 |
commit | 03c54adb9a59c199b5998ca6cac6a431f01a69ee (patch) | |
tree | fe0910ab256bdb582171b0fd62247eb0f91406ad | |
parent | f543b52eb56e2fea11b73a00ad3e911f14e98817 (diff) |
engine/filters: Fix potential out-of-bounds read in setCoefs{2}
To prevent this, the methods now take additional buffer size arguments.
Fixes these MSVC warnings:
src\engine/filters/enginefilteriir.h(99): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt\string.h(130): note: see declaration of 'strcpy'
src\engine/filters/enginefilteriir.h(94): note: while compiling class template member function 'void EngineFilterIIR<4,IIR_HP>::setCoefs(const char *,double,double,double,int)'
src\engine\filters\enginefilterbessel4.cpp(80): note: see reference to function template instantiation 'void EngineFilterIIR<4,IIR_HP>::setCoefs(const char *,double,double,double,int)' being compiled
src\engine/filters/enginefilteriir.h(383): note: see reference to class template instantiation 'EngineFilterIIR<4,IIR_HP>' being compiled
-rw-r--r-- | src/engine/filters/enginefilterbessel4.cpp | 17 | ||||
-rw-r--r-- | src/engine/filters/enginefilterbessel8.cpp | 17 | ||||
-rw-r--r-- | src/engine/filters/enginefilterbiquad1.cpp | 12 | ||||
-rw-r--r-- | src/engine/filters/enginefilterbutterworth4.cpp | 21 | ||||
-rw-r--r-- | src/engine/filters/enginefilterbutterworth8.cpp | 22 | ||||
-rw-r--r-- | src/engine/filters/enginefilteriir.h | 208 | ||||
-rw-r--r-- | src/engine/filters/enginefilterlinkwitzriley2.cpp | 34 | ||||
-rw-r--r-- | src/engine/filters/enginefilterlinkwitzriley4.cpp | 34 | ||||
-rw-r--r-- | src/engine/filters/enginefilterlinkwitzriley8.cpp | 34 |
9 files changed, 271 insertions, 128 deletions
diff --git a/src/engine/filters/enginefilterbessel4.cpp b/src/engine/filters/enginefilterbessel4.cpp index 65054c078c..a47c9a46c3 100644 --- a/src/engine/filters/enginefilterbessel4.cpp +++ b/src/engine/filters/enginefilterbessel4.cpp @@ -1,6 +1,11 @@ #include "engine/filters/enginefilterbessel4.h" #include "util/math.h" +namespace { +constexpr char kFidSpecLowPassBessel4[] = "LpBe4"; +constexpr char kFidSpecBandPassBessel4[] = "BpBe4"; +constexpr char kFidSpecHighPassBessel4[] = "HpBe4"; +} // namespace EngineFilterBessel4Low::EngineFilterBessel4Low(int sampleRate, double freqCorner1) { @@ -10,7 +15,7 @@ EngineFilterBessel4Low::EngineFilterBessel4Low(int sampleRate, void EngineFilterBessel4Low::setFrequencyCorners(int sampleRate, double freqCorner1) { // Copy the old coefficients into m_oldCoef - setCoefs("LpBe4", sampleRate, freqCorner1); + setCoefs(kFidSpecLowPassBessel4, sizeof(kFidSpecLowPassBessel4), sampleRate, freqCorner1); } int EngineFilterBessel4Low::setFrequencyCornersForIntDelay( @@ -53,7 +58,7 @@ int EngineFilterBessel4Low::setFrequencyCornersForIntDelay( quantizedRatio = delayRatioTable[iDelay]; } - setCoefs("LpBe4", 1, quantizedRatio); + setCoefs(kFidSpecLowPassBessel4, sizeof(kFidSpecLowPassBessel4), 1, quantizedRatio); return iDelay; } @@ -66,7 +71,11 @@ EngineFilterBessel4Band::EngineFilterBessel4Band(int sampleRate, void EngineFilterBessel4Band::setFrequencyCorners(int sampleRate, double freqCorner1, double freqCorner2) { - setCoefs("BpBe4", sampleRate, freqCorner1, freqCorner2); + setCoefs(kFidSpecBandPassBessel4, + sizeof(kFidSpecBandPassBessel4), + sampleRate, + freqCorner1, + freqCorner2); } @@ -77,5 +86,5 @@ EngineFilterBessel4High::EngineFilterBessel4High(int sampleRate, void EngineFilterBessel4High::setFrequencyCorners(int sampleRate, double freqCorner1) { - setCoefs("HpBe4", sampleRate, freqCorner1); + setCoefs(kFidSpecHighPassBessel4, sizeof(kFidSpecHighPassBessel4), sampleRate, freqCorner1); } diff --git a/src/engine/filters/enginefilterbessel8.cpp b/src/engine/filters/enginefilterbessel8.cpp index b4f1248c76..fa97b01fc7 100644 --- a/src/engine/filters/enginefilterbessel8.cpp +++ b/src/engine/filters/enginefilterbessel8.cpp @@ -1,6 +1,11 @@ #include "engine/filters/enginefilterbessel8.h" #include "util/math.h" +namespace { +constexpr char kFidSpecLowPassBessel8[] = "LpBe8"; +constexpr char kFidSpecBandPassBessel8[] = "BpBe8"; +constexpr char kFidSpecHighPassBessel8[] = "HpBe8"; +} // namespace EngineFilterBessel8Low::EngineFilterBessel8Low(int sampleRate, double freqCorner1) { @@ -10,7 +15,7 @@ EngineFilterBessel8Low::EngineFilterBessel8Low(int sampleRate, void EngineFilterBessel8Low::setFrequencyCorners(int sampleRate, double freqCorner1) { // Copy the old coefficients into m_oldCoef - setCoefs("LpBe8", sampleRate, freqCorner1); + setCoefs(kFidSpecLowPassBessel8, sizeof(kFidSpecLowPassBessel8), sampleRate, freqCorner1); } @@ -61,7 +66,7 @@ int EngineFilterBessel8Low::setFrequencyCornersForIntDelay( quantizedRatio = delayRatioTable[iDelay]; } - setCoefs("LpBe8", 1, quantizedRatio); + setCoefs(kFidSpecLowPassBessel8, sizeof(kFidSpecLowPassBessel8), 1, quantizedRatio); return iDelay; } @@ -74,7 +79,11 @@ EngineFilterBessel8Band::EngineFilterBessel8Band(int sampleRate, void EngineFilterBessel8Band::setFrequencyCorners(int sampleRate, double freqCorner1, double freqCorner2) { - setCoefs("BpBe8", sampleRate, freqCorner1, freqCorner2); + setCoefs(kFidSpecBandPassBessel8, + sizeof(kFidSpecBandPassBessel8), + sampleRate, + freqCorner1, + freqCorner2); } @@ -85,5 +94,5 @@ EngineFilterBessel8High::EngineFilterBessel8High(int sampleRate, void EngineFilterBessel8High::setFrequencyCorners(int sampleRate, double freqCorner1) { - setCoefs("HpBe8", sampleRate, freqCorner1); + setCoefs(kFidSpecHighPassBessel8, sizeof(kFidSpecHighPassBessel8), sampleRate, freqCorner1); } diff --git a/src/engine/filters/enginefilterbiquad1.cpp b/src/engine/filters/enginefilterbiquad1.cpp index 1bf853462b..ee9572befb 100644 --- a/src/engine/filters/enginefilterbiquad1.cpp +++ b/src/engine/filters/enginefilterbiquad1.cpp @@ -13,7 +13,7 @@ void EngineFilterBiquad1LowShelving::setFrequencyCorners(int sampleRate, double Q, double dBgain) { format_fidspec(m_spec, sizeof(m_spec), "LsBq/%.10f/%.10f", Q, dBgain); - setCoefs(m_spec, sampleRate, centerFreq); + setCoefs(m_spec, sizeof(m_spec), sampleRate, centerFreq); } EngineFilterBiquad1Peaking::EngineFilterBiquad1Peaking(int sampleRate, @@ -27,7 +27,7 @@ void EngineFilterBiquad1Peaking::setFrequencyCorners(int sampleRate, double Q, double dBgain) { format_fidspec(m_spec, sizeof(m_spec), "PkBq/%.10f/%.10f", Q, dBgain); - setCoefs(m_spec, sampleRate, centerFreq); + setCoefs(m_spec, sizeof(m_spec), sampleRate, centerFreq); } EngineFilterBiquad1HighShelving::EngineFilterBiquad1HighShelving(int sampleRate, @@ -42,7 +42,7 @@ void EngineFilterBiquad1HighShelving::setFrequencyCorners(int sampleRate, double Q, double dBgain) { format_fidspec(m_spec, sizeof(m_spec), "HsBq/%.10f/%.10f", Q, dBgain); - setCoefs(m_spec, sampleRate, centerFreq); + setCoefs(m_spec, sizeof(m_spec), sampleRate, centerFreq); } EngineFilterBiquad1Low::EngineFilterBiquad1Low(int sampleRate, @@ -57,7 +57,7 @@ void EngineFilterBiquad1Low::setFrequencyCorners(int sampleRate, double centerFreq, double Q) { format_fidspec(m_spec, sizeof(m_spec), "LpBq/%.10f", Q); - setCoefs(m_spec, sampleRate, centerFreq); + setCoefs(m_spec, sizeof(m_spec), sampleRate, centerFreq); } EngineFilterBiquad1Band::EngineFilterBiquad1Band(int sampleRate, @@ -70,7 +70,7 @@ void EngineFilterBiquad1Band::setFrequencyCorners(int sampleRate, double centerFreq, double Q) { format_fidspec(m_spec, sizeof(m_spec), "BpBq/%.10f", Q); - setCoefs(m_spec, sampleRate, centerFreq); + setCoefs(m_spec, sizeof(m_spec), sampleRate, centerFreq); } EngineFilterBiquad1High::EngineFilterBiquad1High(int sampleRate, @@ -85,5 +85,5 @@ void EngineFilterBiquad1High::setFrequencyCorners(int sampleRate, double centerFreq, double Q) { format_fidspec(m_spec, sizeof(m_spec), "HpBq/%.10f", Q); - setCoefs(m_spec, sampleRate, centerFreq); + setCoefs(m_spec, sizeof(m_spec), sampleRate, centerFreq); } diff --git a/src/engine/filters/enginefilterbutterworth4.cpp b/src/engine/filters/enginefilterbutterworth4.cpp index 9fa4bb1d53..6abe565b19 100644 --- a/src/engine/filters/enginefilterbutterworth4.cpp +++ b/src/engine/filters/enginefilterbutterworth4.cpp @@ -1,5 +1,10 @@ #include "engine/filters/enginefilterbutterworth4.h" +namespace { +constexpr char kFidSpecLowPassButterworth4[] = "LpBu4"; +constexpr char kFidSpecBandPassButterworth4[] = "BpBu4"; +constexpr char kFidSpecHighPassButterworth4[] = "HpBu4"; +} // namespace EngineFilterButterworth4Low::EngineFilterButterworth4Low(int sampleRate, double freqCorner1) { setFrequencyCorners(sampleRate, freqCorner1); @@ -8,7 +13,10 @@ EngineFilterButterworth4Low::EngineFilterButterworth4Low(int sampleRate, double void EngineFilterButterworth4Low::setFrequencyCorners(int sampleRate, double freqCorner1) { // Copy the old coefficients into m_oldCoef - setCoefs("LpBu4", sampleRate, freqCorner1); + setCoefs(kFidSpecLowPassButterworth4, + sizeof(kFidSpecLowPassButterworth4), + sampleRate, + freqCorner1); } @@ -20,7 +28,11 @@ EngineFilterButterworth4Band::EngineFilterButterworth4Band(int sampleRate, doubl void EngineFilterButterworth4Band::setFrequencyCorners(int sampleRate, double freqCorner1, double freqCorner2) { - setCoefs("BpBu4", sampleRate, freqCorner1, freqCorner2); + setCoefs(kFidSpecBandPassButterworth4, + sizeof(kFidSpecBandPassButterworth4), + sampleRate, + freqCorner1, + freqCorner2); } @@ -30,5 +42,8 @@ EngineFilterButterworth4High::EngineFilterButterworth4High(int sampleRate, doubl void EngineFilterButterworth4High::setFrequencyCorners(int sampleRate, double freqCorner1) { - setCoefs("HpBu4", sampleRate, freqCorner1); + setCoefs(kFidSpecHighPassButterworth4, + sizeof(kFidSpecHighPassButterworth4), + sampleRate, + freqCorner1); } diff --git a/src/engine/filters/enginefilterbutterworth8.cpp b/src/engine/filters/enginefilterbutterworth8.cpp index 67c1b20acc..ea5a134b4a 100644 --- a/src/engine/filters/enginefilterbutterworth8.cpp +++ b/src/engine/filters/enginefilterbutterworth8.cpp @@ -1,5 +1,11 @@ #include "engine/filters/enginefilterbutterworth8.h" +namespace { +constexpr char kFidSpecLowPassButterworth8[] = "LpBu8"; +constexpr char kFidSpecBandPassButterworth8[] = "BpBu8"; +constexpr char kFidSpecHighPassButterworth8[] = "HpBu8"; +} // namespace + EngineFilterButterworth8Low::EngineFilterButterworth8Low(int sampleRate, double freqCorner1) { setFrequencyCorners(sampleRate, freqCorner1); } @@ -7,7 +13,10 @@ EngineFilterButterworth8Low::EngineFilterButterworth8Low(int sampleRate, double void EngineFilterButterworth8Low::setFrequencyCorners(int sampleRate, double freqCorner1) { // Copy the old coefficients into m_oldCoef - setCoefs("LpBu8", sampleRate, freqCorner1); + setCoefs(kFidSpecLowPassButterworth8, + sizeof(kFidSpecLowPassButterworth8), + sampleRate, + freqCorner1); } @@ -19,7 +28,11 @@ EngineFilterButterworth8Band::EngineFilterButterworth8Band(int sampleRate, doubl void EngineFilterButterworth8Band::setFrequencyCorners(int sampleRate, double freqCorner1, double freqCorner2) { - setCoefs("BpBu8", sampleRate, freqCorner1, freqCorner2); + setCoefs(kFidSpecBandPassButterworth8, + sizeof(kFidSpecBandPassButterworth8), + sampleRate, + freqCorner1, + freqCorner2); } EngineFilterButterworth8High::EngineFilterButterworth8High(int sampleRate, double freqCorner1) { @@ -28,5 +41,8 @@ EngineFilterButterworth8High::EngineFilterButterworth8High(int sampleRate, doubl void EngineFilterButterworth8High::setFrequencyCorners(int sampleRate, double freqCorner1) { - setCoefs("HpBu8", sampleRate, freqCorner1); + setCoefs(kFidSpecHighPassButterworth8, + sizeof(kFidSpecHighPassButterworth8), + sampleRate, + freqCorner1); } diff --git a/src/engine/filters/enginefilteriir.h b/src/engine/filters/enginefilteriir.h index edef46108a..d30689f0a0 100644 --- a/src/engine/filters/enginefilteriir.h +++ b/src/engine/filters/enginefilteriir.h @@ -1,8 +1,10 @@ #ifndef ENGINEFILTERIIR_H #define ENGINEFILTERIIR_H -#define MIXXX #include <cstdio> +#include <cstring> + +#define MIXXX #include <fidlib.h> #include "engine/engineobject.h" @@ -90,110 +92,136 @@ class EngineFilterIIR : public EngineFilterIIRBase { m_doRamping = true; } - void setCoefs(const char* spec, double sampleRate, - double freq0, double freq1 = 0, int adj = 0) { - + void setCoefs(const char* spec, + size_t bufsize, + double sampleRate, + double freq0, + double freq1 = 0, + int adj = 0) { char spec_d[FIDSPEC_LENGTH]; - if (strlen(spec) < sizeof(spec_d)) { - // Copy to dynamic-ish memory to prevent fidlib API breakage. - strcpy(spec_d, spec); + VERIFY_OR_DEBUG_ASSERT(bufsize <= sizeof(spec_d)) { + return; + } + // Copy to dynamic-ish memory to prevent fidlib API breakage. + std::strncpy(spec_d, spec, bufsize); - // Copy the old coefficients into m_oldCoef - memcpy(m_oldCoef, m_coef, sizeof(m_coef)); + // Copy the old coefficients into m_oldCoef + memcpy(m_oldCoef, m_coef, sizeof(m_coef)); - m_coef[0] = fid_design_coef(m_coef + 1, SIZE, - spec_d, sampleRate, freq0, freq1, adj); + m_coef[0] = fid_design_coef(m_coef + 1, SIZE, spec_d, sampleRate, freq0, freq1, adj); - initBuffers(); + initBuffers(); #if(IIR_ANALYSIS) - char* desc; - FidFilter* filt = fid_design(spec_d, sampleRate, freq0, freq1, adj, &desc); - int delay = fid_calc_delay(filt); - qDebug() << QString().fromLatin1(desc) << "delay:" << delay; - double resp0, phase0; - resp0 = fid_response_pha(filt, freq0 / sampleRate, &phase0); - qDebug() << "freq0:" << freq0 << resp0 << phase0; - if (freq1) { - double resp1, phase1; - resp1 = fid_response_pha(filt, freq1 / sampleRate, &phase1); - qDebug() << "freq1:" << freq1 << resp1 << phase1; - } - double resp2, phase2; - resp2 = fid_response_pha(filt, freq0 / sampleRate / 2, &phase2); - qDebug() << "freq2:" << freq0 / 2 << resp2 << phase0; - double resp3, phase3; - resp3 = fid_response_pha(filt, freq0 / sampleRate * 2, &phase3); - qDebug() << "freq3:" << freq0 * 2 << resp3 << phase0; - double resp4, phase4; - resp4 = fid_response_pha(filt, freq0 / sampleRate / 2.2, &phase4); - qDebug() << "freq4:" << freq0 / 2.2 << resp2 << phase0; - double resp5, phase5; - resp5 = fid_response_pha(filt, freq0 / sampleRate * 2.2, &phase5); - qDebug() << "freq5:" << freq0 * 2.2 << resp3 << phase0; - free(filt); -#endif + char* desc; + FidFilter* filt = fid_design(spec_d, sampleRate, freq0, freq1, adj, &desc); + int delay = fid_calc_delay(filt); + qDebug() << QString().fromLatin1(desc) << "delay:" << delay; + double resp0, phase0; + resp0 = fid_response_pha(filt, freq0 / sampleRate, &phase0); + qDebug() << "freq0:" << freq0 << resp0 << phase0; + if (freq1) { + double resp1, phase1; + resp1 = fid_response_pha(filt, freq1 / sampleRate, &phase1); + qDebug() << "freq1:" << freq1 << resp1 << phase1; } + double resp2, phase2; + resp2 = fid_response_pha(filt, freq0 / sampleRate / 2, &phase2); + qDebug() << "freq2:" << freq0 / 2 << resp2 << phase0; + double resp3, phase3; + resp3 = fid_response_pha(filt, freq0 / sampleRate * 2, &phase3); + qDebug() << "freq3:" << freq0 * 2 << resp3 << phase0; + double resp4, phase4; + resp4 = fid_response_pha(filt, freq0 / sampleRate / 2.2, &phase4); + qDebug() << "freq4:" << freq0 / 2.2 << resp2 << phase0; + double resp5, phase5; + resp5 = fid_response_pha(filt, freq0 / sampleRate * 2.2, &phase5); + qDebug() << "freq5:" << freq0 * 2.2 << resp3 << phase0; + free(filt); +#endif } - void setCoefs2(double sampleRate, int n_coef1, - const char* spec1, double freq01, double freq11, int adj1, - const char* spec2, double freq02, double freq12, int adj2) { + void setCoefs2(double sampleRate, + int n_coef1, + const char* spec1, + size_t spec1size, + double freq01, + double freq11, + int adj1, + const char* spec2, + size_t spec2size, + double freq02, + double freq12, + int adj2) { char spec1_d[FIDSPEC_LENGTH]; char spec2_d[FIDSPEC_LENGTH]; - if (strlen(spec1) < sizeof(spec1_d) && - strlen(spec2) < sizeof(spec2_d)) { - // Copy to dynamic-ish memory to prevent fidlib API breakage. - strcpy(spec1_d, spec1); - strcpy(spec2_d, spec2); - - // Copy the old coefficients into m_oldCoef - memcpy(m_oldCoef, m_coef, sizeof(m_coef)); - m_coef[0] = fid_design_coef(m_coef + 1, n_coef1, - spec1, sampleRate, freq01, freq11, adj1) * - fid_design_coef(m_coef + 1 + n_coef1, SIZE - n_coef1, - spec2, sampleRate, freq02, freq12, adj2); + VERIFY_OR_DEBUG_ASSERT(spec1size <= sizeof(spec1_d) && spec2size <= sizeof(spec2_d)) { + return; + } - initBuffers(); + // Copy to dynamic-ish memory to prevent fidlib API breakage. + std::strncpy(spec1_d, spec1, spec1size); + std::strncpy(spec2_d, spec2, spec2size); + spec1_d[FIDSPEC_LENGTH - 1] = '\0'; + spec2_d[FIDSPEC_LENGTH - 1] = '\0'; + + // Copy the old coefficients into m_oldCoef + memcpy(m_oldCoef, m_coef, sizeof(m_coef)); + m_coef[0] = fid_design_coef(m_coef + 1, + n_coef1, + spec1, + sampleRate, + freq01, + freq11, + adj1) * + fid_design_coef(m_coef + 1 + n_coef1, + SIZE - n_coef1, + spec2, + sampleRate, + freq02, + freq12, + adj2); + + initBuffers(); #if(IIR_ANALYSIS) - char* desc1; - char* desc2; - FidFilter* filt1 = fid_design(spec1, sampleRate, freq01, freq11, adj1, &desc1); - FidFilter* filt2 = fid_design(spec2, sampleRate, freq02, freq12, adj2, &desc2); - FidFilter* filt = fid_cat(1, filt1, filt2, NULL); - int delay = fid_calc_delay(filt); - qDebug() << QString().fromLatin1(desc1) << "X" << QString().fromLatin1(desc2) << "delay:" << delay; - double resp0, phase0; - resp0 = fid_response_pha(filt, freq01 / sampleRate, &phase0); - qDebug() << "freq01:" << freq01 << resp0 << phase0; - resp0 = fid_response_pha(filt, freq01 / sampleRate, &phase0); - qDebug() << "freq02:" << freq02 << resp0 << phase0; - if (freq11) { - double resp1, phase1; - resp1 = fid_response_pha(filt, freq11 / sampleRate, &phase1); - qDebug() << "freq1:" << freq11 << resp1 << phase1; - } - if (freq12) { - double resp1, phase1; - resp1 = fid_response_pha(filt, freq12 / sampleRate, &phase1); - qDebug() << "freq1:" << freq12 << resp1 << phase1; - } - double resp2, phase2; - resp2 = fid_response_pha(filt, freq01 / sampleRate / 2, &phase2); - qDebug() << "freq2:" << freq01 / 2 << resp2 << phase0; - double resp3, phase3; - resp3 = fid_response_pha(filt, freq01 / sampleRate * 2, &phase3); - qDebug() << "freq3:" << freq01 * 2 << resp3 << phase0; - double resp4, phase4; - resp4 = fid_response_pha(filt, freq01 / sampleRate / 2.2, &phase4); - qDebug() << "freq4:" << freq01 / 2.2 << resp2 << phase0; - double resp5, phase5; - resp5 = fid_response_pha(filt, freq01 / sampleRate * 2.2, &phase5); - qDebug() << "freq5:" << freq01 * 2.2 << resp3 << phase0; - free(filt); -#endif + char* desc1; + char* desc2; + FidFilter* filt1 = fid_design(spec1, sampleRate, freq01, freq11, adj1, &desc1); + FidFilter* filt2 = fid_design(spec2, sampleRate, freq02, freq12, adj2, &desc2); + FidFilter* filt = fid_cat(1, filt1, filt2, NULL); + int delay = fid_calc_delay(filt); + qDebug() << QString().fromLatin1(desc1) << "X" + << QString().fromLatin1(desc2) << "delay:" << delay; + double resp0, phase0; + resp0 = fid_response_pha(filt, freq01 / sampleRate, &phase0); + qDebug() << "freq01:" << freq01 << resp0 << phase0; + resp0 = fid_response_pha(filt, freq01 / sampleRate, &phase0); + qDebug() << "freq02:" << freq02 << resp0 << phase0; + if (freq11) { + double resp1, phase1; + resp1 = fid_response_pha(filt, freq11 / sampleRate, &phase1); + qDebug() << "freq1:" << freq11 << resp1 << phase1; + } + if (freq12) { + double resp1, phase1; + resp1 = fid_response_pha(filt, freq12 / sampleRate, &phase1); + qDebug() << "freq1:" << freq12 << resp1 << phase1; } + double resp2, phase2; + resp2 = fid_response_pha(filt, freq01 / sampleRate / 2, &phase2); + qDebug() << "freq2:" << freq01 / 2 << resp2 << phase0; + double resp3, phase3; + resp3 = fid_response_pha(filt, freq01 / sampleRate * 2, &phase3); + qDebug() << "freq3:" << freq01 * 2 << resp3 << phase0; + double resp4, phase4; + resp4 = fid_response_pha(filt, freq01 / sampleRate / 2.2, &phase4); + qDebug() << "freq4:" << freq01 / 2.2 << resp2 << phase0; + double resp5, phase5; + resp5 = fid_response_pha(filt, freq01 / sampleRate * 2.2, &phase5); + qDebug() << "freq5:" << freq01 * 2.2 << resp3 << phase0; + free(filt); +#endif } virtual void assumeSettled() { diff --git a/src/engine/filters/enginefilterlinkwitzriley2.cpp b/src/engine/filters/enginefilterlinkwitzriley2.cpp index 2febe164f2..44527f454b 100644 --- a/src/engine/filters/enginefilterlinkwitzriley2.cpp +++ b/src/engine/filters/enginefilterlinkwitzriley2.cpp @@ -1,5 +1,9 @@ #include "engine/filters/enginefilterlinkwitzriley2.h" +namespace { +constexpr char kFidSpecLowPassButterworth1[] = "LpBu1"; +constexpr char kFidSpecHighPassButterworth1[] = "HpBu1"; +} // namespace EngineFilterLinkwitzRiley2Low::EngineFilterLinkwitzRiley2Low(int sampleRate, double freqCorner1) { setFrequencyCorners(sampleRate, freqCorner1); @@ -8,9 +12,18 @@ EngineFilterLinkwitzRiley2Low::EngineFilterLinkwitzRiley2Low(int sampleRate, dou void EngineFilterLinkwitzRiley2Low::setFrequencyCorners(int sampleRate, double freqCorner1) { // Copy the old coefficients into m_oldCoef - setCoefs2(sampleRate, 1, - "LpBu1", freqCorner1, 0, 0, - "LpBu1", freqCorner1, 0, 0); + setCoefs2(sampleRate, + 1, + kFidSpecLowPassButterworth1, + sizeof(kFidSpecLowPassButterworth1), + freqCorner1, + 0, + 0, + kFidSpecLowPassButterworth1, + sizeof(kFidSpecLowPassButterworth1), + freqCorner1, + 0, + 0); } EngineFilterLinkwitzRiley2High::EngineFilterLinkwitzRiley2High(int sampleRate, double freqCorner1) { @@ -19,7 +32,16 @@ EngineFilterLinkwitzRiley2High::EngineFilterLinkwitzRiley2High(int sampleRate, d void EngineFilterLinkwitzRiley2High::setFrequencyCorners(int sampleRate, double freqCorner1) { - setCoefs2(sampleRate, 1, - "HpBu1", freqCorner1, 0, 0, - "HpBu1", freqCorner1, 0, 0); + setCoefs2(sampleRate, + 1, + kFidSpecHighPassButterworth1, + sizeof(kFidSpecHighPassButterworth1), + freqCorner1, + 0, + 0, + kFidSpecHighPassButterworth1, + sizeof(kFidSpecHighPassButterworth1), + freqCorner1, + 0, + 0); } diff --git a/src/engine/filters/enginefilterlinkwitzriley4.cpp b/src/engine/filters/enginefilterlinkwitzriley4.cpp index de1e8fe7ea..378314c1b7 100644 --- a/src/engine/filters/enginefilterlinkwitzriley4.cpp +++ b/src/engine/filters/enginefilterlinkwitzriley4.cpp @@ -1,5 +1,9 @@ #include "engine/filters/enginefilterlinkwitzriley4.h" +namespace { +constexpr char kFidSpecLowPassButterworth2[] = "LpBu2"; +constexpr char kFidSpecHighPassButterworth2[] = "HpBu2"; +} // namespace EngineFilterLinkwitzRiley4Low::EngineFilterLinkwitzRiley4Low(int sampleRate, double freqCorner1) { setFrequencyCorners(sampleRate, freqCorner1); @@ -8,9 +12,18 @@ EngineFilterLinkwitzRiley4Low::EngineFilterLinkwitzRiley4Low(int sampleRate, dou void EngineFilterLinkwitzRiley4Low::setFrequencyCorners(int sampleRate, double freqCorner1) { // Copy the old coefficients into m_oldCoef - setCoefs2(sampleRate, 2, - "LpBu2", freqCorner1, 0, 0, - "LpBu2", freqCorner1, 0, 0); + setCoefs2(sampleRate, + 2, + kFidSpecLowPassButterworth2, + sizeof(kFidSpecLowPassButterworth2), + freqCorner1, + 0, + 0, + kFidSpecLowPassButterworth2, + sizeof(kFidSpecLowPassButterworth2), + freqCorner1, + 0, + 0); } EngineFilterLinkwitzRiley4High::EngineFilterLinkwitzRiley4High(int sampleRate, double freqCorner1) { @@ -19,7 +32,16 @@ EngineFilterLinkwitzRiley4High::EngineFilterLinkwitzRiley4High(int sampleRate, d void EngineFilterLinkwitzRiley4High::setFrequencyCorners(int sampleRate, double freqCorner1) { - setCoefs2(sampleRate, 2, - "HpBu2", freqCorner1, 0, 0, - "HpBu2", freqCorner1, 0, 0); + setCoefs2(sampleRate, + 2, + kFidSpecHighPassButterworth2, + sizeof(kFidSpecHighPassButterworth2), + freqCorner1, + 0, + 0, + kFidSpecHighPassButterworth2, + sizeof(kFidSpecHighPassButterworth2), + freqCorner1, + 0, + 0); } diff --git a/src/engine/filters/enginefilterlinkwitzriley8.cpp b/src/engine/filters/enginefilterlinkwitzriley8.cpp index e66abf22a0..775460590f 100644 --- a/src/engine/filters/enginefilterlinkwitzriley8.cpp +++ b/src/engine/filters/enginefilterlinkwitzriley8.cpp @@ -1,5 +1,9 @@ #include "engine/filters/enginefilterlinkwitzriley8.h" +namespace { +constexpr char kFidSpecLowPassButterworth4[] = "LpBu4"; +constexpr char kFidSpecHighPassButterworth4[] = "HpBu4"; +} // namespace EngineFilterLinkwitzRiley8Low::EngineFilterLinkwitzRiley8Low(int sampleRate, double freqCorner1) { setFrequencyCorners(sampleRate, freqCorner1); @@ -8,9 +12,18 @@ EngineFilterLinkwitzRiley8Low::EngineFilterLinkwitzRiley8Low(int sampleRate, dou void EngineFilterLinkwitzRiley8Low::setFrequencyCorners(int sampleRate, double freqCorner1) { // Copy the old coefficients into m_oldCoef - setCoefs2(sampleRate, 4, - "LpBu4", freqCorner1, 0, 0, - "LpBu4", freqCorner1, 0, 0); + setCoefs2(sampleRate, + 4, + kFidSpecLowPassButterworth4, + sizeof(kFidSpecLowPassButterworth4), + freqCorner1, + 0, + 0, + kFidSpecLowPassButterworth4, + sizeof(kFidSpecLowPassButterworth4), + freqCorner1, + 0, + 0); } EngineFilterLinkwitzRiley8High::EngineFilterLinkwitzRiley8High(int sampleRate, double freqCorner1) { @@ -19,7 +32,16 @@ EngineFilterLinkwitzRiley8High::EngineFilterLinkwitzRiley8High(int sampleRate, d void EngineFilterLinkwitzRiley8High::setFrequencyCorners(int sampleRate, double freqCorner1) { - setCoefs2(sampleRate, 4, - "HpBu4", freqCorner1, 0, 0, - "HpBu4", freqCorner1, 0, 0); + setCoefs2(sampleRate, + 4, + kFidSpecHighPassButterworth4, + sizeof(kFidSpecHighPassButterworth4), + freqCorner1, + 0, + 0, + kFidSpecHighPassButterworth4, + sizeof(kFidSpecHighPassButterworth4), + freqCorner1, + 0, + 0); } |