Skip to content

Commit 62c87fe

Browse files
Merge pull request SquarePine#13 from Density-One/fix/fx-tweaks
Fix/fx tweaks
2 parents d9a1408 + a75f077 commit 62c87fe

24 files changed

+805
-178
lines changed

modules/squarepine_audio/core/EffectProcessorChain.cpp

Lines changed: 111 additions & 56 deletions
Large diffs are not rendered by default.

modules/squarepine_audio/core/EffectProcessorChain.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ class EffectProcessorChain final : public InternalProcessor
164164
*/
165165
bool setMixLevel (int index, float mixLevel);
166166

167+
using EffectUpdateFn = std::function<void (InternalProcessor&)>;
168+
void setTimeEffectsInChain (EffectUpdateFn f);
169+
167170
//==============================================================================
168171
/** Obtain the name of a plugin that exists within the array of effect plugins
169172
@@ -255,7 +258,7 @@ class EffectProcessorChain final : public InternalProcessor
255258
/** @internal */
256259
[[nodiscard]] double getTailLengthSeconds() const override;
257260
/** @internal */
258-
[[nodiscard]] Identifier getIdentifier() const override{ return "EffectProcessorChain"; }
261+
[[nodiscard]] Identifier getIdentifier() const override { return "EffectProcessorChain"; }
259262
/** @internal */
260263
[[nodiscard]] const String getName() const override;
261264
/** @internal */
@@ -266,7 +269,6 @@ class EffectProcessorChain final : public InternalProcessor
266269
void getStateInformation (MemoryBlock&) override;
267270
/** @internal */
268271
void setStateInformation (const void*, int) override;
269-
270272
private:
271273
//==============================================================================
272274
template<typename FloatType>
@@ -276,13 +278,13 @@ class EffectProcessorChain final : public InternalProcessor
276278

277279
void clear() noexcept
278280
{
279-
for (auto& buff : buffers)
281+
for (auto& buff: buffers)
280282
buff->clear();
281283
}
282284

283285
void prepare (int numChannels, int numSamples)
284286
{
285-
for (auto& buff : buffers)
287+
for (auto& buff: buffers)
286288
buff->setSize (numChannels, numSamples, false, true, true);
287289

288290
clear();
@@ -322,8 +324,7 @@ class EffectProcessorChain final : public InternalProcessor
322324
void process (juce::AudioBuffer<FloatType>&, MidiBuffer&, BufferPackage<FloatType>&);
323325

324326
template<typename FloatType>
325-
void processInternal (juce::AudioBuffer<FloatType>& source, MidiBuffer& midiMessages,
326-
BufferPackage<FloatType>& bufferPackage, int numChannels, int numSamples);
327+
void processInternal (juce::AudioBuffer<FloatType>& source, MidiBuffer& midiMessages, BufferPackage<FloatType>& bufferPackage, int numChannels, int numSamples);
327328

328329
template<typename Type>
329330
[[nodiscard]] EffectProcessor::Ptr insertInternal (const Type& valueOrRef, int destinationIndex, InsertionStyle insertionStyle = InsertionStyle::insert);
@@ -343,7 +344,7 @@ class EffectProcessorChain final : public InternalProcessor
343344
template<void (AudioProcessor::*function)()>
344345
void loopThroughEffectsAndCall()
345346
{
346-
for (auto effect : plugins)
347+
for (auto effect: plugins)
347348
if (effect != nullptr)
348349
if (auto* plugin = effect->plugin.get())
349350
(plugin->*function)();

modules/squarepine_audio/core/InternalProcessor.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ void InternalProcessor::removeProperty (const Identifier& id, UndoManager* um)
111111
{
112112
getState().removeProperty (id, um);
113113
}
114+
//==============================================================================
115+
116+
void InternalProcessor::setEffectPhaseRelativeToProjectDownBeat(double phaseRelativeToProjectDownBeat)
117+
{
118+
effectPhaseRelativeToProjectDownBeat = phaseRelativeToProjectDownBeat;
119+
}
120+
121+
void InternalProcessor::setIsInSteppedTimeMode(bool isInSteppedTimeMode)
122+
{
123+
isSteppedTime = isInSteppedTimeMode;
124+
}
114125

115126
//==============================================================================
116127
void InternalProcessor::setBypass (const bool shouldBeBypassed)

modules/squarepine_audio/core/InternalProcessor.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ class InternalProcessor : public AudioPluginInstance
116116
*/
117117
void removeProperty (const Identifier&, UndoManager* undoManager = nullptr);
118118

119+
//==============================================================================
120+
virtual void setEffectPhaseRelativeToProjectDownBeat (double PhaseRelativeToProjectDownBeat);
121+
122+
virtual void setIsInSteppedTimeMode (bool isInSteppedTimeMode);
119123
//==============================================================================
120124
/** Effectively enables or disables this processor. */
121125
void setBypass (bool shouldBeBypassed);
@@ -195,7 +199,10 @@ class InternalProcessor : public AudioPluginInstance
195199

196200
class BypassParameter;
197201
AudioParameterBool* bypassParameter = nullptr;
198-
202+
203+
double effectPhaseRelativeToProjectDownBeat = 0.0;
204+
205+
bool isSteppedTime = false;
199206
/** */
200207
[[nodiscard]] std::unique_ptr<AudioParameterBool> createBypassParameter() const;
201208

modules/squarepine_audio/effects/PhaseIncrementer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class PhaseIncrementer
2323
angleChange = frequency * 2.0f * f_PI / Fs;
2424
}
2525

26+
void setCurrentAngle (float angleInRadians, int channel)
27+
{
28+
currentAngle[channel] = angleInRadians;
29+
}
30+
2631
private:
2732

2833
float f_PI = static_cast<float> (M_PI);

modules/squarepine_audio/effects/daweffects/CrushProcessor.cpp

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,18 @@ CrushProcessor::~CrushProcessor()
8888
//============================================================================== Audio processing
8989
void CrushProcessor::prepareToPlay (double sampleRate, int bufferSize)
9090
{
91-
bitCrusher.prepareToPlay (sampleRate, bufferSize);
91+
Fs = sampleRate;
92+
93+
downSampler.setRatio (sampleRate, sampleRate);
94+
const int numChannels = 2;
95+
downSampler.prepare (numChannels);
96+
upSampler.prepare (numChannels);
97+
9298
highPassFilter.setFilterType (DigitalFilter::FilterType::HPF);
9399
highPassFilter.setFs (sampleRate);
94-
delayBlock.setFs (static_cast<float> (sampleRate));
95-
dryBuffer = AudioBuffer<float> (2, bufferSize);
100+
dryBuffer = AudioBuffer<float> (numChannels, bufferSize);
101+
resampledBuffer = AudioBuffer<float> (numChannels, bufferSize);
102+
96103
}
97104
void CrushProcessor::processBlock (juce::AudioBuffer<float>& buffer, MidiBuffer& midi)
98105
{
@@ -115,26 +122,32 @@ void CrushProcessor::processBlock (juce::AudioBuffer<float>& buffer, MidiBuffer&
115122
if (abs(colour) < 0.01f)
116123
wet = 0.f;
117124

125+
118126
for (int c = 0; c < numChannels; ++c)
119127
{
120128
dryBuffer.copyFrom (c, 0, buffer, c, 0, buffer.getNumSamples());
121129
}
122-
bitCrusher.processBlock (buffer, midi);
130+
123131
highPassFilter.processBuffer (buffer, midi);
132+
133+
downFs = (1.1f + (1.f - abs(colour))) * std::powf (10.f, (1.f - abs(colour)) + 3.f); // 1.1k - 22k
134+
const auto downSamplingRatio = Fs / downFs;
135+
136+
downSampler.setRatio (Fs, downFs);
137+
upSampler.setRatio (downFs, Fs);
138+
139+
const auto scaledBufferSize = (int) std::round ((double) numSamples / downSamplingRatio);
140+
resampledBuffer.setSize (numChannels, scaledBufferSize, false, true, true);
141+
downSampler.process (buffer, resampledBuffer);
142+
upSampler.process (resampledBuffer, buffer);
124143

125144
for (int c = 0; c < numChannels; ++c)
126145
{
127146
for (int n = 0; n < numSamples; ++n)
128147
{
129-
float x = buffer.getWritePointer (c)[n];
130-
131-
float wetSample = delayBlock.processSample (x, c);
132-
133-
//float y = x + wetSmooth[c] * wetSample;
134-
buffer.getWritePointer (c)[n] = wetSmooth[c] * wetSample * colorSmooth[c];
148+
buffer.getWritePointer (c)[n] *= wetSmooth[c];
135149
dryBuffer.getWritePointer (c)[n] *= (1.f - wetSmooth[c]);
136150
wetSmooth[c] = 0.999f * wetSmooth[c] + 0.001f * wet;
137-
colorSmooth[c] = 0.999f * colorSmooth[c] + 0.001f * colorSign;
138151
}
139152
buffer.addFrom (c, 0, dryBuffer, c, 0, buffer.getNumSamples());
140153
}
@@ -153,37 +166,20 @@ void CrushProcessor::parameterValueChanged (int paramNum, float value)
153166
if (paramNum == 2) {}// wet/dry
154167
else if (paramNum == 3) // "color"
155168
{
156-
float other = otherParam->get();
157-
float samplesOfDelay = jmin (15.f, 1.f + abs (value) * 10.f + other * 10.f);
158-
delayBlock.setDelaySamples (samplesOfDelay);
159169
if (value <= 0.f)
160170
{
161171
highPassFilter.setFreq (20.0);
162-
float normValue = (value * -1.f);
163-
// 4 bits -> normValue = 0
164-
// 9 bits -> normValue = 1
165-
float bitDepth = 5.f * std::sqrt (1.f - normValue) + 4.f;
166-
bitCrusher.setBitDepth (bitDepth);
167-
colorSign = 1.f;
168172
}
169173
else
170174
{
171175
float normValue = value;
172176
// freqHz = 20 -> 5000
173177
float freqHz = 2.f * std::powf (10.f, 3.f * (normValue * 0.8f) + 1.f);
174178
highPassFilter.setFreq (freqHz);
175-
// 9 bits -> value = 0.5, normValue = 0
176-
// 4 bits -> value = 1, normValue = 0
177-
float bitDepth = 5.f * std::sqrt (1.f - normValue) + 4.f;
178-
bitCrusher.setBitDepth (bitDepth);
179-
colorSign = -1.f;
180179
}
181180
}
182181
else if (paramNum == 4)// "other"
183182
{
184-
float color = colourParam->get();
185-
float samplesOfDelay = jmin (15.f, 1.f + value * 10.f + abs (color) * 10.f);
186-
delayBlock.setDelaySamples (samplesOfDelay);
187183
}
188184
}
189185

modules/squarepine_audio/effects/daweffects/CrushProcessor.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,19 @@ class CrushProcessor final : public InternalProcessor,
5858

5959
int idNumber = 1;
6060

61-
BitCrusherProcessor bitCrusher;
61+
double Fs = 48000.0;
6262
DigitalFilter highPassFilter;
63-
FractionalDelay delayBlock;
64-
float colorSign = 1.f;
6563

6664
float wetSmooth[2] = { 0.f };
6765
float colorSmooth[2] = { 0.f };
6866

6967
AudioBuffer<float> dryBuffer;
68+
69+
70+
ZeroOrderHoldResampler downSampler; //ZeroOrderHoldResampler
71+
ZeroOrderHoldResampler upSampler; //LinearResampler //LagrangeResampler
72+
AudioBuffer<float> resampledBuffer;
73+
double downFs = 48000.0;
7074
};
7175

7276
}

0 commit comments

Comments
 (0)