I need to add a "cart" chunk to a RIFF Wave file. This should be pretty simple using File::Format::RIFF, but I guess I'm missing something. Here's what I have so far.
use 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 );
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, neo42

In reply to Chunk-y WAV files by neo42

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.