Would someone mind casting an eye over this code and letting me know where I’m going wrong. I’m trying to stream some audio out of a plugin, actually for now I’m just trying to call getNextAudioBlock() without my plugin hanging. Do these source classes need their own processing threads? In which case should I always create a subclass of my source player. When their start method is called do they start a background thread to read samples? And if so what do you get each time you called getNextAudioBlock(). Apologies for all the questions but I have to admit I’m a little confused! In the posted code I try to call getNextAudioBlock() in my processBlock, but it just hangs each time. fileSource->start() is called with a button press in my plugin editor.
PlaybackPluginAudioProcessor::PlaybackPluginAudioProcessor():thread("audioThread")
{
currentAudioFileSource = NULL;
AudioFormatManager formatManager;
formatManager.registerBasicFormats();
setupAudioFile("/home/rory/sourcecode/cabbage/Examples/banjo.wav");
}
//=============================================================================
PlaybackPluginAudioProcessor::~PlaybackPluginAudioProcessor()
{
fileSource.setSource(0);
deleteAndZero(currentAudioFileSource);
}
//=============================================================================
void PlaybackPluginAudioProcessor::setupAudioFile (String _audioFile)
{
File audioFile (_audioFile);
if(audioFile.exists())Logger::writeToLog("File exists");
AudioFormatManager formatManager;
formatManager.registerBasicFormats();
AudioFormatReader* reader = formatManager.createReaderFor (audioFile);
if (reader != 0)
{
currentAudioFileSource = new AudioFormatReaderSource (reader, true);
fileSource.setSource(currentAudioFileSource, 32768, &thread, reader->sampleRate, 1);
}
}
//=============================================================================
void PlaybackPluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
if(fileSource.isPlaying())
fileSource.getNextAudioBlock(sourceChannelInfo);
for (int channel = 0; channel < getNumInputChannels(); ++channel)
float* channelData = buffer.getSampleData (channel);
for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
buffer.clear (i, 0, buffer.getNumSamples());
}