WE Core
Loading...
Searching...
No Matches
DSPUnitProcessingTests.cpp
Go to the documentation of this file.
1/*
2 * File: DSPUnitProcessingTests.cpp
3 *
4 * Created: 08/09/2018
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"
25
26SCENARIO("CarveDSPUnit: Silence in = silence out") {
27 GIVEN("A CarveDSPUnit and a buffer of silent samples") {
28 std::vector<double> buffer(1024);
30
31 WHEN("The silence samples are processed") {
32 // fill the buffer
33 std::fill(buffer.begin(), buffer.end(), 0);
34
35 // turn the unit on
36 mCarve.setMode(2);
37
38 // do processing
39 for (size_t iii {0}; iii < buffer.size(); iii++) {
40 buffer[iii] = mCarve.process(buffer[iii]);
41 }
42
43 THEN("The output is silence") {
44 for (size_t iii {0}; iii < buffer.size(); iii++) {
45 CHECK(buffer[iii] == Approx(0.0));
46 }
47 }
48 }
49 }
50}
51
52SCENARIO("CarveDSPUnit: Sine Default") {
53 GIVEN("A CarveDSPUnit and a buffer of sine samples") {
54 std::vector<double> buffer(1024);
55 const std::vector<double>& expectedOutput =
56 TestData::Carve::Data.at(Catch::getResultCapture().getCurrentTestName());
57
59
60 // Set some parameters for the input signal
61 constexpr size_t SAMPLE_RATE {44100};
62 constexpr size_t SINE_FREQ {1000};
63 constexpr double SAMPLES_PER_CYCLE {SAMPLE_RATE / SINE_FREQ};
64
65 WHEN("The silence samples are processed") {
66 // fill the buffer
67 std::generate(buffer.begin(),
68 buffer.end(),
69 [iii = 0]() mutable {return std::sin(WECore::CoreMath::LONG_TAU * (iii++ / SAMPLES_PER_CYCLE));} );
70
71 // turn the unit on
72 mCarve.setMode(2);
73
74 // do processing
75 for (size_t iii {0}; iii < buffer.size(); iii++) {
76 buffer[iii] = mCarve.process(buffer[iii]);
77 }
78
79 THEN("The expected output is produced") {
80 for (size_t iii {0}; iii < buffer.size(); iii++) {
81 CHECK(buffer[iii] == Approx(expectedOutput[iii]).margin(0.00001));
82 }
83 }
84 }
85 }
86}
87
88SCENARIO("CarveDSPUnit: Parabolic Soft Default") {
89 GIVEN("A CarveDSPUnit and a buffer of sine samples") {
90 std::vector<double> buffer(1024);
91 const std::vector<double>& expectedOutput =
92 TestData::Carve::Data.at(Catch::getResultCapture().getCurrentTestName());
93
95
96 // Set some parameters for the input signal
97 constexpr size_t SAMPLE_RATE {44100};
98 constexpr size_t SINE_FREQ {1000};
99 constexpr double SAMPLES_PER_CYCLE {SAMPLE_RATE / SINE_FREQ};
100
101 WHEN("The silence samples are processed") {
102 // fill the buffer
103 std::generate(buffer.begin(),
104 buffer.end(),
105 [iii = 0]() mutable {return std::sin(WECore::CoreMath::LONG_TAU * (iii++ / SAMPLES_PER_CYCLE));} );
106
107 // turn the unit on
108 mCarve.setMode(3);
109
110 // do processing
111 for (size_t iii {0}; iii < buffer.size(); iii++) {
112 buffer[iii] = mCarve.process(buffer[iii]);
113 }
114
115 THEN("The expected output is produced") {
116 for (size_t iii {0}; iii < buffer.size(); iii++) {
117 CHECK(buffer[iii] == Approx(expectedOutput[iii]).margin(0.00001));
118 }
119 }
120 }
121 }
122}
123
124SCENARIO("CarveDSPUnit: Parabolic Hard Default") {
125 GIVEN("A CarveDSPUnit and a buffer of sine samples") {
126 std::vector<double> buffer(1024);
127 const std::vector<double>& expectedOutput =
128 TestData::Carve::Data.at(Catch::getResultCapture().getCurrentTestName());
129
131
132 // Set some parameters for the input signal
133 constexpr size_t SAMPLE_RATE {44100};
134 constexpr size_t SINE_FREQ {1000};
135 constexpr double SAMPLES_PER_CYCLE {SAMPLE_RATE / SINE_FREQ};
136
137 WHEN("The silence samples are processed") {
138 // fill the buffer
139 std::generate(buffer.begin(),
140 buffer.end(),
141 [iii = 0]() mutable {return std::sin(WECore::CoreMath::LONG_TAU * (iii++ / SAMPLES_PER_CYCLE));} );
142
143 // turn the unit on
144 mCarve.setMode(4);
145
146 // do processing
147 for (size_t iii {0}; iii < buffer.size(); iii++) {
148 buffer[iii] = mCarve.process(buffer[iii]);
149 }
150
151 THEN("The expected output is produced") {
152 for (size_t iii {0}; iii < buffer.size(); iii++) {
153 CHECK(buffer[iii] == Approx(expectedOutput[iii]).margin(0.00001));
154 }
155 }
156 }
157 }
158}
159
160SCENARIO("CarveDSPUnit: Asymetric Sine Default") {
161 GIVEN("A CarveDSPUnit and a buffer of sine samples") {
162 std::vector<double> buffer(1024);
163 const std::vector<double>& expectedOutput =
164 TestData::Carve::Data.at(Catch::getResultCapture().getCurrentTestName());
165
167
168 // Set some parameters for the input signal
169 constexpr size_t SAMPLE_RATE {44100};
170 constexpr size_t SINE_FREQ {1000};
171 constexpr double SAMPLES_PER_CYCLE {SAMPLE_RATE / SINE_FREQ};
172
173 WHEN("The silence samples are processed") {
174 // fill the buffer
175 std::generate(buffer.begin(),
176 buffer.end(),
177 [iii = 0]() mutable {return std::sin(WECore::CoreMath::LONG_TAU * (iii++ / SAMPLES_PER_CYCLE));} );
178
179 // turn the unit on
180 mCarve.setMode(5);
181
182 // do processing
183 for (size_t iii {0}; iii < buffer.size(); iii++) {
184 buffer[iii] = mCarve.process(buffer[iii]);
185 }
186
187 THEN("The expected output is produced") {
188 for (size_t iii {0}; iii < buffer.size(); iii++) {
189 CHECK(buffer[iii] == Approx(expectedOutput[iii]).margin(0.00001));
190 }
191 }
192 }
193 }
194}
195
196SCENARIO("CarveDSPUnit: Exponent Default") {
197 GIVEN("A CarveDSPUnit and a buffer of sine samples") {
198 std::vector<double> buffer(1024);
199 const std::vector<double>& expectedOutput =
200 TestData::Carve::Data.at(Catch::getResultCapture().getCurrentTestName());
201
203
204 // Set some parameters for the input signal
205 constexpr size_t SAMPLE_RATE {44100};
206 constexpr size_t SINE_FREQ {1000};
207 constexpr double SAMPLES_PER_CYCLE {SAMPLE_RATE / SINE_FREQ};
208
209 WHEN("The silence samples are processed") {
210 // fill the buffer
211 std::generate(buffer.begin(),
212 buffer.end(),
213 [iii = 0]() mutable {return std::sin(WECore::CoreMath::LONG_TAU * (iii++ / SAMPLES_PER_CYCLE));} );
214
215 // turn the unit on
216 mCarve.setMode(6);
217
218 // do processing
219 for (size_t iii {0}; iii < buffer.size(); iii++) {
220 buffer[iii] = mCarve.process(buffer[iii]);
221 }
222
223 THEN("The expected output is produced") {
224 for (size_t iii {0}; iii < buffer.size(); iii++) {
225 CHECK(buffer[iii] == Approx(expectedOutput[iii]).margin(0.00001));
226 }
227 }
228 }
229 }
230}
231
232SCENARIO("CarveDSPUnit: Clipper Default") {
233 GIVEN("A CarveDSPUnit and a buffer of sine samples") {
234 std::vector<double> buffer(1024);
235 const std::vector<double>& expectedOutput =
236 TestData::Carve::Data.at(Catch::getResultCapture().getCurrentTestName());
237
239
240 // Set some parameters for the input signal
241 constexpr size_t SAMPLE_RATE {44100};
242 constexpr size_t SINE_FREQ {1000};
243 constexpr double SAMPLES_PER_CYCLE {SAMPLE_RATE / SINE_FREQ};
244
245 WHEN("The silence samples are processed") {
246 // fill the buffer
247 std::generate(buffer.begin(),
248 buffer.end(),
249 [iii = 0]() mutable {return std::sin(WECore::CoreMath::LONG_TAU * (iii++ / SAMPLES_PER_CYCLE));} );
250
251 // turn the unit on
252 mCarve.setMode(7);
253
254 // do processing
255 for (size_t iii {0}; iii < buffer.size(); iii++) {
256 buffer[iii] = mCarve.process(buffer[iii]);
257 }
258
259 THEN("The expected output is produced") {
260 for (size_t iii {0}; iii < buffer.size(); iii++) {
261 CHECK(buffer[iii] == Approx(expectedOutput[iii]).margin(0.00001));
262 }
263 }
264 }
265 }
266}
SCENARIO("CarveDSPUnit: Silence in = silence out")
T process(T inSample) const
const std::unordered_map< std::string, std::vector< double > > Data