Subject: | _parseStreamInfo - Incorrect decoding of metadata [patch] |
Using the pure perl _parseStreamInfo routine (as opposed to XS and
libFLAC), BITSPERSAMPLE, MAXIMUMBLOCKSIZE and MAXIMUMFRAMESIZE were not
being decoded properly.
I attatch a patch to extend t/basic.t to exercise these and a patch to
correctly decode the metadata in Header.pm
I'm using:
perl v5.8.8
Linux version 2.6.27-gentoo-r7 on x86
Audio::FLAC::Header from github:
http://github.com/dsully/perl-audio-flac-header/commit/49bad1c6663a290d39d6ce8ba2a5525891a04dca
Subject: | 0002-_parseStreamInfo-Fix-incorrect-decoding-of-metadat.patch |
From 5634e3724adaf1bd824b55786f2437686eeb5701 Mon Sep 17 00:00:00 2001
From: Nick Prater <nick@xlmt.com>
Date: Sat, 11 Apr 2009 08:43:11 +0100
Subject: [PATCH] _parseStreamInfo - Fix incorrect decoding of metadata
Using the pure perl _parseStreamInfo routine (as opposed to XS and libFLAC), BITSPERSAMPLE, MAXIMUMBLOCKSIZE and MAXIMUMFRAMESIZE were not being decoded properly.
I attatch a patch to extend t/basic.t to exercise these and a patch to correctly decode the metadata in Header.pm
I'm using:
perl v5.8.8
Linux version 2.6.27-gentoo-r7 on x86
Audio::FLAC::Header from github:
http://github.com/dsully/perl-audio-flac-header/commit/49bad1c6663a290d39d6ce8ba2a5525891a04dca
---
Header.pm | 6 +++---
t/basic.t | 12 +++++++++---
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/Header.pm b/Header.pm
index 76acedf..02a0ec2 100644
--- a/Header.pm
+++ b/Header.pm
@@ -414,13 +414,13 @@ sub _parseStreamInfo {
my $x32 = 0 x 32;
$info->{'MINIMUMBLOCKSIZE'} = unpack('N', pack('B32', substr($x32 . substr($metaBinString, 0, 16), -32)));
- $info->{'MAXIMUMBLOCKSIZE'} = unpack('N', pack('B32', substr($x32 . substr($metaBinString, 16, 32), -32)));
+ $info->{'MAXIMUMBLOCKSIZE'} = unpack('N', pack('B32', substr($x32 . substr($metaBinString, 16, 16), -32)));
$info->{'MINIMUMFRAMESIZE'} = unpack('N', pack('B32', substr($x32 . substr($metaBinString, 32, 24), -32)));
- $info->{'MINIMUMFRAMESIZE'} = unpack('N', pack('B32', substr($x32 . substr($metaBinString, 56, 24), -32)));
+ $info->{'MAXIMUMFRAMESIZE'} = unpack('N', pack('B32', substr($x32 . substr($metaBinString, 56, 24), -32)));
$info->{'SAMPLERATE'} = unpack('N', pack('B32', substr($x32 . substr($metaBinString, 80, 20), -32)));
$info->{'NUMCHANNELS'} = unpack('N', pack('B32', substr($x32 . substr($metaBinString, 100, 3), -32))) + 1;
- $info->{'BITSPERSAMPLE'} = unpack('N', pack('B32', substr($x32 . substr($metaBinString, 100, 5), -32))) + 1;
+ $info->{'BITSPERSAMPLE'} = unpack('N', pack('B32', substr($x32 . substr($metaBinString, 103, 5), -32))) + 1;
# Calculate total samples in two parts
my $highBits = unpack('N', pack('B32', substr($x32 . substr($metaBinString, 108, 4), -32)));
diff --git a/t/basic.t b/t/basic.t
index e3b445f..cd83ba7 100644
--- a/t/basic.t
+++ b/t/basic.t
@@ -1,7 +1,7 @@
#!/usr/bin/perl -w
use strict;
-use Test::More tests => 31;
+use Test::More tests => 43;
use File::Spec::Functions qw(:ALL);
BEGIN { use_ok('Audio::FLAC::Header') };
@@ -15,7 +15,7 @@ BEGIN { use_ok('Audio::FLAC::Header') };
# Only test XS if built
SKIP: {
eval { Audio::FLAC::Header->_new_XS(catdir('data', 'test.flac')) };
- skip "Not built with XS", 15 if $@;
+ skip "Not built with XS", 21 if $@;
push @constructors, '_new_XS';
}
@@ -35,7 +35,13 @@ BEGIN { use_ok('Audio::FLAC::Header') };
ok($flac->info('SAMPLERATE') == 44100, "sample rate");
ok($flac->info('MD5CHECKSUM') eq '592fb7897a3589c6acf957fd3f8dc854', "md5");
ok($flac->info('TOTALSAMPLES') == 153200460, "total samples");
-
+ ok($flac->info('BITSPERSAMPLE') == 16, "bits per sample $constructor");
+ ok($flac->info('NUMCHANNELS') == 2, "channels $constructor");
+ ok($flac->info('MINIMUMBLOCKSIZE') == 4608, "minimum block size $constructor");
+ ok($flac->info('MAXIMUMBLOCKSIZE') == 4608, "maximum block size $constructor");
+ ok($flac->info('MINIMUMFRAMESIZE') == 14, "minimum frame size $constructor");
+ ok($flac->info('MAXIMUMFRAMESIZE') == 18002, "maximum frame size $constructor");
+
my $tags = $flac->tags();
ok($tags, "tags read");
--
1.6.0.6
Subject: | basic.t |
#!/usr/bin/perl -w
use strict;
use Test::More tests => 43;
use File::Spec::Functions qw(:ALL);
BEGIN { use_ok('Audio::FLAC::Header') };
#########################
{
# Always test pure perl
my @constructors = ('_new_PP');
# Only test XS if built
SKIP: {
eval { Audio::FLAC::Header->_new_XS(catdir('data', 'test.flac')) };
skip "Not built with XS", 21 if $@;
push @constructors, '_new_XS';
}
# Be sure to test both code paths.
for my $constructor (@constructors) {
my $flac = Audio::FLAC::Header->$constructor(catdir('data', 'test.flac'));
ok($flac, "constructor: $constructor");
my $info = $flac->info();
ok($info, "info block");
ok($flac->info('SAMPLERATE') == 44100, "sample rate");
ok($flac->info('MD5CHECKSUM') eq '592fb7897a3589c6acf957fd3f8dc854', "md5");
ok($flac->info('TOTALSAMPLES') == 153200460, "total samples");
ok($flac->info('BITSPERSAMPLE') == 16, "bits per sample $constructor");
ok($flac->info('NUMCHANNELS') == 2, "channels $constructor");
ok($flac->info('MINIMUMBLOCKSIZE') == 4608, "minimum block size $constructor");
ok($flac->info('MAXIMUMBLOCKSIZE') == 4608, "maximum block size $constructor");
ok($flac->info('MINIMUMFRAMESIZE') == 14, "minimum frame size $constructor");
ok($flac->info('MAXIMUMFRAMESIZE') == 18002, "maximum frame size $constructor");
my $tags = $flac->tags();
ok($tags, "tags read");
is($flac->tags('AUTHOR'), 'Praga Khan', "AUTHOR ok");
# XXX - should have accessors
ok($flac->{'trackLengthFrames'} =~ /70.00\d+/);
ok($flac->{'trackLengthMinutes'} == 57);
ok($flac->{'bitRate'} =~ /1.236\d+/);
ok($flac->{'trackTotalLengthSeconds'} =~ /3473.93\d+/);
my $cue = $flac->cuesheet();
ok $cue;
ok(scalar @{$cue} == 37);
ok($cue->[35] =~ /REM FLAC__lead-in 88200/);
ok($cue->[36] =~ /REM FLAC__lead-out 170 153200460/);
}
}
__END__
Subject: | Header.pm |
Message body is not shown because it is too large.