[music-dsp] prototyping on perl - contains code

Hans Mikelson hljmm at charter.net
Mon Sep 18 22:10:09 EDT 2000


Hi,

Shifty wrote:

> @MyHeader=pack("Z4V1Z4Z4V1v1v1V1V1v1v1Z4V1",
>                "RIFF",$F1,"WAVE","fmt ",0x10,0x1,0x1,
>                $samplerate,2*$samplerate,0x2,16,"data",$F2);
>
> print @MyHeader;

For whatever reason this did not work on my computer.  I could not find
references Z in the Perl documentation so I used A which seems to work.  My
computer makes me use binary mode.  Here is a simple sine wave:

# Modified Shifty's 16-bit, Mono 44.1KHz Wave Header generation

$samplen = 44100;
$sr      = 44100;
$pi2     = 3.14159265*2;

$sfile = "test.wav";

$F2=2*$samplen;  # 2 bytes per sample
$F1=0x24+$F2;    # that's just the len's of headers.

@MyHeader=pack("A4V1A4A4V1v1v1V1V1v1v1A4V1",
               "RIFF",$F1,"WAVE","fmt ",0x10,0x1,0x1,
               $sr,2*$sr,0x2,16,"data",$F2);

open(SAMP, ">$sfile");
binmode SAMP;
print SAMP @MyHeader;

$fqc = 440;

for ($i=0; $i<$samplen; $i++)
 {
  $value = int(sin($i*$pi2/$sr*$fqc)*30000);
  print SAMP pack("s1",$value);
 }

Bye,
Hans Mikelson


dupswapdrop -- the music-dsp mailing list and website: subscription info,
FAQ, source code archive, list archive, book reviews, dsp links
http://shoko.calarts.edu/musicdsp/




More information about the music-dsp mailing list