1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) 2012-2017 VideoStitch SAS
// Copyright (c) 2018 stitchEm
#pragma once
#include "libvideostitch/audioObject.hpp"
#include <vector>
#define FILTER_BOUNDS_CHECK
namespace VideoStitch {
namespace Audio {
enum class FilterType {
UNITY = 0,
LOW_PASS = 1,
HIGH_PASS = 2,
LOW_SHELF = 5,
HIGH_SHELF = 6,
BELL = 7,
DIRECT_COEFF = 8
};
// Default filter values
//
static const FilterType IIR_DEFAULT_FILTER_TYPE = FilterType::UNITY;
static const std::string IIR_NAME = "IIR filter";
static const double IIR_DEFAULT_FERQUENCY = 1000;
static const double IIR_DEFAULT_GAIN = 0;
static const double IIR_DEFAULT_Q = 1;
// IIR Filter
//
//
class IIR : public AudioObject {
public:
explicit IIR(int sampleRate);
virtual ~IIR() {}
void step(AudioBlock& out,
const AudioBlock& in); // Copy
void step(AudioBlock& buf); // In-place
int getSampleRate() const;
FilterType getFilterType() const;
void setType(FilterType type);
double getFreq() const;
void setFreq(double freq);
double getGain() const;
void setGain(double gain);
double getQ() const;
void setQ(double q);
void setFilterTFGQ(FilterType type, double freq, double gain, double q);
void clearState();
protected:
inline void _biquad(audioSample_t& out, const audioSample_t& in); // Copy
inline void _biquad(audioSample_t& sample); // In place
private:
void _convertParams();
void _convertParamsLPF();
void _convertParamsHPF();
void _convertParamsLS();
void _convertParamsHS();
void _convertParamsBell();
int _sampleRate;
FilterType _type;
double _freq;
double _gain;
double _q;
double _a0;
double _a1;
double _a2;
double _b1;
double _b2;
double _d0;
double _d1;
audioSample_t _tmp;
}; // class AudioProcess::IIR
} // namespace Audio
} // namespace VideoStitch