I would like to understand what this means:

... a WAV file that I am using for storing data logger information.

What is "data logger information"? is it simply a stream of 16-bit littel-endian binary integer data? If so, why put a WAV header on it? (That is, why not just have a "raw" binary file of "data logger information", stored as stream of 16-bit little-endian binary data?)

In case it makes sense for you to start with a "raw" (headerless) file containing only zeros - or some other "test pattern" - the first question is: how big should the file be (how many short ints do you want)? Let's say you want 64K:

# create a file with 65536 bytes of zeros (i.e. 32768 short int zeros) +: perl -e 'print "\0" x 65536' > zeros.raw # create a file with 32768 short int zeros followed by 32768 short int + ones: perl -e 'print pack("s",0) x 32768; print pack("s",1) x 32768' > zeros +-ones.raw
To turn a raw file into a WAV file, I'd use SoX (http://sox.sourceforge.net), but it would involve making up stuff about sample-rate, etc, which might be irrelevant to what you're actually trying to accomplish:
sox -t raw -e signed-integer -b 16 -r 8000 -c 1 zeros.raw zeros.wav
(SoX command-line usage is pretty "unique"... but like I said, do you really need it to be a WAV file?)

As for reading binary 16-bit little-endian integer values from a raw data file (e.g. one of the "*.raw" files created above):

#!/usr/bin/perl use strict; use warnings; my $infile = shift or die "Usage: $0 raw_input_file_name\n"; my $file_size = -s $infile; open( my $fh, $infile ) or die "$infile: $!\n"; read( $fh, my $buf, $file_size ); my @ints=unpack("s*", $buf); print scalar @ints, " short-int elements read\n"; print " ... which seems right\n" if ( @ints == $file_size/2 ); my %h; $h{$ints[$_]}++ for (0..$#ints); print "distinct int values found in $infile:\n"; print " $_ occurs $h{$_} times\n" for (keys %h);

In reply to Re: Audio::WAV data problem by graff
in thread Audio::WAV data problem by spencoid

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.