How can i know if the host stops calling processBlock?

How can i know if the host stops calling processBlock?
Is there a way?

I was hoping to use prepareToPlay to know when host starts calling it and releaseResources to know when it stops. But that is not the way to do it…

Short answer - you don’t.

But, as suggested in many threads here, you can store a timestamp of last time you’ve been called and check it from the message thread or others threads. If the delta is longer than N, it means you’ve not been called for a while.

2 Likes

You can improve this slightly by storing the timestamp and calculating the expected call time of the next block using the buffer size and the sample rate. If the next call happens after more than twice that time, processing cannot have been continuous (in a real-time scenario). You can also use grabCurrentPosition() to get the host time stamp and check that the same way. Some hosts sometimes skip a sample and this will also tell you if the transport jumped f.i. during looping.

Both these things can be checked from another thread based on the last values encountered in processBlock() or at the beginning of the next processBlock(). Often you don’t need to react until you get the first block after a break in processing and this way you can avoid needing another thread to check things.

And always remember if you compare the processed time with the processing time on the wall-clock, you could be in a non-realtime (bounce, preflight, prebuffer) situation. The isNonRealtime flag is often unreliable.

Also, depending on what you need this information for, you may use a Timer. I have some data that’s updated in processBlock, but some hosts will open an editor without calling processBlock until playback is started. So I have an atomic counter set to some max value by processBlock, and decreased by one by the timer callback. When it reaches zero, I assume processBlock is not being called and do my updates on the message thread.