i have the following script that is part of a larger tk script to make 
wav files of various pulses. i have replaced most variables with 
constants to make it simpler. added added a few comments to make a 
little sense out of what it does but the main question is the following: 
the number of repetitions can be increased by entering higher numbers 
but the number of repetitions can never be made smaller. try entering a 
lower repetition number after entering a higher number and see that it 
still does the higher number of repeats. "$data" should be reset each 
time? this must be something stupid i am doing but it is so simple and i 
can't figure it out?

use strict;
use Win32::Sound;
my $repeats = 1;
while ($repeats){
     print "\nenter number of repetitions of pulse \"enter\" to quit.\n";
     $repeats= <STDIN>;
     chomp $repeats;
     do_it();
}
sub do_it{
     my $WAV = new Win32::Sound::WaveOut(44100, 8, 2);
     my $data;
     my $counter;
     my $increment = int (10000/44100);
     my $repeat_width = int((44100 / 1000) * (200));
     my $pulse_width = int((44100 / 1000000) * (1000 / 2));
     my $space = $repeat_width - $pulse_width;
     for ( my $i = 0 ; $i < $repeats ; $i++ ) { # for number of repeats, 
make pulse and space
         for ( my $j = 0 ; $j < $pulse_width ; $j++ ){ # do the pulse
             my $v;
             $v = sin($counter/2*3.14) * 128 + 128;  # for sine wave
             $data .= pack("cc", $v, $v);    # "pack" it twice for left 
and right
         $counter += $increment;
     }
     for ( my $k = 0 ; $k < $space ; $k++ ){ # do the space between pulses
             my $v = 127;
             $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("test.wav"); # write to disk
     $WAV->Unload();          # drop it

-- 
Best regards, Spencer Chase
67550-Bell Springs Rd.
Garberville, CA 95542 Postal service only.
Laytonville, CA 95454 UPS only.
[email protected]
http://www.spencerserolls.com
(707) 984-8356
(425) 791-0309

_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to