Skip to content

Commit 605e75c

Browse files
committed
Fix bypass delay #3
1 parent 474728c commit 605e75c

File tree

6 files changed

+63
-14
lines changed

6 files changed

+63
-14
lines changed

src/StftPitchShiftPlugin/Core.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ class Core
2020

2121
virtual int latency() const = 0;
2222
virtual bool compatible(const int blocksize) const = 0;
23-
virtual void process(const std::span<const float> input, const std::span<float> output) = 0;
23+
24+
virtual void dry(const std::span<const float> input, const std::span<float> output) = 0;
25+
virtual void wet(const std::span<const float> input, const std::span<float> output) = 0;
2426

2527
protected:
2628

src/StftPitchShiftPlugin/Core/DelayedCore.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,24 @@ bool DelayedCore::compatible(const int blocksize) const
2525
return static_cast<size_t>(blocksize) <= synthesis_window_size;
2626
}
2727

28-
void DelayedCore::process(const std::span<const float> input, const std::span<float> output)
28+
void DelayedCore::dry(const std::span<const float> input, const std::span<float> output)
29+
{
30+
process(input, output, [&](std::span<float> x, std::span<float> y)
31+
{
32+
InstantCore::dry(x, y);
33+
});
34+
}
35+
36+
void DelayedCore::wet(const std::span<const float> input, const std::span<float> output)
37+
{
38+
process(input, output, [&](std::span<float> x, std::span<float> y)
39+
{
40+
InstantCore::wet(x, y);
41+
});
42+
}
43+
44+
void DelayedCore::process(const std::span<const float> input, const std::span<float> output,
45+
std::function<void(std::span<float> x, std::span<float> y)> callback)
2946
{
3047
const auto minsamples = input.size();
3148
const auto maxsamples = synthesis_window_size;
@@ -48,7 +65,7 @@ void DelayedCore::process(const std::span<const float> input, const std::span<fl
4865
const auto x = buffer.input.data() + buffer.input.size();
4966
const auto y = buffer.output.data() + buffer.output.size();
5067

51-
InstantCore::process(
68+
callback(
5269
std::span(x - samples, maxsamples),
5370
std::span(y - samples, maxsamples));
5471

src/StftPitchShiftPlugin/Core/DelayedCore.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ class DelayedCore : public InstantCore
1212

1313
int latency() const override;
1414
bool compatible(const int blocksize) const override;
15-
void process(const std::span<const float> input, const std::span<float> output) override;
15+
16+
void dry(const std::span<const float> input, const std::span<float> output) override;
17+
void wet(const std::span<const float> input, const std::span<float> output) override;
1618

1719
private:
1820

@@ -22,4 +24,7 @@ class DelayedCore : public InstantCore
2224

2325
size_t samples;
2426

27+
void process(const std::span<const float> input, const std::span<float> output,
28+
std::function<void(std::span<float> x, std::span<float> y)> callback);
29+
2530
};

src/StftPitchShiftPlugin/Core/InstantCore.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,24 @@ bool InstantCore::compatible(const int blocksize) const
2323
return static_cast<size_t>(blocksize) == synthesis_window_size;
2424
}
2525

26-
void InstantCore::process(const std::span<const float> input, const std::span<float> output)
26+
void InstantCore::dry(const std::span<const float> input, const std::span<float> output)
27+
{
28+
process(input, output, [](std::span<double> x, std::span<double> y)
29+
{
30+
std::copy(x.begin(), x.end(), y.begin());
31+
});
32+
}
33+
34+
void InstantCore::wet(const std::span<const float> input, const std::span<float> output)
35+
{
36+
process(input, output, [&](std::span<double> x, std::span<double> y)
37+
{
38+
stft_pitch_shift(x, y);
39+
});
40+
}
41+
42+
void InstantCore::process(const std::span<const float> input, const std::span<float> output,
43+
std::function<void(std::span<double> x, std::span<double> y)> callback)
2744
{
2845
// shift input buffer
2946
std::copy(
@@ -38,8 +55,8 @@ void InstantCore::process(const std::span<const float> input, const std::span<fl
3855
buffer.input.begin() + analysis_window_size,
3956
transform<float, double>);
4057

41-
// apply pitch shifting within the built-in STFT routine
42-
stft_pitch_shift(buffer.input, buffer.output);
58+
// start processing
59+
callback(buffer.input, buffer.output);
4360

4461
// copy new output samples back
4562
std::transform(

src/StftPitchShiftPlugin/Core/InstantCore.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ class InstantCore : public Core
1212

1313
int latency() const override;
1414
bool compatible(const int blocksize) const override;
15-
void process(const std::span<const float> input, const std::span<float> output) override;
15+
16+
void dry(const std::span<const float> input, const std::span<float> output) override;
17+
void wet(const std::span<const float> input, const std::span<float> output) override;
1618

1719
private:
1820

@@ -21,4 +23,7 @@ class InstantCore : public Core
2123
template<typename X, typename Y>
2224
static Y transform(const X x) { return static_cast<Y>(x); }
2325

26+
void process(const std::span<const float> input, const std::span<float> output,
27+
std::function<void(std::span<double> x, std::span<double> y)> callback);
28+
2429
};

src/StftPitchShiftPlugin/Processor.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,14 @@ void Processor::processBlock(juce::AudioBuffer<float>& audio, juce::MidiBuffer&
182182
audio.getWritePointer(0),
183183
static_cast<size_t>(channel_samples));
184184

185-
core->process(input, output);
185+
if (parameters->bypass())
186+
{
187+
core->dry(input, output);
188+
}
189+
else
190+
{
191+
core->wet(input, output);
192+
}
186193
};
187194

188195
const auto process_stereo_output = [&](const std::string& error = "")
@@ -200,11 +207,7 @@ void Processor::processBlock(juce::AudioBuffer<float>& audio, juce::MidiBuffer&
200207

201208
TIC();
202209

203-
if (parameters->bypass() || (channel_samples < 4))
204-
{
205-
process_stereo_output();
206-
}
207-
else if (!state)
210+
if (!state)
208211
{
209212
process_stereo_output("state is not initialized");
210213
}

0 commit comments

Comments
 (0)