the code is supposed to make play and save a wav file each time you enter a repeat value. on win32, if your sound is turned up you should hear the number of clicks that repeats is set to. temp.wav is also created in the working folder. this all works. the only problem is that something is not resetting. if you enter 2 repeats it does 2 repeats. then enter 5 and it does 5 but if you then enter 1, it does 5 again. here is the script with the variables localized. also tried it with warnings and get back warnings that i do not understand about the data packing.
use strict;
#use warnings;
use Win32::Sound;
my $input = 1;
while ($input){
print "\nenter number of repetitions of pulse \"enter\" to quit.\
+n";
$input=<STDIN>;
chomp $input;
make_wav($input);
}
sub make_wav{
my $repeats = shift;
my $data = "";
my $counter = 0;
my $increment = 440/44100;
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();
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.