First Commit

This commit is contained in:
Legaeli
2025-10-22 09:20:23 +02:00
commit a36f2ca925
4393 changed files with 1570219 additions and 0 deletions
@@ -0,0 +1,22 @@
# ==============================================================================
#
# This file is part of the JUCE framework examples.
# Copyright (c) Raw Material Software Limited
#
# The code included in this file is provided under the terms of the ISC license
# http://www.isc.org/downloads/software-support-policy/isc-license. Permission
# to use, copy, modify, and/or distribute this software for any purpose with or
# without fee is hereby granted provided that the above copyright notice and
# this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
#
# ==============================================================================
_juce_add_pips()
@@ -0,0 +1,207 @@
/*
==============================================================================
This file is part of the JUCE framework examples.
Copyright (c) Raw Material Software Limited
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
to use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
==============================================================================
*/
/*******************************************************************************
The block below describes the properties of this PIP. A PIP is a short snippet
of code that can be read by the Projucer and used to generate a JUCE project.
BEGIN_JUCE_PIP_METADATA
name: ConvolutionDemo
version: 1.0.0
vendor: JUCE
website: http://juce.com
description: Convolution demo using the DSP module.
dependencies: juce_audio_basics, juce_audio_devices, juce_audio_formats,
juce_audio_processors, juce_audio_utils, juce_core,
juce_data_structures, juce_dsp, juce_events, juce_graphics,
juce_gui_basics, juce_gui_extra
exporters: xcode_mac, vs2022, linux_make
moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1
type: Component
mainClass: ConvolutionDemo
useLocalCopy: 1
END_JUCE_PIP_METADATA
*******************************************************************************/
#pragma once
#include "../Assets/DemoUtilities.h"
#include "../Assets/DSPDemos_Common.h"
using namespace dsp;
//==============================================================================
struct ConvolutionDemoDSP
{
void prepare (const ProcessSpec& spec)
{
sampleRate = spec.sampleRate;
convolution.prepare (spec);
updateParameters();
}
void process (ProcessContextReplacing<float> context)
{
context.isBypassed = bypass;
// Load a new IR if there's one available. Note that this doesn't lock or allocate!
bufferTransfer.get ([this] (BufferWithSampleRate& buf)
{
convolution.loadImpulseResponse (std::move (buf.buffer),
buf.sampleRate,
Convolution::Stereo::yes,
Convolution::Trim::yes,
Convolution::Normalise::yes);
});
convolution.process (context);
}
void reset()
{
convolution.reset();
}
void updateParameters()
{
auto* cabinetTypeParameter = dynamic_cast<ChoiceParameter*> (parameters[0]);
if (cabinetTypeParameter == nullptr)
{
jassertfalse;
return;
}
if (cabinetTypeParameter->getCurrentSelectedID() == 1)
{
bypass = true;
}
else
{
bypass = false;
auto selectedType = cabinetTypeParameter->getCurrentSelectedID();
auto assetName = (selectedType == 2 ? "guitar_amp.wav" : "cassette_recorder.wav");
auto assetInputStream = createAssetInputStream (assetName);
if (assetInputStream == nullptr)
{
jassertfalse;
return;
}
AudioFormatManager manager;
manager.registerBasicFormats();
std::unique_ptr<AudioFormatReader> reader { manager.createReaderFor (std::move (assetInputStream)) };
if (reader == nullptr)
{
jassertfalse;
return;
}
AudioBuffer<float> buffer (static_cast<int> (reader->numChannels),
static_cast<int> (reader->lengthInSamples));
reader->read (buffer.getArrayOfWritePointers(), buffer.getNumChannels(), 0, buffer.getNumSamples());
bufferTransfer.set (BufferWithSampleRate { std::move (buffer), reader->sampleRate });
}
}
//==============================================================================
struct BufferWithSampleRate
{
BufferWithSampleRate() = default;
BufferWithSampleRate (AudioBuffer<float>&& bufferIn, double sampleRateIn)
: buffer (std::move (bufferIn)), sampleRate (sampleRateIn) {}
AudioBuffer<float> buffer;
double sampleRate = 0.0;
};
class BufferTransfer
{
public:
void set (BufferWithSampleRate&& p)
{
const SpinLock::ScopedLockType lock (mutex);
buffer = std::move (p);
newBuffer = true;
}
// Call `fn` passing the new buffer, if there's one available
template <typename Fn>
void get (Fn&& fn)
{
const SpinLock::ScopedTryLockType lock (mutex);
if (lock.isLocked() && newBuffer)
{
fn (buffer);
newBuffer = false;
}
}
private:
BufferWithSampleRate buffer;
bool newBuffer = false;
SpinLock mutex;
};
double sampleRate = 0.0;
bool bypass = false;
MemoryBlock currentCabinetData;
Convolution convolution;
BufferTransfer bufferTransfer;
ChoiceParameter cabinetParam { { "Bypass", "Guitar amplifier 8''", "Cassette recorder" }, 1, "Cabinet Type" };
std::vector<DSPDemoParameterBase*> parameters { &cabinetParam };
};
struct ConvolutionDemo final : public Component
{
ConvolutionDemo()
{
addAndMakeVisible (fileReaderComponent);
setSize (750, 500);
}
void resized() override
{
fileReaderComponent.setBounds (getLocalBounds());
}
AudioFileReaderComponent<ConvolutionDemoDSP> fileReaderComponent;
};
@@ -0,0 +1,119 @@
/*
==============================================================================
This file is part of the JUCE framework examples.
Copyright (c) Raw Material Software Limited
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
to use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
==============================================================================
*/
/*******************************************************************************
The block below describes the properties of this PIP. A PIP is a short snippet
of code that can be read by the Projucer and used to generate a JUCE project.
BEGIN_JUCE_PIP_METADATA
name: FIRFilterDemo
version: 1.0.0
vendor: JUCE
website: http://juce.com
description: FIR filter demo using the DSP module.
dependencies: juce_audio_basics, juce_audio_devices, juce_audio_formats,
juce_audio_processors, juce_audio_utils, juce_core,
juce_data_structures, juce_dsp, juce_events, juce_graphics,
juce_gui_basics, juce_gui_extra
exporters: xcode_mac, vs2022, linux_make
moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1
type: Component
mainClass: FIRFilterDemo
useLocalCopy: 1
END_JUCE_PIP_METADATA
*******************************************************************************/
#pragma once
#include "../Assets/DemoUtilities.h"
#include "../Assets/DSPDemos_Common.h"
using namespace dsp;
//==============================================================================
struct FIRFilterDemoDSP
{
void prepare (const ProcessSpec& spec)
{
sampleRate = spec.sampleRate;
fir.state = FilterDesign<float>::designFIRLowpassWindowMethod (440.0f, sampleRate, 21,
WindowingFunction<float>::blackman);
fir.prepare (spec);
}
void process (const ProcessContextReplacing<float>& context)
{
fir.process (context);
}
void reset()
{
fir.reset();
}
void updateParameters()
{
if (! approximatelyEqual (sampleRate, 0.0))
{
auto cutoff = static_cast<float> (cutoffParam.getCurrentValue());
auto windowingMethod = static_cast<WindowingFunction<float>::WindowingMethod> (typeParam.getCurrentSelectedID() - 1);
*fir.state = *FilterDesign<float>::designFIRLowpassWindowMethod (cutoff, sampleRate, 21, windowingMethod);
}
}
//==============================================================================
ProcessorDuplicator<FIR::Filter<float>, FIR::Coefficients<float>> fir;
double sampleRate = 0.0;
SliderParameter cutoffParam { { 20.0, 20000.0 }, 0.4, 440.0f, "Cutoff", "Hz" };
ChoiceParameter typeParam { { "Rectangular", "Triangular", "Hann", "Hamming", "Blackman", "Blackman-Harris", "Flat Top", "Kaiser" },
5, "Windowing Function" };
std::vector<DSPDemoParameterBase*> parameters { &cutoffParam, &typeParam };
};
struct FIRFilterDemo final : public Component
{
FIRFilterDemo()
{
addAndMakeVisible (fileReaderComponent);
setSize (750, 500);
}
void resized() override
{
fileReaderComponent.setBounds (getLocalBounds());
}
AudioFileReaderComponent<FIRFilterDemoDSP> fileReaderComponent;
};
+104
View File
@@ -0,0 +1,104 @@
/*
==============================================================================
This file is part of the JUCE framework examples.
Copyright (c) Raw Material Software Limited
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
to use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
==============================================================================
*/
/*******************************************************************************
The block below describes the properties of this PIP. A PIP is a short snippet
of code that can be read by the Projucer and used to generate a JUCE project.
BEGIN_JUCE_PIP_METADATA
name: GainDemo
version: 1.0.0
vendor: JUCE
website: http://juce.com
description: Gain demo using the DSP module.
dependencies: juce_audio_basics, juce_audio_devices, juce_audio_formats,
juce_audio_processors, juce_audio_utils, juce_core,
juce_data_structures, juce_dsp, juce_events, juce_graphics,
juce_gui_basics, juce_gui_extra
exporters: xcode_mac, vs2022, linux_make
moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1
type: Component
mainClass: GainDemo
useLocalCopy: 1
END_JUCE_PIP_METADATA
*******************************************************************************/
#pragma once
#include "../Assets/DemoUtilities.h"
#include "../Assets/DSPDemos_Common.h"
using namespace dsp;
//==============================================================================
struct GainDemoDSP
{
void prepare (const ProcessSpec&)
{
gain.setGainDecibels (-6.0f);
}
void process (const ProcessContextReplacing<float>& context)
{
gain.process (context);
}
void reset()
{
gain.reset();
}
void updateParameters()
{
gain.setGainDecibels (static_cast<float> (gainParam.getCurrentValue()));
}
//==============================================================================
Gain<float> gain;
SliderParameter gainParam { { -100.0, 20.0 }, 3.0, -6.0, "Gain", "dB" };
std::vector<DSPDemoParameterBase*> parameters { &gainParam };
};
struct GainDemo final : public Component
{
GainDemo()
{
addAndMakeVisible (fileReaderComponent);
setSize (750, 500);
}
void resized() override
{
fileReaderComponent.setBounds (getLocalBounds());
}
AudioFileReaderComponent<GainDemoDSP> fileReaderComponent;
};
@@ -0,0 +1,123 @@
/*
==============================================================================
This file is part of the JUCE framework examples.
Copyright (c) Raw Material Software Limited
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
to use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
==============================================================================
*/
/*******************************************************************************
The block below describes the properties of this PIP. A PIP is a short snippet
of code that can be read by the Projucer and used to generate a JUCE project.
BEGIN_JUCE_PIP_METADATA
name: IIRFilterDemo
version: 1.0.0
vendor: JUCE
website: http://juce.com
description: IIR filter demo using the DSP module.
dependencies: juce_audio_basics, juce_audio_devices, juce_audio_formats,
juce_audio_processors, juce_audio_utils, juce_core,
juce_data_structures, juce_dsp, juce_events, juce_graphics,
juce_gui_basics, juce_gui_extra
exporters: xcode_mac, vs2022, linux_make
moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1
type: Component
mainClass: IIRFilterDemo
useLocalCopy: 1
END_JUCE_PIP_METADATA
*******************************************************************************/
#pragma once
#include "../Assets/DemoUtilities.h"
#include "../Assets/DSPDemos_Common.h"
using namespace dsp;
//==============================================================================
struct IIRFilterDemoDSP
{
void prepare (const ProcessSpec& spec)
{
sampleRate = spec.sampleRate;
iir.state = IIR::Coefficients<float>::makeLowPass (sampleRate, 440.0);
iir.prepare (spec);
}
void process (const ProcessContextReplacing<float>& context)
{
iir.process (context);
}
void reset()
{
iir.reset();
}
void updateParameters()
{
if (! approximatelyEqual (sampleRate, 0.0))
{
auto cutoff = static_cast<float> (cutoffParam.getCurrentValue());
auto qVal = static_cast<float> (qParam.getCurrentValue());
switch (typeParam.getCurrentSelectedID())
{
case 1: *iir.state = IIR::ArrayCoefficients<float>::makeLowPass (sampleRate, cutoff, qVal); break;
case 2: *iir.state = IIR::ArrayCoefficients<float>::makeHighPass (sampleRate, cutoff, qVal); break;
case 3: *iir.state = IIR::ArrayCoefficients<float>::makeBandPass (sampleRate, cutoff, qVal); break;
default: break;
}
}
}
//==============================================================================
ProcessorDuplicator<IIR::Filter<float>, IIR::Coefficients<float>> iir;
ChoiceParameter typeParam { { "Low-pass", "High-pass", "Band-pass" }, 1, "Type" };
SliderParameter cutoffParam { { 20.0, 20000.0 }, 0.5, 440.0f, "Cutoff", "Hz" };
SliderParameter qParam { { 0.3, 20.0 }, 0.5, 1.0 / std::sqrt (2.0), "Q" };
std::vector<DSPDemoParameterBase*> parameters { &typeParam, &cutoffParam, &qParam };
double sampleRate = 0.0;
};
struct IIRFilterDemo final : public Component
{
IIRFilterDemo()
{
addAndMakeVisible (fileReaderComponent);
setSize (750, 500);
}
void resized() override
{
fileReaderComponent.setBounds (getLocalBounds());
}
AudioFileReaderComponent<IIRFilterDemoDSP> fileReaderComponent;
};
@@ -0,0 +1,155 @@
/*
==============================================================================
This file is part of the JUCE framework examples.
Copyright (c) Raw Material Software Limited
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
to use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
==============================================================================
*/
/*******************************************************************************
The block below describes the properties of this PIP. A PIP is a short snippet
of code that can be read by the Projucer and used to generate a JUCE project.
BEGIN_JUCE_PIP_METADATA
name: OscillatorDemo
version: 1.0.0
vendor: JUCE
website: http://juce.com
description: Oscillator demo using the DSP module.
dependencies: juce_audio_basics, juce_audio_devices, juce_audio_formats,
juce_audio_processors, juce_audio_utils, juce_core,
juce_data_structures, juce_dsp, juce_events, juce_graphics,
juce_gui_basics, juce_gui_extra
exporters: xcode_mac, vs2022, linux_make
moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1
type: Component
mainClass: OscillatorDemo
useLocalCopy: 1
END_JUCE_PIP_METADATA
*******************************************************************************/
#pragma once
#include "../Assets/DemoUtilities.h"
#include "../Assets/DSPDemos_Common.h"
using namespace dsp;
//==============================================================================
struct OscillatorDemoDSP
{
void prepare (const ProcessSpec& spec)
{
gain.setGainDecibels (-6.0f);
for (auto&& oscillator : oscillators)
{
oscillator.setFrequency (440.f);
oscillator.prepare (spec);
}
updateParameters();
tempBuffer = AudioBlock<float> (tempBufferMemory, spec.numChannels, spec.maximumBlockSize);
}
void process (const ProcessContextReplacing<float>& context)
{
tempBuffer.copyFrom (context.getInputBlock());
tempBuffer.multiplyBy (static_cast<float> (fileMix));
oscillators[currentOscillatorIdx].process (context);
context.getOutputBlock().multiplyBy (static_cast<float> (1.0 - fileMix));
context.getOutputBlock().add (tempBuffer);
gain.process (context);
}
void reset()
{
oscillators[currentOscillatorIdx].reset();
}
void updateParameters()
{
currentOscillatorIdx = jmin (numElementsInArray (oscillators),
3 * (accuracy.getCurrentSelectedID() - 1) + (typeParam.getCurrentSelectedID() - 1));
auto freq = static_cast<float> (freqParam.getCurrentValue());
for (auto&& oscillator : oscillators)
oscillator.setFrequency (freq);
gain.setGainDecibels (static_cast<float> (gainParam.getCurrentValue()));
fileMix = mixParam.getCurrentValue();
}
//==============================================================================
Oscillator<float> oscillators[6] =
{
// No Approximation
{[] (float x) { return std::sin (x); }}, // sine
{[] (float x) { return x / MathConstants<float>::pi; }}, // saw
{[] (float x) { return x < 0.0f ? -1.0f : 1.0f; }}, // square
// Approximated by a wave-table
{[] (float x) { return std::sin (x); }, 100}, // sine
{[] (float x) { return x / MathConstants<float>::pi; }, 100}, // saw
{[] (float x) { return x < 0.0f ? -1.0f : 1.0f; }, 100} // square
};
int currentOscillatorIdx = 0;
Gain<float> gain;
ChoiceParameter typeParam { {"sine", "saw", "square"}, 1, "Type" };
ChoiceParameter accuracy { {"No Approximation", "Use Wavetable"}, 1, "Accuracy" };
SliderParameter freqParam { { 20.0, 24000.0 }, 0.4, 440.0, "Frequency", "Hz" };
SliderParameter gainParam { { -100.0, 20.0 }, 3.0, -20.0, "Gain", "dB" };
SliderParameter mixParam { { 0.0, 1.0 }, 1.0, 0.0, "File mix" };
HeapBlock<char> tempBufferMemory;
AudioBlock<float> tempBuffer;
double fileMix;
std::vector<DSPDemoParameterBase*> parameters { &typeParam, &accuracy, &freqParam, &gainParam, &mixParam };
};
struct OscillatorDemo final : public Component
{
OscillatorDemo()
{
addAndMakeVisible (fileReaderComponent);
setSize (750, 500);
}
void resized() override
{
fileReaderComponent.setBounds (getLocalBounds());
}
AudioFileReaderComponent<OscillatorDemoDSP> fileReaderComponent;
};
@@ -0,0 +1,134 @@
/*
==============================================================================
This file is part of the JUCE framework examples.
Copyright (c) Raw Material Software Limited
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
to use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
==============================================================================
*/
/*******************************************************************************
The block below describes the properties of this PIP. A PIP is a short snippet
of code that can be read by the Projucer and used to generate a JUCE project.
BEGIN_JUCE_PIP_METADATA
name: OverdriveDemo
version: 1.0.0
vendor: JUCE
website: http://juce.com
description: Overdrive demo using the DSP module.
dependencies: juce_audio_basics, juce_audio_devices, juce_audio_formats,
juce_audio_processors, juce_audio_utils, juce_core,
juce_data_structures, juce_dsp, juce_events, juce_graphics,
juce_gui_basics, juce_gui_extra
exporters: xcode_mac, vs2022, linux_make
moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1
type: Component
mainClass: OverdriveDemo
useLocalCopy: 1
END_JUCE_PIP_METADATA
*******************************************************************************/
#pragma once
#include "../Assets/DemoUtilities.h"
#include "../Assets/DSPDemos_Common.h"
using namespace dsp;
//==============================================================================
struct OverdriveDemoDSP
{
void prepare (const ProcessSpec& spec)
{
sampleRate = spec.sampleRate;
auto& gainUp = overdrive.get<0>();
gainUp.setGainDecibels (24);
auto& bias = overdrive.get<1>();
bias.setBias (0.4f);
auto& wavShaper = overdrive.get<2>();
wavShaper.functionToUse = std::tanh;
auto& dcFilter = overdrive.get<3>();
dcFilter.state = IIR::Coefficients<float>::makeHighPass (sampleRate, 5.0);
auto& gainDown = overdrive.get<4>();
gainDown.setGainDecibels (-18.0f);
overdrive.prepare (spec);
}
void process (const ProcessContextReplacing<float>& context)
{
overdrive.process (context);
}
void reset()
{
overdrive.reset();
}
void updateParameters()
{
if (! approximatelyEqual (sampleRate, 0.0))
{
overdrive.get<0>().setGainDecibels (static_cast<float> (inGainParam.getCurrentValue()));
overdrive.get<4>().setGainDecibels (static_cast<float> (outGainParam.getCurrentValue()));
}
}
//==============================================================================
using GainProcessor = Gain<float>;
using BiasProcessor = Bias<float>;
using DriveProcessor = WaveShaper<float>;
using DCFilter = ProcessorDuplicator<IIR::Filter<float>,
IIR::Coefficients<float>>;
ProcessorChain<GainProcessor, BiasProcessor, DriveProcessor, DCFilter, GainProcessor> overdrive;
SliderParameter inGainParam { { -100.0, 60.0 }, 3, 24.0, "Input Gain", "dB" };
SliderParameter outGainParam { { -100.0, 20.0 }, 3, -18.0, "Output Gain", "dB" };
std::vector<DSPDemoParameterBase*> parameters { &inGainParam, &outGainParam };
double sampleRate = 0.0;
};
struct OverdriveDemo final : public Component
{
OverdriveDemo()
{
addAndMakeVisible (fileReaderComponent);
setSize (750, 500);
}
void resized() override
{
fileReaderComponent.setBounds (getLocalBounds());
}
AudioFileReaderComponent<OverdriveDemoDSP> fileReaderComponent;
};
@@ -0,0 +1,177 @@
/*
==============================================================================
This file is part of the JUCE framework examples.
Copyright (c) Raw Material Software Limited
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
to use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
==============================================================================
*/
/*******************************************************************************
The block below describes the properties of this PIP. A PIP is a short snippet
of code that can be read by the Projucer and used to generate a JUCE project.
BEGIN_JUCE_PIP_METADATA
name: SIMDRegisterDemo
version: 1.0.0
vendor: JUCE
website: http://juce.com
description: SIMD register demo using the DSP module.
dependencies: juce_audio_basics, juce_audio_devices, juce_audio_formats,
juce_audio_processors, juce_audio_utils, juce_core,
juce_data_structures, juce_dsp, juce_events, juce_graphics,
juce_gui_basics, juce_gui_extra
exporters: xcode_mac, vs2022, linux_make
moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1
type: Component
mainClass: SIMDRegisterDemo
useLocalCopy: 1
END_JUCE_PIP_METADATA
*******************************************************************************/
#pragma once
#include "../Assets/DemoUtilities.h"
#include "../Assets/DSPDemos_Common.h"
using namespace dsp;
template <typename T>
static T* toBasePointer (SIMDRegister<T>* r) noexcept
{
return reinterpret_cast<T*> (r);
}
constexpr auto registerSize = dsp::SIMDRegister<float>::size();
//==============================================================================
struct SIMDRegisterDemoDSP
{
void prepare (const ProcessSpec& spec)
{
sampleRate = spec.sampleRate;
iirCoefficients = IIR::Coefficients<float>::makeLowPass (sampleRate, 440.0f);
iir.reset (new IIR::Filter<SIMDRegister<float>> (iirCoefficients));
interleaved = AudioBlock<SIMDRegister<float>> (interleavedBlockData, 1, spec.maximumBlockSize);
zero = AudioBlock<float> (zeroData, SIMDRegister<float>::size(), spec.maximumBlockSize);
zero.clear();
auto monoSpec = spec;
monoSpec.numChannels = 1;
iir->prepare (monoSpec);
}
template <typename SampleType>
auto prepareChannelPointers (const AudioBlock<SampleType>& block)
{
std::array<SampleType*, registerSize> result {};
for (size_t ch = 0; ch < result.size(); ++ch)
result[ch] = (ch < block.getNumChannels() ? block.getChannelPointer (ch) : zero.getChannelPointer (ch));
return result;
}
void process (const ProcessContextReplacing<float>& context)
{
jassert (context.getInputBlock().getNumSamples() == context.getOutputBlock().getNumSamples());
jassert (context.getInputBlock().getNumChannels() == context.getOutputBlock().getNumChannels());
const auto& input = context.getInputBlock();
const auto numSamples = (int) input.getNumSamples();
auto inChannels = prepareChannelPointers (input);
using Format = AudioData::Format<AudioData::Float32, AudioData::NativeEndian>;
AudioData::interleaveSamples (AudioData::NonInterleavedSource<Format> { inChannels.data(), registerSize, },
AudioData::InterleavedDest<Format> { toBasePointer (interleaved.getChannelPointer (0)), registerSize },
numSamples);
iir->process (ProcessContextReplacing<SIMDRegister<float>> (interleaved));
auto outChannels = prepareChannelPointers (context.getOutputBlock());
AudioData::deinterleaveSamples (AudioData::InterleavedSource<Format> { toBasePointer (interleaved.getChannelPointer (0)), registerSize },
AudioData::NonInterleavedDest<Format> { outChannels.data(), registerSize },
numSamples);
}
void reset()
{
iir.reset();
}
void updateParameters()
{
if (! approximatelyEqual (sampleRate, 0.0))
{
auto cutoff = static_cast<float> (cutoffParam.getCurrentValue());
auto qVal = static_cast<float> (qParam.getCurrentValue());
switch (typeParam.getCurrentSelectedID())
{
case 1: *iirCoefficients = IIR::ArrayCoefficients<float>::makeLowPass (sampleRate, cutoff, qVal); break;
case 2: *iirCoefficients = IIR::ArrayCoefficients<float>::makeHighPass (sampleRate, cutoff, qVal); break;
case 3: *iirCoefficients = IIR::ArrayCoefficients<float>::makeBandPass (sampleRate, cutoff, qVal); break;
default: break;
}
}
}
//==============================================================================
IIR::Coefficients<float>::Ptr iirCoefficients;
std::unique_ptr<IIR::Filter<SIMDRegister<float>>> iir;
AudioBlock<SIMDRegister<float>> interleaved;
AudioBlock<float> zero;
HeapBlock<char> interleavedBlockData, zeroData;
ChoiceParameter typeParam { { "Low-pass", "High-pass", "Band-pass" }, 1, "Type" };
SliderParameter cutoffParam { { 20.0, 20000.0 }, 0.5, 440.0f, "Cutoff", "Hz" };
SliderParameter qParam { { 0.3, 20.0 }, 0.5, 0.7, "Q" };
std::vector<DSPDemoParameterBase*> parameters { &typeParam, &cutoffParam, &qParam };
double sampleRate = 0.0;
};
struct SIMDRegisterDemo final : public Component
{
SIMDRegisterDemo()
{
addAndMakeVisible (fileReaderComponent);
setSize (750, 500);
}
void resized() override
{
fileReaderComponent.setBounds (getLocalBounds());
}
AudioFileReaderComponent<SIMDRegisterDemoDSP> fileReaderComponent;
};
@@ -0,0 +1,121 @@
/*
==============================================================================
This file is part of the JUCE framework examples.
Copyright (c) Raw Material Software Limited
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
to use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
==============================================================================
*/
/*******************************************************************************
The block below describes the properties of this PIP. A PIP is a short snippet
of code that can be read by the Projucer and used to generate a JUCE project.
BEGIN_JUCE_PIP_METADATA
name: StateVariableFilterDemo
version: 1.0.0
vendor: JUCE
website: http://juce.com
description: State variable filter demo using the DSP module.
dependencies: juce_audio_basics, juce_audio_devices, juce_audio_formats,
juce_audio_processors, juce_audio_utils, juce_core,
juce_data_structures, juce_dsp, juce_events, juce_graphics,
juce_gui_basics, juce_gui_extra
exporters: xcode_mac, vs2022, linux_make
moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1
type: Component
mainClass: StateVariableFilterDemo
useLocalCopy: 1
END_JUCE_PIP_METADATA
*******************************************************************************/
#pragma once
#include "../Assets/DemoUtilities.h"
#include "../Assets/DSPDemos_Common.h"
using namespace dsp;
//==============================================================================
struct StateVariableFilterDemoDSP
{
void prepare (const ProcessSpec& spec)
{
sampleRate = spec.sampleRate;
filter.prepare (spec);
}
void process (const ProcessContextReplacing<float>& context)
{
filter.process (context);
}
void reset()
{
filter.reset();
}
void updateParameters()
{
if (! approximatelyEqual (sampleRate, 0.0))
{
filter.setCutoffFrequency (static_cast<float> (cutoffParam.getCurrentValue()));
filter.setResonance (static_cast<float> (qParam.getCurrentValue()));
switch (typeParam.getCurrentSelectedID() - 1)
{
case 0: filter.setType (StateVariableTPTFilterType::lowpass); break;
case 1: filter.setType (StateVariableTPTFilterType::bandpass); break;
case 2: filter.setType (StateVariableTPTFilterType::highpass); break;
default: jassertfalse; break;
};
}
}
//==============================================================================
StateVariableTPTFilter<float> filter;
ChoiceParameter typeParam {{ "Low-pass", "Band-pass", "High-pass" }, 1, "Type" };
SliderParameter cutoffParam {{ 20.0, 20000.0 }, 0.5, 440.0f, "Cutoff", "Hz" };
SliderParameter qParam {{ 0.3, 20.0 }, 0.5, 1.0 / MathConstants<double>::sqrt2, "Resonance" };
std::vector<DSPDemoParameterBase*> parameters { &typeParam, &cutoffParam, &qParam };
double sampleRate = 0.0;
};
struct StateVariableFilterDemo final : public Component
{
StateVariableFilterDemo()
{
addAndMakeVisible (fileReaderComponent);
setSize (750, 500);
}
void resized() override
{
fileReaderComponent.setBounds (getLocalBounds());
}
AudioFileReaderComponent<StateVariableFilterDemoDSP> fileReaderComponent;
};
@@ -0,0 +1,103 @@
/*
==============================================================================
This file is part of the JUCE framework examples.
Copyright (c) Raw Material Software Limited
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
to use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
==============================================================================
*/
/*******************************************************************************
The block below describes the properties of this PIP. A PIP is a short snippet
of code that can be read by the Projucer and used to generate a JUCE project.
BEGIN_JUCE_PIP_METADATA
name: WaveShaperTanhDemo
version: 1.0.0
vendor: JUCE
website: http://juce.com
description: Wave shaper tanh demo using the DSP module.
dependencies: juce_audio_basics, juce_audio_devices, juce_audio_formats,
juce_audio_processors, juce_audio_utils, juce_core,
juce_data_structures, juce_dsp, juce_events, juce_graphics,
juce_gui_basics, juce_gui_extra
exporters: xcode_mac, vs2022, linux_make
moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1
type: Component
mainClass: WaveShaperTanhDemo
useLocalCopy: 1
END_JUCE_PIP_METADATA
*******************************************************************************/
#pragma once
#include "../Assets/DemoUtilities.h"
#include "../Assets/DSPDemos_Common.h"
using namespace dsp;
//==============================================================================
struct WaveShaperTanhDemoDSP
{
void prepare (const ProcessSpec&) {}
void process (const ProcessContextReplacing<float>& context)
{
shapers[currentShaperIdx].process (context);
}
void reset()
{
for (auto&& shaper : shapers)
shaper.reset();
}
void updateParameters()
{
currentShaperIdx = jmin (numElementsInArray (shapers), accuracy.getCurrentSelectedID() - 1);
}
//==============================================================================
WaveShaper<float> shapers[2] { { std::tanh }, { FastMathApproximations::tanh } };
int currentShaperIdx = 0;
ChoiceParameter accuracy {{ "No Approximation", "Use fast-math approximation" }, 1, "Accuracy" };
std::vector<DSPDemoParameterBase*> parameters { &accuracy }; // no params for this demo
};
struct WaveShaperTanhDemo final : public Component
{
WaveShaperTanhDemo()
{
addAndMakeVisible (fileReaderComponent);
setSize (750, 500);
}
void resized() override
{
fileReaderComponent.setBounds (getLocalBounds());
}
AudioFileReaderComponent<WaveShaperTanhDemoDSP> fileReaderComponent;
};