I've written the attached script to strip audio data out of flac files.

This is useful if you need to submit sample files to slim devices for tagging-related debugging purposes.

Contact me with any bugs/comments, etc.

R.
--
http://robinbowes.com

If a man speaks in a forest,
and his wife's not there,
is he still wrong?
#!/usr/bin/perl -w

use strict;
use Carp;

my $SYNCCODE_CHAR_ONE = 0xFF; # 11111111 in binary
my $SYNCCODE_CHAR_TWO = 0xF8; # 11111000 in binary

#  Notice the complet lack of error checking

# loop over all filenames supplied on command-line
for my $filename (@ARGV) {
    open my $file, '<', $filename or croak "Can't open '$filename': $!";
    binmode($file);

    my $SyncCode_Char_One_Found = 0;
    my $SyncCode_Position = 0;

    READBYTE:
    while ( sysread($file, my $byte, 1) ) {
        if ($SyncCode_Char_One_Found) {
            if (ord($byte) == $SYNCCODE_CHAR_TWO) {
                last READBYTE;
            } else {
                $SyncCode_Char_One_Found = 0;
                $SyncCode_Position++;
            }
        };
        if (ord($byte)== $SYNCCODE_CHAR_ONE) {
            $SyncCode_Char_One_Found = 1;
            next READBYTE;
        } else {
            $SyncCode_Position++;
        }
    }

    close $file;

    truncate ($filename, $SyncCode_Position)
        or croak "Couldn't truncate file '$filename': $!";

    print "File: $filename truncated to $SyncCode_Position bytes\n";

}
_______________________________________________
beta mailing list
[email protected]
http://lists.slimdevices.com/lists/listinfo/beta

Reply via email to