I’m trying to make a simple console application that takes in two files (say source and impulse) and convolves one with the other using the Convolution class in JUCE. I am able to load both the source and the impulse and play the source back, but I am unsure of how/where to actually call process() on the convolution itself with the source as input.
I’m very good with nitty-gritty, sample-level DSP and know my way around C++ but the JUCE framework is confusing me. Below is my class:
class MyConvolver: public Convolution
{
public:
// members
ProcessSpec spec;
ScopedPointer<AudioFormatReaderSource> source;
MyConvolver(File &sourceFile, File &hrir, double sampleRate, int samplesPerBlock) {
spec.sampleRate = sampleRate;
spec.maximumBlockSize = samplesPerBlock;
spec.numChannels = 2;
source = new AudioFormatReaderSource(formatManager.createReaderFor(sourceFile), true);
this->prepareToPlay(impulse);
}
void prepareToPlay(File &impulse)
{
// spec.numChannels = getTotalNumOutputChannels();
this->reset();
this->prepare(spec);
this->loadImpulseResponse(impulse, Convolution::Stereo::yes, Convolution::Trim::yes, 0, Convolution::Normalise::yes);
}
void playSource(juce::AudioDeviceManager &audioDeviceManager) {
AudioIODevice* device = audioDeviceManager.getCurrentAudioDevice();
if (device && source) {
std::cout << "yay" << std::endl;
source->prepareToPlay (device->getDefaultBufferSize(),
device->getCurrentSampleRate());
ScopedPointer<AudioSourcePlayer> player = new AudioSourcePlayer ();
player->setSource (source);
audioDeviceManager.addAudioCallback(player);
// actually makes the sound???
while (source->getNextReadPosition() < source->getTotalLength())
Thread::sleep(100);
}
}
};
Perhaps subclassing Convoltion is unnecessary here?
(I think my larger difficulty is with understanding signal flow in JUCE in general. Where exactly is audio written? When is audioDeviceIOCallback() called versus getNextAudioBlock()? I think I understand that JUCE needs to have an audio callback to a device manager to actually process audio, but I’m not sure how to tell it to use the process() method or send the ProcessContext to it.)