WE Core
Loading...
Searching...
No Matches
SimpleCompressorTests.cpp
Go to the documentation of this file.
1/*
2 * File: TPTSVFilterTests.cpp
3 *
4 * Created: 04/12/2020
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
26
27SCENARIO("SimpleCompressor: Parameters can be set and retrieved correctly") {
28 GIVEN("A new SimpleCompressor object") {
29
31
32 WHEN("Nothing is changed") {
33 THEN("Parameters have their default values") {
34 CHECK(compressor.getDirection() == Comp::Direction::DOWNWARD);
35 CHECK(compressor.getAttack() == Approx(10.0));
36 CHECK(compressor.getRelease() == Approx(100.0));
37 CHECK(compressor.getThreshold() == Approx(0.0));
38 CHECK(compressor.getRatio() == Approx(2.0));
39 CHECK(compressor.getKneeWidth() == Approx(2.0));
40 }
41 }
42
43 WHEN("All parameters are changed to unique values") {
44 compressor.setDirection(Comp::Direction::UPWARD);
45 compressor.setAttack(0.11);
46 compressor.setRelease(1.1);
47 compressor.setThreshold(-10.0);
48 compressor.setRatio(1.2);
49 compressor.setKneeWidth(1.3);
50
51 THEN("They all get their correct unique values") {
52 CHECK(compressor.getDirection() == Comp::Direction::UPWARD);
53 CHECK(compressor.getAttack() == Approx(0.11));
54 CHECK(compressor.getRelease() == Approx(1.1));
55 CHECK(compressor.getThreshold() == Approx(-10.0));
56 CHECK(compressor.getRatio() == Approx(1.2));
57 CHECK(compressor.getKneeWidth() == Approx(1.3));
58 }
59 }
60 }
61}
62
63SCENARIO("SimpleCompressor: Parameters enforce their bounds correctly") {
64 GIVEN("A new SimpleCompressor object") {
65
67
68 WHEN("All parameter values are too low") {
69 compressor.setAttack(-10);
70 compressor.setRelease(-10);
71 compressor.setThreshold(-100);
72 compressor.setRatio(-10);
73 compressor.setKneeWidth(-10);
74
75 THEN("Parameters enforce their lower bounds") {
76 CHECK(compressor.getAttack() == Approx(0.1));
77 CHECK(compressor.getRelease() == Approx(1.0));
78 CHECK(compressor.getThreshold() == Approx(-60.0));
79 CHECK(compressor.getRatio() == Approx(1.0));
80 CHECK(compressor.getKneeWidth() == Approx(1.0));
81 }
82 }
83
84 WHEN("All parameter values are too high") {
85 compressor.setAttack(1000);
86 compressor.setRelease(10000);
87 compressor.setThreshold(10);
88 compressor.setRatio(100);
89 compressor.setKneeWidth(100);
90
91 THEN("Parameters enforce their upper bounds") {
92 CHECK(compressor.getAttack() == Approx(500));
93 CHECK(compressor.getRelease() == Approx(5000));
94 CHECK(compressor.getThreshold() == Approx(0));
95 CHECK(compressor.getRatio() == Approx(30));
96 CHECK(compressor.getKneeWidth() == Approx(10));
97 }
98 }
99 }
100}
101
102SCENARIO("SimpleCompressor: Silence in = silence out") {
103 GIVEN("A SimpleCompressor and a buffer of silent samples") {
104
105 std::vector<double> buffer(1024);
107
108 WHEN("The silence samples are processed") {
109 // fill the buffer
110 std::fill(buffer.begin(), buffer.end(), 0);
111
112 // do processing
113 compressor.process1in1out(&buffer[0], buffer.size());
114
115 THEN("The output is silence") {
116 for (size_t iii {0}; iii < buffer.size(); iii++) {
117 CHECK(buffer[iii] == Approx(0.0));
118 }
119 }
120 }
121 }
122}
SCENARIO("SimpleCompressor: Silence in = silence out")
virtual void process1in1out(SampleType *inSamples, size_t numSamples) override