ResamplingAudioSource questions


The constructor's 'numChannels' parameter, is that the number of channels in the souce or the output (after resampling)?  How can I programactically know the output sampling rate?  Can the AudioDeviceManager tell me?  AudioSourcePlayer?  Or is it all hard-coded for 44.1k?



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);

// 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...

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)
    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

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);


I got it working.  My short->byte[]->float conversions are all messed up.  I changed all of my buffers to use floats and I was able to get it to work.  So, now I just need to revisit my conversions as my true source (from a device driver) will be a byte[].


Quick question:  Do all of the native windows audio interfaces require floats?  Or do some of them accept ints as well?  Maybe WASAPI requries floats but the old MME required ints?


Everything is done as floats, for all audio devices on all platforms.