=head1 NAME read_wav =head1 SYNOPSYS perl read_wav chimes.wav > chimes.dat =head1 DESCRIPTION This routine reads a .wav file and prints out the waveform so that it can be graphed with gnuplot or processed by some other program. This program only works on 8 bit sound files. =cut $/ = ""; $_ = <>; @val= unpack("C*", $_); $file_type= pack("C*", splice(@val,0,4)); # print "File type: $file_type\n"; $garbage= pack("C*", splice(@val,0,4)); # print "garbage: $garbage\n"; $wave_chunk= pack("C*", splice(@val,0,4)); # print "wave chunk: $wave_chunk\n"; while ($#val > 0) { $chunk_type= pack("C*", splice(@val,0,4)); # print "chunk type: $chunk_type\n"; $chunk_size= &my_pack_dword(splice(@val,0,4)); # print "chunk size: $chunk_size\n"; @chunk= splice(@val,0,$chunk_size); if ($chunk_type eq "data") { if ($fmt_cat != 1 and $channels != 1) {die "Unsupported format";} for ($i=0; $i< $#chunk; $i++) { print $i/$samp_per_sec." ".($chunk[$i]-128)."\n"; } } elsif ($chunk_type eq "fmt ") { $fmt_cat= &my_pack_word(splice(@chunk, 0, 2)); $channels= &my_pack_word(splice(@chunk, 0, 2)); $samp_per_sec= &my_pack_dword(splice(@chunk, 0, 4)); $bytes_per_sec= &my_pack_dword(splice(@chunk, 0, 4)); $block_size= &my_pack_word(splice(@chunk, 0, 2)); # print "format section:\n"; # print "format: $fmt_cat\n"; # print "channels: $channels\n"; # print "samp_per_sec: $samp_per_sec\n"; # print "bytes_per_sec: $bytes_per_sec\n"; # print "block_size: $block_size\n"; } } sub my_pack_dword { $b0= shift; $b1= shift; $b2= shift; $b3= shift; $b0+256*$b1+65536*$b2+16777216*$b3; } sub my_pack_word { $b0= shift; $b1= shift; $b0+256*$b1; }