PDA

View Full Version : Patch: Slim/Format/Flac.pm optimization



Caleb Epstein
2003-12-01, 12:47
While clearly not as neat as the forthcoming rewrite which
will read the FLAC tags natively instead of using metaflac,
here is a small patch to the Flac.pm module which fixes some
non-optimal behavior (e.g. getting file size twice for each
line in the metaflac output). It should help with speed when
indexing a large number of FLACs.

Also included is a patch for convert.conf which should make
shorten -> mp3 resampling and shorten -> wav playing work.
I'm not sure if its valid to have two different dest_formats
for the same source_format though.

Next up: "native" shorten support :)

diff -ur -x '*~' -x '*.log' SlimServer_v5.0.1.orig/Slim/Formats/Flac.pm SlimServer_v5.0.1/Slim/Formats/Flac.pm
--- SlimServer_v5.0.1.orig/Slim/Formats/Flac.pm 2003-11-28 19:40:21.000000000 -0500
+++ SlimServer_v5.0.1/Slim/Formats/Flac.pm 2003-12-01 14:38:52.000000000 -0500
@@ -64,46 +64,36 @@
foreach (@output)
{
if (/ARTIST=([^\n]*)\n/i)
- {$tag->{'ARTIST'} = $1; }
-
- if (/ALBUM=([^\n]*)\n/i)
- {$tag->{'ALBUM'} = $1;}
-
- if (/TITLE=([^\n]*)\n/i)
- {$tag->{'TITLE'} = $1;}
-
- if (/TRACKNUMBER=([^\n]*)\n/i)
- {$tag->{'TRACKNUM'} = $1;}
-
- if (/DATE=([^\n]*)\n/i)
- {$tag->{'YEAR'} = $1;}
-
- if (/GENRE=([^\n]*)\n/i)
- {$tag->{'GENRE'} = $1;}
-
- $tag->{'SIZE'} = -s $file;
- $tag->{'FS'} = -s $file;;
- $tag->{'CT'} = "flac";
-
+ {$tag->{'ARTIST'} = $1; }
+ elsif (/ALBUM=([^\n]*)\n/i)
+ {$tag->{'ALBUM'} = $1;}
+ elsif (/TITLE=([^\n]*)\n/i)
+ {$tag->{'TITLE'} = $1;}
+ elsif (/TRACKNUMBER=([^\n]*)\n/i)
+ {$tag->{'TRACKNUM'} = $1;}
+ elsif (/DATE=([^\n]*)\n/i)
+ {$tag->{'YEAR'} = $1;}
+ elsif (/GENRE=([^\n]*)\n/i)
+ {$tag->{'GENRE'} = $1;}
# Compute number of seconds from sample rate and num samples
- if (/sample_rate: (\d*) Hz/i)
- {
- $sampleRate = $1;
- $tag->{'RATE'} = $sampleRate;
+ elsif (/sample_rate: (\d*) Hz/i) {
+ $sampleRate = $1;
+ $tag->{'RATE'} = $sampleRate;
}
-
- if (/total samples: (\d*)/i)
- { $nSamples = $1; }
-
- if (defined($nSamples) && defined($sampleRate))
- { $tag->{'SECS'} = $nSamples / $sampleRate; }
- # Set this so to non-zero so it will play.
- else
- { $tag->{'SECS'} = 1; }
-
- if (/channels: (\*d)/i)
- { $tag->{'CHANNELS'} = $1; }
- }
+ elsif (/total samples: (\d*)/i)
+ { $nSamples = $1; }
+ elsif (/channels: (\*d)/i)
+ { $tag->{'CHANNELS'} = $1; }
+ }
+
+ $tag->{'SIZE'} = $tag->{'FS'} = -s $file;
+ $tag->{'CT'} = "flac";
+
+ if (defined $nSamples and defined $sampleRate and $sampleRate > 0)
+ { $tag->{'SECS'} = $nSamples / $sampleRate; }
+ # Set this so to non-zero so it will play.
+ else
+ { $tag->{'SECS'} = 1; }
}
return $tag;
}
diff -ur -x '*~' -x '*.log' SlimServer_v5.0.1.orig/convert.conf SlimServer_v5.0.1/convert.conf
--- SlimServer_v5.0.1.orig/convert.conf 2003-11-28 19:40:23.000000000 -0500
+++ SlimServer_v5.0.1/convert.conf 2003-12-01 14:41:32.000000000 -0500
@@ -44,7 +44,10 @@
$lame$ --silent -b $BITRATE$ $FILE$ -

shn mp3 * *
- shorten -d $FILE$ | $lame$ --silent -b $BITRATE$ - -
+ shorten -x $FILE$ - | $lame$ --silent -b $BITRATE$ - -
+
+shn wav * *
+ shorten -x $file -

flc mp3 * *
flac -dc $FILE$ | $lame$ --silent -b $BITRATE$ - -


--
Caleb Epstein | bklyn . org | All the really good ideas I ever had came to
cae at | Brooklyn Dust | me while I was milking a cow.
bklyn dot org | Bunny Mfg. | -- Grant Wood

Dan Sully
2003-12-01, 12:53
* Caleb Epstein <cae (AT) bklyn (DOT) org> shaped the electrons to say...

> While clearly not as neat as the forthcoming rewrite which
> will read the FLAC tags natively instead of using metaflac,
> here is a small patch to the Flac.pm module which fixes some
> non-optimal behavior (e.g. getting file size twice for each
> line in the metaflac output). It should help with speed when
> indexing a large number of FLACs.

That's already been commited to cvs - grab the nightly build.

-D
--
This movie has warped my fragile little mind.

Caleb Epstein
2003-12-01, 12:58
On Mon, Dec 01, 2003 at 11:53:47AM -0800, Dan Sully wrote:

> * Caleb Epstein <cae (AT) bklyn (DOT) org> shaped the electrons to say...
>
> > While clearly not as neat as the forthcoming rewrite which
> > will read the FLAC tags natively instead of using metaflac,
> > here is a small patch to the Flac.pm module which fixes some
> > non-optimal behavior (e.g. getting file size twice for each
> > line in the metaflac output). It should help with speed when
> > indexing a large number of FLACs.
>
> That's already been commited to cvs - grab the nightly build.

Where can I find a URL for the nightly build?

--
Caleb Epstein | bklyn . org | Whom the gods wish to destroy they first
cae at | Brooklyn Dust | call promising.
bklyn dot org | Bunny Mfg. |

dean
2003-12-01, 13:46
I got yer URL right here:

http://www.slimdevices.com/downloads/nightly/latest


On Dec 1, 2003, at 11:58 AM, Caleb Epstein wrote:

> On Mon, Dec 01, 2003 at 11:53:47AM -0800, Dan Sully wrote:
>
>> * Caleb Epstein <cae (AT) bklyn (DOT) org> shaped the electrons to say...
>>
>>> While clearly not as neat as the forthcoming rewrite which
>>> will read the FLAC tags natively instead of using metaflac,
>>> here is a small patch to the Flac.pm module which fixes some
>>> non-optimal behavior (e.g. getting file size twice for each
>>> line in the metaflac output). It should help with speed when
>>> indexing a large number of FLACs.
>>
>> That's already been commited to cvs - grab the nightly build.
>
> Where can I find a URL for the nightly build?
>
> --
> Caleb Epstein | bklyn . org | Whom the gods wish to destroy they
> first
> cae at | Brooklyn Dust | call promising.
> bklyn dot org | Bunny Mfg. |
>

Kevin Deane-Freeman
2003-12-01, 14:33
Quoting Caleb Epstein <cae (AT) bklyn (DOT) org>:

> shn mp3 * *

might just want:
shn mp3 slimp3 *
This will use mp3 conversion for slimp3 clients since it would be required.
For all others, you will get wav output from the lines below which squeezebox
can handle. Otherwise, the current convert.conf in cvs has shn to mp3 for all
devices.
-kdf
> - shorten -d $FILE$ | $lame$ --silent -b $BITRATE$ - -
> + shorten -x $FILE$ - | $lame$ --silent -b $BITRATE$ - -
> +
> +shn wav * *
> + shorten -x $file -
>
> flc mp3 * *
> flac -dc $FILE$ | $lame$ --silent -b $BITRATE$ - -

Caleb Epstein
2003-12-01, 14:37
On Mon, Dec 01, 2003 at 01:33:16PM -0800, Kevin Deane-Freeman wrote:

> Quoting Caleb Epstein <cae (AT) bklyn (DOT) org>:
>
> > shn mp3 * *
>
> might just want:
> shn mp3 slimp3 *
> This will use mp3 conversion for slimp3 clients since it would be required.
> For all others, you will get wav output from the lines below which squeezebox
> can handle. Otherwise, the current convert.conf in cvs has shn to mp3 for all
> devices.

Please note the command line change for the shorten program.
The -x flag tells it to extract the file. The -d flag is for
discarding bytes at the start of the input data and is clearly
not the right one to use (not to mention requiring an
additional argument)

Here's the output of shorten -h:

shorten version 3.5.1: (c) 1992-1999 Tony Robinson and SoftSound Ltd
Seek extensions by Wayne Stielau; UNIX maintenance by Jason Jordan
Usage: shorten {options} [input file] [output file]
-a 0 bytes to copy verbatim to align file
-b 256 block size
-c 1 number of channels
-d 0 number of bytes to discard before compression or decompression
-e erase seek table appended to input file
-h help (this message)
-i inquire as to whether a seek table is appended to input file
-k append seek table information to existing shorten file
-l print the license giving the distribution and usage conditions
-m 4 number of past block for mean estimation
-n 256 minimum signal to noise ratio in dB (256 == lossless coding)
-p 0 maximum LPC predictor order (0 == fast polynomial predictor)
-q 0 acceptable quantisation error in bits
-r 32.0 maximum number of bits per sample (32.0 == lossless coding)
-s generate seek table information in separate file [input file].skt
-S[name] generate seek table information in separate file given by [name]
-t wav specify the bit packing and byte ordering of the sample file from
{aiff,wav,ulaw,alaw,s8,u8,s16,u16,s16x,u16x,s16hl, u16hl,s16lh,u16lh}
-u merge the two zero codes in ulaw files
-v 3 format version number (2: no seek info; 3: default)
-x extract (all other options except -a, -d and -t are ignored)

> -kdf
> > - shorten -d $FILE$ | $lame$ --silent -b $BITRATE$ - -
> > + shorten -x $FILE$ - | $lame$ --silent -b $BITRATE$ - -
> > +
> > +shn wav * *
> > + shorten -x $file -
> >
> > flc mp3 * *
> > flac -dc $FILE$ | $lame$ --silent -b $BITRATE$ - -
>
>