Call prepareToPlay() manually

Hi, i’m trying to call method ::prepareToPlay(int samplesPerBlockExpected, double sampleRate) from AudioSource (call it manually, not by AudioSourcePlayer callback), but at this point i dont know where to get samplesPerBlockExpected from, while sampleRate can be retrieved from AudioDeviceManager. Thanks in advance

getSampleRate() and getBlockSize() of AudioProcessor

@Mrugalla I don’t use AudioProcessor, just a simple player program with AudioTransportSource, AudioDeviceManager and AudioSourcePlayer

oh, looks like a more lowlevel thing. nvm. looking forward to read the solution, too :slight_smile:

1 Like

When you code the players yourself, then you need to know what to supply. So the answer is “depends”.

You need to know what is going to call getNextAudioBlock. And if there is e.g. a resampling stage, in which case you need to supply a multiple plus safety margin for the state of the resampler.

If it is pulled from an AudioIODeviceCallback, you can get the numbers from the current AudioIODevice.
If you create an export task, you are free to pick any number, just don’t exceed it when you call getNextAudioBlock.

Or any other scenario, in which case we need to know more details.

@daniel If it’s that complicated then i might just call AudioSourcePlayer.setSource() and AudioTransportSource.start() then wait for the prepareToPlay() callback itself

@daniel Oh sorry i didn’t read it carefully, i actually have access to the current AudioIODevice, but i don’t see any familiar function or property to get the samplesPerBlockExpected from

No worries, they are:
getCurrentBufferSizeSamples() and
getCurrentSampleRate()

But setSource() is indeed conventient. It will get the information from AudioSourcePlayer, which got it set, when it was added as callback to the AudioIODevice.

It is a bit inconsistent, so I would always check the sources, which AudioSource propagates prepareToPlay and which expects to be prepared before it is added in a pipeline.

1 Like

@daniel Got it working, thanks. Btw, i always use the result from the prepareToPlay callback, this is just a special circumtance where i have to take it from AudioIODeviceManager

Yes, sometimes you have to, e.g. I often prepare them myself before hot-swapping into the pipeline.

1 Like