Skip to content

Commit

Permalink
Starting on Frequency Shifter module
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Jan 7, 2024
1 parent bfe6139 commit 748fa60
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ target_sources(BYOD PRIVATE
processors/other/Compressor.cpp
processors/other/Delay.cpp
processors/other/EnvelopeFilter.cpp
processors/other/FrequencyShifter.cpp
processors/other/LevelDetective.cpp
processors/other/Gate.cpp
processors/other/Octaver.cpp
Expand Down
2 changes: 2 additions & 0 deletions src/processors/ProcessorStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "other/Compressor.h"
#include "other/Delay.h"
#include "other/EnvelopeFilter.h"
#include "other/FrequencyShifter.h"
#include "other/Gate.h"
#include "other/LevelDetective.h"
#include "other/Octaver.h"
Expand Down Expand Up @@ -148,6 +149,7 @@ ProcessorStore::StoreMap ProcessorStore::store = {
{ "Crying Child", { &processorFactory<CryBaby>, { ProcessorType::Other, CryBaby::numInputs, CryBaby::numOutputs } } },
{ "Delay", { &processorFactory<DelayModule>, { ProcessorType::Other, 1, 1 } } },
{ "Envelope Filter", { &processorFactory<EnvelopeFilter>, { ProcessorType::Other, EnvelopeFilter::numInputs, EnvelopeFilter::numOutputs } } },
{ "Frequency Shifter", { &processorFactory<FrequencyShifter>, { ProcessorType::Other, 1, 1 } } },
{ "Level Detective", { &processorFactory<LevelDetective>, { ProcessorType::Other, 1, 1 } } },
{ "Gate", { &processorFactory<Gate>, { ProcessorType::Other, 1, 1 } } },
{ "Octaver", { &processorFactory<Octaver>, { ProcessorType::Other, 1, 1 } } },
Expand Down
48 changes: 48 additions & 0 deletions src/processors/other/FrequencyShifter.cpp
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
}
23 changes: 23 additions & 0 deletions src/processors/other/FrequencyShifter.h
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)
};

0 comments on commit 748fa60

Please sign in to comment.