Last active
June 14, 2024 12:21
-
-
Save olilarkin/5dfa44d265bc8cf7ec0fe350e079eb0d to your computer and use it in GitHub Desktop.
IPlugOverSampler
This file contains hidden or 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 "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; | |
} | |
} |
This file contains hidden or 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" | |
#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