#!/usr/bin/perl -w
#
# spam2wav      --crb3 30Dec06
#
# how many spammers does it take to recreate the soundtrack to
# Katamari Damacy? filling in bycts after all is saved to disk
# allows for piping concatenated spam in via STDIN (-s operator
# might not like pipes).
#
$riffsize=$databyct=0;

$samrate=11025;                 # a comfy samplerate, ~5KHz bandwidth
$bytrate=$samrate;

die "no WAVfile specified\n" unless defined($outf=$ARGV[0]);

open(W,">$outf"or die "can't make outfile $outf\n";
&write_headers;
while(defined($ln=<STDIN>)){
  chomp $ln;                    # unpleasant periodicity removed
  $databyct += length($ln);
  print W $ln;
}
$riffsize=$databyct+8+16+4;     # takes in other headers
seek(W,0,0);
&write_headers;                 # this time with real sizes
close(W);

sub write_headers {
  $headers=pack("a4Ia4"."a4IvvIIvv"."a4I",
        'RIFF',
        $riffsize,              # hoping the native endian is vax/intel
        'WAVE',

        'fmt ',
        16,                     # fmtcnt, size of 'fmt ' args
        1,
        1,                      # channels
        $samrate,
        $bytrate,
        1,                      # bytes per sample-block
        8,                      # bits per sample

        'data',
        $databyct  );
  print W $headers;
}

Grab a
gzipped
copy
here
 
Syntax highlighting using Syntax::Highlight::Engine::Kate