SynthMaker

Peak meter algo

Archive · 2012 8 old posts

From the original SynthMaker forum (2004–2014), with its members’ names and dates.

AxeSlash ·

First post here, so be gentle 🙂

I'm trying to make an accurate peak meter for a snare drum plug that basically adds a sinewave to the audio; so when the incoming audio goes over a threshold level, a sine wave (with an envelope follower) is triggered.

That part all works fine, except the meters aren't fast enough. I've tried all sorts of stuff to try and get them to see the really fast transients of a snare that's been 'transient designer-ed', to no avail.

Currently the best code I've found is this (think I found this on KVR somewhere):

streamin in; streamout out;

float max; float input; input = in; max = max(abs(in),(max(max, abs(in)))*0.9999);//0.9999 controls the release time. out = max;

Then I follow that with a mono to float running off a tick25. Then I've stolen Loopeytunes' green stuff to trigger the individual LEDs.

Something's going wrong somewhere though - a sine wave meters fine with that, but transients are often showing up lower than they should on the meter. I suspect that the code is decaying the signal before the mono to float can pick it up...I'm not too good with code, so is there a better way of doing this? Like holding the max til the ticker has seen it?

The standard envelope followers always seem too slow...

Thanks in advance

nix ·

G'day, I recommend switching the tick25 for a tick 100 to start with. It seems like you need to have a longer release, not faster, hmm Good luck and all success, Nick

AxeSlash ·

I'm almost there; I figured out that I needed to hold the peak until the ticker has seen it (and how to do it in Excel anyway), so now I got this:

streamin in; streamout out; streamin ticktrig;

float lastticktrig; float peakrelease; float lastpeakrelease; float peakhold; float lastpeakheld; float releaseconstant = 0.9999;

peakrelease = max(max(abs(in),(lastpeakrelease*releaseconstant)),lastpeakrelease); peakhold = peakrelease + (lastticktrig>0 & ((max(peakrelease,lastpeakheld))-peakrelease)); lastpeakheld = peakhold; lastpeakrelease = peakrelease; lastticktrig=ticktrig; out = peakhold

Ticktrig is fed by a Trigger Pulse that is triggered by the Tick 25 (see attached)

This doesn't work. The formulas work fine in Excel, though, it all acts as expected there, but I'm guessing I've somehow messed up in translating it to SE - I just can't figure out where.

cyto ·

Hi AxeSlash and welcome 🙂

I think even if you were to get your second example working, you still might suffer from the same problems. The "green" math and the stream math are done on two different CPU threads and don't really sync up well at all. So I would imagine that expecting sample-perfect timing from that trigger pulse thingy is going to leave you disappointed.

I threw together a quick little example of how I would go about doing it. Basically, the working theory is to hold the peak values for a set amount of time before starting the release envelope. I did this with just a simple counter. To show you how effective this can be, I included in the schematic a little module that sends out a single sample pulse when you trigger it. You'll notice that every single pulse is detected. The "hold" and "release" times are adjustable and will be consistent at different sample rates (the release multiplier in you first example isn't).

If you need anything clarified, let me know and I'll be happy to explain.

-cyto

Mo ·

Looks good cyto. You can optimize the scope by place a "String Changed" between the array and the redraw primitive to stop it from constantly redrawing. Then change to tick 100 to make it more smooth.

AxeSlash ·

I'll have a look at that osm in a sec, cyto, but just out of curiosity, the trigger pulse thing makes the bool true for a period that you can supply (in this case I've set it to 1ms), so the 'sync' (for want of a better term) it's not meant to be sample accurate.

I actually get no LEDs lit at all as it is...

AxeSlash ·

Works perfectly, Cyto 🙂

Although I've just realised my first effort probably worked better than I thought, I had some gain structure issues in my test project (duh!) :P

Thanks guys

AxeSlash ·

And here's the final meter for anyone that's interested, pretty easily customisable.

If anyone has any reccomendations to optimise it, they're welcome 🙂

Wrote something here? To have a post removed or your name hidden, write to [email protected].

Before your first post

A few rules keep this a friendly place. You agree to them once.

Shown next to what you post, here and in the app. It doesn’t have to be your real name: 3–24 lower-case letters, digits or _ (capitals become lower case, spaces become _).

    Then your post goes up straight away.

    Delete this reply?

    Open it in SynthMaker?

    It goes on the track you’re editing there, in place of that track’s sound, and into My sounds. Your other tracks stay as they are.

    Want to keep that track’s sound? Start a new song in SynthMaker first (Song › New song), then open this.

    Report this reply?

    Only the developer reads reports. The person isn’t told who reported them.

    What’s wrong with it?

    Block this person?

    You won’t see their posts and replies here any more. They aren’t told, and you can unblock them at any time.

    People you’ve blocked

    Their posts and replies are hidden from you. Unblock someone to see them again.

    The community rules

    A few rules keep this a friendly place. Everyone agrees to them once, before their first post.