True Peak Normalizing

Questions, discussion and recipes for scripting and batch processing in Audacity.
See also the "Scripting" section of the Audacity manual.
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
Post Reply
afro
Posts: 4
Joined: Mon Sep 13, 2021 4:26 am
Operating System: Windows 10

True Peak Normalizing

Post by afro » Mon Sep 13, 2021 4:28 am

Hey, I work with lots of audio files that need to be normalized to a certain db level True Peak. The way i'm trying to do it is through a macro:

SetProject:Rate="192000"
Normalize:ApplyGain="1" PeakLevel="-1" RemoveDcOffset="0" StereoIndependent="0"
SetProject:Rate="44100"

But it seems that audacity is not resampling the actual files to the higher sample rate, just the project's.
Is there something i'm missing? how do I batch resample a bunch of files to a higher sample rate in order to simulate true peak normalizing?

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

Re: True Peak Normalizing

Post by kozikowski » Mon Sep 13, 2021 8:20 am

audacity is not resampling the actual files to the higher sample rate
Audacity converts sound files to its own high quality internal format for editing. It doesn't work on the original file. When it's done, you can tell Audacity to Export the show to the original file name and it will downconvert the quality back to normal and overwrite the original file.

There is an upper limit to the sampling rate that Audacity can use and I don't remember what it is.
I work with lots of audio files
MP3 files? Because of the double conversion process, the quality of the corrected MP3 files is always worse than the original.

You may decide you want one of the "pure" MP3 editors missing the conversions.

https://mpesch3.de/

Koz

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

Re: True Peak Normalizing

Post by steve » Mon Sep 13, 2021 9:55 am

When working with "normal" audio, "True Peak" will only be a small fraction of a dB higher than the highest sample value.
Rather than worrying about fractions of a dB, I just normalize lossless file formats to -1 dB, which leaves plenty of space for the "true" peaks.


afro wrote:
Mon Sep 13, 2021 4:28 am
how do I batch resample a bunch of files to a higher sample rate in order to simulate true peak normalizing?
You need to add the command "MixAndRender:"

Code: Select all

SetProject:Rate="192000"
SelectAll:
MixAndRender:
Normalize:
ExportWAV
SetProject:Rate="44100"
Note that although Audacity's resampling is extremely good, down-sampling (lowering the sample rate) is never "perfect". If you resample the exported file back to 44100 Hz, the small losses due to resampling will be greater than if you had not bothered about "True Peak" and just normalized to -1 dB.

Note that MP3 requires more headroom as peaks may be higher due to encoding losses.

Note that "True Peak" may be more or less that "actual peak" after it has gone through the D/A converter, as D/A converters are not perfect.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

afro
Posts: 4
Joined: Mon Sep 13, 2021 4:26 am
Operating System: Windows 10

Re: True Peak Normalizing

Post by afro » Mon Sep 13, 2021 1:48 pm

steve wrote:
Mon Sep 13, 2021 9:55 am
afro wrote:
Mon Sep 13, 2021 4:28 am
how do I batch resample a bunch of files to a higher sample rate in order to simulate true peak normalizing?
You need to add the command "MixAndRender:"

Code: Select all

SetProject:Rate="192000"
SelectAll:
MixAndRender:
Normalize:
ExportWAV
SetProject:Rate="44100"
If i slightly modify this script to remove the final export:

Code: Select all

SetProject:Rate="192000"
SelectAll:
MixAndRender:
Normalize:ApplyGain="1" PeakLevel="-1" RemoveDcOffset="0" StereoIndependent="0"
SetProject:Rate="44100"
It works perfectly for a single file at a time, if I try doing this with multiple files on the project, it combines every file into one (I'm assuming because of SelectAll > MixAndRender). Is there a way to do this per track and keep all the files separate?

Also, I'm fine with exporting the files myself through File > Export > Export Multiple, the macro doesn't need to do it for me, since I'll be saving the files to somewhere else on my computer.

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

Re: True Peak Normalizing

Post by steve » Mon Sep 13, 2021 2:11 pm

afro wrote:
Mon Sep 13, 2021 1:48 pm
Is there a way to do this per track and keep all the files separate?
Yes. It's called "batch processing".

1. Launch Audacity (an empty Audacity window appears)
2. "Tools menu > Macros"
3. Select the macro that you want to run
4. Click the "Files" button (at the bottom)
5. Select the files that you want to process (they must all be in the same folder)

Note that the macro must include one of the "Export" commands.

The processed files will then be exported to the "macro-output" folder. This is configurable, see: https://manual.audacityteam.org/man/dir ... ences.html

When running the macro as a batch, you won't need the final SetProject:Rate="44100" (but you do need the ExportWAV command)
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

afro
Posts: 4
Joined: Mon Sep 13, 2021 4:26 am
Operating System: Windows 10

Re: True Peak Normalizing

Post by afro » Mon Sep 13, 2021 2:54 pm

steve wrote:
Mon Sep 13, 2021 2:11 pm
afro wrote:
Mon Sep 13, 2021 1:48 pm
Is there a way to do this per track and keep all the files separate?
Yes. It's called "batch processing".

1. Launch Audacity (an empty Audacity window appears)
2. "Tools menu > Macros"
3. Select the macro that you want to run
4. Click the "Files" button (at the bottom)
5. Select the files that you want to process (they must all be in the same folder)

Note that the macro must include one of the "Export" commands.

The processed files will then be exported to the "macro-output" folder. This is configurable, see: https://manual.audacityteam.org/man/dir ... ences.html

When running the macro as a batch, you won't need the final SetProject:Rate="44100" (but you do need the ExportWAV command)
Ah, batch processing makes a lot more sense than trying to do it all in a single project.
I tried it without setting the project back to 44100 and it saved the files in 192000, which I guess I should have expected, so I included the final downsampling back to 44100 and now it works almost exactly the way I want it to.

Now the only thing that's slightly bothering me is that the files are exported as 16 bit .wav files, whereas the original files are in 32 bit. I know it may seem like a minor thing, but is there a way to save them as 32 bit? The settings in my Preferences > Quality are set to 44100 32-bit float and i can't find any Render/Export quality settings, It seems like the only way to export a 32 bit file is by changing the option to "WAV (Microsoft) 32-bit float PCM" in the Export Audio window, which is not possible to change to from the macro command.

You've been very helpful so far, so if this is not possible I'll just accept it and move on!

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

Re: True Peak Normalizing

Post by steve » Mon Sep 13, 2021 3:17 pm

afro wrote:
Mon Sep 13, 2021 2:54 pm
is there a way to save them as 32 bit?
Unfortunately Audacity does not yet have a way to set the export options for the macro Export commands.
Fortunately there is a workaround:

Before running the macro, just export from Audacity (manually) with "File menu > Export > Export as WAV" and select the required format (probably "32-bit float" if you want it to be the same as Audacity uses internally).
The settings that you use are remembered by Audacity as the default for next time you export as WAV.

After doing that, go back to an empty project, and run your batch process.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

afro
Posts: 4
Joined: Mon Sep 13, 2021 4:26 am
Operating System: Windows 10

Re: True Peak Normalizing

Post by afro » Mon Sep 13, 2021 3:24 pm

steve wrote:
Mon Sep 13, 2021 3:17 pm
Before running the macro, just export from Audacity (manually) with "File menu > Export > Export as WAV" and select the required format (probably "32-bit float" if you want it to be the same as Audacity uses internally).
The settings that you use are remembered by Audacity as the default for next time you export as WAV.
This works perfectly, you've just saved me tons of time :D
Thank you so much for all the quick responses!

Post Reply