neo42 has asked for the wisdom of the Perl Monks concerning the following question:
For most applications, the cart chunk can be appended to the end of the file... read: the order of the chunks doesn't matter. For some reason, the file I end up with is scrambled. What am I missing here? TIA, neo42use File::Format::RIFF; open( in, 'original.wav' ) or die "Could not open file: $!"; # This fi +le has the "cart chunk" data I need. my ( $riff1 ) = File::Format::RIFF->read( \*in ); # Read the WAV into + RIFF structure. close ( in ); $riff1->dump; # Dump info, just for reference. open ( middle, 'target.wav') or die "Could not open file: $!"; # This +is an MP2-encoded wav. # The idea is to get the "cart chunk" from $riff1 and add it to $riff2 +, then overwrite target file. my ( $riff2 ) = File::Format::RIFF->read ( \*middle ); # read target +file in to RIFF container close ( middle ); foreach my $chunk ( $riff1->data ) # step thru original wav, skippi +ng all but "Cart" chunk { if ( $chunk->id eq 'cart' ) { $riff2->addChunk( $chunk->id, $chunk->data); # Add cart chunk f +rom $riff1 to $riff2 } } open(out, '>target.wav') or die "Couldn't open file: $!"; # overwrite + mp2 file with "chunked" data $riff2->write( \*out ); close( out );
|
|---|