2 ############################################################################
3 # soepkiptng (c) copyright 2000 Eric Lammerts <eric@lammerts.org>.
4 ############################################################################
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License, version 2, as
7 # published by the Free Software Foundation.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # A copy of the GNU General Public License is available on the World Wide Web
15 # at `http://www.gnu.org/copyleft/gpl.html'. You can also obtain it by
16 # writing to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 # Boston, MA 02111-1307, USA.
18 ############################################################################
26 # try with att=1, double att until clipping=0
27 # successive approximation
34 open M
, "madplay --ignore-crc -a $gain -owav:/dev/null - 2>&1 |";
36 /(\d+) clipped sample/ and $clipped = $1;
39 $?
and die "madplay failed, skipping file\n";
40 warn "trying $gain -> $clipped\n";
50 while(clip
($gain_max) == 0) {
51 $gain_min = $gain_max;
54 $dbh->do("UPDATE song SET gain=18000 WHERE filename=?", undef, $f);
56 } elsif($gain_max > 18) {
61 while(clip
($gain_min) > 0) {
62 if($gain_min < -175) {
69 while(($gain_max - $gain_min) > 0.05) {
70 $gain = ($gain_min + $gain_max) / 2;
77 printf "%f %s\n", $gain_min, $f;
78 my $g = int($gain_min * 1000 + 0.5);
79 if($g < -32768) { $g = 32768; }
80 elsif($g > 32767) { $g = 32767; }
81 $dbh->do("UPDATE song SET gain=? WHERE filename=?", undef, $g, $f);
85 # find program directory
88 my $l = readlink or die "readlink $_: $!\n";
89 if($l =~ m
|^/|) { $_ = $l; } else { s|[^/]*$|/$l|; }
92 my $progdir = abs_path
($1);
94 require "$progdir/soepkiptng.lib";
98 read_configfile
(\
%conf, $opt_c);
102 $dbh = connect_to_db
(\
%conf);
104 $sth = $dbh->prepare(
105 "SELECT filename FROM song WHERE present AND gain IS NULL AND filename LIKE '/%'" .
106 "AND (encoding LIKE 'mp3%' OR encoding LIKE 'mpeg%layer%')");
108 while($_ = $sth->fetchrow_hashref) {
109 -e
$_->{filename
} or next;
110 open STDIN
, $_->{filename
} or do {
111 warn "$_->{filename}: $!\n";
114 eval { doit
($_->{filename
}); };