mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 02:45:33 +08:00
Doxygen/style, test for div/0
This commit is contained in:
@@ -7,10 +7,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "biquadfilter.h"
|
#include "biquadfilter.h"
|
||||||
|
#include "blackmisc/verify.h"
|
||||||
|
#include "blackconfig/buildconfig.h"
|
||||||
|
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace BlackMisc;
|
||||||
|
using namespace BlackConfig;
|
||||||
|
|
||||||
namespace BlackSound
|
namespace BlackSound
|
||||||
{
|
{
|
||||||
@@ -19,27 +23,29 @@ namespace BlackSound
|
|||||||
float BiQuadFilter::transform(float inSample)
|
float BiQuadFilter::transform(float inSample)
|
||||||
{
|
{
|
||||||
// compute result
|
// compute result
|
||||||
double result = a0 * inSample + a1 * x1 + a2 * x2 - a3 * y1 - a4 * y2;
|
double result = m_a0 * inSample + m_a1 * m_x1 + m_a2 * m_x2 - m_a3 * m_y1 - m_a4 * m_y2;
|
||||||
|
|
||||||
// shift x1 to x2, sample to x1
|
// shift x1 to x2, sample to x1
|
||||||
x2 = x1;
|
m_x2 = m_x1;
|
||||||
x1 = inSample;
|
m_x1 = inSample;
|
||||||
|
|
||||||
// shift y1 to y2, result to y1
|
// shift y1 to y2, result to y1
|
||||||
y2 = y1;
|
m_y2 = m_y1;
|
||||||
y1 = static_cast<float>(result);
|
m_y1 = static_cast<float>(result);
|
||||||
|
|
||||||
return y1;
|
return m_y1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BiQuadFilter::setCoefficients(double aa0, double aa1, double aa2, double b0, double b1, double b2)
|
void BiQuadFilter::setCoefficients(double aa0, double aa1, double aa2, double b0, double b1, double b2)
|
||||||
{
|
{
|
||||||
|
if (CBuildConfig::isLocalDeveloperDebugBuild()) { BLACK_VERIFY_X(qAbs(aa0) > 1E-06, Q_FUNC_INFO, "Div by zero?"); }
|
||||||
|
|
||||||
// precompute the coefficients
|
// precompute the coefficients
|
||||||
a0 = b0 / aa0;
|
m_a0 = b0 / aa0;
|
||||||
a1 = b1 / aa0;
|
m_a1 = b1 / aa0;
|
||||||
a2 = b2 / aa0;
|
m_a2 = b2 / aa0;
|
||||||
a3 = aa1 / aa0;
|
m_a3 = aa1 / aa0;
|
||||||
a4 = aa2 / aa0;
|
m_a4 = aa2 / aa0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BiQuadFilter::setLowPassFilter(float sampleRate, float cutoffFrequency, float q)
|
void BiQuadFilter::setLowPassFilter(float sampleRate, float cutoffFrequency, float q)
|
||||||
|
|||||||
@@ -8,8 +8,8 @@
|
|||||||
|
|
||||||
//! \file
|
//! \file
|
||||||
|
|
||||||
#ifndef BIQUADFILTER_H
|
#ifndef BLACKSOUND_DSP_BIQUADFILTER_H
|
||||||
#define BIQUADFILTER_H
|
#define BLACKSOUND_DSP_BIQUADFILTER_H
|
||||||
|
|
||||||
#include "blacksound/blacksoundexport.h"
|
#include "blacksound/blacksoundexport.h"
|
||||||
|
|
||||||
@@ -24,28 +24,34 @@ namespace BlackSound
|
|||||||
//! Ctor
|
//! Ctor
|
||||||
BiQuadFilter() = default;
|
BiQuadFilter() = default;
|
||||||
|
|
||||||
|
//! Transform
|
||||||
float transform(float inSample);
|
float transform(float inSample);
|
||||||
|
|
||||||
|
//! Set filter parameters @{
|
||||||
void setCoefficients(double aa0, double aa1, double aa2, double b0, double b1, double b2);
|
void setCoefficients(double aa0, double aa1, double aa2, double b0, double b1, double b2);
|
||||||
void setLowPassFilter(float sampleRate, float cutoffFrequency, float q);
|
void setLowPassFilter(float sampleRate, float cutoffFrequency, float q);
|
||||||
void setPeakingEq(float sampleRate, float centreFrequency, float q, float dbGain);
|
void setPeakingEq(float sampleRate, float centreFrequency, float q, float dbGain);
|
||||||
void setHighPassFilter(float sampleRate, float cutoffFrequency, float q);
|
void setHighPassFilter(float sampleRate, float cutoffFrequency, float q);
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
//! Get filters @{
|
||||||
static BiQuadFilter lowPassFilter(float sampleRate, float cutoffFrequency, float q);
|
static BiQuadFilter lowPassFilter(float sampleRate, float cutoffFrequency, float q);
|
||||||
static BiQuadFilter highPassFilter(float sampleRate, float cutoffFrequency, float q);
|
static BiQuadFilter highPassFilter(float sampleRate, float cutoffFrequency, float q);
|
||||||
static BiQuadFilter peakingEQ(float sampleRate, float centreFrequency, float q, float dbGain);
|
static BiQuadFilter peakingEQ(float sampleRate, float centreFrequency, float q, float dbGain);
|
||||||
|
//! @}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double a0;
|
double m_a0 = 0.0;
|
||||||
double a1;
|
double m_a1 = 0.0;
|
||||||
double a2;
|
double m_a2 = 0.0;
|
||||||
double a3;
|
double m_a3 = 0.0;
|
||||||
double a4;
|
double m_a4 = 0.0;
|
||||||
|
|
||||||
// state
|
// state
|
||||||
float x1 = 0.0;
|
float m_x1 = 0.0;
|
||||||
float x2 = 0.0;
|
float m_x2 = 0.0;
|
||||||
float y1 = 0.0;
|
float m_y1 = 0.0;
|
||||||
float y2 = 0.0;
|
float m_y2 = 0.0;
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
Reference in New Issue
Block a user