projectTimeSamples not always as expected?

SDK for VST 3 audio plug-in and host development.
Post Reply
howardantares
Posts: 132
Joined: Tue Jun 21, 2016 1:46 pm

projectTimeSamples not always as expected?

Post by howardantares »

We keep track of the current sample position during playback, to correctly align a graph and corrections made by the user with the audio. For this, we need to detect if there is a jump or loop-back, so that we cease working with the data we were using and fetch the data for the new location instead.

To accomplish this, inside process(), we record prevSamplePos = data.processContext->projectTimeSamples, and prevNumSampes = data.numSamples. On the next process() call, we expect that the new data.processContext->projectTimeSamples value will equal prevSamplePos + prevNumSamples, since the position plus the number of samples should get you to the first sample of the next block.

Unfortunately, sometimes Cubase (haven't tested this in Nuendo) is off by 1, so our software thinks there has been a jump or loop, and it stops its current work and prepares for processing from the new location. For one test audio file that i use, this happens about 50% of the time, but always at the same location (or approximately the same location, I haven't verified if it's the *exactly* the same).

I'm not sure how to handle this safely. I am either recording data from the process() function, or using data previously recorded (and possibly modified) to write back to a known position. And the position has to match. Adding an extra sample or skipping a sample just isn't acceptable. I can't just ignore it, especially when recording the data.

Why does this happen? Is there any chance this difference will ever be MORE than 1 sample? If it's only ever 1 single sample, then I can perhaps work around it by adjusting my copying of my internal process buffer to accommodate, and something similar when playing back later, and assuming that the *current* sample position is *always* accurate.

Or, could this be a bug in Cubase, where some kind of floating point error builds up over time until it adds a whole sample position? (If so, then I don't get why it would happen sometimes, but not always, and why always in the same place in that one file?)

User avatar
ygrabit
Posts: 184
Joined: Fri Jun 17, 2016 7:52 am
Location: Hamburg
Contact:

Re: projectTimeSamples not always as expected?

Post by ygrabit »

this is strange... which samplerate and audio blocksize are you using ?
YVan Grabit

howardantares
Posts: 132
Joined: Tue Jun 21, 2016 1:46 pm

Re: projectTimeSamples not always as expected?

Post by howardantares »

The block size currently is 512 samples, and the sample rate is 44.1k. But this has happened for years, at various different settings, as far as I know. The new version I'm working on doesn't handle that difference as easily as the existing one in the field, and I'd like to keep it that way, if possible. It doesn't happen with other hosts (whether VST3 or AU or AAX), just Cubase/Nuendo as far as I know.

User avatar
ygrabit
Posts: 184
Joined: Fri Jun 17, 2016 7:52 am
Location: Hamburg
Contact:

Re: projectTimeSamples not always as expected?

Post by ygrabit »

i have extended the VST3 Host Checker plugin to visualize this kind of discontinuity... no strange report so far with Cubase or Nuendo
YVan Grabit

howardantares
Posts: 132
Joined: Tue Jun 21, 2016 1:46 pm

Re: projectTimeSamples not always as expected?

Post by howardantares »

Here is one test file we observe this happening on about half the time:
You do not have the required permissions to view the files attached to this post.

User avatar
ygrabit
Posts: 184
Joined: Fri Jun 17, 2016 7:52 am
Location: Hamburg
Contact:

Re: projectTimeSamples not always as expected?

Post by ygrabit »

Thanks Howard, i was able to reproduce it... it seems like a rounding issue from converting between sample to second and back to sample...let´s see for a fix.
YVan Grabit

howardantares
Posts: 132
Joined: Tue Jun 21, 2016 1:46 pm

Re: projectTimeSamples not always as expected?

Post by howardantares »

Ok, that's good to hear. Thanks, Yvan!

sgretscher
Posts: 19
Joined: Tue Jul 05, 2016 6:30 pm

Re: projectTimeSamples not always as expected?

Post by sgretscher »

We've seen rounding issues like that in several hosts over the years - is there a canonical way of doing the seconds-to-sample conversion?

For reference, internally we use something like:
samplePos = static_cast<int64_t> (std::floor (timePos * sampleRate + 0.5))

So we're using a rounding window of 0.5 around each discrete sample position, and for both positive and negative time positions values exactly between two samples are always rounded to the left. This prevents all rounding issues internally, but some hosts seem to do it differently and sometimes even inconsistently, causing problems when going back and forth between plug-ins and hosts, hence the question.

Thanks,
Stefan

Post Reply