From alan@alanspector.org Wed Jun 16 17:19:20 2004
Return-Path: <alan@alanspector.org>
Delivered-To: sander@rietveld.vanzoest.com
Received: (qmail 366 invoked by uid 2500); 16 Jun 2004 17:19:19 -0000
Delivered-To: vanzoest-sander@vanzoest.com
Received: (qmail 361 invoked by uid 208); 16 Jun 2004 17:19:19 -0000
Received: from x1.develooper.com (HELO x1.develooper.com) (63.251.223.170) by rietveld.vanzoest.com (qpsmtpd/0.26) with SMTP; Wed, 16 Jun 2004 10:19:16 -0700
Received: (qmail 11892 invoked by uid 225); 16 Jun 2004 17:19:03 -0000
Delivered-To: svanzoest@cpan.org
Received: (qmail 11877 invoked by alias); 16 Jun 2004 17:19:02 -0000
X-Spam-Status: No, hits=-4.9 required=8.0	tests=BAYES_00
X-Spam-Check-By: la.mx.develooper.com
Received: from h008.c001.snv.cp.net (HELO c001.snv.cp.net) (209.228.32.122)  by la.mx.develooper.com (qpsmtpd/0.27.1) with SMTP; Wed, 16 Jun 2004 10:18:59 -0700
Received: (cpmta 24349 invoked from network); 16 Jun 2004 10:18:56 -0700
Received: from 208.55.254.110 (HELO ?10.254.245.124?)  by smtp.register-admin.com (209.228.32.122) with SMTP; 16 Jun 2004 10:18:56 -0700
X-Sent: 16 Jun 2004 17:18:56 GMT
Mime-Version: 1.0 (Apple Message framework v618)
In-Reply-To: <20040616165334.GA70877@rietveld.vanzoest.com>
References: <F7093A11-BF40-11D8-8133-000A95908F9A@alanspector.org> <20040616165334.GA70877@rietveld.vanzoest.com>
Content-Type: text/plain; charset=US-ASCII; format=flowed
Message-Id: <CC3B80AA-BFB9-11D8-8133-000A95908F9A@alanspector.org>
Content-Transfer-Encoding: 7bit
From: alan spector <alan@alanspector.org>
Subject: Re: MusicBrainz::TRM
Date: Wed, 16 Jun 2004 13:22:52 -0400
To: Sander van Zoest <svanzoest@cpan.org>
X-Mailer: Apple Mail (2.618)
X-SMTPD: qpsmtpd/0.26, http://develooper.com/code/qpsmtpd/
X-Spam-Check-By: rietveld.vanzoest.com
Spam: No ; 0.0 / 5.0
Status: RO
Content-Length: 3705
Lines: 104

Hey! thanks for the reply. I poked around last night with 
Audio::MPEG... couldn't get it to compile correctly ( i will mess with 
it more after I get some sleep) so landed up doing a system call to 
lame to decode the mp3 and strip .wav header info and then open the tmp 
file with IO::File and feed to generate_signature...unfortunately... it 
looks like musicbrainz.org got hacked so i couldnt get a trm back to 
see if it worked alright. I'll just wait till you have your next 
version out and brainz is back up.

oh here is the code i was using for my test... evnetually I was going 
to write a File::Find::Rules::MP3::TRM type module to find duplicates 
but for testing i did this

#!/usr/local/bin/perl

use MusicBrainz::TRM;
use MusicBrainz::Client;
use Data::Dumper;
use IO::File;



my $mb = MusicBrainz::Client->new();

my ($duration, $bitrate, $stereo, $samplerate ) =  
$mb->get_mp3_info($ARGV[0]);

          my $trm = MusicBrainz::TRM->new();
         $trm->set_proxy("musicbrainz.org", 80);
          $trm->set_pcm_data_info($samplerate,$stereo,$bitrate);
         $trm->set_song_length(($duration/1000));
         system( qq{lame --decode -t  "$ARGV[0]" /tmp/foo.pcm});
         my $pcmfh = new IO::File;
         $pcmfh->open("/tmp/foo.pcm", "r") || die "Can't open $ARGV[0] 
$!\n";
         my $status = 1;
         my $data;

         while ( ! $pcmfh->eof() and $status )
         {
                 $data = $pcmfh->getline();
                 $status = $trm->generate_signature($data);
         }
         $pcmfh->close;
         unlink "/tmp/foo.pcm";
          my $sig = $trm->finalize_signature();
          print $sig, "\n";
          my $ascii_sig = $trm->convert_sig_to_ascii($sig) if( $sig);
          print "Signature: ", $ascii_sig, "\n";



again thanks for your reply,

regards,

alan


On Jun 16, 2004, at 12:53 PM, Sander van Zoest wrote:

> On Tue, Jun 15, 2004 at 10:57:55PM -0400, alan spector wrote:
>> I've recently discovered MusicBrainz and went to CPAN to find some 
>> Perl
>> modules to use it. Basically, I have a large mp3 collection which I
>> know has dupes in it and thought a great way of finding out which ones
>> where would be to generate TRMs for each file use them as keys in a
>> hash and value be array ref of the files... then I can easy weed out
>> the dupes out. Read the perldoc for MusicBrainz::TRM and saw the 
>> sample
>> code:
>>
>> while( (! $pcmfh->eof() &&
>>          (! $trm->generate_signature($pcmfh->getline()) );
>>
>> my question is what is pcmfh? is that just an IO::File obj to the mp3,
>> something from Audio::MPEG. etc.....
>
> $pcmfh stands for PCM File Handle. To generate a signature for an MP3
> file, you will need to decode the MP3 file to a PCM Audio Stream.
>
> There are many ways of decoding MP3 to PCM and as mentioned Audio::MPEG
> is one of the ways of doing that. The section on Data Transformations
> talks about doing audio processing on a PCM stream, but since we
> just need read-only access the PCM stream and not re-encoding it to
> create another stream.
>
> So you could use Audio::MPEG::Output to create a PCM stream (and set
> the type via MusicBrainz::TRM::set_pcm_data_info() ) and pass the
> PCM data returned by Audio::MPEG::Output::encode() on to
> $MusicBrainz::TRM::generate_signature().
>
>> thanks for your help in advance... and thanks for putting together
>> these modules...
>
> No problem. Let me know how it goes. I currently have a version issue
> with MusicBrainz::Client that I am in the process of resolving. So,
> if you are planning on using those modules, you might want to wait
> till I release a fix. I am hoping to do that in the next day or two.
>
> Cheers,
>
> -- Sander
>

