Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
IPlugOverSampler
#include "IPlugOverSampler.h"
#include "IPlug_include_in_plug_src.h"
IPlugOverSampler::IPlugOverSampler(const InstanceInfo& instanceInfo)
: Plugin(instanceInfo, MakeConfig(kNumParams, kNumPrograms))
{
GetParam(kGain)->InitDouble("Gain", 1., 1., 100.0, 0.01, "*");
GetParam(kOverSampling)->InitEnum("OverSampling", 0, 5, "", 0, "", OVERSAMPLING_FACTORS_VA_LIST);
}
void IPlugOverSampler::ProcessBlock(sample** inputs, sample** outputs, int nFrames)
{
if(mFactorChanged)
{
mOverSampler.SetOverSampling((EFactor) GetParam(kOverSampling)->Int()); // Warning, this could allocate.
mFactorChanged = false;
}
// // process per-block - WARNING - capture may allocate memory
// mOverSampler.ProcessBlock(inputs, outputs, nFrames, 1 /* how many chans to process */,
// [&](sample** inputs, sample** outputs, int nFrames) {
// for (auto s = 0; s < nFrames; s++) {
// outputs[0][s] = std::tanh(inputs[0][s] * GetParam(kGain)->Value());
// }
// });
// process per-sample
for (auto s = 0; s < nFrames; s++) {
outputs[0][s] = mOverSampler.Process(inputs[0][s] * GetParam(kGain)->Value(), [](sample input) {
return std::tanh(input);
});
}
}
void IPlugOverSampler::OnReset()
{
mOverSampler.Reset(GetBlockSize());
}
void IPlugOverSampler::OnParamChange(int paramIdx, EParamSource, int sampleOffset)
{
switch (paramIdx)
{
case kOverSampling:
mFactorChanged = true; // TODO: maybe check existing factor
break;
default:
break;
}
}
#pragma once
#include "IPlug_include_in_plug_hdr.h"
#include "Oversampler.h"
const int kNumPrograms = 1;
enum EParams
{
kGain = 0,
kOverSampling,
kNumParams
};
using namespace iplug;
class IPlugOverSampler : public Plugin
{
public:
IPlugOverSampler(const InstanceInfo& instanceInfo);
void ProcessBlock(sample** inputs, sample** outputs, int nFrames) override;
void OnReset() override;
void OnParamChange(int paramIdx, EParamSource, int sampleOffset) override;
private:
bool mFactorChanged = true;
OverSampler<sample> mOverSampler {kNone, true, 1}; // init with no upsampling, block processing, mono
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment