-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added Reverb effect first implementation * Added unit test for Reverb effect * removed test gain setting
- Loading branch information
1 parent
025080a
commit 82230c3
Showing
8 changed files
with
146 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
|
||
#include <guitar_fx_lib/fx/delay.hpp> | ||
#include <guitar_fx_lib/interfaces/effect.hpp> | ||
|
||
class Reverb : public Effect | ||
{ | ||
public: | ||
Reverb() : delay1(3000), delay2(2000), delay3(1000) | ||
{ | ||
} | ||
|
||
~Reverb() = default; | ||
|
||
std::string get_name() override | ||
{ | ||
return "Reverb"; | ||
} | ||
|
||
protected: | ||
void on_gain_update(const float &new_gain) override | ||
{ | ||
// TODO change the depth of each delay | ||
// delay1.set_depth(something) | ||
// delay2.set_depth(something else) | ||
// delay3.set_depth(another value again) | ||
} | ||
|
||
bool apply_fx(const float &input, float &output) override | ||
{ | ||
// The effect simulates 3+ different delays at different depths | ||
|
||
float output1, output2, output3; | ||
|
||
// Remove the input portion from each delay processed signal so that the | ||
// input can be added only once | ||
delay1.process(input, output1); | ||
output1 -= input; | ||
delay2.process(input, output2); | ||
output2 -= input; | ||
delay3.process(input, output3); | ||
output3 -= input; | ||
|
||
output = (input + output1 + output2 + output3) / DECAY; | ||
|
||
return true; | ||
} | ||
|
||
private: | ||
static constexpr uint32_t DECAY = 4; | ||
|
||
Delay delay1; | ||
Delay delay2; | ||
Delay delay3; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include <guitar_fx_lib/fx/reverb.hpp> | ||
|
||
class TestEffectReverb : public ::testing::Test | ||
{ | ||
}; | ||
|
||
TEST_F(TestEffectReverb, testEffectInit) | ||
{ | ||
ASSERT_NO_THROW(Reverb()); | ||
|
||
Reverb rev; | ||
ASSERT_EQ(rev.get_name(), "Reverb"); | ||
} | ||
|
||
TEST_F(TestEffectReverb, testSetGain) | ||
{ | ||
Reverb rev; | ||
|
||
ASSERT_TRUE(rev.set_gain(0.0f)); | ||
ASSERT_TRUE(rev.set_gain(0.12f)); | ||
ASSERT_TRUE(rev.set_gain(0.7f)); | ||
ASSERT_TRUE(rev.set_gain(1.0f)); | ||
|
||
ASSERT_FALSE(rev.set_gain(-1.0f)); | ||
ASSERT_FALSE(rev.set_gain(-0.1f)); | ||
ASSERT_FALSE(rev.set_gain(1.1f)); | ||
ASSERT_FALSE(rev.set_gain(100.1f)); | ||
} | ||
|
||
TEST_F(TestEffectReverb, testProcessValidSignal) | ||
{ | ||
float output = 0.0f; | ||
|
||
Reverb rev; | ||
rev.set_gain(0.5f); | ||
|
||
for (float input = -1.0f; input <= 1.0f; input += 0.1f) | ||
{ | ||
ASSERT_TRUE(rev.process(input, output)) << "Failed with input " << input; | ||
ASSERT_GE(output, -1.0f); | ||
ASSERT_LE(output, 1.0f); | ||
} | ||
} | ||
|
||
TEST_F(TestEffectReverb, testProcessInvalidSignal) | ||
{ | ||
float output = 0; | ||
|
||
Reverb rev; | ||
|
||
for (float input = -100.0f; input <= 100.0f; input += 0.1f) | ||
{ | ||
if (input < -1.0f or input > 1.0f) | ||
{ | ||
ASSERT_FALSE(rev.process(input, output)); | ||
ASSERT_EQ(0, output); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters