renderNextBlock and looping audio


#1

I am trying to have my VST play a looped audio sample slaved to the host transport. So in the renderNextBlock I'm simply checking if the host isPlaying and thus rendering the buffer from sample position 0. As the host continues to play, I'm incrementing the sampleCount. This is all fine on the first pass (silence is produced when nulling the audio against an audio track with the same sample loop).

However, when the host loops and also my sample loops by using in my renderNextBlock:


if (sampleCurrentPosition == playbackEndPosition)
{
  // move back to start
  sampleCurrentPosition = (float) playbackStartPosition;
}

The sample loops but the tracks no longer null. Can anyone explain why this happens? Is there an elegant way of handling this?

 

Thank you.


#2

If your audio advances blockwise, it is not very probable that the sampleCurrentPosition hits exactly the playbackEndPosition. So you will need to check if sampleCurrentPosition is greater than playbackEndPosition and do something with the overlapping part (or the other way round, whatever fits your design). But that is only one possible error...

HTH