|
Search Forums |
Tag Search |
Advanced Search |
Quick Links |
Contact Us |
Forum Rules |
Today's Posts |
FAQ |
Pictures & Albums |
All Albums |
Miscellaneous |
What is My IP |
Whois |
Mark Forums Read |
#!/usr/bin/perl # Audio Oscillograph, (uncalibrated AF Oscilloscope). # NOTE: Many terminal escape codes are not supported, so workarounds ARE needed. # Oscillograph.pl use warnings; use strict; # Global variables... my $horiz=9; my $vert=9; my $plot=""; # ######################################################### # Clear the screen and reset the terminal. sub clrscn { my $clearscn=1; print "\x1B[0m\x1Bc"; for($clearscn=1; $clearscn<=25; $clearscn=$clearscn+1) { print " \n"; } system("/usr/bin/printf", "\x1B[1;1f"); } # ######################################################### # Screen DISPLAY setup function. For a terminal size of 80 x 24. sub display { # Set foreground and background graticule colours and foreground and background other window colours. print "\x1B[H\x1B[0;36;44m +-------+-------+-------+---[\x1B[1;37;44mDISPLAY\x1B[0;36;44m]---+-------+-------+--------+ | | | | + | | | | \x1B[0;31;44mMAX\x1B[0;36;44m | | | | + | | | | | | | | + | | | | \x1B[0;31;44m+ve\x1B[0;36;44m +-------+-------+-------+-------+-------+-------+-------+--------+ | | | | + | | | | | | | | + | | | | | | | | + | | | | \x1B[1;32;44m0\x1B[0;36;44m +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+--+ \x1B[1;32;44mREF\x1B[0;36;44m | | | | + | | | | | | | | + | | | | | | | | + | | | | \x1B[0;30;44m-ve\x1B[0;36;44m +-------+-------+-------+-------+-------+-------+-------+--------+ | | | | + | | | | | | | | + | | | | | | | | + | | | | | | | | + | | | | \x1B[0;30;44mMIN\x1B[0;36;44m +-------+-------+-----[\x1B[1;37;44mAUDIO OSCILLOGRAPH\x1B[0;36;44m]-----+-------+--------+ \x1B[0m\n\n" } # ######################################################### # Plot the points in the terminal window. sub plotter { for($horiz=9; $horiz<=72; $horiz=$horiz+1) { # Simulate an 8 bit grab and divide by 16 to give 4 bit depth. Add offset of 2 to allow # for mssing the top graticule line... $vert=int(rand(256/16)+2); $plot="\x1B["."$vert".";"."$horiz"."f\x1B[1;37;44m*"; # NOTE: 'print "$plot";' does not work because '\x1B[v;hf' is not supported! system("printf", "$plot"); } } # ######################################################### # Main loop. clrscn; while(1) { display; plotter; # The hard coded line below is not supported, use 'system("/usr/bin/printf", "\x1B[23;1f")' instead... # print "\x1B[21;1f"; system("printf", "\x1B[21;1f\x1B[0mPress Ctrl-C to stop! "); sleep(1); }
system("/usr/bin/printf", "\x1B[1;1f");
system("printf", "$plot");
system("printf", "\x1B[21;1f\x1B[0mPress Ctrl-C to stop! ");
#!/usr/bin/perl # plotter.pl use warnings; use strict; # Centre of terminal window. my $horiz=34; my $vert=11; my $plotter="\033["."$vert".";"."$horiz"."fHello World.\n"; print "$plotter";
#!/usr/bin/perl # ######################################################### # Audio Oscillograph, (uncalibrated AF Oscilloscope). # NOTE: Many terminal escape codes are not supported, so workarounds ARE needed. # Oscillograph.pl # # This is perl 5, version 18, subversion 2 (v5.18.2) built for darwin-thread-multi-2level # (with 2 registered patches, see perl -V for more detail # ######################################################### # Needed! use warnings; use strict; # ######################################################### # Global variables... my $horiz=9; my $vert=9; my $plot=""; # Manually alter the variable below to suit your system, DEMO, DSP, ALSA or QT. my $capture_mode='DEMO'; # ######################################################### # Clear the screen and reset the terminal. sub clrscn { my $clearscn=1; print "\x1B[0m\x1Bc"; for($clearscn=1; $clearscn<=25; $clearscn=$clearscn+1) { print " \n"; } print "\x1B[1;1f"; } # ######################################################### # This generates a shell script that runs an applescript to access QuickTime Player. sub QT_script { system("echo '/usr/bin/osascript << AppleSampler tell application \"QuickTime Player\" activate set savePath to \"Macintosh HD:tmp:Untitled.m4a\" set recording to new audio recording set visible of front window to false delay 2 start recording delay 2 stop recording export document \"Untitled\" in file savePath using settings preset \"Audio Only\" close (every document whose name contains \"Untitled\") saving no tell application \"System Events\" to click menu item \"Hide Export Progress\" of menu \"Window\" of menu bar 1 of process \"QuickTime Player\" delay 1 quit end tell AppleSampler' > /tmp/qt.scpt"); } # ######################################################### # Screen DISPLAY setup function. For a terminal size of 80 x 24. sub display { # Set foreground and background graticule colours and foreground and background other window colours. print "\x1B[H\x1B[0;36;44m +-------+-------+-------+---[\x1B[1;37;44mDISPLAY\x1B[0;36;44m]---+-------+-------+--------+ | | | | + | | | | \x1B[0;31;44mMAX\x1B[0;36;44m | | | | + | | | | | | | | + | | | | \x1B[0;31;44m+ve\x1B[0;36;44m +-------+-------+-------+-------+-------+-------+-------+--------+ | | | | + | | | | | | | | + | | | | | | | | + | | | | \x1B[1;32;44m0\x1B[0;36;44m +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+--+ \x1B[1;32;44mREF\x1B[0;36;44m | | | | + | | | | | | | | + | | | | | | | | + | | | | \x1B[0;30;44m-ve\x1B[0;36;44m +-------+-------+-------+-------+-------+-------+-------+--------+ | | | | + | | | | | | | | + | | | | | | | | + | | | | | | | | + | | | | \x1B[0;30;44mMIN\x1B[0;36;44m +-------+-------+-----[\x1B[1;37;44mAUDIO OSCILLOGRAPH\x1B[0;36;44m]-----+-------+--------+ \x1B[0m\n\n"; } # ######################################################### # Capture methods, '/dev/urandom', '/dev/dsp', '/usr/bin/arecord' and 'QuickTime Player'. sub capture { # IMPORTANT! None are used yet and NOT tested inside Perl. if ("$capture_mode" eq 'DEMO') { # DEMO mode that requires no HW access. system("/bin/dd if=/dev/urandom of=/tmp/waveform.raw bs=1 count=8000 > /dev/null 2>&1"); sleep(1); } if ($capture_mode eq 'DSP') { # DSP mode for the likes of old Linux boxes and CygWin, (OSS or PulseAudio). system("/bin/dd if=/dev/dsp of=/tmp/waveform.raw bs=1 count=8000 > /dev/null 2>&1"); } if ($capture_mode eq 'ALSA') { # ALSA mode for Linux boxes that have 'arecord'. !!! Not tested yet. !!! system("/usr/bin/arecord -d 1 -c 1 -f U8 -r 8000 -t raw /tmp/waveform.raw > /dev/null 2>&1"); } if ($capture_mode eq 'QT') { # A crucifyingly SSLLOOWW mode for Apple, OSX Mojave. # Conversion to RAW file not done yet... system("/bin/sh", "/tmp/qt.scpt"); } } # ######################################################### # Plot the points in the terminal window. sub plotter { for($horiz=9; $horiz<=72; $horiz=$horiz+1) { # Simulate an 8 bit grab and divide by 16 to give 4 bit depth. # Add offset of 2 to allow for missing the top graticule line. # IMPORTATNT! Using the builtin random number generator at present for DEMO. $vert=int(rand(256/16)+2); $plot="\x1B["."$vert".";"."$horiz"."f\x1B[1;37;44m*"; print "$plot"; } } # ######################################################### # Initiation and main loop. clrscn; if ($capture_mode eq 'QT') { print "Setting up QT for first time (re)run!"; QT_script; system("/bin/sh", "/tmp/qt.scpt"); } display; while(1) { capture; display; plotter; print "\x1B[21;1f\x1B[0m$capture_mode mode, press Ctrl-C to stop! "; }
AMIGA:amiga~/Desktop/Code/Perl> ls -l /tmp/ total 80 drwx------ 4 root wheel 128 16 Nov 2018 PKInstallSandbox.MMTz8b -rw-r--r--@ 1 amiga wheel 26312 20 Aug 20:38 Untitled.m4a drwx------ 3 amiga wheel 96 20 Aug 18:15 com.apple.launchd.Dk0vVDZ1G8 drwx------ 3 amiga wheel 96 20 Aug 18:15 com.apple.launchd.y5Rib6CVUt drwxr-xr-x 2 root wheel 64 20 Aug 18:14 powerlog -rw-r--r-- 1 amiga wheel 591 20 Aug 20:33 qt.scpt -rw-r--r-- 1 amiga wheel 8000 20 Aug 20:50 waveform.raw AMIGA:amiga~/Desktop/Code/Perl> cat /tmp/qt.scpt /usr/bin/osascript << AppleSampler tell application "QuickTime Player" activate set savePath to "Macintosh HD:tmp:Untitled.m4a" set recording to new audio recording set visible of front window to false delay 2 start recording delay 2 stop recording export document "Untitled" in file savePath using settings preset "Audio Only" close (every document whose name contains "Untitled") saving no tell application "System Events" to click menu item "Hide Export Progress" of menu "Window" of menu bar 1 of process "QuickTime Player" delay 1 quit end tell AppleSampler AMIGA:amiga~/Desktop/Code/Perl> _
#!/usr/bin/perl # ######################################################### # Audio Oscillograph, (uncalibrated AF Oscilloscope). # NOTE: Many terminal escape codes are not supported, so workarounds ARE needed. # Oscillograph.pl # # This is perl 5, version 18, subversion 2 (v5.18.2) built for darwin-thread-multi-2level # (with 2 registered patches, see perl -V for more detail # ######################################################### # Needed! use warnings; use strict; # ######################################################### # Make sure a bare config file exists in the current directory. unless(-e "Oscillograph.config") { my $config='$capture_mode="DEMO"; 1; '; open(my $config_file, '>', 'Oscillograph.config'); print $config_file "$config"; close($config_file); } # ######################################################### # Global variables... my $blankline=" "; my $horiz=9; my $vert=9; my $plot=""; my @hexdump_array=(); our $capture_mode="DEMO"; require 'Oscillograph.config'; # ######################################################### # Clear the screen and reset the terminal. sub clrscn { print "\x1B[0m\x1Bc\x1B[2J\x1B[H"; } # ######################################################### # Basic command processing... sub commands { print "\x1B[23;1f\x1B[0m$blankline"; print "\x1B[23;1f\x1B[0mEnter 'QUIT'<CR> to quit or <CR> to [Re-]Run:- "; my $command=<STDIN>; chomp $command; if ( $command eq 'QUIT' ) { my $config='$capture_mode="'."$capture_mode".'"; 1; '; open(my $config_file, '>', 'Oscillograph.config'); print $config_file "$config"; close($config_file); &clrscn(); print "Saved Oscillograph.config and resetting the terminal to the default state.\n"; exit(0); } if ( $command eq 'DEMO' ) { $capture_mode='DEMO'; } if ( $command eq 'DSP' ) { $capture_mode='DSP'; } if ( $command eq 'ALSA' ) { $capture_mode='ALSA'; } if ( $command eq 'QT' ) { $capture_mode='QT'; &QT_script(); system("/bin/sh", "/tmp/QT.scpt"); } } # ######################################################### # This generates a shell script that runs an applescript to access QuickTime Player. sub QT_script { my $AppleScript='/usr/bin/osascript << AppleSampler tell application "QuickTime Player" activate set savePath to "Macintosh HD:tmp:Untitled.m4a" set recording to new audio recording set visible of front window to false delay 2 start recording delay 2 stop recording export document "Untitled" in file savePath using settings preset "Audio Only" close (every document whose name contains "Untitled") saving no tell application "System Events" to click menu item "Hide Export Progress" of menu "Window" of menu bar 1 of process "QuickTime Player" delay 1 quit end tell AppleSampler '; open(my $QuickTime, '>', '/tmp/QT.scpt'); print $QuickTime "$AppleScript"; close($QuickTime); } # ######################################################### # Screen DISPLAY setup function. For a terminal size of 80 x 24. sub display { # Set foreground and background graticule colours and foreground and background other window colours. print "\x1B[H\x1B[0;36;44m +-------+-------+-------+---[\x1B[1;37;44mDISPLAY\x1B[0;36;44m]---+-------+-------+--------+ | | | | + | | | | \x1B[0;31;44mMAX\x1B[0;36;44m | | | | + | | | | | | | | + | | | | | | | | + | | | | \x1B[0;31;44m+ve\x1B[0;36;44m +-------+-------+-------+-------+-------+-------+-------+--------+ | | | | + | | | | | | | | + | | | | | | | | + | | | | \x1B[1;32;44m0\x1B[0;36;44m +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+--+ \x1B[1;32;44mREF\x1B[0;36;44m | | | | + | | | | | | | | + | | | | | | | | + | | | | \x1B[0;30;44m-ve\x1B[0;36;44m +-------+-------+-------+-------+-------+-------+-------+--------+ | | | | + | | | | | | | | + | | | | | | | | + | | | | \x1B[0;30;44mMIN\x1B[0;36;44m +-------+-------+-----[\x1B[1;37;44mAUDIO OSCILLOGRAPH\x1B[0;36;44m]-----+-------+--------+ \x1B[0m Commands available: QUIT, DEMO, DSP, ALSA and QT.\n\n\n"; } # ######################################################### # Capture methods, '/dev/urandom', '/dev/dsp', '/usr/bin/arecord' and 'QuickTime Player'. sub capture { # IMPORTANT! None are used yet and NOT tested inside Perl. if ("$capture_mode" eq 'DEMO') { # DEMO mode that requires no HW access. system("/bin/dd if=/dev/urandom of=/tmp/waveform.raw bs=1 count=64 > /dev/null 2>&1"); sleep(1); } if ($capture_mode eq 'DSP') { # DSP mode for the likes of old Linux boxes and CygWin, (OSS or PulseAudio). system("/bin/dd if=/dev/dsp of=/tmp/waveform.raw bs=1 count=8000 > /dev/null 2>&1"); } if ($capture_mode eq 'ALSA') { # ALSA mode for Linux boxes that have 'arecord'. !!! Not tested yet. !!! system("/usr/bin/arecord -d 1 -c 1 -f U8 -r 8000 -t raw /tmp/waveform.raw > /dev/null 2>&1"); } if ($capture_mode eq 'QT') { # A crucifyingly SSLLOOWW mode for Apple, OSX Mojave. # Conversion to RAW file not done yet... system("/bin/sh", "/tmp/QT.scpt"); } @hexdump_array=`/usr/bin/hexdump -v -e '1/1 "%u\n"' /tmp/waveform.raw`; } # ######################################################### # Plot the points in the terminal window. sub plotter { for($horiz=9; $horiz<=72; $horiz=$horiz+1) { # Simulate an 8 bit grab and divide by 16 to give 4 bit depth. # Add offset of 2 to allow for missing the top graticule line. # IMPORTATNT! Using the builtin random number generator at present for DEMO. # $vert=int(rand(255/16)+2); chomp(${hexdump_array[($horiz-9)]}); $vert="${hexdump_array[($horiz-9)]}"; $vert=int(($vert/16)+2); # invert the signal. I'll let you work out why... $vert=(19-$vert); $plot="\x1B["."$vert".";"."$horiz"."f\x1B[1;37;44m*"; print "$plot"; } } # ######################################################### # Initialisation and main loop. &clrscn(); &display(); if ($capture_mode eq 'QT') { # Initialise Quicktime Player when 'QT' is selected. &QT_script(); system("/bin/sh", "/tmp/QT.scpt"); } while(1) { &capture(); &display(); &plotter(); &commands(); }
+-------+-------+-------+---[DISPLAY]---+-------+-------+--------+ |* | * | | * + * * | | | MAX | * | *| * | * +* | | |* * * | | | * | | + | | | | | * * | | * + | | **| * | +ve +-------+-------*--*-*--+-----*-+-------+--*----+-------+--------+ | | * | *| + | *|* | *| | |* | | + | | | * | | | * | |* + | | | | 0 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-*-**+-+-+-+-+-+-*-+-+-+-+-+-+--+ REF | | | * | + * | * * | | | | | | + | | | * | | *| | * * ** * | | * | | -ve +--*-*--+-------+-------+-------+-------+----*--+----*--+--------+ | * | | * | + | * | | | | * | | | + *| | * | | | |* | + |* * | | * | MIN +-------+-------+-----[AUDIO OSCILLOGRAPH]-----+-------+--------+ Commands available: QUIT, DEMO, DSP, ALSA and QT. Enter 'QUIT'<CR> to quit or <CR> to [Re-]Run:-
44 awk-[gmn]awk-native ( ... ) 280 perl ( ... ) 176 sh 1182 total
clenfi CLip ENds from FIle, n,m or --top=n --bottom=m; trim, omit. pll Print long-line, section, trim, shorten to width as necessary. trim Remove strings of whitespace at beginning and end of lines.
+-------+-------+-------+---[DISPLAY]---+-------+-------+--------+ |* * * + * * | MAX | * * * * +* * * * | | * + | | * * * + ** * | +ve + + * * * + * + + * + + + | * * + * * *| | * + * | | * * + | 0 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-*-**+-+-+-+-+-+-*-+-+-+-+-+-+--+ REF | * + * * * | | + * | | * * * ** * * | ve + * * + + + + + * + * + + | * * + * | | * + * * | | * + * * * | MIN +-------+-------+-----[AUDIO OSCILLOGRAPH]-----+-------+--------+
Books: Title: Learning Perl Subtitle: Making Easy Things Easy & Hard Things Possible Author: R Schwartz, T Phoenix Edition: 4th Date: July 14, 2005 Publisher: O'Reilly ISBN: 0596101058 Pages: 304 Categories: perl, text manipulation, development, scripting, programming Comments: I have 3rd, 2001 Comments: 4 stars (290 reviews, Amazon, 2007.12) Title: Intermediate Perl Subtitle: Beyond the Basics of Learning Perl Author: R Schwartz, b d foy, T Phoenix Edition: 2nd Date: 2006 Publisher: O'Reilly ISBN: 0596102062 Pages: 278 Categories: perl, text manipulation, development, scripting, programming Comments: 2nd edition, but first was named "Learning Perl Objects ..." Comments: 4.5 stars (9 reviews, Amazon, 2007.12) Title: Mastering Perl Subtitle: Creating Professional Programs with Perl Author: b d foy Edition: 1st Date: July 16, 2007 Publisher: O'Reilly ISBN: 0596527241 Pages: 342 Categories: perl, text manipulation, development, scripting, programming Comments: 4.5 stars (5 reviews, Amazon, 2007.12) Title: Perl Best Practices Subtitle: Standards and Styles for Developing Maintainable Code Author: Damian Conway Date: 2005 Publisher: O'Reilly ISBN: 0596001738 Pages: 500 Categories: perl, standard, development, scripting, programming Comments: 4.5 stars (39 reviews, 2011.08) at Amazon.
align Align columns of text. (what) Path : ~/p/stm/common/scripts/align Version : 1.7.0 Length : 270 lines Type : Perl script, ASCII text executable Shebang : #!/usr/bin/perl Help : probably available with --help Home : http://kinzler.com/me/align/ (doc) Modules : (for perl codes) Getopt::Std 1.10 perltidy a perl script indenter and reformatter (man) Path : /usr/bin/perltidy Version : (local) Type : HTML document, ASCII text ...) Repo : Debian 8.11 (jessie) Home : http://perltidy.sourceforge.net/ (pm) Modules : (for perl codes) Perl::Tidy 20140328 Excel::Writer::XLSX::Package::Theme 0.24
|
|