WE Core
Loading...
Searching...
No Matches
StereoWidthProcessorTests.cpp
Go to the documentation of this file.
1/*
2 * File: StereoWidthProcessorTests.cpp
3 *
4 * Created: 05/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"
23#include "General/CoreMath.h"
24#include "TestUtils.h"
26
27SCENARIO("StereoWidthProcessor: Parameters can be set and retrieved correctly") {
28 GIVEN("A new StereoWidthProcessor object") {
29
31
32 WHEN("Nothing is changed") {
33 THEN("Parameters have their default values") {
34 CHECK(processor.getWidth() == Approx(1.0));
35 }
36 }
37
38 WHEN("All parameters are changed to unique values") {
39 processor.setWidth(1.5);
40
41 THEN("They all get their correct unique values") {
42 CHECK(processor.getWidth() == Approx(1.5));
43 }
44 }
45 }
46}
47
48SCENARIO("StereoWidthProcessor: Parameters enforce their bounds correctly") {
49 GIVEN("A new StereoWidthProcessor object") {
50
52
53 WHEN("All parameter values are too low") {
54 processor.setWidth(-10);
55
56 THEN("Parameters enforce their lower bounds") {
57 CHECK(processor.getWidth() == Approx(0.0));
58 }
59 }
60
61 WHEN("All parameter values are too high") {
62 processor.setWidth(10);
63
64
65 THEN("Parameters enforce their upper bounds") {
66 CHECK(processor.getWidth() == Approx(2.0));
67
68 }
69 }
70 }
71}
72
73SCENARIO("StereoWidthProcessor: Silence in = silence out") {
74 GIVEN("A StereoWidthProcessor and a buffer of silent samples") {
75
76 std::vector<double> leftBuffer(1024);
77 std::vector<double> rightBuffer(1024);
79
80 // Fill the buffer
81 std::fill(leftBuffer.begin(), leftBuffer.end(), 0);
82 std::fill(rightBuffer.begin(), rightBuffer.end(), 0);
83
84 WHEN("The silence samples are processed") {
85
86 // Do processing
87 processor.process2in2out(&leftBuffer[0], &rightBuffer[0], leftBuffer.size());
88
89 THEN("The output is silence") {
90 for (size_t index {0}; index < leftBuffer.size(); index++) {
91 CHECK(leftBuffer[index] == Approx(0.0));
92 CHECK(rightBuffer[index] == Approx(0.0));
93 }
94 }
95 }
96 }
97}
98
99SCENARIO("StereoWidthProcessor: Neutral width position") {
100 GIVEN("A StereoWidthProcessor and a buffer of sine samples") {
101
102 std::vector<double> leftBuffer(1024);
103 std::vector<double> rightBuffer(1024);
105
106 // Fill the buffers
107 WECore::TestUtils::generateSine(leftBuffer, 44100, 1000);
108 std::copy(leftBuffer.begin(), leftBuffer.end() , rightBuffer.begin());
109
110 // Set the expected output
111 std::vector<double> expectedOutput(1024);
112 std::copy(leftBuffer.begin(), leftBuffer.end() , expectedOutput.begin());
113
114 WHEN("The samples are processed") {
115 // Do processing
116 processor.process2in2out(&leftBuffer[0], &rightBuffer[0], leftBuffer.size());
117
118 THEN("The output is silence") {
119 for (size_t index {0}; index < leftBuffer.size(); index++) {
120 CHECK(leftBuffer[index] == Approx(expectedOutput[index]));
121 CHECK(rightBuffer[index] == Approx(expectedOutput[index]));
122 }
123 }
124 }
125 }
126}
127
128SCENARIO("StereoWidthProcessor: Stereo to full mono") {
129 GIVEN("A StereoWidthProcessor and a buffer of sine samples") {
130
131 std::vector<double> leftBuffer(1024);
132 std::vector<double> rightBuffer(1024);
134
135 // Fill the buffers with different frequency sines
136 WECore::TestUtils::generateSine(leftBuffer, 44100, 1000);
137 WECore::TestUtils::generateSine(leftBuffer, 44100, 1500);
138
139 WHEN("The width is set to mono and samples are processed") {
140
141 processor.setWidth(0);
142
143 // Do processing
144 processor.process2in2out(&leftBuffer[0], &rightBuffer[0], leftBuffer.size());
145
146 THEN("The output is the same for each channel") {
147 for (size_t index {0}; index < leftBuffer.size(); index++) {
148 CHECK(leftBuffer[index] == Approx(rightBuffer[index]));
149 }
150 }
151 }
152 }
153}
SCENARIO("StereoWidthProcessor: Silence in = silence out")
virtual void process2in2out(SampleType *inSamplesLeft, SampleType *inSamplesRight, size_t numSamples) override
static void generateSine(std::vector< double > &buffer, double sampleRate, double frequency)
Definition TestUtils.h:27