Skip to content

Instantly share code, notes, and snippets.

@olilarkin
Created November 30, 2020 11:31
Show Gist options
  • Save olilarkin/1a6e07a1d4ed6c9e20e81938fc1e1b2b to your computer and use it in GitHub Desktop.
Save olilarkin/1a6e07a1d4ed6c9e20e81938fc1e1b2b to your computer and use it in GitHub Desktop.
VST3 Sample accurate parameters
#include "IPlugEffect.h"
#include "IPlug_include_in_plug_src.h"
#include "IControls.h"
IPlugEffect::IPlugEffect(const InstanceInfo& info)
: Plugin(info, MakeConfig(kNumParams, kNumPresets))
{
GetParam(kGain)->InitDouble("Gain", 0., 0., 100.0, 0.01, "%");
}
void IPlugEffect::OnParamChange(int paramIdx, EParamSource src, int sampleOffset)
{
if(sampleOffset != -1) // sampleOffset > -1 indicates that the method is called on the audio thread, even if sampleOffset == 0, sampleOffset only > 0 during playback
mParamChangesForBlock.Get()[sampleOffset] = GetParam(kGain)->GetNormalized();
}
void IPlugEffect::OnReset()
{
mParamChangesForBlock.Resize(GetBlockSize());
memset(mParamChangesForBlock.Get(), 0, GetBlockSize() * sizeof(sample));
}
void IPlugEffect::ProcessBlock(sample** inputs, sample** outputs, int nFrames)
{
for (int s = 0; s < nFrames; s++) {
outputs[0][s] = mParamChangesForBlock.Get()[s];
outputs[1][s] = outputs[0][s];
}
}
#pragma once
#include "IPlug_include_in_plug_hdr.h"
/*
This is a basic example of how to get sample accurate parameter changes in iPlug2 VST3 builds
In reality you probably want to use some kind of queue such as those in the VST3 sdk... "public.sdk/source/vst/hosting/parameterchanges.h"
Here we just write parameter changes into a buffer at their sample offset and output those values
*/
const int kNumPresets = 1;
enum EParams
{
kGain = 0,
kNumParams
};
using namespace iplug;
using namespace igraphics;
class IPlugEffect final : public Plugin
{
public:
IPlugEffect(const InstanceInfo& info);
void OnParamChange(int paramIdx, EParamSource src, int sampleOffset) override;
void ProcessBlock(sample** inputs, sample** outputs, int nFrames) override;
void OnReset() override;
WDL_TypedBuf<sample> mParamChangesForBlock; // a buffer, the size of the audio block
};
@TBProAudio
Copy link

Hello,

seems that this code does not work 100%. Did some tests and found, that the plugin receives only the last value of the block:

This part of the code in IPlugVST3_ProcessorBase.cpp seems to be faulty:

if (paramQueue->getPoint(numPoints - 1, offsetSamples, value) == kResultTrue)

I guess it should be something like this:

       for (int j = 0; j < numPoints; j++) 
        {
            (paramQueue->getPoint(j, offsetSamples, value) ;

With the change the plugin receives all sample accurate values.

Quickfix:
replace

        if (paramQueue->getPoint(numPoints - 1,  offsetSamples, value) == kResultTrue)
        {

with

        for (int j = 0; j < numPoints; j++)     // TBPROAUDIO 28062023 quick hack to get all values from DAW
        {
            if (paramQueue->getPoint(j, offsetSamples, value) != kResultTrue)
                continue;

Thanks
Thomas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment