NeuralPi

Raspberry Pi guitar pedal using neural networks to emulate real amps and effects
Log | Files | Refs | Submodules | README

commit db8f783fe0c4bb49998b66f0a257ddbb860c6434
parent ba22a1521585974dbb64bb44628e3f5ba4e46213
Author: keith <[email protected]>
Date:   Sun, 11 Jul 2021 06:19:38 -0500

Initial IR loading from example

Diffstat:
MNeuralPi.jucer | 1+
ASource/CabSim.h | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MSource/PluginProcessor.cpp | 10++++++++--
MSource/PluginProcessor.h | 11++++-------
Aresources/cassette_recorder.wav | 0
Aresources/guitar_amp.wav | 0
6 files changed, 80 insertions(+), 9 deletions(-)

diff --git a/NeuralPi.jucer b/NeuralPi.jucer @@ -16,6 +16,7 @@ <GROUP id="{70CE292C-E9C5-C029-B95A-F7DF41E5F74C}" name="Source"> <FILE id="VgCJPH" name="AmpOSCReceiver.h" compile="0" resource="0" file="Source/AmpOSCReceiver.h"/> + <FILE id="HvJFu8" name="CabSim.h" compile="0" resource="0" file="Source/CabSim.h"/> <FILE id="s1HQuK" name="Eq4Band.cpp" compile="1" resource="0" file="Source/Eq4Band.cpp"/> <FILE id="xtLEtv" name="Eq4Band.h" compile="0" resource="0" file="Source/Eq4Band.h"/> <FILE id="hNjQV9" name="PluginEditor.cpp" compile="1" resource="0" diff --git a/Source/CabSim.h b/Source/CabSim.h @@ -0,0 +1,66 @@ +/* + ============================================================================== + + CabSim + + ============================================================================== +*/ +#include "../JuceLibraryCode/JuceHeader.h" + +#pragma once + + +//============================================================================== +//template <typename Type> +class CabSim +{ +public: + //============================================================================== + CabSim() + { + auto dir = juce::File::getCurrentWorkingDirectory(); + //auto dir = juce::File("C:\\Users\\rache\\Desktop\\dev\\NeuralPi\\resources"); + int numTries = 0; + + while (! dir.getChildFile ("resources").exists() && numTries++ < 15) + dir = dir.getParentDirectory(); + + auto& convolution = processorChain.template get<convolutionIndex>(); + //convolution.loadImpulseResponse(dir.getChildFile("cassette_recorder.wav"), + convolution.loadImpulseResponse(dir.getChildFile("resources").getChildFile("guitar_amp.wav"), + juce::dsp::Convolution::Stereo::yes, + juce::dsp::Convolution::Trim::no, + 1024); + } + + //============================================================================== + void prepare (const juce::dsp::ProcessSpec& spec) + { + //juce::ignoreUnused (spec); + processorChain.prepare(spec); + } + + //============================================================================== + template <typename ProcessContext> + void process(const ProcessContext& context) noexcept + { + processorChain.process(context); + } + + //============================================================================== + void reset() noexcept + { + processorChain.reset(); + } + +private: + //============================================================================== + enum + { + convolutionIndex + }; + + juce::dsp::ProcessorChain<juce::dsp::Convolution> processorChain; + + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CabSim) +}; +\ No newline at end of file diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp @@ -125,6 +125,9 @@ void NeuralPiAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlo dcBlocker.coefficients = dsp::IIR::Coefficients<float>::makeHighPass(sampleRate, 35.0f); dsp::ProcessSpec spec{ sampleRate, static_cast<uint32> (samplesPerBlock), 2 }; dcBlocker.prepare(spec); + + // Set up IR + cabSimIR.prepare(spec); } void NeuralPiAudioProcessor::releaseResources() @@ -193,6 +196,11 @@ void NeuralPiAudioProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffe LSTM.process(buffer.getReadPointer(0), buffer.getWritePointer(0), numSamples); } + // Process IR + auto block = dsp::AudioBlock<float>(buffer).getSingleChannelBlock(0); + auto context = juce::dsp::ProcessContextReplacing<float>(block); + cabSimIR.process(context); + // Master Volume buffer.applyGain(master); } @@ -245,8 +253,6 @@ void NeuralPiAudioProcessor::setStateInformation(const void* data, int sizeInByt int NeuralPiAudioProcessor::getModelIndex(float model_param) { - //return static_cast<int>(model_param * (jsonFiles.size() - 1.0)); - //return static_cast<int>(model_param * (num_models - 1.0)); int a = static_cast<int>(round(model_param * (num_models - 1.0))); if (a > num_models - 1) { a = num_models - 1; diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h @@ -12,6 +12,7 @@ #include "RTNeuralLSTM.h" #include "AmpOSCReceiver.h" #include "Eq4Band.h" +#include "CabSim.h" #pragma once @@ -83,15 +84,8 @@ public: void set_ampEQ(float bass_slider, float mid_slider, float treble_slider, float presence_slider); - // Overdrive Pedal float convertLogScale(float in_value, float x_min, float x_max, float y_min, float y_max); - // Amp - /* - void set_ampDrive(float db_ampCleanDrive); - void set_ampMaster(float db_ampMaster); - void set_ampEQ(float bass_slider, float mid_slider, float treble_slider, float presence_slider); - */ float decibelToLinear(float dbValue); void addDirectory(const File& file); @@ -128,6 +122,9 @@ private: dsp::IIR::Filter<float> dcBlocker; + // IR processing + CabSim cabSimIR; + //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NeuralPiAudioProcessor) }; diff --git a/resources/cassette_recorder.wav b/resources/cassette_recorder.wav Binary files differ. diff --git a/resources/guitar_amp.wav b/resources/guitar_amp.wav Binary files differ.