Old 02-07-2019, 05:54 PM   #1
Pollo
Human being with feelings
 
Join Date: Jan 2015
Location: Amsterdam
Posts: 74
Default VstTimeInfo problem

I am working on a plugin that relies on VstTimeInfo, specifically the value of ppqPos. This seemed to work well, until I started a project that had the (admittedly) uncommon tempo of 117 BPM. Now Reaper returns values for ppqPos that seem to be plain wrong.

To give an example: I have a project in 4/4, tempo is 120 BPM. I set the cursor at the beginning of bar 5. When I start playback, the first ppqPos value I receive is 32.00000000. This is right

Now I change the tempo to 117. Again I start playback at bar 5. Now the first ppqPos value I get is 31.999986394557823. That is wrong.

Is this a known bug?
How to deal with this? I can maybe use the samplePos value instead and calculate the exact beat position myself. But then maybe I run out of sync with the Reaper metronome?
You would think that it's not that hard to calculate this correctly. Why is it unreliable?

I'd appreciate any suggestions.
Pollo is offline   Reply With Quote
Old 02-08-2019, 01:59 PM   #2
Pollo
Human being with feelings
 
Join Date: Jan 2015
Location: Amsterdam
Posts: 74
Default

Nobody has a solution? Well, I can understand. It's not easy stuff.

I did some more investigating. I thought I had a solution. I figured it might be some rounding error converting from float to int. But that didn't work out.

So now I'm trying to figure out how Reaper calculates the values I get from VstTimeInfo. It doesn't make any sense to me. Not only are the numbers off, they are not even consistent between themselves. samplePos doesn't seem to have a logical connection with ppqPos. The only common factor is that they are all wrong.
Worst thing is that I can't even find a work-around solution.

Must the conclusion be that it is impossible for a plugin to reliable sync with Reaper? Come on, Reaper. You are better than that.
Pollo is offline   Reply With Quote
Old 02-09-2019, 08:36 AM   #3
snooks
Human being with feelings
 
Join Date: Sep 2015
Posts: 1,580
Default

It looks like it is lack of precision in floating point arithmetic. You can't reliably compare two floating point numbers that are the result of calculations directly because of this - you need to compare a range, in this case +/- around 0.00001.
snooks is offline   Reply With Quote
Old 02-09-2019, 08:55 AM   #4
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 9,761
Default

Quote:
Originally Posted by Pollo View Post
I can maybe use the samplePos value instead and calculate the exact beat position myself.
I believe that calculation will give you the same number.
schwa is offline   Reply With Quote
Old 02-09-2019, 05:24 PM   #5
Pollo
Human being with feelings
 
Join Date: Jan 2015
Location: Amsterdam
Posts: 74
Default

So any idea why it is not correct?
Pollo is offline   Reply With Quote
Old 02-10-2019, 06:39 AM   #6
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 9,761
Default

Because you can't have a fractional sample. It is reporting the correct PPQ position for the current sample position.

32 / 120 * 60 * 44100 = 705600 exactly
31.999986394557823 / 117 * 60 * 44100 = 723692 exactly
schwa is offline   Reply With Quote
Old 02-13-2019, 05:03 AM   #7
Pollo
Human being with feelings
 
Join Date: Jan 2015
Location: Amsterdam
Posts: 74
Default

schwa, you're right of course.

I solved the sync problem. It's working perfectly now. There was an error in my code.

Whenever I think Reaper is doing something wrong, it always turns out to be not true.
Pollo is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 08:47 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.