Moderator: Moderators (Main)
by mynamewontfitin; Wed Nov 21, 2012 3:46 am
I'm attempting to make a Flanger plug-in for one of my University projects, and I'm a little stuck on how to implement the LFO to control the delay time parameter in C++ code. I was just wondering if anyone could suggest some example code of a very generic Flanger unit. Would I need to create a sine wave array via the sampling frequency, and then multiply each index by a sample in the buffer?
I'd really appreciate anyone's help with this
by BertKoor; Wed Nov 21, 2012 5:12 am
You have a bucket brigade delay. Modulation influences the rate at which the buckets are processed.
Back to building that in software: you have a fixed size buffer for the delay. The LFO changes the rate at which samples are put in and read out. So the first requirement is you have a mechanism to run the delay buffer at variating rate, which is different than the sampling rate of the host. So some flexible form of resampling / sample rate conversion is needed. Got that part already?
Now the LFO: it's trivial to make an oscillator. Waveform doesn't need to be sine, can be triangular also (more used in practice I think) which is easier to implement. How often do you ask the LFO it's value? At each incoming sample?
My MusicCalc is back online!!
by mystran; Wed Nov 21, 2012 8:57 am
Classic digital flangers are much easier to implement in software: you simply need a ring-buffer (or something equivalent) which stores a few milliseconds of previous input, and you "access backwards" using interpolated reads (start with linear interpolation, implement something better later if you want to improve quality). How much you access backwards depends on the LFO value.
by mynamewontfitin; Fri Nov 23, 2012 3:49 am
and BertKoor: I'm not cheating, honest! I know it looks bad from here, but I really DO want to fully understand how they all work, rather than just submitting a copied project and learning nothing from it. Plus, I don't want to insult anyone's intelligence by assuming that they won't be able to spot an obviously-plagiarised code
by mystran; Fri Nov 23, 2012 4:50 am
Other than that, the high-level description sounds fine. Note though that you probably want to control the LFO rate, the max delay time, and the depth of the modulation. Flangers often also allow feedback (mixing the output from the delay back to the input; for stability keep the feedback gain strictly between -1 and 1 and be careful not to blow your ears when testing).
edit: Remember the delay ring-buffer can be larger than what you actually need. It's often easier to keep a constant size buffer even when modifying the actual delay, and some people might even round the delay size up to a power-of-two to allow bitmasking the indexes for cheap modulo.
by mynamewontfitin; Fri Nov 23, 2012 5:13 am