(SOT) Programmatically detecting normalized wav files

This section is now closed.
Forum rules
Audacity 1.2.x is now obsolete. Please use the current Audacity 2.1.x version.

The final version of Audacity for Windows 98/ME is the legacy 2.0.0 version.
dgoldsmith
Posts: 26
Joined: Mon Apr 06, 2009 8:25 pm
Operating System: Please select

(SOT) Programmatically detecting normalized wav files

Post by dgoldsmith » Sun Mar 07, 2010 1:40 am

Hi, folks. I have a bunch of wav files - some are normalized (using audacity), some are not, and I don't know which are which. I'd like to write a Python script that can figure out which are which; is there some way, just by reading a wav file as binary data, to detect if it's normalized, e.g., grab it in 16 bit chunks (after a suitable offset), looking for a sequence of 16 ones? Or is the "signal" portion of a wav file encoded such that that wouldn't work, even if I could figure out the correct offset? Any other ideas? Thanks!

DG

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

Re: (SOT) Programmatically detecting normalized wav files

Post by kozikowski » Sun Mar 07, 2010 3:21 am

Since you can't do that, you should probably tell us what you're really trying to do.

Audacity tracks can be normalized and amplified (cousin tools) to any number. You can easily have a natural track that looks like it's been normalized but hasn't. So there's no goal to code for.

Koz

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

Re: (SOT) Programmatically detecting normalized wav files

Post by steve » Sun Mar 07, 2010 3:23 am

If you normalized a track to 0dB in Audacity there will be at least one sample per track that is + or - 1.0. However, since Normalizing works to bring the highest peak up to the target level there may only be one sample that is at +/- 1.0 and it could be anywhere in the track.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

dgoldsmith
Posts: 26
Joined: Mon Apr 06, 2009 8:25 pm
Operating System: Please select

Re: (SOT) Programmatically detecting normalized wav files

Post by dgoldsmith » Sun Mar 07, 2010 3:42 am

Koz: Since you can't do that, you should probably tell us what you're really trying to do.
Precisely what I state: sort the tracks into normalized and not normalized
Koz: Audacity tracks can be normalized and amplified (cousin tools) to any number. You can easily have a natural track that looks like it's been normalized but hasn't. So there's no goal to code for.
I always normalize to the maximum level that won't clip any portion (leaving it to Audacity to figure out what that should be for the given track, which it appears to do quite well); in other words, I just select normalize, and Audacity makes the maximum amplitude 1dB - more than that, I do not know.
stevethefiddle: If you normalized a track to 0dB in Audacity
See above.
there will be at least one sample per track that is + or - 1.0.
The amplitudes are stored as floats between + and -1???
However, since Normalizing works to bring the highest peak up to the target level there may only be one sample that is at +/- 1.0 and it could be anywhere in the track.
I know that, that's why I want to write a program to find it!

DG

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

Re: (SOT) Programmatically detecting normalized wav files

Post by kozikowski » Sun Mar 07, 2010 4:00 am

<<<Audacity makes the maximum amplitude 1dB - more than that, I do not know.>>>

I hope not. Undistorted audio goes from 0 dBFS and down. Not up. All negative numbers. Default Normalize and Amplify are both 0, not -1dB. You can change the value to anything including +1 by clicking on "Distortion is OK."

The difference between the two tools is Amplify applies one correction to both tracks (Left and Right) of the whole show and Normalize changes each track individually.

<<<Precisely what I state: sort the tracks into normalized and not normalized>>>

Because you intend to do something to one of the two sets? You're describing a poem that stops in the wrong place.

Koz

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

Re: (SOT) Programmatically detecting normalized wav files

Post by steve » Sun Mar 07, 2010 4:23 am

dgoldsmith wrote:The amplitudes are stored as floats between + and -1???
In Audacity, yes. After it has been exported as an audio file, then it depends on the file format.

A quick way in Audacity to see if a file has been normalized: Select the "Amplify" effect and if the track has been normalised to 0dB the Amplify effect will indicate an amplification amount of 0.0dB.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

dgoldsmith
Posts: 26
Joined: Mon Apr 06, 2009 8:25 pm
Operating System: Please select

Re: (SOT) Programmatically detecting normalized wav files

Post by dgoldsmith » Sun Mar 07, 2010 5:44 am

I hope not. Undistorted audio goes from 0 dBFS and down. Not up. All negative numbers. Default Normalize and Amplify are both 0, not -1dB. You can change the value to anything including +1 by clicking on "Distortion is OK."
OK, I guess dB is the wrong unit; what is the unit of the ordinate (i.e., along the y-axis) when you load a track into the editing window, and the wave form is plotted between -1 and +1? What ever it is, that's what I'm referring to when I speak of normalize making the maximum amplitude + or -1.
Because you intend to do something to one of the two sets? You're describing a poem that stops in the wrong place.
Normalize the ones I haven't.
In Audacity, yes. After it has been exported as an audio file, then it depends on the file format.
That's why I marked my subject "SOT" (slightly off topic): I want to scan _wav_ files (not audacity files, and not using audacity, unless audacity can do that, which would be pleasant "news to me"; I thought I was pretty clear about what I wanted to do in my original post) to determine if they've been normalized.
A quick way in Audacity to see if a file has been normalized: Select the "Amplify" effect and if the track has been normalised to 0dB the Amplify effect will indicate an amplification amount of 0.0dB.
Can that be done programatically, e.g., using a chain? (I know I can do that manually, but I have tens of thousands of files I want to check - there's no way I'm checking 'em all "by hand"; if it turns out there's just no way to programatically sort them as I want, I'll just have to re-apply my normalize chain to everything - I just don't want to have to waste the time reapplying it to ones I've already applied it to if I can find some way not to.)

Thanks!

DG

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

Re: (SOT) Programmatically detecting normalized wav files

Post by kozikowski » Sun Mar 07, 2010 6:16 am

<<<Normalize the ones I haven't.>>>

Normalize will have no effect on the ones already normalized. That's one of its talents. The Normalize available range of corrections includes zero.

Koz

dgoldsmith
Posts: 26
Joined: Mon Apr 06, 2009 8:25 pm
Operating System: Please select

Re: (SOT) Programmatically detecting normalized wav files

Post by dgoldsmith » Sun Mar 07, 2010 7:15 am

Normalize will have no effect on the ones already normalized. That's one of its talents. The Normalize available range of corrections includes zero.
I know that (that's what I'll be taking advantage of if I have to just re-apply normalize to everything), but can it determine whether or not a file has been normalized w/out having to read it in to the editor, e.g., when used in a chain? For 10000 files, approx. 7000 of which have already been normalized, if it has to read the file in to the editor before it can determine whether or not it's pointless to continue, well, that's a lot of wasted CPU time.

DG

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

Re: (SOT) Programmatically detecting normalized wav files

Post by steve » Sun Mar 07, 2010 12:45 pm

dgoldsmith wrote:I know that (that's what I'll be taking advantage of if I have to just re-apply normalize to everything), but can it determine whether or not a file has been normalized w/out having to read it in to the editor, e.g., when used in a chain? For 10000 files, approx. 7000 of which have already been normalized,
This question has changed in emphasis quite considerably since the first post where we were looking at sorting "a bunch of wav files". I guess that 10000 files could still be described as "a bunch" but it's a darned big bunch. A bit more information could help to come up with the best solution, for example - could the "last modified" date tell you which have been normalised?

If you need to batch process all of the files you will probably find "SOX" a lot more efficient than Audacity. http://sox.sourceforge.net/
The basic command for normalising with SOX is:

Code: Select all

 sox --norm infile -b 16 outfile rate 44100 dither -s
If you want to reinvent the wheel and write your own script, if your files are "WAV (Microsoft) signed 16 bit PCM", then each sample value is a signed 16 bit number.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Locked