I thought Resampling would fix my issue, but for some reason I don't hear anything from this code snippet (see below). I think I have hooked everything up correctly, did I miss something?
ScopedPointer<AudioDeviceManager> audioDeviceManager = new AudioDeviceManager();
audioDeviceManager->initialiseWithDefaultDevices (0, 1);
AudioSourcePlayer audioSourcePlayer;
MyAudioSource myAudioSource(1024*20);
// for now assume numChannels is 'source channels' not 'output channels'
ResamplingAudioSource resampledSource (&myAudioSource, false, 1);
// our source is 8k and I _assume_ output is 44.1k
resampledSource.setResamplingRatio (8000.0/44100.0);
audioSourcePlayer.setSource (&resampledSource);
audioDeviceManager->addAudioCallback(&audioSourcePlayer);
// for now we will read the PCM (16-bit, 8K, mono) from a file
// as a means to emulate the stream we will receive from our device driver
FileInputStream *inputStream = srcFile.createInputStream();
unsigned char readBuffer[2048];
// allow the source to accept data and its callback to return samples...
myAudioSource.start();
int totalBytesRead = 0;
int totalBytesQueued = 0;
// Read ~10s of audio and place it into source's buffer, so the player can access it...
for (int i = 0; i < 80; ++i)
{
int bytesRead = inputStream->read(readBuffer, 2048);
int bytesQueued = myAudioSource.addDataToBuffer(readBuffer, bytesRead);
totalBytesRead += bytesRead;
totalBytesQueued += bytesQueued;
// emulate real-time passing (1024 samples, or 2048 bytes, per 1/8th second)
Sleep(125);
printf("r: %d -- q: %d -- s: %d\r\n", totalBytesRead, totalBytesQueued, myAudioSource.samplesRead());
}
...
The output from the above code looks like this...(shouldn't the sample rate be 8k?)
MyAudioSource::prepareToPlay-->samplesPerBlockExpected: 448 sampleRate: 44100.000000
r: 2048 -- q: 2048 -- s: 1024
r: 4096 -- q: 4096 -- s: 1999
r: 6144 -- q: 6144 -- s: 2974
r: 8192 -- q: 8192 -- s: 4031
where...
r == bytes read from source file
q == bytes written to MyAudioSource's buffer
s == samples request of MyAudioSource via ResamplingAudioSource
Looking at ResamplingAudioSoucre's prepareToPlay method, I think this line is incorrect? As sampleRate is the output samplerate, but this call to prepareToPlay is on the resampler's source which could have a different rate (8K in my case). Or am I misunderstanding this bit of code?
input->prepareToPlay (samplesPerBlockExpected, sampleRate);