WE Core
Loading...
Searching...
No Matches
DSPUnitParameterTests.cpp
Go to the documentation of this file.
1/*
2 * File: CarveDSPUnitTests.cpp
3 *
4 * Created: 26/12/2016
5 *
6 * This file is part of WECore.
7 *
8 * WECore is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * WECore is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with WECore. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "catch.hpp"
24
25SCENARIO("CarveDSPUnit: Parameters can be set and retrieved correctly") {
26 GIVEN("A new CarveDSPUnit object") {
28
29 WHEN("Nothing is changed") {
30 THEN("Parameters have their default values") {
31 CHECK(mCarve.getMode() == 2);
32 CHECK(mCarve.getPreGain() == Approx(1.0));
33 CHECK(mCarve.getPostGain() == Approx(0.5));
34 CHECK(mCarve.getTweak() == Approx(0.0));
35 }
36 }
37
38 WHEN("All parameters are changed to unique values") {
39 mCarve.setMode(2);
40 mCarve.setPreGain(0.02);
41 mCarve.setPostGain(0.03);
42 mCarve.setTweak(0.04);
43
44 THEN("They all get their correct unique values") {
45 CHECK(mCarve.getMode() == 2);
46 CHECK(mCarve.getPreGain() == Approx(0.02));
47 CHECK(mCarve.getPostGain() == Approx(0.03));
48 CHECK(mCarve.getTweak() == Approx(0.04));
49 }
50 }
51 }
52}
53
54SCENARIO("CarveDSPUnit: Parameters enforce their bounds correctly") {
55 GIVEN("A new CarveDSPUnit object") {
57
58 WHEN("All parameter values are too low") {
59 mCarve.setMode(-5);
60 mCarve.setPreGain(-5);
61 mCarve.setPostGain(-5);
62 mCarve.setTweak(-5);
63
64 THEN("Parameters enforce their lower bounds") {
65 CHECK(mCarve.getMode() == 1);
66 CHECK(mCarve.getPreGain() == Approx(0.0));
67 CHECK(mCarve.getPostGain() == Approx(0.0));
68 CHECK(mCarve.getTweak() == Approx(0.0));
69 }
70 }
71
72 WHEN("All parameter values are too high") {
73 mCarve.setMode(10);
74 mCarve.setPreGain(5);
75 mCarve.setPostGain(5);
76 mCarve.setTweak(5);
77
78 THEN("Parameters enforce their upper bounds") {
79 CHECK(mCarve.getMode() == 7);
80 CHECK(mCarve.getPreGain() == Approx(2.0));
81 CHECK(mCarve.getPostGain() == Approx(2.0));
82 CHECK(mCarve.getTweak() == Approx(1.0));
83 }
84 }
85 }
86}
87
88SCENARIO("CarveDSPUnit: Parameter combinations that should result in silence output for any input") {
89 GIVEN("A new CarveDSPUnit object and a buffer of 0.5fs") {
90 std::vector<double> buffer(1024);
92
93 WHEN("The unit is turned off") {
94 // fill the buffer
95 std::fill(buffer.begin(), buffer.end(), 0.5);
96
97 // turn the unit off
98 mCarve.setMode(1);
99
100 // do processing
101 for (size_t iii {0}; iii < buffer.size(); iii++) {
102 buffer[iii] = mCarve.process(buffer[iii]);
103 }
104
105 THEN("The output is silence") {
106 for (size_t iii {0}; iii < buffer.size(); iii++) {
107 CHECK(buffer[iii] == Approx(0.0));
108 }
109 }
110 }
111
112 WHEN("Unit is on but has 0 pregain") {
113 // fill the buffer
114 std::fill(buffer.begin(), buffer.end(), 0.5);
115
116 // turn the unit on, set pregain
117 mCarve.setMode(2);
118 mCarve.setPreGain(0);
119
120 // do processing
121 for (size_t iii {0}; iii < buffer.size(); iii++) {
122 buffer[iii] = mCarve.process(buffer[iii]);
123 }
124
125 THEN("The output is silence") {
126 for (size_t iii {0}; iii < buffer.size(); iii++) {
127 CHECK(buffer[iii] == Approx(0.0));
128 }
129 }
130 }
131
132 WHEN("Unit is on but has 0 postgain") {
133 // fill the buffer
134 std::fill(buffer.begin(), buffer.end(), 0.5);
135
136 // turn the unit on, set pregain and postgain
137 mCarve.setMode(2);
138 mCarve.setPreGain(1);
139 mCarve.setPostGain(0);
140
141 // do processing
142 for (size_t iii {0}; iii < buffer.size(); iii++) {
143 buffer[iii] = mCarve.process(buffer[iii]);
144 }
145
146 THEN("The output is silence") {
147 for (size_t iii {0}; iii < buffer.size(); iii++) {
148 CHECK(buffer[iii] == Approx(0.0));
149 }
150 }
151 }
152 }
153}
154
SCENARIO("CarveNoiseFilter: Silence in = silence out")
T process(T inSample) const
void setPostGain(double val)
void setPreGain(double val)