I’m starting to get into some more complicated plug-in projects with JUCE, and working on keeping code as sane and readable as possible as the complexity grows.
One area that’s already a bit messy is the use of magic numbers in the Processor constructor, when setting up filters or other dsp object instances whose values won’t be changing during runtime.
For example, say I’m doing some kind of guitar amp sim, and for part of that there’s a bank of biquad filters for emulating the amp’s tone stack. Those frequencies won’t be changing during runtime. In the Processor’s constructor, I’ve got something like this:
biquad.init(sr, 4, 100, 0.8); biquad.init(sr, 3, 1000, 1.2); biquad.init(sr, 5, 5000, 0.7);
Now, if instead of using magic numbers in those
init calls, the frequency and Q values could be replaced by constants of some kind. It would allow a quicker read of all the hardcoded parameters’ values in one place at the top of the Processor file, and it would allow a clearer read of the biquad
init calls when viewing this constructor code. Yet I don’t see this done in the code examples I’ve looked at.
So, I’m hoping to open the “best practices” of this up for discussion here. But as one specific question: which type of constant do you think would be best for this case?
const float tonestackLowFreq = 100;
#define TONESTACK_LOW_FREQ 100
Besides the stylistic choice, there’s the difference of type checking when using a
const float. But do you see that difference as more of an advantage, or an (unwelcome) constraint, in this context?