Plug'n Script - Tempo-Sync Issue (Buffersize)
-
- KVRist
- Topic Starter
- 33 posts since 5 Sep, 2018
(i know i already wrote you an email about this but hopefully someone who reads this forum has another idea!)
when using the positionInQuarterNotes to determine if something is in line with the project position and tempo i noticed that it kinda oscillates between being tight and being slightly untight. i found out that it must have something to do with the buffersize, because positionInQuarterNotes always returns the first sample of the buffer of the note, instead of the actual position of the note, so if you use a huge buffer it will be untight. but i don't wanna force people to decrease their daw's buffer size obviously. is there a way to improve the precision of this quarterNotes-counter? can i for example let plug'n script pretend like the buffers come in smaller blocks or so?
when using the positionInQuarterNotes to determine if something is in line with the project position and tempo i noticed that it kinda oscillates between being tight and being slightly untight. i found out that it must have something to do with the buffersize, because positionInQuarterNotes always returns the first sample of the buffer of the note, instead of the actual position of the note, so if you use a huge buffer it will be untight. but i don't wanna force people to decrease their daw's buffer size obviously. is there a way to improve the precision of this quarterNotes-counter? can i for example let plug'n script pretend like the buffers come in smaller blocks or so?
-
Blue Cat Audio Blue Cat Audio https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=39981
- KVRAF
- 5820 posts since 8 Sep, 2004 from Paris (France)
It will probably be easier with the code posted on the PnS developers group (if you are the same developer):
The problem here is that you have to update the actual position in quarter note for every sample, as you are moving forward in the buffer.
Typically:
This should give you sample-accurate precision (instead of buffer-accurate).
And to optimize a little bit, you can avoid re-computing everything for every sample with something like this:
Hope this helps!
Code: Select all
void processBlock(BlockData& data){
uint midiIndex=0;
for(uint i=0;i<data.samplesToProcess;i++){
pos = floor(data.transport.positionInQuarterNotes*pow(2,speed));
for(uint ch=0;ch<audioInputsCount;ch++){
if(pos%2==0)data.samples[ch][i]=data.samples[ch][i];
else data.samples[ch][i]=0;
}
}
}
Typically:
Code: Select all
void processBlock(BlockData& data){
uint midiIndex=0;
for(uint i=0;i<data.samplesToProcess;i++){
pos = floor((data.transport.positionInQuarterNotes+double(i)*data.transport.bpm/(60.0*sampleRate))*pow(2,speed));
for(uint ch=0;ch<audioInputsCount;ch++){
if(pos%2==0)data.samples[ch][i]=data.samples[ch][i];
else data.samples[ch][i]=0;
}
}
}
And to optimize a little bit, you can avoid re-computing everything for every sample with something like this:
Code: Select all
void processBlock(BlockData& data){
uint midiIndex=0;
double currentPosQuarterNotes=data.transport.positionInQuarterNotes;
double posIncrement=data.transport.bpm/(60.0*sampleRate);
for(uint i=0;i<data.samplesToProcess;i++){
pos = floor(currentPosQuarterNotes*pow(2,speed));
for(uint ch=0;ch<audioInputsCount;ch++){
if(pos%2==0)data.samples[ch][i]=data.samples[ch][i];
else data.samples[ch][i]=0;
}
currentPosQuarterNotes+=posIncrement;
}
}
-
- KVRist
- Topic Starter
- 33 posts since 5 Sep, 2018
thank you i'll try that very soon! that probably ends all my current problems in pns
-
- KVRist
- Topic Starter
- 33 posts since 5 Sep, 2018
YEAH IT WORKS! great! this also helped me a lot on my way to understand how buffers work but i'm not quite there yet.