Bladeren bron

ensure coeffs ptr is writable before using

dds
John Robinson 3 jaren geleden
bovenliggende
commit
9faffc2d0d
Geen bekende sleutel gevonden voor deze handtekening in de database
1 gewijzigde bestanden met toevoegingen van 11 en 8 verwijderingen
  1. +11
    -8
      biquad.h

+ 11
- 8
biquad.h Bestand weergeven

@@ -31,6 +31,7 @@

#include "Arduino.h"
#include <arm_math.h>
#include <type_traits>

enum class BiquadType {
LOW_PASS, HIGH_PASS, BAND_PASS, NOTCH, ALL_PASS, PEAKING, LOW_SHELF, HIGH_SHELF
@@ -39,7 +40,7 @@ enum class BiquadType {
template <typename T>
void getCoefficients(T* coeffs, BiquadType type, double dbGain, double freq, double srate, double bandwidthOrQOrS, bool isBandwidthOrS=false){
const double A =(type == BiquadType::PEAKING || type == BiquadType::LOW_SHELF || type == BiquadType::HIGH_SHELF) ? pow(10., dbGain / 40.) : pow(10, dbGain / 20);
const double omega = 2 * M_PI * freq / srate;
const double sn = sin(omega);
const double cs = cos(omega);
@@ -124,11 +125,13 @@ void getCoefficients(T* coeffs, BiquadType type, double dbGain, double freq, dou
break;
}

*coeffs++=(T)(b0 * a0Inv);
*coeffs++=(T)(b1 * a0Inv);
*coeffs++=(T)(b2 * a0Inv);
*coeffs++=(T)(-a1 * a0Inv);
*coeffs=(T)(-a2 * a0Inv);
using writable_type = typename std::remove_const<T>::type;
writable_type* coeffs_ptr = const_cast<writable_type*>(coeffs);
*coeffs_ptr++ = (T)(b0 * a0Inv);
*coeffs_ptr++ = (T)(b1 * a0Inv);
*coeffs_ptr++ = (T)(b2 * a0Inv);
*coeffs_ptr++ = (T)(-a1 * a0Inv);
*coeffs_ptr = (T)(-a2 * a0Inv);
}

template <typename T, typename BIQUAD, typename BTYPE>
@@ -189,7 +192,7 @@ void getCoefficients(T* coeffs, BiquadType type, double dbGain, double freq, dou
*pDst++=(T)yn;
}
}
}
}

template <typename B>
void preload(const B* S, double val=0.){
@@ -201,4 +204,4 @@ void getCoefficients(T* coeffs, BiquadType type, double dbGain, double freq, dou
*(S->pState) = (*(S->pCoeffs+1) + *(S->pCoeffs+3)) * val + *(S->pState+1);
}

#endif
#endif

Laden…
Annuleren
Opslaan