[sdiy] VU meter algorithms
tom at electricdruid.net
Mon Mar 25 21:34:39 CET 2019
If anyone is interested or would find such a thing useful, I’ve put code and details online:
It’s a cheap-and-available way to not need the LM391x series chips, which used to do this job. Except my modern version has the Peak Hold feature described below, so I’ve managed to get some little improvement in there too.
Thanks to everyone who provided ideas and feedback. It’s great to kick ideas around with you all.
Synth & Stompbox DIY
> On 21 Mar 2019, at 13:31, Tom Wiltshire <tom at electricdruid.net> wrote:
> I implemented the typical Peak Hold algorithm as described by Ben Bradley, and it does a much better job than an “instant attack, slow decay” type filter.
> However, the problem that Brian points out is valid, so I had a think about it and I’ve made the following modifications to the algorithm:
> We need to keep track of a secondary “fallback” peak, with its own timeout counter. If the main peak hold timeout counter times out, then instead of resetting it to zero, we set it to the value of the fallback peak and copy the vale of the fallback timeout counter. That fallback peak is then the one that gets reset to zero.
> When new data comes in, it is compared firstly to the main peak hold.
> If it is greater or equal then the new data is used as the new peak hold value and the timeout counter is reset to its maximum value. In this case the fallback is reset to zero so that its ready to detect any new secondary peaks that might come along.
> If it’s not greater or equal to the main peak hold, it’s compared to the fallback value. If its higher or equal to that, it replaces that value, and the timeout counter for that is reset.
> And that’s it. It seems to prevent the problem described, and although it’s not perfect in that there are situations in which a “third place” peak could get lost, in practice I doubt you’d care much.
> Electric Druid
> Synth & Stompbox DIY
>> On 20 Mar 2019, at 06:33, rsdio at audiobanshee.com wrote:
>> Tom, I think your disappointing results are due to applying a traditional decay to the Peak Hold. What you really want is a literal hold of the same value for some amount of time. The value isn’t actually supposed to decay during that time. Also, you don’t want to make the time window as short as 16 samples, otherwise you’ll see the jumpy results that you don’t like.
>> As Ben described, you want an instant attack that updates the Peak on every sample. Then, rather than using typical signal processing for “decay,” just implement a counter that will hold the value constant for a minimum time (unless a new peak arrives).
>> To answer your question, what Ben described is the standard algorithm. There are some bugs with the algorithm, and every Peak Hold meter I’ve ever seen has the same bug.
>> To be specific, the bug I’m talking about is due to the Peak clearing itself after the Hold time. Each new Peak erases the previous Peak. What can happen is that a new “near” Peak can occur right before the Hold time expires, but the algorithm will completely miss this, clearing the Peak almost immediately. The reason I can be sure that Ben’s description is standard is that all Peak Hold meters have this same flaw.
>> On 18 Mar 2019, at 19:11, Ben Bradley <ben.pi.bradley at gmail.com> wrote:
>> For peak, use a "hold time" of perhaps 1/2 or 1/5 second. When a peak
>> is detected, set the bargraph level to it, and set a timeout of the
>> hold time. When the timeout occurs, set the peak level to zero. If
>> there's still a signal, it will immediately set the currently held
>> peak to the new peak value. But wait, there's more: Have the peak
>> detection code continue to run during this timeout time, If there's a
>> new higher peak, save it as the current peak AND reset the timeout to
>> the hold time, so it stays at this new level.
> Synth-diy mailing list
> Synth-diy at synth-diy.org
More information about the Synth-diy