-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starting on Frequency Shifter module
- Loading branch information
1 parent
bfe6139
commit 748fa60
Showing
5 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
Submodule chowdsp_utils
updated
2 files
+6 −0 | modules/dsp/chowdsp_sources/Oscillators/chowdsp_SineWave.h | |
+18 −0 | tests/dsp_tests/chowdsp_sources_test/SineTest.cpp |
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,48 @@ | ||
#include "FrequencyShifter.h" | ||
#include "processors/ParameterHelpers.h" | ||
|
||
FrequencyShifter::FrequencyShifter (UndoManager* um) | ||
: BaseProcessor ("Frequency Shifter", createParameterLayout(), um) | ||
{ | ||
using namespace ParameterHelpers; | ||
loadParameterPointer (shiftParam, vts, "shift"); | ||
|
||
uiOptions.backgroundColour = Colours::palevioletred.brighter (0.1f); | ||
uiOptions.powerColour = Colours::yellow; | ||
uiOptions.info.description = "A frequency shifter effect."; | ||
uiOptions.info.authors = StringArray { "Jatin Chowdhury" }; | ||
} | ||
|
||
ParamLayout FrequencyShifter::createParameterLayout() | ||
{ | ||
using namespace ParameterHelpers; | ||
auto params = createBaseParams(); | ||
|
||
createFreqParameter (params, "shift", "Shift", 0.0f, 200.0f, 20.0f, 20.0f); | ||
|
||
return { params.begin(), params.end() }; | ||
} | ||
|
||
void FrequencyShifter::prepare (double sampleRate, int samplesPerBlock) | ||
{ | ||
hilbertFilter.reset(); | ||
modulator.prepare ({ sampleRate, (uint32_t) samplesPerBlock, 1}); | ||
} | ||
|
||
void FrequencyShifter::processAudio (AudioBuffer<float>& buffer) | ||
{ | ||
modulator.setFrequency (shiftParam->getCurrentValue()); | ||
|
||
for (auto [ch, data] : chowdsp::buffer_iters::channels (buffer)) | ||
{ | ||
for (auto& x : data) | ||
{ | ||
const auto [x_re, x_im] = hilbertFilter.process (x); | ||
const auto [mod_sin, mod_cos] = modulator.processSampleQuadrature(); | ||
|
||
x = x_re * mod_sin - x_im * mod_cos; | ||
} | ||
} | ||
|
||
// TODO: DC blocker | ||
} |
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,23 @@ | ||
#pragma once | ||
|
||
#include "../BaseProcessor.h" | ||
|
||
class FrequencyShifter : public BaseProcessor | ||
{ | ||
public: | ||
explicit FrequencyShifter (UndoManager* um = nullptr); | ||
|
||
ProcessorType getProcessorType() const override { return Other; } | ||
static ParamLayout createParameterLayout(); | ||
|
||
void prepare (double sampleRate, int samplesPerBlock) override; | ||
void processAudio (AudioBuffer<float>& buffer) override; | ||
|
||
private: | ||
chowdsp::FloatParameter* shiftParam = nullptr; | ||
|
||
chowdsp::HilbertFilter<float> hilbertFilter; | ||
chowdsp::SineWave<float> modulator {}; | ||
|
||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FrequencyShifter) | ||
}; |