Plug'n Script - Tempo-Sync Issue (Buffersize)

Official support for: bluecataudio.com
Post Reply New Topic
RELATED
PRODUCTS
Plug'n Script

Post

(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?

Post

It will probably be easier with the code posted on the PnS developers group (if you are the same developer):

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;
        }
    }
}
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:

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;
        }
    }
}
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:

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;
    }
}
Hope this helps!

Post

thank you :) i'll try that very soon! that probably ends all my current problems in pns

Post

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.

Post Reply

Return to “Blue Cat Audio”