Im making c++ audio plugin using juce. When Im trying to hook up two or more impulses using my IR loader plugin, my ASIO load increases up to 90%. Any advice would be helpful.
PluginProcessor.cpp
void IRLoaderAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{
// Use this method as the place to do any pre-playback
// initialisation that you need..
spec.maximumBlockSize = samplesPerBlock;
spec.sampleRate = sampleRate;
spec.numChannels = getTotalNumOutputChannels();
IRLoader.reset();
IRLoader.prepare(spec);
IRLoader2.reset();
IRLoader2.prepare(spec);
}
void IRLoaderAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
juce::ScopedNoDenormals noDenormals;
auto totalNumInputChannels = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();
juce::dsp::AudioBlock<float> block{ buffer };
IRLoader.process(juce::dsp::ProcessContextReplacing<float>(block));
IRLoader2.process(juce::dsp::ProcessContextReplacing<float>(block));
}
void IRLoaderAudioProcessor::getStateInformation (juce::MemoryBlock& destData)
{
treeState.state.appendChild(variableTree, nullptr);
juce::MemoryOutputStream stream(destData, false);
treeState.state.writeToStream(stream);
}
void IRLoaderAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
auto tree = juce::ValueTree::readFromData(data, size_t(sizeInBytes));
variableTree = tree.getChildWithName("Variables");
if (tree.isValid())
{
treeState.state = tree;
savedFile = juce::File(variableTree.getProperty("file1"));
root = juce::File(variableTree.getProperty("root"));
savedFile2 = juce::File(variableTree.getProperty("file2"));
root2 = juce::File(variableTree.getProperty("root2"));
IRLoader.loadImpulseResponse(savedFile,
juce::dsp::Convolution::Stereo::yes, juce::dsp::Convolution::Trim::yes, 0);
IRLoader2.loadImpulseResponse(savedFile2,
juce::dsp::Convolution::Stereo::yes, juce::dsp::Convolution::Trim::yes, 0);
}
// You should use this method to restore your parameters from this memory block,
// whose contents will have been created by the getStateInformation() call.
}
PluginEditor.cpp
IRLoaderAudioProcessorEditor::IRLoaderAudioProcessorEditor (IRLoaderAudioProcessor& p)
: AudioProcessorEditor (&p), audioProcessor (p)
{
// Make sure that before the constructor has finished, you've set the
// editor's size to whatever you need it to be.
addAndMakeVisible(loadBtn1);
loadBtn1.setButtonText("Load IR 1");
loadBtn1.onClick = [this]()
{
fileChooser = std::make_unique<juce::FileChooser>
("Choose File", audioProcessor.root,"*");
const auto fileChooserFlags = juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles | juce::FileBrowserComponent::canSelectDirectories;
fileChooser->launchAsync(fileChooserFlags, [this](const juce::FileChooser& chooser)
{
juce::File result(chooser.getResult());
if (result.getFileExtension() == ".wav" | result.getFileExtension() == ".mp3")
{
audioProcessor.savedFile = result;
audioProcessor.variableTree.setProperty("file1",
audioProcessor.savedFile.getFullPathName(), nullptr);
audioProcessor.variableTree.setProperty("root",
audioProcessor.savedFile.getParentDirectory().getFullPathName(), nullptr);
audioProcessor.root = audioProcessor.savedFile.getParentDirectory().getFullPathName();
audioProcessor.IRLoader.loadImpulseResponse(audioProcessor.savedFile,
juce::dsp::Convolution::Stereo::yes,
juce::dsp::Convolution::Trim::yes, 0);
IRName.setText(result.getFileName(), juce::dontSendNotification);
}
});
};
addAndMakeVisible(IRName);
addAndMakeVisible(loadBtn2);
loadBtn2.setButtonText("Load IR 2");
loadBtn2.onClick = [this]()
{
fileChooser = std::make_unique<juce::FileChooser>
("Choose File", audioProcessor.root, "*");
const auto fileChooserFlags = juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles | juce::FileBrowserComponent::canSelectDirectories;
fileChooser->launchAsync(fileChooserFlags, [this](const juce::FileChooser& chooser)
{
juce::File result(chooser.getResult());
if (result.getFileExtension() == ".wav" || result.getFileExtension() == ".mp3")
{
audioProcessor.savedFile2 = result;
audioProcessor.variableTree.setProperty("file2",
audioProcessor.savedFile2.getFullPathName(), nullptr);
audioProcessor.variableTree.setProperty("root2",
audioProcessor.savedFile2.getParentDirectory().getFullPathName(), nullptr);
audioProcessor.root = audioProcessor.savedFile2.getParentDirectory().getFullPathName();
audioProcessor.IRLoader2.loadImpulseResponse(audioProcessor.savedFile2,
juce::dsp::Convolution::Stereo::yes,
juce::dsp::Convolution::Trim::yes, 0);
IRName2.setText(result.getFileName(), juce::dontSendNotification);
}
});
};
addAndMakeVisible(IRName2);
setSize (400, 300);
}