Implementing an AudioSource questions


#1

My AudioSource prototype is working, but I have a couple of questions for "edge" cases:

In MyAudioSource::getNextAudioBlock implementation...if the full number of samples requested (info.numSamples) are not availble (network latency), what should I do?

  • Pad output buffer with 0?  Yikes!
  • Use info.buffer->clear (startSample, numSamples) to 'pad' the buffer?
  • Use info.buffer->setSize to resize the buffer?
  • Or should I just wait (block thread) until more data arrives?

Today I have just been filling the buffer with as many samples as I have and ignoring the rest of the samples.  I don't notice any issues, but I have to think that isn't the ideal behavior.

If MyAudioSource is 'paused', or 'muted', MyAudioSource::getNextAudioBlock should invoke 'info.clearActiveBufferRegion', correct?

 

Minor Question

My audio source has a 8K sampling rate, so I have been using ResamplingAudioSource to handle the upsampling.  When ResamplingAudioSource calls MyAudioSource::prepareToPlay, shouldn't the 'sampleRate' be 8K?  Based on testing, it is always set to 44.1K. It seems like ResamplingAudioSouce should request source and destination sampling rate and not just a ratio, thoughts?


#2

That's a pretty interesting question.  All the examples suggest that AudioSource should produce a continuous stream and I'm not sure any of the answers are correct. 

Resizing doesn't sound great.  Blocking or padding sound like they could be the right answer. Padding if you are working in real-time and blocking if you are not.  You might need either behaviour. It'd depend on the application. 

It'd be more convenient if you the app could find out in advance whether there was enough data ready...