I've a problem syncing my plugin with DAW
I've check the PPQ value the DAW send to my plugin at every buffer (which are variable in size, not fixed).
I'm analysing these values, because I need to trigger somethings at every 1/96 beat (which is the PPQ of my DAW, FL Studio; 96 pulses per beat, thus 384 per bar).
These are the first 7 values I got at 300BPM (Sample rate 44100):
buffer: 0 => PPQ 0
buffer: 92 => PPQ 0.0104308
buffer: 184 => PPQ 0.0208617
buffer: 256 => PPQ 0.0290249
buffer: 276 => PPQ 0.0312925
as you can see, 0, 92, 184 and 276 are fixed buffer that represent 1/96 (more or less), while 256 is a variable buffer between 184 and 276. (that I need to ignore).
Since I need to sync only with 0,92,184 and 276, I need to understand why they got those PPQ values.
In fact, double divisions in C++ returns:
1/96. = 0.0104167
2/96. = 0.0208333
3/96. = 0.03125
which are different of the ones from DAW.
Which kind of approx is this?
How would you check PPQ values from DAW and understanding (so trigger) that I'm at 1/96? I need this approch (instead of just summing samples and check the sum/position) because I change tempo during the playing.
I hope the question and my target is clear, and that you can help me as you always did in the past! Thank you very much!
[EDIT]
I could try to use sampleToNextClock, but FL Studio doesn't send this value to the plug (so, even enabling it within IPlug, I always get 0). I find this on internet, to calculate it at every buffer:
Code: Select all
double clockperquaternote = 96.0;
double clocksperminute = (param_Value_Tempo * clockperquaternote);
double clocksperseconds = clocksperminute / 60.0;
int blocksize = nFrames;
double currentsample = timeInfo.mSamplePos;
double secondsinsong = currentsample / GetSampleRate();
double nextmidiclock = secondsinsong * clocksperseconds;
double sampleToNextClock = ceil(floor(nextmidiclock) / clocksperseconds * GetSampleRate()) - (currentsample - blocksize);
