Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@olilarkin
Last active August 20, 2021 07:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olilarkin/5dfa44d265bc8cf7ec0fe350e079eb0d to your computer and use it in GitHub Desktop.
Save olilarkin/5dfa44d265bc8cf7ec0fe350e079eb0d to your computer and use it in GitHub Desktop.
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