Skip to content

Commit 223b3e4

Browse files
authored
Merge pull request #25 from mike919192/rename
Make naming more consistent
2 parents 70bbd28 + bbd1007 commit 223b3e4

File tree

2 files changed

+59
-59
lines changed

2 files changed

+59
-59
lines changed

include/sdsp/casc2orderIIR.h

+12-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace sdsp
77
{
88
template <size_t M>
9-
class casc2orderIIR {
9+
class casc_2o_IIR {
1010
private:
1111
int pos{ 0 };
1212

@@ -20,12 +20,12 @@ class casc2orderIIR {
2020
FilterType fType{ FilterType::None };
2121

2222
public:
23-
casc2orderIIR()
23+
casc_2o_IIR()
2424
{
2525
static_assert(M % 2 == 0, "M must be even!");
2626
}
2727

28-
void copy_coeff_from(const casc2orderIIR<M> &otherFilter)
28+
void copy_coeff_from(const casc_2o_IIR<M> &otherFilter)
2929
{
3030
gain = otherFilter.gain;
3131
bCoeff = otherFilter.bCoeff;
@@ -34,7 +34,7 @@ class casc2orderIIR {
3434
}
3535

3636
template <typename Iter>
37-
void Process(Iter begin, Iter end)
37+
void process(Iter begin, Iter end)
3838
{
3939
constexpr int order{ 2 };
4040
constexpr int j1{ 1 };
@@ -79,7 +79,7 @@ class casc2orderIIR {
7979
mem = y;
8080
}
8181

82-
void SetBPCoeff(double f0, double fs, double Q, double gainIn = 1.0)
82+
void set_bp_coeff(double f0, double fs, double Q, double gainIn = 1.0)
8383
{
8484
gain = gainIn;
8585
double q2{ 2 * Q };
@@ -137,7 +137,7 @@ class casc2orderIIR {
137137
}
138138
}
139139

140-
void SetHPCoeff(double f0, double fs, double gainIn = 1.0)
140+
void set_hp_coeff(double f0, double fs, double gainIn = 1.0)
141141
{
142142
gain = gainIn;
143143
fType = FilterType::HighPass;
@@ -165,7 +165,7 @@ class casc2orderIIR {
165165
}
166166
}
167167

168-
void SetLPCoeff(double f0, double fs, double gainIn = 1.0)
168+
void set_lp_coeff(double f0, double fs, double gainIn = 1.0)
169169
{
170170
gain = gainIn;
171171
fType = FilterType::LowPass;
@@ -194,7 +194,7 @@ class casc2orderIIR {
194194
}
195195

196196
// preload the filter memory for steady state input equal to value parameter
197-
void PreloadFilter(double value)
197+
void preload_filter(double value)
198198
{
199199
double preload_value = value * gain;
200200
std::array<std::array<double, 3>, M + 1> memVals{ 0 };
@@ -215,7 +215,7 @@ class casc2orderIIR {
215215
};
216216

217217
template <size_t M>
218-
class casc_2o_IIR {
218+
class casc_2o_IIR_base {
219219
protected:
220220
int pos{ 0 };
221221

@@ -264,7 +264,7 @@ class casc_2o_IIR {
264264
};
265265

266266
template <size_t M>
267-
class casc_2o_IIR_lp : casc_2o_IIR<M> {
267+
class casc_2o_IIR_lp : casc_2o_IIR_base<M> {
268268
public:
269269
casc_2o_IIR_lp()
270270
{
@@ -322,7 +322,7 @@ class casc_2o_IIR_lp : casc_2o_IIR<M> {
322322
};
323323

324324
template <size_t M>
325-
class casc_2o_IIR_hp : casc_2o_IIR<M> {
325+
class casc_2o_IIR_hp : casc_2o_IIR_base<M> {
326326
public:
327327
casc_2o_IIR_hp()
328328
{
@@ -380,7 +380,7 @@ class casc_2o_IIR_hp : casc_2o_IIR<M> {
380380
};
381381

382382
template <size_t M>
383-
class casc_2o_IIR_bp : casc_2o_IIR<M> {
383+
class casc_2o_IIR_bp : casc_2o_IIR_base<M> {
384384
public:
385385
casc_2o_IIR_bp()
386386
{

test/testIIR.cpp

+47-47
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ TEST_CASE("Filter test")
3434
std::string path = "../../../test_data/impulse_response";
3535
for (const auto &entry : std::filesystem::directory_iterator(path)) {
3636
auto [readImpulse, fType, fs, f0, Q] = csvreadImpulse2(entry.path().string());
37-
sdsp::casc2orderIIR<4> df;
37+
sdsp::casc_2o_IIR<4> df;
3838

3939
if (fType == sdsp::FilterType::LowPass) {
40-
df.SetLPCoeff(f0, fs);
40+
df.set_lp_coeff(f0, fs);
4141
} else if (fType == sdsp::FilterType::HighPass) {
42-
df.SetHPCoeff(f0, fs);
42+
df.set_hp_coeff(f0, fs);
4343
} else if (fType == sdsp::FilterType::BandPass) {
44-
df.SetBPCoeff(f0, fs, Q);
44+
df.set_bp_coeff(f0, fs, Q);
4545
} else {
4646
throw std::runtime_error("Unknown filter type");
4747
}
48-
sdsp::casc2orderIIR<4> df2 = df;
48+
sdsp::casc_2o_IIR<4> df2 = df;
4949
std::vector<double> data(readImpulse.size());
5050
data.at(0) = 1.0;
51-
df.Process(data.begin(), data.end());
51+
df.process(data.begin(), data.end());
5252

5353
std::vector<double> error(readImpulse.size());
5454

@@ -65,11 +65,11 @@ TEST_CASE("Filter test")
6565
constexpr unsigned int blockSize{ 32 };
6666
unsigned int index{ 0 };
6767
for (index = 0; index <= data2.size() - blockSize; index += blockSize) {
68-
df2.Process(std::next(data2.begin(), index), std::next(data2.begin(), index + blockSize));
68+
df2.process(std::next(data2.begin(), index), std::next(data2.begin(), index + blockSize));
6969
}
7070

7171
if (index < data2.size()) {
72-
df2.Process(std::next(data2.begin(), index), data2.end());
72+
df2.process(std::next(data2.begin(), index), data2.end());
7373
}
7474

7575
REQUIRE(data == data2);
@@ -86,14 +86,14 @@ TEST_CASE("Filter test")
8686
std::array<double, 1024> impulse2{ 0 };
8787
impulse2.at(0) = 1.0;
8888

89-
sdsp::casc2orderIIR<4> df;
90-
df.SetLPCoeff(f0, fs);
89+
sdsp::casc_2o_IIR<4> df;
90+
df.set_lp_coeff(f0, fs);
9191

92-
sdsp::casc2orderIIR<4> df2;
93-
df2.SetLPCoeff(f0, fs, 2.0);
92+
sdsp::casc_2o_IIR<4> df2;
93+
df2.set_lp_coeff(f0, fs, 2.0);
9494

95-
df.Process(impulse1.begin(), impulse1.end());
96-
df2.Process(impulse2.begin(), impulse2.end());
95+
df.process(impulse1.begin(), impulse1.end());
96+
df2.process(impulse2.begin(), impulse2.end());
9797

9898
auto times_two = [](double &n) { n = 2.0 * n; };
9999
std::for_each(impulse1.begin(), impulse1.end(), times_two);
@@ -117,14 +117,14 @@ TEST_CASE("Filter test")
117117
std::array<double, 1024> impulse2{ 0 };
118118
impulse2.at(0) = 1.0;
119119

120-
sdsp::casc2orderIIR<4> df;
121-
df.SetHPCoeff(f0, fs);
120+
sdsp::casc_2o_IIR<4> df;
121+
df.set_hp_coeff(f0, fs);
122122

123-
sdsp::casc2orderIIR<4> df2;
124-
df2.SetHPCoeff(f0, fs, 2.0);
123+
sdsp::casc_2o_IIR<4> df2;
124+
df2.set_hp_coeff(f0, fs, 2.0);
125125

126-
df.Process(impulse1.begin(), impulse1.end());
127-
df2.Process(impulse2.begin(), impulse2.end());
126+
df.process(impulse1.begin(), impulse1.end());
127+
df2.process(impulse2.begin(), impulse2.end());
128128

129129
auto times_two = [](double &n) { n = 2.0 * n; };
130130
std::for_each(impulse1.begin(), impulse1.end(), times_two);
@@ -149,14 +149,14 @@ TEST_CASE("Filter test")
149149
std::array<double, 1024> impulse2{ 0 };
150150
impulse2.at(0) = 1.0;
151151

152-
sdsp::casc2orderIIR<4> df;
153-
df.SetBPCoeff(f0, fs, Q);
152+
sdsp::casc_2o_IIR<4> df;
153+
df.set_bp_coeff(f0, fs, Q);
154154

155-
sdsp::casc2orderIIR<4> df2;
156-
df2.SetBPCoeff(f0, fs, Q, 2.0);
155+
sdsp::casc_2o_IIR<4> df2;
156+
df2.set_bp_coeff(f0, fs, Q, 2.0);
157157

158-
df.Process(impulse1.begin(), impulse1.end());
159-
df2.Process(impulse2.begin(), impulse2.end());
158+
df.process(impulse1.begin(), impulse1.end());
159+
df2.process(impulse2.begin(), impulse2.end());
160160

161161
auto times_two = [](double &n) { n = 2.0 * n; };
162162
std::for_each(impulse1.begin(), impulse1.end(), times_two);
@@ -180,10 +180,10 @@ TEST_CASE("Filter test")
180180
{
181181
std::array<double, 1024> steadyLP;
182182
steadyLP.fill(steadyValue);
183-
sdsp::casc2orderIIR<4> lpFilter;
184-
lpFilter.SetLPCoeff(f0, fs);
185-
lpFilter.PreloadFilter(steadyValue);
186-
lpFilter.Process(steadyLP.begin(), steadyLP.end());
183+
sdsp::casc_2o_IIR<4> lpFilter;
184+
lpFilter.set_lp_coeff(f0, fs);
185+
lpFilter.preload_filter(steadyValue);
186+
lpFilter.process(steadyLP.begin(), steadyLP.end());
187187
auto calcError = [steadyValue](double &n) { n = std::abs(n - steadyValue); };
188188
std::for_each(steadyLP.begin(), steadyLP.end(), calcError);
189189
double maxErrorLP = *std::max_element(steadyLP.begin(), steadyLP.end());
@@ -193,10 +193,10 @@ TEST_CASE("Filter test")
193193
{
194194
std::array<double, 1024> steadyHP;
195195
steadyHP.fill(steadyValue);
196-
sdsp::casc2orderIIR<4> hpFilter;
197-
hpFilter.SetHPCoeff(f0, fs);
198-
hpFilter.PreloadFilter(steadyValue);
199-
hpFilter.Process(steadyHP.begin(), steadyHP.end());
196+
sdsp::casc_2o_IIR<4> hpFilter;
197+
hpFilter.set_hp_coeff(f0, fs);
198+
hpFilter.preload_filter(steadyValue);
199+
hpFilter.process(steadyHP.begin(), steadyHP.end());
200200
auto calcError = [](double &n) { n = std::abs(n); };
201201
std::for_each(steadyHP.begin(), steadyHP.end(), calcError);
202202
double maxErrorHP = *std::max_element(steadyHP.begin(), steadyHP.end());
@@ -206,10 +206,10 @@ TEST_CASE("Filter test")
206206
{
207207
std::array<double, 1024> steadyBP;
208208
steadyBP.fill(steadyValue);
209-
sdsp::casc2orderIIR<4> bpFilter;
210-
bpFilter.SetBPCoeff(f0, fs, Q);
211-
bpFilter.PreloadFilter(steadyValue);
212-
bpFilter.Process(steadyBP.begin(), steadyBP.end());
209+
sdsp::casc_2o_IIR<4> bpFilter;
210+
bpFilter.set_bp_coeff(f0, fs, Q);
211+
bpFilter.preload_filter(steadyValue);
212+
bpFilter.process(steadyBP.begin(), steadyBP.end());
213213
auto calcError = [](double &n) { n = std::abs(n); };
214214
std::for_each(steadyBP.begin(), steadyBP.end(), calcError);
215215
double maxErrorBP = *std::max_element(steadyBP.begin(), steadyBP.end());
@@ -470,8 +470,8 @@ TEST_CASE("Filter benchmarks")
470470
constexpr double f0{ 10e3 };
471471
// constexpr double Q {1.1};
472472

473-
sdsp::casc2orderIIR<4> df;
474-
df.SetLPCoeff(f0, fs);
473+
sdsp::casc_2o_IIR<4> df;
474+
df.set_lp_coeff(f0, fs);
475475

476476
sdsp::casc_2o_IIR_lp<4> df2;
477477
df2.set_coeff(f0, fs);
@@ -482,7 +482,7 @@ TEST_CASE("Filter benchmarks")
482482
BENCHMARK("Runtime configurable LP filter benchmark")
483483
{
484484
std::array<double, 4096> data2 = data;
485-
df.Process(data2.begin(), data2.end());
485+
df.process(data2.begin(), data2.end());
486486
return data2;
487487
};
488488

@@ -501,8 +501,8 @@ TEST_CASE("Filter benchmarks")
501501
constexpr double f0{ 10e3 };
502502
// constexpr double Q {1.1};
503503

504-
sdsp::casc2orderIIR<4> df;
505-
df.SetHPCoeff(f0, fs);
504+
sdsp::casc_2o_IIR<4> df;
505+
df.set_hp_coeff(f0, fs);
506506

507507
sdsp::casc_2o_IIR_hp<4> df2;
508508
df2.set_coeff(f0, fs);
@@ -513,7 +513,7 @@ TEST_CASE("Filter benchmarks")
513513
BENCHMARK("Runtime configurable HP filter benchmark")
514514
{
515515
std::array<double, 4096> data2 = data;
516-
df.Process(data2.begin(), data2.end());
516+
df.process(data2.begin(), data2.end());
517517
return data2;
518518
};
519519

@@ -532,8 +532,8 @@ TEST_CASE("Filter benchmarks")
532532
constexpr double f0{ 10e3 };
533533
constexpr double Q{ 1.1 };
534534

535-
sdsp::casc2orderIIR<4> df;
536-
df.SetBPCoeff(f0, fs, Q);
535+
sdsp::casc_2o_IIR<4> df;
536+
df.set_bp_coeff(f0, fs, Q);
537537

538538
sdsp::casc_2o_IIR_bp<4> df2;
539539
df2.set_coeff(f0, fs, Q);
@@ -544,7 +544,7 @@ TEST_CASE("Filter benchmarks")
544544
BENCHMARK("Runtime configurable BP filter benchmark")
545545
{
546546
std::array<double, 4096> data2 = data;
547-
df.Process(data2.begin(), data2.end());
547+
df.process(data2.begin(), data2.end());
548548
return data2;
549549
};
550550

0 commit comments

Comments
 (0)