PDA

View Full Version : Patch for Audio::Wav



Caleb Epstein
2003-12-10, 09:42
Not sure if you are still actively maintaining this Perl
module, but here is a patch which incorporates a number of
small fixes which have been made to support the SlimDevices
server software (http://www.slimdevices.com). I have CC'ed
the SlimDevices developer list on this message.

The changes are as follows:

* Allow reading WAV from a pipeline as well as a physical file
* Skip unknown chunks and believe their length. The code in
version 0.02 will spew tons of garbage errors without this
when it encounters a chunk type its not aware of.
* Protect from various undefined variable warnings

Thanks for your attention,

diff -ur Audio-Wav-0.02/Wav/Read.pm /home/cae/src/slimserver/SlimServer_v2003-12-09/CPAN/Audio/Wav/Read.pm
--- Audio-Wav-0.02/Wav/Read.pm 2001-08-25 09:51:20.000000000 -0400
+++ /home/cae/src/slimserver/SlimServer_v2003-12-09/CPAN/Audio/Wav/Read.pm 2003-12-09 22:14:12.000000000 -0500
@@ -41,7 +41,7 @@
my $tools = shift;
$file =~ s#//#/#g;
my $size = -s $file;
- my $handle = new FileHandle "<$file";
+ my $handle = new FileHandle $file;

my $self = {
'real_size' => $size,
@@ -61,9 +61,11 @@

$self -> {'data'} = $self -> _read_file();
my $details = $self -> details();
- $self -> _init_read_sub();
- $self -> {'pos'} = $details -> {'data_start'};
- $self -> move_to();
+ if ($details) {
+ $self -> _init_read_sub();
+ $self -> {'pos'} = $details -> {'data_start'};
+ $self -> move_to();
+ }
return $self;
}

@@ -216,7 +218,7 @@
my $details = $self -> {'data'};
my $channels = $details -> {'channels'};
my $sub;
- if ( $details -> {'bits_sample'} <= 8 ) {
+ if ($details->{'bits_sample'} && $details -> {'bits_sample'} <= 8 ) {
my $offset = ( 2 ** $details -> {'bits_sample'} ) / 2;
$sub = sub { return map $_ - $offset, unpack( 'C'.$channels, shift() ) };
} else {
@@ -320,7 +322,13 @@
sub length_seconds {
my $self = shift;
my $data = $self -> {'data'};
- return $data -> {'data_length'} / $data -> {'bytes_sec'};
+ my $length = $data -> {'data_length'};
+ my $rate = $data -> {'bytes_sec'};
+ if ($length || $rate) {
+ return $length / $rate;
+ } else {
+ return 0;
+ }
}

=head2 details
@@ -399,8 +407,9 @@
$details{'data_length'} = $chunk_len;
} else {
$head =~ s/[^\w]+//g;
- $self -> _error( "ignored unknown block type: $head at $self->{pos} for $chunk_len", 'warn' );
- next if $chunk_len > 100;
+ $self -> _error( "ignored unknown block type: $head at $self->{pos} for $chunk_len", 'warn' );
+# djb - we should just skip over unknown chunks, rather than restarting the scan
+# next if $chunk_len > 100;
}

seek $handle, $chunk_len, 1;
diff -ur Audio-Wav-0.02/Wav/Tools.pm /home/cae/src/slimserver/SlimServer_v2003-12-09/CPAN/Audio/Wav/Tools.pm
--- Audio-Wav-0.02/Wav/Tools.pm 2001-08-25 09:41:08.000000000 -0400
+++ /home/cae/src/slimserver/SlimServer_v2003-12-09/CPAN/Audio/Wav/Tools.pm 2003-12-09 08:01:29.000000000 -0500
@@ -131,7 +131,7 @@
'filename' => $filename,
'message' => $msg ? $msg : '',
);
- $hash{'warning'} = 1 if $type eq 'warn';
+ $hash{'warning'} = 1 if ($type && $type eq 'warn');
&$handler( %hash );
} else {
my $txt = $filename ? "$filename: $msg\n" : "$msg\n";

--
Caleb Epstein | bklyn . org | Arbitrary systems, pl.n.:
cae at | Brooklyn Dust | Systems about which nothing general
bklyn dot org | Bunny Mfg. | can be said, save "nothing general
| | can be said."

dean
2003-12-10, 10:53
Thanks, Caleb.

Should I be expecting an updated integrated patch for all the changes
discussed recently?

On Dec 10, 2003, at 8:42 AM, Caleb Epstein wrote:

>
> Not sure if you are still actively maintaining this Perl
> module, but here is a patch which incorporates a number of
> small fixes which have been made to support the SlimDevices
> server software (http://www.slimdevices.com). I have CC'ed
> the SlimDevices developer list on this message.
>
> The changes are as follows:
>
> * Allow reading WAV from a pipeline as well as a physical file
> * Skip unknown chunks and believe their length. The code in
> version 0.02 will spew tons of garbage errors without this
> when it encounters a chunk type its not aware of.
> * Protect from various undefined variable warnings
>
> Thanks for your attention,
>
> diff -ur Audio-Wav-0.02/Wav/Read.pm
> /home/cae/src/slimserver/SlimServer_v2003-12-09/CPAN/Audio/Wav/Read.pm
> --- Audio-Wav-0.02/Wav/Read.pm 2001-08-25 09:51:20.000000000 -0400
> +++
> /home/cae/src/slimserver/SlimServer_v2003-12-09/CPAN/Audio/Wav/Read.pm
> 2003-12-09 22:14:12.000000000 -0500
> @@ -41,7 +41,7 @@
> my $tools = shift;
> $file =~ s#//#/#g;
> my $size = -s $file;
> - my $handle = new FileHandle "<$file";
> + my $handle = new FileHandle $file;
>
> my $self = {
> 'real_size' => $size,
> @@ -61,9 +61,11 @@
>
> $self -> {'data'} = $self -> _read_file();
> my $details = $self -> details();
> - $self -> _init_read_sub();
> - $self -> {'pos'} = $details -> {'data_start'};
> - $self -> move_to();
> + if ($details) {
> + $self -> _init_read_sub();
> + $self -> {'pos'} = $details -> {'data_start'};
> + $self -> move_to();
> + }
> return $self;
> }
>
> @@ -216,7 +218,7 @@
> my $details = $self -> {'data'};
> my $channels = $details -> {'channels'};
> my $sub;
> - if ( $details -> {'bits_sample'} <= 8 ) {
> + if ($details->{'bits_sample'} && $details -> {'bits_sample'} <= 8
> ) {
> my $offset = ( 2 ** $details -> {'bits_sample'} ) / 2;
> $sub = sub { return map $_ - $offset, unpack( 'C'.$channels, shift()
> ) };
> } else {
> @@ -320,7 +322,13 @@
> sub length_seconds {
> my $self = shift;
> my $data = $self -> {'data'};
> - return $data -> {'data_length'} / $data -> {'bytes_sec'};
> + my $length = $data -> {'data_length'};
> + my $rate = $data -> {'bytes_sec'};
> + if ($length || $rate) {
> + return $length / $rate;
> + } else {
> + return 0;
> + }
> }
>
> =head2 details
> @@ -399,8 +407,9 @@
> $details{'data_length'} = $chunk_len;
> } else {
> $head =~ s/[^\w]+//g;
> - $self -> _error( "ignored unknown block type: $head at
> $self->{pos} for $chunk_len", 'warn' );
> - next if $chunk_len > 100;
> + $self -> _error( "ignored unknown block type: $head at
> $self->{pos} for $chunk_len", 'warn' );
> +# djb - we should just skip over unknown chunks, rather than
> restarting the scan
> +# next if $chunk_len > 100;
> }
>
> seek $handle, $chunk_len, 1;
> diff -ur Audio-Wav-0.02/Wav/Tools.pm
> /home/cae/src/slimserver/SlimServer_v2003-12-09/CPAN/Audio/Wav/
> Tools.pm
> --- Audio-Wav-0.02/Wav/Tools.pm 2001-08-25 09:41:08.000000000 -0400
> +++
> /home/cae/src/slimserver/SlimServer_v2003-12-09/CPAN/Audio/Wav/
> Tools.pm 2003-12-09 08:01:29.000000000 -0500
> @@ -131,7 +131,7 @@
> 'filename' => $filename,
> 'message' => $msg ? $msg : '',
> );
> - $hash{'warning'} = 1 if $type eq 'warn';
> + $hash{'warning'} = 1 if ($type && $type eq 'warn');
> &$handler( %hash );
> } else {
> my $txt = $filename ? "$filename: $msg\n" : "$msg\n";
>
> --
> Caleb Epstein | bklyn . org | Arbitrary systems, pl.n.:
> cae at | Brooklyn Dust | Systems about which nothing
> general
> bklyn dot org | Bunny Mfg. | can be said, save "nothing
> general
> | | can be said."
>