My goal is fairly simple; to create a tempo synchronized gating effect that simply switches the sound on and off.
Using the demo plugin, and stripping it down to the gainer, I’ve determined how to use ppq and/or samplerate/bpm to determine when the sound should be switched on or off, but I seem to be taking the wrong approach to get the timing right.
Whenever processBlock is called, I check against the current ppqPosition and set applyGain to 1 or 0. This works, but the timing is only as accurate as AudioSampleBuffer which is determined by the soundcard settings.
I’m pretty sure I need to do something on a sample-by-sample basis within the block, using the samplerate/bpm to determine the switch of the gain. This I can determine the math for myself.
My question is how to work on a sample-by-sample basis within processBlock? Would that be the right approach? I am seeking to get the timing as accurate as 12 cycles per beat depending on the input variable. Once I determine this, I will then add smoothing and some other features.
unfortunately I can’t help you in this topic but would like to ask you if you would
share some code snipped for the above as I am still struggling with passing Midi events from the process block to a physical Midi output (not used by the host)
on time. I am not good in doing the math for it
where
mCounter is a member variable (int) initialized to mDurationInSamples .
mDurationInSamples is a member variable (int) holding the time in samples derived from bpm and SR;
mGain is a member variable (int) initialized to 1. it is flipped between 1 and 0 whenever mCounter reaches zero.
this is a simple example and doesn’t work when you fast forward in the host or change positions.
to work with transport changes you have to include the abs. PPQ position as well.