Skip Menu |

This queue is for tickets about the Audio-Wav CPAN distribution.

Report information
The Basics
Id: 57093
Status: stalled
Priority: 0/
Queue: Audio-Wav

People
Owner: Nobody in particular
Requestors: sergstesh [...] yahoo.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: problem with bits per sample other than 16
Date: Fri, 30 Apr 2010 12:20:02 -0700 (PDT)
To: bug-Audio-Wav [...] rt.cpan.org
From: Sergei Steshenko <sergstesh [...] yahoo.com>
Hello, I've tried to use version 0.11 of the module with other than 16 bits per sample and the WAV file produced very distorted sound. The distortions are obviously seen in, say, 'audacity'. After briefly looking into the code in lib/site_perl/5.10.1/Audio/Wav/Write.pm file I've noticed the following piece of code: 266 sub write { 267 my ($self, @args) = @_; 268 my $channels = $self -> {'details'} -> {'channels'}; 269 if ( $self -> {'use_offset'} ) { 270 return $self -> write_raw( pack 'C'.$channels, map { $_ + $self -> {'use_offset'} } @args ); 271 } else { 272 return $self -> write_raw( pack 'v'.$channels, @args ); 273 } 274 } , specifically, line #272. If I understand correctly, this line actually writes samples using for this Perl built-in 'pack' function. Manpage on 'pack' function says: " v An unsigned short (16-bit) in "VAX" (little-endian) order. ", i.e. 16 bits appear to be hard-coded. ... Replacing 'v' with 'V'. i.e. " V An unsigned long (32-bit) in "VAX" (little-endian) order " and setting 32 bits per sample produced a good (both in 'audacity' and from the point of view of undistorted sound) file. So, apparently the 'v' is the culprit. The parameter should apparently be a function bits per sample, and I'm not sure what can/should be done for 24 bits per sample, i.e. what packing should be used. Probably the simplest thing to do is to limit the allowed values to 16 and 32 bits per sample and to add a check in the constructor. Thanks, Sergei.
Thanks for your detailed report. I've confirmed it and, I believe, fixed the problem in r2469 (including for 24-bit writes). Please check it out and see if it works for you: https://chronicle.allafrica.com:8080/repository/misc/skix/cpan/Audio-Wav/ The source of the change is here: http://chronicle.allafrica.com/viewvc/viewvc.cgi/misc/skix/cpan/Audio-Wav/Wav/Write.pm?root=allafrica&r1=2466&r2=2469 For the moment, we always grab a 32-bit integer in vax format, and then use substr to grab the bytes we care about. If you could test it out by checking out -HEAD (not rev2469), I'd very much appreciate it. I haven't forgotten your other bug report, but I'm very pressed for time ATM, so I'm not sure when. Thanks! Brian Szymanski
Subject: Re: [rt.cpan.org #57093] Resolved: problem with bits per sample other than 16
Date: Sun, 27 Jun 2010 15:35:23 -0700 (PDT)
To: bug-Audio-Wav [...] rt.cpan.org
From: Sergei Steshenko <sergstesh [...] yahoo.com>
--- On Thu, 6/3/10, Brian Szymanski via RT <bug-Audio-Wav@rt.cpan.org> wrote: Show quoted text
> From: Brian Szymanski via RT <bug-Audio-Wav@rt.cpan.org> > Subject: [rt.cpan.org #57093] Resolved: problem with bits per sample other than 16 > To: sergstesh@yahoo.com > Date: Thursday, June 3, 2010, 9:54 PM > <URL: https://rt.cpan.org/Ticket/Display.html?id=57093 > > > According to our records, your request has been resolved. > If you have any > further questions or concerns, please respond to this > message. >
I have used (hopefully correctly) the fix you've suggested: 266 sub write { 267 my ($self, @args) = @_; 268 my $channels = $self -> {'details'} -> {'channels'}; 269 if ( $self -> {'use_offset'} ) { 270 return $self -> write_raw( pack 'C'.$channels, map { $_ + $self -> {'use_offset'} } @args ); 271 } else { 272 #return $self -> write_raw( pack 'V'.$channels, @args ); 273 my $bytes_per_sample = $self->{'details'}->{'bits_sample'} >> 3; 274 my @samples = map { substr pack('V1', $_), 0, $bytes_per_sample } @args; 275 return $self -> write_raw( @samples ); 276 } 277 } . The fix doesn't work for me - when I run the same program I used to run with my fix (now commented out on line #272), I'm getting a bunch of " Argument "\0\0\0\0" isn't numeric in addition (+) at /home/sergei/my_perl-5.10.1/lib/site_perl/5.10.1/Audio/Wav/Write.pm line 307. " messages, here is the context for line #307: 292 sub write_raw { 293 my $self = shift; 294 my $data = shift; 295 my $len = shift; 296 $len = length $data unless $len; 297 return unless $len; 298 my $wrote = $len; 299 if ( $self -> {'use_cache'} ) { 300 $self -> {'write_cache'} .= $data; 301 my $cache_len = length $self -> {'write_cache'}; 302 $self -> _purge_cache( $cache_len ) unless $cache_len < $self -> {'cache_size'}; 303 } else { 304 $wrote = syswrite $self -> {'handle'}, $data, $len; 305 } 306 307 $self -> {'pos'} += $wrote; 308 return $wrote; 309 } . I think the bug should be reopened. Thanks, Sergei.
Hi Sergei. Thanks again for reporting this. I added a fix soon after I responded to this ticket which may or may not be causing the behavior you are seeing. Specifically, I added "use bytes". Possibly not related, but it should cause problems to omit it: ski@portege:~/mysrc/skix/cpan/Audio-Wav$ diff -w -u yours mine --- yours 2010-07-01 10:26:04.183776886 -0400 +++ mine 2010-07-01 10:26:41.533773025 -0400 @@ -4,9 +4,15 @@ if ( $self -> {'use_offset'} ) { return $self -> write_raw( pack 'C'.$channels, map { $_ + $self -> {'use_offset'} } @args ); } else { -#return $self -> write_raw( pack 'V'.$channels, @args ); + #TODO: performance: when we move to _init_write_sub, just use: + #32: pack 'V1', ... + #24: substr pack('V1', ...), 3 + #16: pack 'v1', ... my $bytes_per_sample = $self->{'details'}->{'bits_sample'} >> 3; + use bytes; my @samples = map { substr pack('V1', $_), 0, $bytes_per_sample } @args; +#warn "bits/sample: $self->{'details'}->{'bits_sample'}, bytes/sample: $bytes_per_sample"; +#warn "output samples(".scalar @samples."): ".join "-", map ord, split //, join '', @samples; return $self -> write_raw( @samples ); } } If that doesn't fix the problem, can you boil your program down to a (preferably small ;-) ) script that shows the errant behavior? Also, to be sure we are on the same page, please use r2473 directly from SVN - I've attached it here for your convenience. And if you do encounter problems, please add and uncomment the warn statements in the above diff (lines 279 and 280 in the attached tarball / r2473). Thanks! Brian On Sun Jun 27 18:35:34 2010, sergstesh wrote: Show quoted text
> > > --- On Thu, 6/3/10, Brian Szymanski via RT <bug-Audio-Wav@rt.cpan.org> > wrote: >
> > From: Brian Szymanski via RT <bug-Audio-Wav@rt.cpan.org> > > Subject: [rt.cpan.org #57093] Resolved: problem with bits per sample
> other than 16
> > To: sergstesh@yahoo.com > > Date: Thursday, June 3, 2010, 9:54 PM > > <URL: https://rt.cpan.org/Ticket/Display.html?id=57093 > > > > > According to our records, your request has been resolved. > > If you have any > > further questions or concerns, please respond to this > > message. > >
> > I have used (hopefully correctly) the fix you've suggested: > > 266 sub write { > 267 my ($self, @args) = @_; > 268 my $channels = $self -> {'details'} -> {'channels'}; > 269 if ( $self -> {'use_offset'} ) { > 270 return $self -> write_raw( pack 'C'.$channels, map { > $_ + $self -> {'use_offset'} } @args ); > 271 } else { > 272 #return $self -> write_raw( pack 'V'.$channels, @args > ); > 273 my $bytes_per_sample = $self->{'details'}-
> >{'bits_sample'} >> 3;
> 274 my @samples = map { substr pack('V1', $_), 0, > $bytes_per_sample } @args; > 275 return $self -> write_raw( @samples ); > 276 } > 277 } > . > > The fix doesn't work for me - when I run the same program I used to > run > with my fix (now commented out on line #272), I'm getting a bunch of > > " > Argument "\0\0\0\0" isn't numeric in addition (+) at > /home/sergei/my_perl-5.10.1/lib/site_perl/5.10.1/Audio/Wav/Write.pm > line 307. > " > > messages, here is the context for line #307: > > 292 sub write_raw { > 293 my $self = shift; > 294 my $data = shift; > 295 my $len = shift; > 296 $len = length $data unless $len; > 297 return unless $len; > 298 my $wrote = $len; > 299 if ( $self -> {'use_cache'} ) { > 300 $self -> {'write_cache'} .= $data; > 301 my $cache_len = length $self -> {'write_cache'}; > 302 $self -> _purge_cache( $cache_len ) unless $cache_len > < $self -> {'cache_size'}; > 303 } else { > 304 $wrote = syswrite $self -> {'handle'}, $data, $len; > 305 } > 306 > 307 $self -> {'pos'} += $wrote; > 308 return $wrote; > 309 } > . > > I think the bug should be reopened. > > Thanks, > Sergei. > > > >
Subject: Audio-Wav-r2473.tgz
Download Audio-Wav-r2473.tgz
application/x-compressed-tar 22.6k

Message body not shown because it is not plain text.

One more thing - are you using stereo output files? That is "known to be broken" for all but mono output at the moment. On Sun Jun 27 18:35:34 2010, sergstesh wrote: Show quoted text
> > > --- On Thu, 6/3/10, Brian Szymanski via RT <bug-Audio-Wav@rt.cpan.org> > wrote: >
> > From: Brian Szymanski via RT <bug-Audio-Wav@rt.cpan.org> > > Subject: [rt.cpan.org #57093] Resolved: problem with bits per sample
> other than 16
> > To: sergstesh@yahoo.com > > Date: Thursday, June 3, 2010, 9:54 PM > > <URL: https://rt.cpan.org/Ticket/Display.html?id=57093 > > > > > According to our records, your request has been resolved. > > If you have any > > further questions or concerns, please respond to this > > message. > >
> > I have used (hopefully correctly) the fix you've suggested: > > 266 sub write { > 267 my ($self, @args) = @_; > 268 my $channels = $self -> {'details'} -> {'channels'}; > 269 if ( $self -> {'use_offset'} ) { > 270 return $self -> write_raw( pack 'C'.$channels, map { > $_ + $self -> {'use_offset'} } @args ); > 271 } else { > 272 #return $self -> write_raw( pack 'V'.$channels, @args > ); > 273 my $bytes_per_sample = $self->{'details'}-
> >{'bits_sample'} >> 3;
> 274 my @samples = map { substr pack('V1', $_), 0, > $bytes_per_sample } @args; > 275 return $self -> write_raw( @samples ); > 276 } > 277 } > . > > The fix doesn't work for me - when I run the same program I used to > run > with my fix (now commented out on line #272), I'm getting a bunch of > > " > Argument "\0\0\0\0" isn't numeric in addition (+) at > /home/sergei/my_perl-5.10.1/lib/site_perl/5.10.1/Audio/Wav/Write.pm > line 307. > " > > messages, here is the context for line #307: > > 292 sub write_raw { > 293 my $self = shift; > 294 my $data = shift; > 295 my $len = shift; > 296 $len = length $data unless $len; > 297 return unless $len; > 298 my $wrote = $len; > 299 if ( $self -> {'use_cache'} ) { > 300 $self -> {'write_cache'} .= $data; > 301 my $cache_len = length $self -> {'write_cache'}; > 302 $self -> _purge_cache( $cache_len ) unless $cache_len > < $self -> {'cache_size'}; > 303 } else { > 304 $wrote = syswrite $self -> {'handle'}, $data, $len; > 305 } > 306 > 307 $self -> {'pos'} += $wrote; > 308 return $wrote; > 309 } > . > > I think the bug should be reopened. > > Thanks, > Sergei. > > > >
Subject: Re: [rt.cpan.org #57093] problem with bits per sample other than 16
Date: Thu, 1 Jul 2010 07:47:25 -0700 (PDT)
To: bug-Audio-Wav [...] rt.cpan.org
From: Sergei Steshenko <sergstesh [...] yahoo.com>
--- On Thu, 7/1/10, Brian Szymanski via RT <bug-Audio-Wav@rt.cpan.org> wrote: Show quoted text
> From: Brian Szymanski via RT <bug-Audio-Wav@rt.cpan.org> > Subject: [rt.cpan.org #57093] problem with bits per sample other than 16 > To: sergstesh@yahoo.com > Date: Thursday, July 1, 2010, 7:39 AM > <URL: https://rt.cpan.org/Ticket/Display.html?id=57093 > > > One more thing - are you using stereo output files? That is > "known to be > broken" for all but mono output at the moment. >
With my "fix" I was using stereo (kind of) output - i.e. I was intentionally generating two-channel output file with identical data in both channels; 'audacity' was correctly showing two channels with visually identical data. For me a fix (or a module) producing mono output is not an option - eventually I'll need true stereo (rather, completely uncorrelated data) output. Actually, I will need even more than two channels after that. Thanks, Sergei.
Subject: Re: [rt.cpan.org #57093] problem with bits per sample other than 16
Date: Thu, 1 Jul 2010 07:54:08 -0700 (PDT)
To: bug-Audio-Wav [...] rt.cpan.org
From: Sergei Steshenko <sergstesh [...] yahoo.com>
--- On Thu, 7/1/10, Brian Szymanski via RT <bug-Audio-Wav@rt.cpan.org> wrote: Show quoted text
> From: Brian Szymanski via RT <bug-Audio-Wav@rt.cpan.org> > Subject: [rt.cpan.org #57093] problem with bits per sample other than 16 > To: sergstesh@yahoo.com > Date: Thursday, July 1, 2010, 7:39 AM > <URL: https://rt.cpan.org/Ticket/Display.html?id=57093 > > > One more thing - are you using stereo output files? That is > "known to be > broken" for all but mono output at the moment. >
I have just modified my program to produce two channels with amplitude ratio 1 : 0.5 - the output looks find in 'audacity'. I mean, the module with my "fix". Thanks, Sergei.
Marking stalled, as this still needs to be fixed properly in the long run. Thanks Sergei. Brian On Thu Jul 01 10:54:18 2010, sergstesh wrote: Show quoted text
> > > --- On Thu, 7/1/10, Brian Szymanski via RT <bug-Audio-Wav@rt.cpan.org> > wrote: >
> > From: Brian Szymanski via RT <bug-Audio-Wav@rt.cpan.org> > > Subject: [rt.cpan.org #57093] problem with bits per sample other
> than 16
> > To: sergstesh@yahoo.com > > Date: Thursday, July 1, 2010, 7:39 AM > > <URL: https://rt.cpan.org/Ticket/Display.html?id=57093 > > > > > One more thing - are you using stereo output files? That is > > "known to be > > broken" for all but mono output at the moment. > >
> > I have just modified my program to produce two channels with amplitude > ratio 1 : 0.5 - the output looks find in 'audacity'. I mean, the > module > with my "fix". > > Thanks, > Sergei. > > >