PDA

View Full Version : OT: Normalising FLACS



2004-12-03, 10:50
Not being a programmer myself. I have no idea on how to user this script. Can someone please provide some guidance on this?

Thanks in advance

NH

-----Original Message-----
From: discuss-bounces (AT) lists (DOT) slimdevices.com [mailto:discuss-bounces (AT) lists (DOT) slimdevices.com]On Behalf Of Jeff Coffler
Sent: Monday, November 29, 2004 6:47 PM
To: Slim Devices Discussion
Subject: [slim] OT: Normalising FLACS


Hi Ben,

I've finished ripping my CD collection to FLAC (One FLAC per track, no CUE files) and now realise that a handful of my CDs are really quiet. I could dig all my CDs out again and re-rip the quiet ones with normalisation turned on, but was wondering if I can normalise my FLAC albums as this would be loads quicker.

Use a script like this, provided by Robin Bowes when I asked about this on October 20th. For further information, look at list archives for subject "Questions on FLAC (encoding w/ReplayGain, native flac support)" in October. Hope this helps ... -- Jeff


#!/usr/bin/perl -w
#
# Applies replaygain tags to all .flac files found within the
# specified directory tree. Album gain is also calculated for all
# files within each directory

use strict;

my $metaflac = "/usr/bin/metaflac";
my @flacargs = qw ( --preserve-modtime --add-replay-gain );

@ARGV = ('.') unless @ARGV;

process_dirs(@ARGV);

sub process_dirs {
my @dirlist = @_;
foreach my $dir (@dirlist) {
# get all directory entries
print "Processing directory: $dir\n";
opendir(DIR, $dir) or die "Couldn't open directory $dir\n";
my @direntries = readdir(DIR) or
die "Couldn't read directory entries for directory $dir\n";
closedir(DIR);

# get all target files within the present directory
my @target_files = map { $_->[1] } # extract pathnames
map { [ $_, "$dir/$_" ] } # form (name, path)
grep { /\.flac$/ } # just flac files
@direntries;

# get all subdirs of the present directory
my @subdirs = map { $_->[1] } # extract pathnames
grep { -d $_->[1] } # only directories
map { [ $_, "$dir/$_" ] } # form (name, path)
grep { !/^\.\.?$/ } # not . or ..
@direntries;

if (@target_files) {
# run metaflac on all target files in present directory
system ($metaflac, @flacargs, @target_files);
}
# process any subdirs of present directory
if (@subdirs) {
&process_dirs(@subdirs);
}
}
}

Robin Bowes
2004-12-03, 11:58
Emile_Weekes (AT) Dell (DOT) com wrote:
> Not being a programmer myself. I have no idea on how to user this
> script. Can someone please provide some guidance on this?

I might be able to help... :)

I shall try and keep this as generic as I can, not knowing if you're on
Linux or Windows.

1. Copy the script to a a new file and save it as flac_replaygain.pl (or
whatever name you choose).

2. Change the following line to point to where the metaflac program
lives on your system:

my $metaflac = "/usr/bin/metaflac";

For windows, you might need something like this:
****** Not tested ******
my $metaflac = "c:\flac\metaflac.exe"
****** Not tested ******
(Let me know if this works)

3. Open up a shell (command) prompt.

4. Type the following:

perl -w /path/to/flac_replaygain.pl /path/to/your/music/folder

and press Enter

You can also change into your music folder and run the script - if no
directory is given on the command line it defaults to the current directory.

That's it.

Hope this gets you started.

R.

Daniel Cohen
2004-12-03, 13:47
On 3/12/04 at 6:58 pm +0000, Robin Bowes wrote
>I shall try and keep this as generic as I can, not knowing if you're
>on Linux or Windows.
>
>1. Copy the script to a a new file and save it as flac_replaygain.pl
>(or whatever name you choose).

And I'll ad another point that one can forget if not familiar with
it. Different operating systems use different methods of ending
lines. For instance, Mac line endings are Carriage Return, Unix ones
are Line Feed.

If one is running a perl script under Mac OS X, one needs to have the
lines ending with a Line Feed, not Carriage Return. Various text
editors can make this change.

This one caught me the first time I used a script.
--
Daniel Cohen