Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
jurihock committed Dec 30, 2023
1 parent be159d0 commit 75d6dd2
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <StftPitchShiftPlugin/Core.h>
#include <StftPitchShiftPlugin/Effect.h>

Core::Core(const double samplerate, const int blocksize, const int dftsize, const int overlap) :
Effect::Effect(const double samplerate, const int blocksize, const int dftsize, const int overlap) :
samplerate(samplerate), blocksize(blocksize), dftsize(dftsize), overlap(overlap),
analysis_window_size(static_cast<size_t>(dftsize + dftsize)),
synthesis_window_size(static_cast<size_t>(blocksize))
Expand All @@ -14,31 +14,31 @@ Core::Core(const double samplerate, const int blocksize, const int dftsize, cons
core = std::make_unique<stftpitchshift::StftPitchShiftCore<double>>(fft, winsize, hopsize, samplerate);
}

Core::~Core()
Effect::~Effect()
{
}

void Core::normalize(bool value)
void Effect::normalize(bool value)
{
core->normalization(value);
}

void Core::quefrency(double value)
void Effect::quefrency(double value)
{
core->quefrency(value);
}

void Core::timbre(double value)
void Effect::timbre(double value)
{
core->distortion(value);
}

void Core::pitch(std::vector<double> values)
void Effect::pitch(std::vector<double> values)
{
core->factors(values);
}

void Core::stft_pitch_shift(const std::span<const double> input, const std::span<double> output) const
void Effect::stft_pitch_shift(const std::span<const double> input, const std::span<double> output) const
{
(*stft)(input, output, [&](std::span<std::complex<double>> dft)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#include <StftPitchShift/STFT.h>
#include <StftPitchShift/StftPitchShiftCore.h>

class Core
class Effect
{

public:

Core(const double samplerate, const int blocksize, const int dftsize, const int overlap);
virtual ~Core();
Effect(const double samplerate, const int blocksize, const int dftsize, const int overlap);
virtual ~Effect();

void normalize(bool value);
void quefrency(double value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <StftPitchShiftPlugin/Core/DelayedCore.h>
#include <StftPitchShiftPlugin/Effect/DelayedEffect.h>

DelayedCore::DelayedCore(const double samplerate, const int blocksize, const int dftsize, const int overlap) :
InstantCore(samplerate, dftsize + dftsize, dftsize, overlap), host_block_size(blocksize)
DelayedEffect::DelayedEffect(const double samplerate, const int blocksize, const int dftsize, const int overlap) :
InstantEffect(samplerate, dftsize + dftsize, dftsize, overlap), host_block_size(blocksize)
{
const auto total_buffer_size = analysis_window_size + synthesis_window_size;

Expand All @@ -11,37 +11,37 @@ DelayedCore::DelayedCore(const double samplerate, const int blocksize, const int
samples = 0;
}

DelayedCore::~DelayedCore()
DelayedEffect::~DelayedEffect()
{
}

int DelayedCore::latency() const
int DelayedEffect::latency() const
{
return 6 * dftsize - host_block_size;
}

bool DelayedCore::compatible(const int blocksize) const
bool DelayedEffect::compatible(const int blocksize) const
{
return static_cast<size_t>(blocksize) <= synthesis_window_size;
}

void DelayedCore::dry(const std::span<const float> input, const std::span<float> output)
void DelayedEffect::dry(const std::span<const float> input, const std::span<float> output)
{
process(input, output, [&](std::span<float> x, std::span<float> y)
{
InstantCore::dry(x, y);
InstantEffect::dry(x, y);
});
}

void DelayedCore::wet(const std::span<const float> input, const std::span<float> output)
void DelayedEffect::wet(const std::span<const float> input, const std::span<float> output)
{
process(input, output, [&](std::span<float> x, std::span<float> y)
{
InstantCore::wet(x, y);
InstantEffect::wet(x, y);
});
}

void DelayedCore::process(const std::span<const float> input, const std::span<float> output,
void DelayedEffect::process(const std::span<const float> input, const std::span<float> output,
std::function<void(std::span<float> x, std::span<float> y)> callback)
{
const auto minsamples = input.size();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#pragma once

#include <StftPitchShiftPlugin/Core/InstantCore.h>
#include <StftPitchShiftPlugin/Effect/InstantEffect.h>

class DelayedCore : public InstantCore
class DelayedEffect : public InstantEffect
{

public:

DelayedCore(const double samplerate, const int blocksize, const int dftsize, const int overlap);
~DelayedCore();
DelayedEffect(const double samplerate, const int blocksize, const int dftsize, const int overlap);
~DelayedEffect();

int latency() const override;
bool compatible(const int blocksize) const override;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
#include <StftPitchShiftPlugin/Core/InstantCore.h>
#include <StftPitchShiftPlugin/Effect/InstantEffect.h>

InstantCore::InstantCore(const double samplerate, const int blocksize, const int dftsize, const int overlap) :
Core(samplerate, blocksize, dftsize, overlap)
InstantEffect::InstantEffect(const double samplerate, const int blocksize, const int dftsize, const int overlap) :
Effect(samplerate, blocksize, dftsize, overlap)
{
const auto total_buffer_size = analysis_window_size + synthesis_window_size;

buffer.input.resize(total_buffer_size);
buffer.output.resize(total_buffer_size);
}

InstantCore::~InstantCore()
InstantEffect::~InstantEffect()
{
}

int InstantCore::latency() const
int InstantEffect::latency() const
{
return static_cast<int>(synthesis_window_size);
}

bool InstantCore::compatible(const int blocksize) const
bool InstantEffect::compatible(const int blocksize) const
{
return static_cast<size_t>(blocksize) == synthesis_window_size;
}

void InstantCore::dry(const std::span<const float> input, const std::span<float> output)
void InstantEffect::dry(const std::span<const float> input, const std::span<float> output)
{
process(input, output, [](std::span<double> x, std::span<double> y)
{
std::copy(x.begin(), x.end(), y.begin());
});
}

void InstantCore::wet(const std::span<const float> input, const std::span<float> output)
void InstantEffect::wet(const std::span<const float> input, const std::span<float> output)
{
process(input, output, [&](std::span<double> x, std::span<double> y)
{
stft_pitch_shift(x, y);
});
}

void InstantCore::process(const std::span<const float> input, const std::span<float> output,
void InstantEffect::process(const std::span<const float> input, const std::span<float> output,
std::function<void(std::span<double> x, std::span<double> y)> callback)
{
// shift input buffer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#pragma once

#include <StftPitchShiftPlugin/Core.h>
#include <StftPitchShiftPlugin/Effect.h>

class InstantCore : public Core
class InstantEffect : public Effect
{

public:

InstantCore(const double samplerate, const int blocksize, const int dftsize, const int overlap);
~InstantCore();
InstantEffect(const double samplerate, const int blocksize, const int dftsize, const int overlap);
~InstantEffect();

int latency() const override;
bool compatible(const int blocksize) const override;
Expand Down
50 changes: 25 additions & 25 deletions src/StftPitchShiftPlugin/Processor.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <StftPitchShiftPlugin/Processor.h>

#include <StftPitchShiftPlugin/Core/InstantCore.h>
#include <StftPitchShiftPlugin/Core/DelayedCore.h>
#include <StftPitchShiftPlugin/Effect/InstantEffect.h>
#include <StftPitchShiftPlugin/Effect/DelayedEffect.h>

#include <StftPitchShiftPlugin/Logger.h>

Expand All @@ -16,31 +16,31 @@ Processor::Processor() :
parameters->onnormalize([&]()
{
std::lock_guard lock(mutex);
if (core) { core->normalize(parameters->normalize()); }
if (effect) { effect->normalize(parameters->normalize()); }
});

parameters->onquefrency([&]()
{
std::lock_guard lock(mutex);
if (core) { core->quefrency(parameters->quefrency()); }
if (effect) { effect->quefrency(parameters->quefrency()); }
});

parameters->ontimbre([&]()
{
std::lock_guard lock(mutex);
if (core) { core->timbre(parameters->timbre()); }
if (effect) { effect->timbre(parameters->timbre()); }
});

parameters->onpitch([&]()
{
std::lock_guard lock(mutex);
if (core) { core->pitch(parameters->pitch()); }
if (effect) { effect->pitch(parameters->pitch()); }
});

parameters->onreset([&]()
{
std::lock_guard lock(mutex);
if (state) { resetCore(state.value()); }
if (state) { resetEffect(state.value()); }
});
}

Expand Down Expand Up @@ -102,7 +102,7 @@ void Processor::prepareToPlay(double samplerate, int blocksize)
std::lock_guard lock(mutex);

state = std::nullopt;
core = nullptr;
effect = nullptr;

if (samplerate < 1)
{
Expand All @@ -122,7 +122,7 @@ void Processor::prepareToPlay(double samplerate, int blocksize)

try
{
resetCore(state.value());
resetEffect(state.value());
}
catch(const std::exception& exception)
{
Expand All @@ -139,7 +139,7 @@ void Processor::releaseResources()
LOG("Release resources");

state = std::nullopt;
core = nullptr;
effect = nullptr;
}

void Processor::processBlock(juce::AudioBuffer<float>& audio, juce::MidiBuffer& midi)
Expand Down Expand Up @@ -184,11 +184,11 @@ void Processor::processBlock(juce::AudioBuffer<float>& audio, juce::MidiBuffer&

if (parameters->bypass())
{
core->dry(input, output);
effect->dry(input, output);
}
else
{
core->wet(input, output);
effect->wet(input, output);
}
};

Expand All @@ -211,11 +211,11 @@ void Processor::processBlock(juce::AudioBuffer<float>& audio, juce::MidiBuffer&
{
process_stereo_output("state is not initialized");
}
else if (!core)
else if (!effect)
{
process_stereo_output("core is not initialized");
process_stereo_output("effect is not initialized");
}
else if (!core->compatible(channel_samples))
else if (!effect->compatible(channel_samples))
{
State oldstate = state.value();
State newstate = oldstate;
Expand All @@ -226,7 +226,7 @@ void Processor::processBlock(juce::AudioBuffer<float>& audio, juce::MidiBuffer&

try
{
resetCore(newstate);
resetEffect(newstate);

state = newstate;

Expand Down Expand Up @@ -264,7 +264,7 @@ void Processor::processBlock(juce::AudioBuffer<float>& audio, juce::MidiBuffer&
}
}

void Processor::resetCore(const State& state)
void Processor::resetEffect(const State& state)
{
const bool lowlatency = parameters->lowlatency();

Expand All @@ -273,31 +273,31 @@ void Processor::resetCore(const State& state)
const int dftsize = parameters->dftsize(blocksize);
const int overlap = parameters->overlap(blocksize);

LOG("Reset core (dftsize %d, overlap %d)", dftsize, overlap);
LOG("Reset effect (dftsize %d, overlap %d)", dftsize, overlap);

if (lowlatency)
{
core = std::make_unique<InstantCore>(
effect = std::make_unique<InstantEffect>(
samplerate,
blocksize,
dftsize,
overlap);
}
else
{
core = std::make_unique<DelayedCore>(
effect = std::make_unique<DelayedEffect>(
samplerate,
blocksize,
dftsize,
overlap);
}

core->normalize(parameters->normalize());
core->quefrency(parameters->quefrency());
core->timbre(parameters->timbre());
core->pitch(parameters->pitch());
effect->normalize(parameters->normalize());
effect->quefrency(parameters->quefrency());
effect->timbre(parameters->timbre());
effect->pitch(parameters->pitch());

const int latency = core->latency();
const int latency = effect->latency();

LOG("Latency %d (%d ms)", latency, static_cast<int>(1e+3 * latency / samplerate));

Expand Down
6 changes: 3 additions & 3 deletions src/StftPitchShiftPlugin/Processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <JuceHeader.h>

#include <StftPitchShiftPlugin/Chronometer.h>
#include <StftPitchShiftPlugin/Core.h>
#include <StftPitchShiftPlugin/Editor.h>
#include <StftPitchShiftPlugin/Effect.h>
#include <StftPitchShiftPlugin/Parameters.h>

class Processor final : public juce::AudioProcessor
Expand Down Expand Up @@ -53,10 +53,10 @@ class Processor final : public juce::AudioProcessor

std::mutex mutex;
std::optional<State> state;
std::unique_ptr<Core> core;
std::unique_ptr<Effect> effect;
std::shared_ptr<Parameters> parameters;

void resetCore(const State& state);
void resetEffect(const State& state);

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Processor)

Expand Down

0 comments on commit 75d6dd2

Please sign in to comment.