I want to create a plug-in which processes a pre-determined audio file instead of sound device (or microphone) inputs. The music starts when the application starts, but plays without the effect. I couldn’t understand how can I redirect this sound.
The code in PluginProcessor.cpp is like:
#include “PluginProcessor.h”
#include “PluginEditor.h”
juce::File& currentDir = juce::File::getCurrentWorkingDirectory();
juce::File& audioFile = currentDir.getChildFile(“audio.mp3”);
TilteqAudioProcessor::TilteqAudioProcessor()
#ifndef JucePlugin_PreferredChannelConfigurations
: AudioProcessor(BusesProperties()
#if ! JucePlugin_IsMidiEffect
#if ! JucePlugin_IsSynth
.withInput(“Input”, juce::AudioChannelSet::stereo(), true)
#endif
.withOutput(“Output”, juce::AudioChannelSet::stereo(), true)
#endif
),
parameters(*this, nullptr)
#endif
{
auto audioFormatManager = new juce::AudioFormatManager();
audioFormatManager->registerBasicFormats();
// Format reader
auto audioFormatReader = audioFormatManager->createReaderFor(audioFile);
// Reader source
auto audioFormatReaderSource = new juce::AudioFormatReaderSource(audioFormatReader, true);
// Transport source
auto audioTransportSource = new juce::AudioTransportSource();
audioTransportSource->setSource(audioFormatReaderSource, 0, nullptr, 44100.0, 2);
audioTransportSource->start();
// Source player
auto audioSourcePlayer = new juce::AudioSourcePlayer();
audioSourcePlayer->setSource(audioTransportSource);
// Device manager
auto audioDeviceManager = new juce::AudioDeviceManager();
audioDeviceManager->initialise(2, 2, 0, true);
audioDeviceManager->addAudioCallback(audioSourcePlayer);
parameters.createAndAddParameter(std::make_unique<juce::AudioParameterFloat>("freq",
"Frequency", juce::NormalisableRange<float>(500.0f, 2000.0f, 1.0f, 0.63f), 1000.0f, "Hz"));
parameters.createAndAddParameter(std::make_unique<juce::AudioParameterFloat>("gain",
"Gain", juce::NormalisableRange<float>(-6.0f, 6.0f, 0.25f), 0.0f, "dB"));
parameters.state = juce::ValueTree("savedParams");
}
void TilteqAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock)
{
tiltEQ.prepare(sampleRate, samplesPerBlock);
tiltEQ.setParameters(parameters);
}
void TilteqAudioProcessor::processBlock(juce::AudioBuffer& buffer, juce::MidiBuffer&)
{
juce::ScopedNoDenormals noDenormals;
for (auto i = getTotalNumInputChannels(); i < getTotalNumOutputChannels(); ++i)
buffer.clear(i, 0, buffer.getNumSamples());
for (int channel = 0; channel < getTotalNumInputChannels(); ++channel)
{
auto* channelData = buffer.getWritePointer(channel);
tiltEQ.process(buffer);
}
}