Is there a class in the ‘processor’ audio classes that takes an AudioFormatReader (or subsection reader)?
Is there an official link between the two sets of classes right now? I’d like to use a graph in an app, but have more familiarity with the audio ‘Source’ classes.
Bruce
I don’t think there is any “official” link. It’s fairly easy, though, to construct an AudioProcessor that will play a clip (and then use the AudioFormatReader class to read all the data to a buffer).
Something like this:
myAudioProcessor::loadAudio()
{
// Create a reader
AudioFormatManager formatManager;
formatManager.registerBasicFormats();
AudioFormatReader* reader = formatManager.createReaderFor(fileToLoad);
// read data to buffer
int length = reader->lengthInSamples;
sampleBuffer = new juce::AudioSampleBuffer(2, length); // resized dynamically when files are loaded ...
sampleBuffer->readFromAudioReader(reader, 0, length, 0, true, true);
}
myAudioProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
// play whats in the buffer ....
int numSamples = buffer.getNumSamples();
int numChannels = buffer.getNumChannels();
for (int chan = 0; chan < numSamples; chan++)
buffer.addFrom(chan, 0, sampleBuffer->getSampleData(numChannels, playPosition), numSamples);
playPosition += numSamples;
}