Skip to content

Instantly share code, notes, and snippets.

@olilarkin
Created February 21, 2019 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olilarkin/1103fb82de3ace6d4c94660d534100d9 to your computer and use it in GitHub Desktop.
Save olilarkin/1103fb82de3ace6d4c94660d534100d9 to your computer and use it in GitHub Desktop.
static constexpr int kNumModSources = 10;
class MySynth
{
public:
MySynth()
{
SetScratchBuffers(DEFAULT_BLOCK_SIZE);
}
// call in OnReset()
void SetScratchBuffers(int blockSize)
{
// could check and only resize if blockSize > current blocksize
mModScratch.Resize(blockSize * kNumModSources); // resize scratch buffers
memset(mModScratch.Get(), 0, blockSize * kNumModSources * sizeof(float)); zero the memory
mModulations.Empty(); // empty the ptr list
for(auto i = 0; i < kNumModSources; i++)
{
mModulations.Add(mModScratch.Get() + (i * blockSize)); // update the ptrs
}
}
void ProcessBlock(int nFrames)
{
float** moduation = mModulations.GetList();
float* mod1 = modulation[0];
for(int i=0i<nFrames;i++)
{
*mod1 = runMyLFO(); // update per sample
mod1++;
}
}
private:
WDL_TypedBuf<float> mModScratch;
WDL_PtrList<float> mModulations;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment