-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathwaveFx.cpp
116 lines (89 loc) · 2.8 KB
/
waveFx.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "../src/core/waveFx.h"
#include "../src/core/const.h"
#include "../src/core/types.h"
#include "../src/core/wave.h"
#include <catch2/catch.hpp>
#include <memory>
using namespace giada;
using namespace giada::m;
TEST_CASE("waveFx")
{
static const int SAMPLE_RATE = 44100;
static const int BUFFER_SIZE = 4000;
static const int BIT_DEPTH = 32;
Wave waveMono(0);
Wave waveStereo(0);
waveMono.alloc(BUFFER_SIZE, 1, SAMPLE_RATE, BIT_DEPTH, "path/to/sample-mono.wav");
waveStereo.alloc(BUFFER_SIZE, 2, SAMPLE_RATE, BIT_DEPTH, "path/to/sample-stereo.wav");
SECTION("test mono->stereo conversion")
{
int prevSize = waveMono.getBuffer().countFrames();
REQUIRE(wfx::monoToStereo(waveMono) == G_RES_OK);
REQUIRE(waveMono.getBuffer().countFrames() == prevSize); // size does not change, channels do
REQUIRE(waveMono.getBuffer().countChannels() == 2);
SECTION("test mono->stereo conversion for already stereo wave")
{
/* Should do nothing. */
int prevSize = waveStereo.getBuffer().countFrames();
REQUIRE(wfx::monoToStereo(waveStereo) == G_RES_OK);
REQUIRE(waveStereo.getBuffer().countFrames() == prevSize);
REQUIRE(waveStereo.getBuffer().countChannels() == 2);
}
}
SECTION("test silence")
{
int a = 20;
int b = 57;
wfx::silence(waveStereo, a, b);
for (int i = a; i < b; i++)
for (int k = 0; k < waveStereo.getBuffer().countChannels(); k++)
REQUIRE(waveStereo.getBuffer()[i][k] == 0.0f);
}
SECTION("test cut")
{
int a = 47;
int b = 210;
int range = b - a;
int prevSize = waveStereo.getBuffer().countFrames();
wfx::cut(waveStereo, a, b);
REQUIRE(waveStereo.getBuffer().countFrames() == prevSize - range);
}
SECTION("test paste")
{
const int sourceSize = 512;
const int originalDestSize = waveStereo.getBuffer().countFrames();
Wave source(0);
source.alloc(sourceSize, 2, SAMPLE_RATE, BIT_DEPTH, "path/to/source.wav");
wfx::paste(source, waveStereo, 16);
REQUIRE(waveStereo.getBuffer().countFrames() == sourceSize + originalDestSize);
}
SECTION("test trim")
{
int a = 47;
int b = 210;
int area = b - a;
wfx::trim(waveStereo, a, b);
REQUIRE(waveStereo.getBuffer().countFrames() == area);
}
SECTION("test fade")
{
int a = 47;
int b = 500;
wfx::fade(waveStereo, a, b, wfx::Fade::IN);
wfx::fade(waveStereo, a, b, wfx::Fade::OUT);
REQUIRE(waveStereo.getBuffer()[a][0] == 0.0f);
REQUIRE(waveStereo.getBuffer()[a][1] == 0.0f);
REQUIRE(waveStereo.getBuffer()[b][0] == 0.0f);
REQUIRE(waveStereo.getBuffer()[b][1] == 0.0f);
}
SECTION("test smooth")
{
int a = 11;
int b = 79;
wfx::smooth(waveStereo, a, b);
REQUIRE(waveStereo.getBuffer()[a][0] == 0.0f);
REQUIRE(waveStereo.getBuffer()[a][1] == 0.0f);
REQUIRE(waveStereo.getBuffer()[b][0] == 0.0f);
REQUIRE(waveStereo.getBuffer()[b][1] == 0.0f);
}
}