SynthMaker

Peak Hold in a Display

Archive · 2011 20 old posts

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

wasabeevst ·

Hi!

I'm trying to develop a plug-in which show the numeric value of output in a Display. So, I want that in the display the user can see the max. value of peak that the signal arribe... how's it possible?

sorry 4 my bad english but I don't speak...

Thanx everybody!

trogluddite ·

Hi, I assume that you want to find the max of a stream signal (changing at sample rate, like audio) - so you need to get the max using stream (blue) parts. The simplest way, is to use an arrangement like this...

When 'On/Off' = TRUE. The 'Max' primitive (top one) here, will compare the present input value with the previous output value and keep the biggest one. This works because when you have feedback from output back to input, the feedback is always the result from the previous sample. Also Boolean TRUE = 1 so the output value is not changed.

When On/Off = FALSE. FALSE = 0, so the max now finds the biggest of the input value and zero --> just the input value. So now the peak is reset.

If you are looking for peaks in an audio signal, remember that sometimes the negative (downwards) part of the audio might be the biggest - so you can add a 'stream abs' to the main input to find only the size of peak, even if it is a negative peak.

Mo ·

Nice solution Trog. I think it will be better to make this in green for a display. Also stream abs would use a lot cpu. I tried but it turned red, so found another solution for green:

Here build into the Mono Readout:

trogluddite ·

Mo wrote: think it will be better to make this in green for a display

The problem with using the green method, is that the M2F can only trigger at max.100Hz (25Hz for your schematic) - so it is unlikely that the maxima that you find will truly capture the peaks of the audio. To guarantee a true maximum it is necessary to find the peaks in stream form before converting to green.

Mo wrote: Also stream abs would use a lot cpu

True, the stock abs function is not compiled as efficiently as it could be - there is a much quicker way if written directly in assembly, using bitmasking to remove the sign bit...

streamin in; streamout out; int absMask = 2147483647; //largest positive 32bit integer

movaps xmm0,in; andps xmm0,absMask; //sign bit to zero movaps out,xmm0;

Mo ·

trogluddite wrote: The problem with using the green method, is that the M2F can only trigger at max.100Hz (25Hz for your schematic) - so it is unlikely that the maxima that you find will truly capture the peaks of the audio. To guarantee a true maximum it is necessary to find the peaks in stream form before converting to green.

Ah yes. Too slow for analyse most audio. trogluddite wrote: there is a much quicker way if written directly in assembly, using bitmasking to remove the sign bit...

Thanks for reminding me, it is a cmpps, a sub and a add less than the new abs code function.

infuzion ·

trogluddite wrote: Mo wrote: think it will be better to make this in green for a display

The problem with using the green method, is that the M2F can only trigger at max.100Hz (25Hz for your schematic) - so it is unlikely that the maxima that you find will truly capture the peaks of the audio. To guarantee a true maximum it is necessary to find the peaks in stream form before converting to green.

Mo wrote: Also stream abs would use a lot cpu

True, the stock abs function is not compiled as efficiently as it could be - there is a much quicker way if written directly in assembly, using bitmasking to remove the sign bit...

streamin in; streamout out; int absMask = 2147483647; //largest positive 32bit integer

movaps xmm0,in; andps xmm0,absMask; //sign bit to zero movaps out,xmm0;

I agree, but you have to reset the held max value after it is drawn. This "Peak Hold" is exactly why I made this post: Green 2 Stream - Missed Triggers

tor ·

To get it displayed you still need to use the M2F. If there only a few samples exceeding 1 or whatever value there is no guarantee the overshot is detected. I have done this faulty in the Equilibre meters so I need to fix it with a code inbetween abs and M2F that sample and hold overshoots for a certain amount of time to be sure the overshot is detected and displayed.

trogluddite ·

I think it depends what you want from the max. I interpreted the question as - show me the maximum value that has ever happened since the last manual reset - in which case my little doo-dad should work fine when followed by an M2F to drive the display. I quite like latching 'max' indicators, as I'm often not in the same room as my VDU when setting levels - maybe that biased my interpretation. If building a peak reading meter, or 'flashing' overs indicators, then yes, you need something to make sure that they get shown for long enough to be seen - and then reset for the next interval.

tor ·

Ah.. yes, you are right. And thank you. Now I see how to improve the peak detector on my eq in a simpler and CPU efficient manner 🙂

wasabeevst ·

wow! Thank u all!!! Mo this osm is fantastic but I need to show the max value (like your scheme and the manual reset is cool) in dB... I want to show the same value like te meter of the chanel in our DAW (Cubase for example)... Pro Tools have a Peak Hold each channel in the display of the bottom... anybody know what i mean?

I want to show the maximum output value in dB... any idea?

infuzion ·

wasabeevst wrote: I want to show the maximum output value in dB... any idea?

Doesn't the SM's Toolbox have a compressor?

Mo ·

Here's a more precise Peak Hold Readout using trog's idea and coded in ASM. Readout is dB. Enjoy. Just click the display to reset.

trogluddite ·

Mo wrote: Here's a more precise Peak Hold Readout

Whoa, that boy is fast! 😀 Good work Mo. I can see a couple of tiny improvements, just to lower the CPU load a bit... 1) Tick 25 ought to be enough - the max value is held until reset, so it doesn't need a super-fast screen update. 2) 'Float changed' after the M2F, so that the maths and re-draw are only done at the times when the peak value changes.

Mo ·

trogluddite wrote: Float changed' after the M2F, so that the maths and re-draw are only done at the times when the peak value changes.

There seems to be no difference in the Trigger counter with a Float changed. I think it is already build into the M2F.

trogluddite ·

Mo wrote: Float changed. I think it is already build into the M2F.

Well, I'll be darned!! 😮 I had never noticed that before - I tried out a few little designs, and you're quite right, the M2F does indeed appear to have a built-in 'Float Changed! Very weird that it should be the only primitive with this feature (assuming it is the only one!) - but pretty useful, all the same. That's something else to add to my "exception to the rule" chapter of the trigger tutorial.

wasabeevst ·

wow thanks!!! that's what I need!!!!

CONGRATS! it's fantastic!

lesobrod ·

Hey people please let me up this thread. I like searching some weird and intricate processes so very need something like Min-Max detector. But it should do at least 2 detection - total, global Min-Max finding (until some Reset comes) and scanning for local Min-Max within some time period. Сomparison of all data helps to understand what is going on. I made a kind of module (and it works not bad) but it looks clumsy (I mean "made by axe"; is it correct word?). So maybe someone look inside and make some suggestion? 😉

trogluddite ·

Hi, This should be a bit of an improvement...

Seemed to me that the way that the displays showed the reset to zero, then rise/fall to the max/min was very confusing. In this version the min/max are calculated in Temp variables for the interval duration - then passed to the outputs once at the end - so the display now holds a steady min/max value for each interval.

Renaming min/max to minTemp/maxTemp also helps make the code easier to parse (for SM and for humans!) - it is not a good idea to have variables with the same name as a code command/function. I usually begin all variable names with a capital letter for this reason.

The ideal way for this to work would be so that the output shows the true min/max for the previous 'N' samples, constantly updated. I have wanted this for a long time, but the only way I find is to scan through a large circular buffer for every iteration, which IMHO is just too greedy for CPU. However, I think that the current method, used with an accurate stream timer, and something like Martin's pitch detector (to calculate the period) might be effective enough to get the local maxima for a good PSOLA algorithm. (I guess from questions in your other threads that maybe this is what you are looking for?).

lesobrod ·

OK this looks like made by laser! +100 to karma 😀 😀 P.S. Now I see that its allow to put many statements with ";" into one line of code. 😊 But how to do a hyphenation of long statement to the next line?

trogluddite ·

lesobrod wrote: But how to do a hyphenation of long statement to the next line?

LongStatement = ThisLine +AnotherLine +max(MoreLines,AsManyAsYouLike) +TerminateWithSemicolon;

That's it - line breaks are ignored by the parser, the statement simply ends with the semicolon - no need for any special 'hyphenation' characters or anything.

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.