understanding peak-meters

Audio software developers forum.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
duchamp
Posts: 3
Joined: Sun Nov 14, 2010 9:09 pm
Operating System: Please select

understanding peak-meters

Post by duchamp » Sun Nov 14, 2010 10:01 pm

Dear forum,
this is my first post here, so ... nice to meet you (and forgive my English) :)

I'm trying to understand how audacity peak meter works, and so far these are my knowledges:

1) the "core" thing is into Meter::UpdateDisplay(int numChannels, int numFrames, float *sampleData)
2) the formula: average of a window of samples (something like 1/10 seconds of audio data), then 20 * log10 (fabs(average of samples))

Now, let's take for example a sine wave with a -1.0 / 1.0 range of amplitude and apply the formula 2): the average will be something like 0.6 which means a value of -4.4 dB (values very approximated). This is obviously NOT the maximum. So why Audacity displays correctly a peak in its meter, drawing the bar exactly at 0 dB? Maybe the secret lies into ClipZeroToOne(float) or the strange conversion (db + range) / range, which I can't understand completely? :oops:
Thank you in advance for any suggestion!

kozikowski
Forum Staff
Posts: 69357
Joined: Thu Aug 02, 2007 5:57 pm
Operating System: macOS 10.13 High Sierra

Re: understanding peak-meters

Post by kozikowski » Mon Nov 15, 2010 2:34 am

<<<So why Audacity displays correctly a peak in its meter, drawing the bar exactly at 0 dB?>>>

That is a mistake. Audacity only meters the top half of the blue waves. Not the bottom. It may have been corrected since I saw this problem.

I generated a natural sound test signal with a microphone. I intentionally damaged it by reversing the top and bottom waves. A correct meter would not change, but the Audacity meter did change.

Koz

steve
Site Admin
Posts: 81609
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: understanding peak-meters

Post by steve » Mon Nov 15, 2010 6:41 pm

kozikowski wrote:Audacity only meters the top half of the blue waves. Not the bottom. It may have been corrected since I saw this problem.
The meters show both peak and RMS values by using two different shades of green (playback meter) or red (recording meter).
The (higher) darker shade is the peak measurement and the lighter shade is the RMS measurement.
In the current version of Audacity, the peak measurement shows positive peaks.
The RMS measurement is displayed correctly in the normal way.

@Koz have you previously raised this issue about the peak meter? Did you get a answer as to whether it is a bug or a feature?
If it's considered to be a feature, then I think that we need a feature request for the meters to display "absolute peak" (that is, peak positive or negative).
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

duchamp
Posts: 3
Joined: Sun Nov 14, 2010 9:09 pm
Operating System: Please select

Re: understanding peak-meters

Post by duchamp » Tue Nov 16, 2010 11:28 am

Audacity only meters the top half of the blue waves
Hi Koz, if with "top half" you mean positive values, I think that this is the right way, because you need to know only the absolute value of a sample (modulus). Please correct me if I'm wrong!

steve
Site Admin
Posts: 81609
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: understanding peak-meters

Post by steve » Tue Nov 16, 2010 6:55 pm

Yes, you only need to know the absolute value of a sample (modulus), but that is not what the Peak meters show.

If you look at the waveform on an Audacity track you will notice that the default view has a linear vertical scale in the range +/- 1
A waveform will clip (distort) if the waveform exceeds this range. However, the peak meters only look at the positive values (0 to +1) and ignore the negative values (< 0).
Koz and myself are in agreement that a "peak" value of -1 (minus one) should show on the peak meter as 0dB and I suspect that you are of like mind.

To test this, select part of an audio track and run this code in the "Nyquist Prompt" effect:

Code: Select all

(sum 0.5 (scale 0.5 (osc 60)))
This will generate a sine tone that is offset so that it is all in the range of 0 to +1
When you play this track, as expected the peak level is immediately shown in dark green as 0dB and the RMS value (shown in light green) climbs up to -4.3dB

Now run this code:

Code: Select all

(sum -0.5 (scale 0.5 (osc 60)))
This will generate a sine tone that is offset the other direction so that it is all in the range of 0 to -1
As expected the RMS level climbs up to -4.3dB, but the peak level is nowhere to be seen because the meter is measuring it as -infinity dB.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

whomper
Probationer
Posts: 1251
Joined: Sat Jan 23, 2010 9:36 pm
Operating System: Please select

Re: understanding peak-meters

Post by whomper » Wed Nov 17, 2010 4:08 pm

Agree that peak should be max of + - not just +.

Why not just do absolute value before computing it?
Would that slow things down too much while recording?

It should not matter unless there is really bad DC offset.
Recordings should be -24dBFS (-18dbFB if you live dangerously).
So a couple of db on the peak meter is noise.
The peak from Plus values is good enough for govt work.

When editing, the abs value should be used. As that is a batch computation the time to do it should not be a concern.

Suggestions:
Leave it alone for recording.
Fix it (if needed) for fx and batch processing.

steve
Site Admin
Posts: 81609
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: understanding peak-meters

Post by steve » Wed Nov 17, 2010 6:22 pm

whomper wrote:Why not just do absolute value before computing it?
Would that slow things down too much while recording?
I don't know if it would have much of a performance hit, but I wouldn't have expected it to. If you write a patch against SVN head I'd be happy to test it.
whomper wrote:It should not matter unless there is really bad DC offset.
Waveforms are not necessarily symmetrical even if they have no DC offset, so with some waveforms it will matter.
whomper wrote:Recordings should be -24dBFS
If you are talking about the peak recording level, then as has been explained to you many times before, -24dBfs is a bit lower than ideal. The Audacity documentation (and most other authoritative texts) recommend that, in most situations, aiming for a peak level of around -6dB is about right. However, this is not the subject being discussed in this topic.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

duchamp
Posts: 3
Joined: Sun Nov 14, 2010 9:09 pm
Operating System: Please select

Re: understanding peak-meters

Post by duchamp » Wed Nov 17, 2010 10:01 pm

Thank you guys for the detailed explanations and inspirations, now I have a clear picture of this case.
So Audacity takes the maximum value inside a buffer of samples, but only the positive ones (and this seems to be an issue).

I don't think that something like fabs(x) would slow down the processing, I'm already using it in an ultraraw peak meter and my CPU doesn't complain.

steve
Site Admin
Posts: 81609
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: understanding peak-meters

Post by steve » Wed Nov 17, 2010 10:36 pm

duchamp wrote:So Audacity takes the maximum value inside a buffer of samples, but only the positive ones (and this seems to be an issue).
Yes it appears to do so, but in normal recording practice it would a very rare occurrence for it to be a significant problem.

It is however a little disconcerting that the left channel of this waveform (which HAS been Normalized) meters at very close to 0 dB,
firsttrack000.png
firsttrack000.png (18.66 KiB) Viewed 3635 times
whereas if the waveform is inverted (see below) the same (left) channel meters at around -3 dB
firsttrack001.png
inverted
firsttrack001.png (18.47 KiB) Viewed 3636 times
Fortunately the red clipping indicators work with both positive and negative peaks.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

billw58
Forum Staff
Posts: 5601
Joined: Wed Aug 12, 2009 2:10 am
Operating System: macOS 10.15 Catalina or later

Re: understanding peak-meters

Post by billw58 » Wed Nov 17, 2010 11:49 pm

Confirmed on 1.3.13 Nov 7. It's also fairly easy to generate an asymmetrical wave. Generate tone into three separate mono tracks: 220, 440 and 880 Hz at level 0.2. Slide the 440 and 880 Hz tracks so the first peak lines up with the first peak in the 220 Hz track. Mix and Render.

-- Bill

Post Reply