NeuralPi

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

commit e72f44ab35e519fbe2b9980e91156a56e7d3c826
parent edc96dd9b90aa44e1e4bb9e66b50c8a651da823f
Author: keith <[email protected]>
Date:   Tue,  1 Jun 2021 19:27:31 -0500

Changed model param to int, cleaned up comments

Diffstat:
MSource/AmpOSCReceiver.h | 23+++++++++++++++--------
MSource/PluginEditor.cpp | 43+++++++++++++------------------------------
MSource/PluginEditor.h | 8+-------
MSource/PluginProcessor.cpp | 43++++++-------------------------------------
MSource/PluginProcessor.h | 13+------------
5 files changed, 36 insertions(+), 94 deletions(-)

diff --git a/Source/AmpOSCReceiver.h b/Source/AmpOSCReceiver.h @@ -62,25 +62,32 @@ private: modelAddressPattern = "/parameter/" + ampName + "/Model"; } - void oscMessageReceived (const OSCMessage& message) override + void oscMessageReceived(const OSCMessage& message) override { - DBG ("Message Received: "); + DBG("Message Received: "); if (message.size() == 1 && message[0].isFloat32()) { - DBG (" value " + String (message[0].getFloat32()) + " to AP " + message.getAddressPattern().toString()); + DBG(" value " + String(message[0].getFloat32()) + " to AP " + message.getAddressPattern().toString()); if (message.getAddressPattern().matches(gainAddressPattern)) { - gainValue.setValue (jlimit (-12.0f, 12.0f, message[0].getFloat32())); + gainValue.setValue(jlimit(0.0f, 1.0f, message[0].getFloat32())); } - else if (message.getAddressPattern().matches (masterAddressPattern)) + else if (message.getAddressPattern().matches(masterAddressPattern)) { - masterValue.setValue (jlimit (-48.0f, 0.0f, message[0].getFloat32())); + masterValue.setValue(jlimit(0.0f, 1.0f, message[0].getFloat32())); } - else if (message.getAddressPattern().matches (modelAddressPattern)) + + } + else if (message.size() == 1 && message[0].isInt32()) + { + DBG(" value " + String(message[0].getInt32()) + " to AP " + message.getAddressPattern().toString()); + + if (message.getAddressPattern().matches(modelAddressPattern)) { - modelValue.setValue (jlimit (0.0f, 1.0f, message[0].getFloat32())); + //modelValue.setValue(jlimit(0.0f, 1.0f, message[0].getFloat32())); + modelValue.setValue(message[0].getInt32()); } } } diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp @@ -23,7 +23,6 @@ NeuralPiAudioProcessorEditor::NeuralPiAudioProcessorEditor (NeuralPiAudioProcess // Make sure that before the constructor has finished, you've set the // editor's size to whatever you need it to - //modelSliderAttach = std::make_unique<AudioProcessorValueTreeState::SliderAttachment>(processor.treeState, MODEL_ID, modelKnob); addAndMakeVisible(modelKnob); //ampGainKnob.setLookAndFeel(&ampSilverKnobLAF); modelKnob.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::TextBoxBelow, false, 50, 20); @@ -34,7 +33,7 @@ NeuralPiAudioProcessorEditor::NeuralPiAudioProcessorEditor (NeuralPiAudioProcess modelKnob.setSliderStyle(juce::Slider::SliderStyle::RotaryVerticalDrag); modelKnob.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::NoTextBox, false, 50, 20); modelKnob.setNumDecimalPlacesToDisplay(1); - modelKnob.setDoubleClickReturnValue(true, 0.0); + modelKnob.setDoubleClickReturnValue(true, 0); auto modelValue = getParameterValue(modelName); Slider& modelSlider = getModelSlider(); @@ -42,15 +41,15 @@ NeuralPiAudioProcessorEditor::NeuralPiAudioProcessorEditor (NeuralPiAudioProcess modelKnob.onValueChange = [this] { - const float sliderValue = static_cast<float> (getModelSlider().getValue()); - const float modelValue = getParameterValue(modelName); + const int sliderValue = static_cast<int> (getModelSlider().getValue()); + const int modelValue = getParameterValue(modelName); if (!approximatelyEqual(modelValue, sliderValue)) { setParameterValue(modelName, sliderValue); // create and send an OSC message with an address and a float value: - float value = static_cast<float> (getModelSlider().getValue()); + int value = static_cast<int> (getModelSlider().getValue()); if (!oscSender.send(modelAddressPattern, value)) { @@ -120,7 +119,6 @@ NeuralPiAudioProcessorEditor::NeuralPiAudioProcessorEditor (NeuralPiAudioProcess } }; - //masterSliderAttach = std::make_unique<AudioProcessorValueTreeState::SliderAttachment>(processor.treeState, MASTER_ID, ampMasterKnob); addAndMakeVisible(ampMasterKnob); //ampMasterKnob.setLookAndFeel(&ampSilverKnobLAF); ampMasterKnob.setTextBoxStyle(juce::Slider::TextEntryBoxPosition::TextBoxBelow, false, 50, 20); @@ -211,7 +209,6 @@ NeuralPiAudioProcessorEditor::NeuralPiAudioProcessorEditor (NeuralPiAudioProcess connectSender(); - // Size of plugin GUI setSize(250, 350); @@ -224,13 +221,8 @@ NeuralPiAudioProcessorEditor::~NeuralPiAudioProcessorEditor() //============================================================================== void NeuralPiAudioProcessorEditor::paint (Graphics& g) { - //background = ImageCache::getFromMemory(BinaryData::pedal_blank_png, BinaryData::pedal_blank_pngSize); - - //g.drawImageAt(background, 0, 0); - g.setColour (Colours::white); g.setFont (15.0f); - } void NeuralPiAudioProcessorEditor::resized() @@ -315,26 +307,15 @@ void NeuralPiAudioProcessorEditor::buttonClicked(juce::Button* button) void NeuralPiAudioProcessorEditor::sliderValueChanged(Slider* slider) { - // Amp - /* - if (slider == &ampGainKnob) - processor.set_ampDrive(slider->getValue()); - else if (slider == &ampMasterKnob) - processor.set_ampMaster(slider->getValue()); - */ - //else if (slider == &modelKnob) if (slider->getValue() >= 0 && slider->getValue() < processor.jsonFiles.size()) { //processor.loadConfig(processor.jsonFiles[slider->getValue()]); //processor.current_model_index = modelSelect.getSelectedItemIndex(); modelSelect.setSelectedItemIndex(slider->getValue(), juce::NotificationType::dontSendNotification); - } - - + } } // OSC Messages - Slider& NeuralPiAudioProcessorEditor::getGainSlider() { return ampGainKnob; @@ -431,12 +412,14 @@ void NeuralPiAudioProcessorEditor::labelTextChanged(Label* labelThatHasChanged) const String newIP = getIPField().getTextValue().toString(); updateOutgoingIP(newIP); } - //else if (labelThatHasChanged == getAmpNameField()) - //{ - // ampName = getAmpNameField().getTextValue().toString(); - // buildAddressPatterns(); - // oscReceiver.updateAmpName(getAmpNameField().getTextValue().toString()); - //} + /* + else if (labelThatHasChanged == getAmpNameField()) + { + ampName = getAmpNameField().getTextValue().toString(); + buildAddressPatterns(); + oscReceiver.updateAmpName(getAmpNameField().getTextValue().toString()); + } + */ } void NeuralPiAudioProcessorEditor::updateInConnectedLabel() diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h @@ -100,7 +100,6 @@ private: Label outConnectedLabel{ "(connected)" }; // OSC Messages - Slider& getGainSlider(); Slider& getMasterSlider(); Slider& getModelSlider(); @@ -125,11 +124,6 @@ private: float getParameterValue(const String& paramId); void setParameterValue(const String& paramId, float value); -/* -public: - std::unique_ptr <AudioProcessorValueTreeState::SliderAttachment> gainSliderAttach; - std::unique_ptr <AudioProcessorValueTreeState::SliderAttachment> modelSliderAttach; - std::unique_ptr <AudioProcessorValueTreeState::SliderAttachment> masterSliderAttach; -*/ + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NeuralPiAudioProcessorEditor) }; diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp @@ -23,10 +23,7 @@ NeuralPiAudioProcessor::NeuralPiAudioProcessor() #endif .withOutput("Output", AudioChannelSet::stereo(), true) #endif - )//, - //treeState(*this, nullptr, "PARAMETER", { std::make_unique<AudioParameterFloat>(GAIN_ID, GAIN_NAME, NormalisableRange<float>(-10.0f, 10.0f, 0.01f), 0.0f), - // std::make_unique<AudioParameterFloat>(MODEL_ID, MODEL_NAME, NormalisableRange<float>(0, 1, 1), 0), - // std::make_unique<AudioParameterFloat>(MASTER_ID, MASTER_NAME, NormalisableRange<float>(-36.0f, 0.0f, 0.01f), 0.0f) }) + ) #endif { @@ -39,10 +36,7 @@ NeuralPiAudioProcessor::NeuralPiAudioProcessor() // initialize parameters: addParameter(gainParam = new AudioParameterFloat(GAIN_ID, GAIN_NAME, NormalisableRange<float>(-0.0f, 1.0f, 0.01f), 0.5f)); addParameter(masterParam = new AudioParameterFloat(MASTER_ID, MASTER_NAME, NormalisableRange<float>(0.0f, 1.0f, 0.01f), 0.5f)); - addParameter(modelParam = new AudioParameterFloat(MODEL_ID, MODEL_NAME, NormalisableRange<float>(0, jsonFiles.size()-1, 1), 0)); - - //treeState.createAndAddParameter(std::make_unique<AudioParameterFloat>(MODEL_ID, MODEL_NAME, NormalisableRange<float>(0, jsonFiles.size() - 1, 1), 0)); - + addParameter(modelParam = new AudioParameterInt(MODEL_ID, MODEL_NAME, 0, jsonFiles.size()-1, 0)); } @@ -163,10 +157,8 @@ void NeuralPiAudioProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffe if (amp_state == 1) { auto gain = static_cast<float> (gainParam->get()); auto master = static_cast<float> (masterParam->get()); - auto model = static_cast<float> (modelParam->get()); - int model_index = static_cast<int>(model); - //buffer.applyGain(ampDrive); - //buffer.applyGain(decibelToLinear(gain)); + auto model_index = static_cast<int> (modelParam->get()); + buffer.applyGain(gain); // Apply LSTM model @@ -174,16 +166,12 @@ void NeuralPiAudioProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffe if (current_model_index != model_index) { loadConfig(jsonFiles[model_index]); current_model_index = model_index; - //current_model_index = modelSelect.getSelectedItemIndex(); - //setSelectedItemIndex(slider->getValue(), juce::NotificationType::dontSendNotification); } LSTM.process(buffer.getReadPointer(0), buffer.getWritePointer(0), numSamples); } // Master Volume - //buffer.applyGain(ampMaster); buffer.applyGain(master); - //buffer.applyGain(decibelToLinear(master)); } for (int ch = 1; ch < buffer.getNumChannels(); ++ch) @@ -208,7 +196,7 @@ void NeuralPiAudioProcessor::getStateInformation(MemoryBlock& destData) stream.writeFloat(*gainParam); stream.writeFloat(*masterParam); - stream.writeFloat(*modelParam); + stream.writeInt(*modelParam); } void NeuralPiAudioProcessor::setStateInformation(const void* data, int sizeInBytes) @@ -217,7 +205,7 @@ void NeuralPiAudioProcessor::setStateInformation(const void* data, int sizeInByt gainParam->setValueNotifyingHost(stream.readFloat()); masterParam->setValueNotifyingHost(stream.readFloat()); - modelParam->setValueNotifyingHost(stream.readFloat()); + modelParam->setValueNotifyingHost(stream.readInt()); } void NeuralPiAudioProcessor::loadConfig(File configFile) @@ -292,12 +280,10 @@ void NeuralPiAudioProcessor::installTones() // //==================================================================== { - // Default tones File ts9_tone = userAppDataDirectory_tones.getFullPathName() + "/ts9_model_best.json"; File bjdirty_tone = userAppDataDirectory_tones.getFullPathName() + "/bj_model_best.json"; - if (ts9_tone.existsAsFile() == false) { std::string string_command = ts9_tone.getFullPathName().toStdString(); const char* char_ts9_tone = &string_command[0]; @@ -330,23 +316,6 @@ float NeuralPiAudioProcessor::convertLogScale(float in_value, float x_min, float return converted_value; } -/* -void NeuralPiAudioProcessor::set_ampDrive(float db_ampDrive) -{ - gainParam = decibelToLinear(db_ampDrive); - ampGainKnobState = db_ampDrive; -} - -void NeuralPiAudioProcessor::set_ampMaster(float db_ampMaster) -{ - ampMasterKnobState = db_ampMaster; - if (db_ampMaster == -48.0) { - ampMaster = decibelToLinear(-100.0); - } else { - ampMaster = decibelToLinear(db_ampMaster); - } -} -*/ float NeuralPiAudioProcessor::decibelToLinear(float dbValue) { diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h @@ -96,26 +96,15 @@ public: int model_loaded = 0; int current_model_index = 0; - // Amp knob states - //float ampGainKnobState = 0.0; - //float ampMasterKnobState = -24.0; - RT_LSTM LSTM; - - //AudioProcessorValueTreeState treeState; - private: - // Amp - //float ampDrive = 1.0; - //float ampMaster = 1.0; - var dummyVar; AudioParameterFloat* gainParam; AudioParameterFloat* masterParam; - AudioParameterFloat* modelParam; + AudioParameterInt* modelParam; //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NeuralPiAudioProcessor)