Hi
I’m trying to design a simple rectangle meter . The result is not satisfactory since its jumpy and not accurate. I will lay out what i have done and maybe experts could give me some advise on this.
in my processor (inside process block):
a) UI: Is this the right approach to drawing the meter?
b) DSP: Why I’m getting incorrect values from envelope follower? It moves up and down (Seams like low frequency) even when the input has a static level. It doesn’t react any good to fast hits either.
Thanks in advance.
Your enveloper follower is wrong because it should add and not substract the term for the release to your envelope state variable.
Moreover, such an envelope follower would make some sense only if the release constant time is a lot higher than the attack constant time.
If you do so, you will have something that looks like a meter. But coding a proper meter isn’t an easy task…
The envelope follower is used in general for the UI instead of in the DSP classes. Indeed, if you do a peak-style meter, you want the maximum peak value to be displayed, not to be affected by an envelope follower…
It is better to use a HighResTimer in this situation than a simple Timer, so your repainting is put in another thread than the other UI tasks
In general, a buffer is used for the calculation of the value to display which has a fixed size. With your implementation, the behaviour of the meter changes depending on the audio buffer size, which is not right…
Finally, the communication between the DSP and the UI is better handled by lock-free structures, so it is thread-safe without any potential deadlock or any wrong concurrency coding issues. The reason why we care about that is because your algorithm might return wrong values in “stress situations”, when the CPU is already being used a lot by other plug-ins. A way to do so in your implementation would be for example to make your ChannelData variable an Atomic instead of a simple float. See also that thread for more information : Concurrency, meters, JUCE classes