Using the sample code provided in the win32 sound module in a loop demonstrates the problem i am having. i need to generate a bunch of wav files with different pulse widths and repeat periods. i have a more complicated graphical program that allows me to change parameters. the problem is that once i create one wav file, i can never make one with fewer repeats. try the simple code below to see what i mean and please help me figure out how to make wav files with fewer repeats.
use strict; use Win32::Sound; my $data = ""; my $counter = 0; my $increment = 440/44100; my $repeats; my $input = 1; while ($input){ print "\nenter number of reps \"enter\" to quit.\n"; $input=<STDIN>; chomp $input; $repeats = $input; make_wav(); } sub make_wav{ my $WAV = new Win32::Sound::WaveOut(44100, 8, 2); $data = ""; $counter = 0; for ( my $i = 1 ; $i < $repeats + 1 ; $i++ ) { print "\ndoing repeat number $i"; for my $j (1..4410) { my $v = sin($counter/2*3.14) * 128 + 128; $data .= pack("cc", $v, $v); $counter += $increment; } for my $k (1..440) { #silence between pulses my $v = 128; $data .= pack("cc", $v, $v); } } $WAV->Unload(); # drop it $WAV->Load($data); # get it $WAV->Write(); # hear it 1 until $WAV->Status(); # wait for completion $WAV->Save("temp.wav",$data); # write to disk $WAV->Close(); }

In reply to win32 sound 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.