I need to play a wave file. I have, more or less, harvested code snippets from the JUCE Demo solution to accomplish this first bit of work (see below), but I'm having problems with an exception being thrown when I exit.
Looking at the debugger it appears as though there is still an active WSAPI thread running, so I assume I haven't performed proper shutdown/clean-up on one of objects (maybe the reader object??). Any ideas?
AudioFormatManager formatManager;
formatManager.registerBasicFormats();
ScopedPointer<AudioDeviceManager> deviceManager = new AudioDeviceManager();
deviceManager->initialise (2, 2, nullptr, true, String::empty, nullptr);
AudioSourcePlayer audioSourcePlayer;
deviceManager->addAudioCallback(&audioSourcePlayer);
AudioTransportSource transportSource;
audioSourcePlayer.setSource (&transportSource);
ScopedPointer<AudioFormatReader> reader = formatManager.createReaderFor(srcFile);
ScopedPointer<AudioFormatReaderSource> currentAudioFileSource =
new AudioFormatReaderSource (reader, true);
transportSource.setSource (currentAudioFileSource, 0, nullptr, reader->sampleRate);
transportSource.start();
// in the future other will be done here
// this works until that process is hooked up
getchar();
// stop and clean-up...
transportSource.stop();
transportSource.releaseResources();
currentAudioFileSource->releaseResources();
transportSource.setSource (nullptr);
audioSourcePlayer.setSource (nullptr);
deviceManager->removeAudioCallback (&audioSourcePlayer);
return; // exception thrown here....
