Created
November 30, 2020 11:31
-
-
Save olilarkin/1a6e07a1d4ed6c9e20e81938fc1e1b2b to your computer and use it in GitHub Desktop.
VST3 Sample accurate parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
With the change the plugin receives all sample accurate values.
Quickfix:
replace
with
Thanks
Thomas