-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiirfilterchain.cpp
93 lines (73 loc) · 1.88 KB
/
iirfilterchain.cpp
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
/*
This file is part of WaverIIR
Copyright (C) 2021 Peter Papp
Please visit https://launchpad.net/waveriir for details
*/
#include "iirfilterchain.h"
// constructor one: empty chain
IIRFilterChain::IIRFilterChain()
{
// initialization
filterCount = 0;
for (int i = 0; i < MAX_FILTERS; i++) {
filters[i] = nullptr;
}
}
// constructor two: chain from list of coefficient lists
IIRFilterChain::IIRFilterChain(QList<CoefficientList> coefficientLists)
{
// initialization
filterCount = 0;
for (int i = 0; i < MAX_FILTERS; i++) {
filters[i] = nullptr;
}
// append the filters
for (int i = 0; i < coefficientLists.size(); i++) {
appendFilter(coefficientLists.at(i));
}
}
// destructor
IIRFilterChain::~IIRFilterChain()
{
for (int i = 0; i < MAX_FILTERS; i++) {
if (filters[i] != nullptr) {
delete filters[i];
}
}
}
// append a filter
void IIRFilterChain::appendFilter(CoefficientList coefficientList)
{
if (filterCount >= MAX_FILTERS) {
return;
}
filters[filterCount] = new IIRFilter(coefficientList);
filterCount++;
}
// return pointer to a filter
IIRFilter *IIRFilterChain::getFilter(int index)
{
if ((index < 0) || (index >= filterCount)) {
return nullptr;
}
return filters[index];
}
// return the current count of filters
int IIRFilterChain::getFilterCount()
{
return filterCount;
}
// apply the whole chain of filters to PCM data
void IIRFilterChain::processPCMData(void *data, int byteCount, IIRFilter::SampleTypes sampleType, int channelCount)
{
for (int i = 0; i < filterCount; i++) {
filters[i]->processPCMData(data, byteCount, sampleType, channelCount);
}
}
// reset buffers of every filter in the chain
void IIRFilterChain::reset()
{
for (int i = 0; i < filterCount; i++) {
filters[i]->reset();
}
}