use warnings; use strict; use Win32::Sound; # Create the object my $WAV = new Win32::Sound::WaveOut(44100, 8, 2); my $data = ""; my $counter = 0; my $increment = 440/44100; # Generate 44100 samples ( = 1 second) for my $i (1..44100) { # Calculate the pitch # (range 0..255 for 8 bits) my $v = sin($counter*2*3.14) * 127 + 128; # "pack" it twice for left and right $data .= pack("CC", $v, $v); $counter += $increment; } $WAV->Load($data); # get it $WAV->Write(); # hear it 1 until $WAV->Status(); # wait for completion $WAV->Save("sinus.wav"); # write to disk my $otherFile = $ENV{TEMP} . '/sinus.wav'; $WAV->Save($otherFile); # write to disk elsewhere $WAV->Unload(); # drop it ############ $|++; for('sinus.wav', './sinus.wav', $otherFile, 'DoesNotExist') { sleep(1); printf "'%s' does%s exist and is%s readable\n", $_, (-f $_ ? '' : ' not'), (-r $_ ? '' : ' not'); Win32::Sound::Play($_); (my $f = $_) =~ s{/}{\\}; print qx(cmd.exe /c dir /N "$f"); print "\n" x 4; } __END__ 'sinus.wav' does exist and is readable Volume in drive C is Windows Volume Serial Number is XXXX-XXXX Directory of C:\usr\local\share\PassThru\perl\perlmonks 02/08/2019 03:08 PM 96,278 sinus.wav 1 File(s) 96,278 bytes 0 Dir(s) 113,186,381,824 bytes free './sinus.wav' does exist and is readable Volume in drive C is Windows Volume Serial Number is XXXX-XXXX Directory of C:\usr\local\share\PassThru\perl\perlmonks 02/08/2019 03:08 PM 96,278 sinus.wav 1 File(s) 96,278 bytes 0 Dir(s) 113,186,381,824 bytes free 'C:\Users\pryrt\AppData\Local\Temp/sinus.wav' does exist and is readable Volume in drive C is Windows Volume Serial Number is XXXX-XXXX Directory of C:\Users\pryrt\AppData\Local\Temp 02/08/2019 03:08 PM 96,278 sinus.wav 1 File(s) 96,278 bytes 0 Dir(s) 113,186,381,824 bytes free 'DoesNotExist' does not exist and is not readable File Not Found Volume in drive C is Windows Volume Serial Number is XXXX-XXXX Directory of C:\usr\local\share\PassThru\perl\perlmonks