Skip to content

Commit

Permalink
Merge pull request #24 from jorshi/feat/drywet
Browse files Browse the repository at this point in the history
Dry Wet Parameter
  • Loading branch information
jorshi authored Jul 22, 2024
2 parents f372753 + 75b620e commit f70cf7a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
31 changes: 26 additions & 5 deletions source/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Parameters
parameters.push_back(offThreshold);
parameters.push_back(waitSamples);
parameters.push_back(sensitivity);
parameters.push_back(drywet);
}

void add(juce::AudioProcessor& processor) const
Expand All @@ -19,6 +20,7 @@ class Parameters
processor.addParameter(offThreshold);
processor.addParameter(waitSamples);
processor.addParameter(sensitivity);
processor.addParameter(drywet);
}

// Free parameters -- this is here to support unit testing.
Expand All @@ -29,15 +31,34 @@ class Parameters
delete param;
}

// Raw pointers. They will be owned by either the processor or the APVTS (if you use it)
// Raw pointers.
// They will be owned by the AudioProcessor in the application.
juce::AudioParameterFloat* onThreshold =
new juce::AudioParameterFloat({ "onThreshold", 1 }, "On Threshold", 0.5f, 32.f, 16.0f);
new juce::AudioParameterFloat({ "onThreshold", 1 },
"On Threshold",
0.5f,
32.f,
16.0f);
juce::AudioParameterFloat* offThreshold =
new juce::AudioParameterFloat({ "offThreshold", 1 }, "Off Threshold", 0.0f, 32.f, 4.66f);
new juce::AudioParameterFloat({ "offThreshold", 1 },
"Off Threshold",
0.0f,
32.f,
4.66f);
juce::AudioParameterInt* waitSamples =
new juce::AudioParameterInt({ "waitSamples", 1 }, "Wait Samples", 0, 5000, 1000);
new juce::AudioParameterInt({ "waitSamples", 1 },
"Wait Samples",
0,
5000,
1000);
juce::AudioParameterFloat* sensitivity =
new juce::AudioParameterFloat({ "sensitivity", 1 }, "Mapping Sensitivity", 0.f, 4.f, 1.0f);
new juce::AudioParameterFloat({ "sensitivity", 1 },
"Mapping Sensitivity",
0.f,
4.f,
1.0f);
juce::AudioParameterFloat* drywet =
new juce::AudioParameterFloat({ "drywet", 1 }, "Dry/Wet", 0.0f, 1.0f, 1.0f);

private:
std::vector<juce::RangedAudioParameter*> parameters;
Expand Down
23 changes: 13 additions & 10 deletions source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ void TorchDrumProcessor::processBlock(juce::AudioBuffer<float>& buffer,

// Parameters to update once per block
auto& onsetDetection = synthController.getOnsetDetection();
onsetDetection.updateParameters(
parameters.onThreshold->get(),
parameters.offThreshold->get(),
parameters.waitSamples->get());
onsetDetection.updateParameters(parameters.onThreshold->get(),
parameters.offThreshold->get(),
parameters.waitSamples->get());

// Square Root 3dB Dry/Wet Mix
auto drywet = parameters.drywet->get();
float dry = std::sqrt(1.0f - drywet);
float wet = std::sqrt(drywet);

for (int sample = 0; sample < buffer.getNumSamples(); ++sample)
{
Expand All @@ -54,7 +58,7 @@ void TorchDrumProcessor::processBlock(juce::AudioBuffer<float>& buffer,
for (int channel = 0; channel < buffer.getNumChannels(); ++channel)
{
auto* channelData = buffer.getWritePointer(channel);
channelData[sample] = synthSample;
channelData[sample] = synthSample * wet + channelData[sample] * dry;
}
}
}
Expand Down Expand Up @@ -82,14 +86,14 @@ void TorchDrumProcessor::getStateInformation(juce::MemoryBlock& destData)

// Save model path and feature normalizers
juce::ValueTree modelPath("ModelPath");
modelPath.setProperty("Path", juce::String(synthController.getModelPath()), nullptr);
modelPath.setProperty(
"Path", juce::String(synthController.getModelPath()), nullptr);
pluginPreset.appendChild(modelPath, nullptr);

copyXmlToBinary(*pluginPreset.createXml(), destData);
}

void TorchDrumProcessor::setStateInformation(const void* data,
int sizeInBytes)
void TorchDrumProcessor::setStateInformation(const void* data, int sizeInBytes)
{
// Loads your parameters, and any other potential data from an XML:

Expand All @@ -102,8 +106,7 @@ void TorchDrumProcessor::setStateInformation(const void* data,

for (auto& param : getParameters())
{
auto paramTree =
params.getChildWithName(PluginHelpers::getParamID(param));
auto paramTree = params.getChildWithName(PluginHelpers::getParamID(param));

if (paramTree.isValid())
param->setValueNotifyingHost(paramTree["Value"]);
Expand Down

0 comments on commit f70cf7a

Please sign in to comment.