The SamplerSound class doesn’t support disk streaming, so it needs to load the entire file into RAM. The AudioFormatReader itself does allow you to stream data without decoding the entire file, but you’d have to come up with a class of your own that streams (which isn’t trivial, as I understand it).
I don’t think you need to create your own streaming class; Juce should have everything you need. Here’s some code that associates an AudioFormatReader with an AudioTransportSource for buffered, positionable audio streaming:
// create a new source from the file
AudioFormatManager mgr;
mgr.registerBasicFormats();
AudioFormatReader* rdr = mgr.createReaderFor(file);
if(rdr != 0)
{
reader = new AudioFormatReaderSource(rdr, true /* delete rdr when done */);
transport.setSource(reader,
32768, // read ahead this many samples
rdr->sampleRate);
}
Here’s the code that actually plays the file:
[code]void AudioPlayer::audioDeviceIOCallback (const float **inputChannelData,
int totalNumInputChannels,
float **outputChannelData,
int totalNumOutputChannels,
int numSamples)
{
The above can be simplified further by setting the source of an instance of AudioSourcePlayer to your AudioTransportSource; at the end of the first code snippet add: myAudioSourcePlayer->setSource(transport) and then set myAudioSourcePlayer as the AudioIOCallback object for the current audio device. The advantage of the code in the second snippet is that you can manipulate the samples whereas AudioSourcePlayer is just playback of whatever AudioSource it’s attached to (although you can manipulate which samples get played back via the AudioTransportSource).