My first PERL incarnation... Audio Oscillograph

Hi all...
Well guys and gals, I jumped in at the deep end and found things that PERL cannot do by default.
Many tricky terminal escape codes are not catered for so I had to create workarounds.

One thing I searched for was this:

Passing perl variable to shell command

AND, @Neo this was top of the Google search list.

I thanked Chubler_XL for the post as it saved an awful lot of head scratching.

I might add that Python 2.0.x to the current 3.7.4 can do ALL of the escape codes that the shell can.

Right, I am now open to criticism just on this part alone...

I will include, ' arecord ' for ALSA systems and ' /dev/dsp ' for others. This is just a taster to see how convoluted PERL is...

#!/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);
}

Have fun shredding it... ;o)

1 Like

Thanks for sharing, wisecracker!

My only comments is "so great to see someone enjoying their hobby and posting their thoughts and results here".

Thank you again for your many contributions to these forums, in so many ways.

1 Like

To answer you previous question: perl or python,
Perl is certainly better in this kind of turning the bits and bytes inside out.

The following should be improved:

The built-in print and printf are much more powerful than the shell's printf.

1 Like

Hi MadeInGermany...

I didn't try the Perl builtin 'printf' as 'print' DID support terminal colours, so I made an assumption that 'printf' wouldn't plot either.

I will experiment with plotting using 'printf' and get back to you.
If I get stuck and plotting is still unable to be done then I will come back on here for solutions.

TIA.

EDIT:
Well a cold start with the builtin 'print' DOES work but believe me, I tried for hours with hard coded valus as well is variables and I kept getting an major 'scalar' error report finally ending up saying it couldn't complie the code - hence reverting to the 'system' command.

I honestly do not know why I kept getting major errors when now it is working..

Here is the original test code i couldn't get working, but it is actually calling me a liar now.

#!/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";

And finally I am in the process of using 4 capture modes, DEMO, DSP, ALSA and QT, (DEMO is obviously working using the builtin random number generator but the final cut will create a raw 'noise' file using /dev/urandom).
I have already done the section to create the AppleScript and call it, but not done the binary file to byte sized decmial array or list yet but I am working on it...

Hopefully this will not attach itsekf to the previous.

I will let this go as it is so far, to show I am not being idle with it...

#!/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! ";
}

And the listing so for:

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> _

NOTE:
'Untitled.m4a' and 'qt.scpt' are related to QT, DO NOT USE THIS MODE YET!

Hi all...

Modified greatly and now captures real bytes from '/dev/urandom' and displays the plots.
Removed system() function calls where possible, (compare with post #1).
Saves a 'config' file to the current directory and loads on program restart, it just saves the capture mode on quitting at the moment.
As this is just an exercise in me learning the basics of Perl then this will not go anywhere near as sophisticated as AudioScope[.sh].
It is also ONLY capturing 64 bytes and running at maximum speed of 1mS per division as this is just a personal learning exercise.
Commented out the RANDOM line for the vertical axis FTTB.

#!/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();
}

Results before quitting:

       +-------+-------+-------+---[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:-      

All criticism welcome!

2 Likes

Hi.

Good to see people picking up perl. Although use has declined, I still find it very useful. The O'Reilly trilogy is quite useful, and I have found the PBP to be especially valuable. The tools I use the most are align and perltidy . We get many non-standard codes and libraries from The Comprehensive Perl Archive Network - www.cpan.org as well as The world�s leading software development platform . GitHub

Of the 1000+ scripts we have almost 300 are in perl:

       44 awk-[gmn]awk-native
( ... )
      280 perl
( ... )
      176 sh
     1182 total

For example, to trim things:

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.

In looking at graphs, I get visually confused by too much ink. Going by Tufte https://www.amazon.com/Visual-Display-Quantitative-Information/dp/0961392142/ and Vellemanhttps://www.amazon.com/Applications-Basics-Computing-Exploratory-Analysis/dp/087150409X I tend toward less is more, as below.

Keep up the good work ... cheers, drl

       +-------+-------+-------+---[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.

Codes:

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
3 Likes

Hi drl...

I tried your _graticule_ but it reminded me of my Cossor 339[A] Oscillograph given to me when I was a young kid but reverted back again.
Well Quicktime Player is now capturing a signal CRUCIFYINGLY slowly.
The image is a low level signal around 1KHz whistled into the microphone.
This line in the QT capture had me stumped all of yesterday evening, 27-08-2019, then voila I went to bed and slept on it and realised my mistake:

system("/usr/bin/afconvert -f WAVE -c 1 -d UI8\@8000 /tmp/Untitled.m4a /tmp/waveform.wav");

Yes it was converting to '.wav' but was ignoring the sample rate and it wasn't until I woke up this morning I realised I was using double quotes and '@' is important in perl.
The code so far. A few additions to cater for '_bit_error_', '_noise_floor_' artifacts affecting the display.
As I have not done the drawing routine yet then the image of the low level whistle into mic looks as though it is joined up.

#!/usr/bin/perl

# #########################################################
# Audio Oscillograph, (uncalibrated AF Oscilloscope).
# 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
# Developed on a[n] MBP, OSX Mojave, Version 10.14.3.
# NOT tested on OSX greater than version 10.14.3!

# #########################################################
# 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 "\033[0m\033c\033[2J\033[H";
}

# #########################################################
# Basic command processing...
sub commands
{
    print "\033[23;1f\033[0m$blankline";
    print "\033[23;1f\033[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");
    }
    if ( $command eq 'RESTART' )
    {
        $capture_mode='DEMO';
        system("/bin/rm Oscillograph.config");
    }
}

# #########################################################
# 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 1
        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 "\033[H\033[0;36;44m       +-------+-------+-------+---[\033[1;37;44mDISPLAY\033[0;36;44m]---+-------+-------+--------+       
       |       |       |       |       +       |       |       |        | \033[0;31;44mMAX\033[0;36;44m   
       |       |       |       |       +       |       |       |        |       
       |       |       |       |       +       |       |       |        |       
   \033[0;31;44m+ve\033[0;36;44m +-------+-------+-------+-------+-------+-------+-------+--------+       
       |       |       |       |       +       |       |       |        |       
       |       |       |       |       +       |       |       |        |       
       |       |       |       |       +       |       |       |        |       
     \033[1;32;44m0\033[0;36;44m +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+--+ \033[1;32;44mREF\033[0;36;44m   
       |       |       |       |       +       |       |       |        |       
       |       |       |       |       +       |       |       |        |       
       |       |       |       |       +       |       |       |        |       
   \033[0;30;44m-ve\033[0;36;44m +-------+-------+-------+-------+-------+-------+-------+--------+       
       |       |       |       |       +       |       |       |        |       
       |       |       |       |       +       |       |       |        |       
       |       |       |       |       +       |       |       |        |       
       |       |       |       |       +       |       |       |        | \033[0;30;44mMIN\033[0;36;44m   
       +-------+-------+-----[\033[1;37;44mAUDIO  OSCILLOGRAPH\033[0;36;44m]-----+-------+--------+       \033[0m

Commands available: QUIT, DEMO, DSP, ALSA, QT and RESTART.\n$blankline\n$blankline\n";
}

# #########################################################
# Capture methods, '/dev/urandom', '/dev/dsp', '/usr/bin/arecord' and 'QuickTime Player'.
sub capture
{
    if ("$capture_mode" eq 'DEMO')
    {
        # DEMO mode that requires no HW access, working as of 27-06-2019.
        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=64 > /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.
        # Working as of 28-08-2019.
        system("/bin/sh", "/tmp/QT.scpt");
        system("/usr/bin/afconvert -f WAVE -c 1 -d UI8\@8000 /tmp/Untitled.m4a /tmp/waveform.wav");
        system("dd if=/tmp/waveform.wav of=/tmp/waveform.raw skip=5120 bs=1 count=64 > /dev/null 2>&1");
    }
    @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.
        chomp(${hexdump_array[($horiz-9)]});
        $vert="${hexdump_array[($horiz-9)]}";
        if ($vert == 127)
        {
            # This allows for centreline 0, zero, AC voltage bit error, (noise).
            $vert=128;
        }
        $vert=int(($vert/16)+2);
        # invert the signal. I'll let you work out why...
        $vert=(19-$vert);
        $plot="\033["."$vert".";"."$horiz"."f\033[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();
}

I am beginning to enjoy this as it has been much harder to do than in the shell, believe it or not.
I still feel the shell is unbelievably flexible for my uses, but perl makes me think for a change.

BTW I have found pdfs' of the first two books and will be using them for the next stages, many thanks for the information.
I have no idea if those pdfs' contain malware, but I don't care... ;o)

Bazza.

2 Likes

So much fun from wisecracker.

Thanks for the updates!

1 Like

Hi.

Looks like progress.

When I run into trouble with perl that I cannot seem to solve by looking in the books, I often search PerlMonks - The Monastery Gates -- they have an enormous body of snippets, articles, questions/answers, and discussions to address many issues.

If you are interested in pretty-printing/tidying your code on macOS, I see that perltidy is available via brew :

Results for program brew (key "b")
 ( brew writes to /usr/local )
==> Formulae
perltidy

 Results for program fink (key "f")
 ( fink writes to /sw )
Scanning package description files
Information about 306 packages read in 2 seconds.

 Results for program port (key "p")
 ( port writes to /opt/local )
Error: Port perltidy not found

So I'm using:

OS, ker|rel, machine: Apple/BSD, Darwin 18.7.0, x86_64
Distribution        : macOS 10.14.6 (18G84), Mojave
perltidy - ( local: /usr/local/bin/perltidy, v20190601 )

The graph looks better to me -- keep on perlin' ... cheers, drl

2 Likes

Great!
I checked all system() and found only

 system("/bin/rm Oscillograph.config");

that can be replaced with

 unlink "Oscillograph.config";

Described in

man perlfunc
1 Like

Hi MadeInGermany...

Thanks for that info, 'system("command")' removed and your 'unlink...' line inserted in its place...

Hi fellas and dames...
(Apologies for any typos, etc...)

I have not been idle on this but I am on holiday/vacation and I only have limited www access AND Linux Mint 19, current updates as of 06-09-2019. My OSX machine is safely at home.
Well needless to say, what works in OSX 10.14.3 and the Perl version it possesses didn't work in Linux Mint and its Perl version. ;o/

As I am still out here on holiday I have released this Linux Mint 19 version so far. I have no idea what needs compromising until I get home and test on OSX 10.14.3.
"DSP", '/dev/dsp/' and "ALSA", 'arecord' now work as planned, 'RESTART' is now a complete 'RESET'.
This line in the 'RESET' section, exit(system("$abs_path")); is way cool, and the 'Title Bar' now reads "Perl Audio Oscillograph.".
I am NOT taking this fun project to the same limits as AudioScope.sh at all, just enough to whet peoples appetites and better it or reconstruct/translate the idea completely to another language.
There are lots of other changes that are in there too.
When I return home I will let you all know about how OSX 10.14.3 and 'QT' reacts to these changes.
Bizarre as it might sound I could NOT get Linux Mint's Perl version to recognise the 'current directory' as the valid default, so PATHs are now absolute.
As I have NOT done the drawing routine yet this is a low level whistle into the internal microphone using the ALSA capture mode.

#!/usr/bin/perl

# #########################################################
# Audio Oscillograph, (uncalibrated AF Oscilloscope).
# 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)
# Developed on a[n] MBP, OSX Mojave, Version 10.14.3!
# NOT tested on OSX greater than version 10.14.3!
#
# This is perl 5, version 26, subversion 1 (v5.26.1) built for x86_64-linux-gnu-thread-multi
# (with 67 registered patches, see perl -V for more detail)
# Co-developed on Linux Mint 19, full Mint 19 updates as of 06-09-2019!
#
# Thanks to drl and MadeInGermany for further info.

# #########################################################
# Needed!
use warnings;
use strict;
use Cwd 'abs_path';

print "\033]0;Perl Audio Oscillograph.\007";

# #########################################################
# Global variables...
my $abs_path=abs_path('Oscillograph.config');
my $blankline="                                                                                ";
my $horiz=9;
my $vert=9;
my $plot="";
my @hexdump_array=();
our $capture_mode="DEMO";
our $mode=" DEMO  ";

# #########################################################
# Make sure a bare config file exists in the current directory.
unless(-e "$abs_path")
{
    my $config='$capture_mode="DEMO";
$mode=" DEMO  ";
1;
';
    open(my $config_file, '>', "$abs_path");
    print $config_file "$config";
    close($config_file);
}

# #########################################################
# Source config file as required.
require "$abs_path";

# #########################################################
# Clear the screen and reset the terminal.
sub clrscn
{
    print "\033[0m\033c\033[2J\033[H";
}

# #########################################################
# Basic command processing...
sub commands
{
    print "\033[23;1f\033[0m$blankline";
    print "\033[23;1f\033[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".'";
$mode="'."$mode".'";
1;
';
        open(my $config_file, '>', "$abs_path");
        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';
        $mode=' DEMO  ';
    }
    if($command eq 'DSP')
    {
        $capture_mode='DSP';
        $mode='  DSP  ';
    }
    if($command eq 'ALSA')
    {
        $capture_mode='ALSA';
        $mode=' ALSA  ';
    }
    if($command eq 'QT')
    {
        $capture_mode='QT';
        $mode=' QEMAC ';
        &QT_script();
        system("/bin/sh", "/tmp/QT.scpt");
    }
    if($command eq 'RESET')
    {
        &clrscn();
        # Thanks MaedInGermany for the line below.
        unlink("$abs_path") or die "Cannot delete Oscillograph.config!";
        $abs_path=abs_path('Oscillograph.pl');
        exit(system("$abs_path"));
    }
    if($command eq 'TEST')
    {
        $capture_mode='TEST';
        $mode=' TEST  ';
        # Use ASCII characters ONLY for DC offset test waveform, exactly 1KHz, 1mS/DIV timebase speed.
        #
        # Sinewave...
        # my $waveform="Oq~qO- -Oq~qO- -Oq~qO- -Oq~qO- -Oq~qO- -Oq~qO- -Oq~qO- -Oq~qO- -";
        #
        # Squarewave...
        my $waveform="    ~~~~    ~~~~    ~~~~    ~~~~    ~~~~    ~~~~    ~~~~    ~~~~";
        open(my $waveform_file, '>', '/tmp/waveform.raw');
        print $waveform_file "$waveform";
        close($waveform_file);
    }
    print "\033[23;1f\033[0m$blankline";
    print "\033[23;1f\033[0mEnter 'QUIT'<CR> to quit or <CR> to [Re-]Run:- ";    
}

# #########################################################
# 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 1
        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 "\033[H\033[0;36;44m       +-------+-------+-------+---[\033[1;37;44mDISPLAY\033[0;36;44m]---+-------+-------+--------+       
       |       |       |       |       +       |       |       |        | \033[0;31;44mMAX\033[0;36;44m   
       |       |       |       |       +       |       |       |        |       
       |       |       |       |       +       |       |       |        |       
   \033[0;31;44m+ve\033[0;36;44m +-------+-------+-------+-------+-------+-------+-------+--------+       
       |       |       |       |       +       |       |       |        |       
       |       |       |       |       +       |       |       |        |       
       |       |       |       |       +       |       |       |        |       
     \033[1;32;44m0\033[0;36;44m +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+--+ \033[1;32;44mREF\033[0;36;44m   
       |       |       |       |       +       |       |       |        |       
       |       |       |       |       +       |       |       |        |       
       |       |       |       |       +       |       |       |        |       
   \033[0;30;44m-ve\033[0;36;44m +-------+-------+-------+-------+-------+-------+-------+--------+       
       |       |       |       |       +       |       |       |        |       
       |       |       |       |       +       |       |       |        |       
       |       |       |       |       +       |       |       |        |       
       |       |       |       |       +       |       |       |        | \033[0;30;44mMIN\033[0;36;44m   
       +-------+-------+-----[\033[1;37;44mAUDIO  OSCILLOGRAPH\033[0;36;44m]-----+-------+--------+       \033[0m

Commands available: QUIT, DEMO, DSP, ALSA, QT, RESET and TEST.
$blankline
$blankline
$blankline\033[23;1f\033[0mEnter 'QUIT'<CR> to quit or <CR> to [Re-]Run:- 
   \033[0;36m\$VER: Audio_Oscillograph._Author_B.Walker,_G0LCU_courtesy_of_www.unix.com.\033[0m   ";
}

# #########################################################
# Capture methods, '/dev/urandom', '/dev/dsp', '/usr/bin/arecord' and 'QuickTime Player'.
sub capture
{
    if("$capture_mode" eq 'DEMO')
    {
        # DEMO mode that requires no HW access, working as of 27-06-2019.
        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), working as of 06-09-2019.
        system("/bin/dd if=/dev/dsp of=/tmp/waveform.bin bs=1 count=8000 > /dev/null 2>&1");
        system("/bin/dd if=/tmp/waveform.bin of=/tmp/waveform.raw skip=5120 bs=1 count=64 > /dev/null 2>&1");
    }
    if($capture_mode eq 'ALSA')
    {
        # ALSA mode for Linux boxes that have 'arecord', working as of 06-09-2019.
        system("/usr/bin/arecord -d 1 -c 1 -f U8 -r 8000 -t wav /tmp/waveform.wav > /dev/null 2>&1");
        system("/bin/dd if=/tmp/waveform.wav of=/tmp/waveform.raw skip=5120 bs=1 count=64 > /dev/null 2>&1");
    }
    if($capture_mode eq 'QT')
    {
        # A crucifyingly SSLLOOWW mode for Apple, OSX Mojave.
        # Working as of 28-08-2019.
        system("/bin/sh", "/tmp/QT.scpt");
        system("/usr/bin/afconvert -f WAVE -c 1 -d UI8\@8000 /tmp/Untitled.m4a /tmp/waveform.wav");
        system("dd if=/tmp/waveform.wav of=/tmp/waveform.raw skip=5120 bs=1 count=64 > /dev/null 2>&1");
    }
    if($capture_mode eq 'TEST')
    {
        # Use ASCII characters ONLY for offset waveform, exactly 1KHz.
        # Sinewave...
        # my $waveform="Oq~qO- -Oq~qO- -Oq~qO- -Oq~qO- -Oq~qO- -Oq~qO- -Oq~qO- -Oq~qO- -";
        # Squarewave...
        my $waveform="    ~~~~    ~~~~    ~~~~    ~~~~    ~~~~    ~~~~    ~~~~    ~~~~";
        open(my $waveform_file, '>', '/tmp/waveform.raw');
        print $waveform_file "$waveform";
        close($waveform_file);
    }
    @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.
        chomp(${hexdump_array[($horiz-9)]});
        $vert="${hexdump_array[($horiz-9)]}";
        if($capture_mode eq 'TEST')
        {
            $vert=$vert+50;
        }
        if($vert == 127)
        {
            # This allows for centreline 0, zero, AC voltage bit error, (noise).
            $vert=128;
        }
        $vert=int(($vert/16)+2);
        # invert the signal. I'll let you work out why...
        $vert=(19-$vert);
        $plot="\033["."$vert".";"."$horiz"."f\033[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();
    print "\033[1;37f\033[1;32;44m$mode\033[23;48f\033[0;36;44m";
 }

Have fun ripping it apart...

1 Like

A quicky everyone...
Now tested on OSX...

I don't know who as tried this out but you will notice that inside the white [DISPLAY] area at the top if the image, during an audio capture it turns green and displays the capture mode in use.

Well I have now tested it on OSX 10.14.3 and I noticed a spelling error in there, 'QEMAC' which should read 'QTMAC'. oh well it will be picked up on the next upload, DUH.
It runs exactly the same as Linux Mint without alteration EXCEPT QuickTime Player is excruciatingly SSLLOOWW.

I am not going to use SoX as that is a dependency so ALSA, DSP and QT are the only 3 REAL modes to use.
I am not even going to test under CygWin either because I have no idea whether Perl is available under CygWin.

Back to coding again...

It is. I'm currently working with cygwin. It's a reliable way to get many of the essential tools if you have to use windows. But it's a bit slow. I don't know, if it's fast enough for this program.

1 Like

Hi stomp...
(Apologies for typos.)

I can give a few pointers as I designed the bash script 'AudioScope.sh' here: AudioScope Project. to include it.
It captures using the now defunct 'SoundRecorder.exe' for Windows 8.1 OR CygWin's builtin '/dev/dsp'. Both methods take around 2 seconds total for a 1 second burst, BUT, because CygWin is _emulating_, (for want of a better description), a UNIX style environment accessing either capture mode takes around 1/8th of a second berfore the audio device activates.
SoundRecorder.exe, (which is no longer part of Windows 10), can only do a standard '.wav' file at 44100sps and /dev/dsp a '.raw' unsigned integer file at 8000sps from the command line.
The 'mintty' terminal is quite capable of all the escape codes I have used so far, including the title bar.
The above shell project was designed for hopefully ALL *NIX flavours with bash and included SoX, a dependency, as the prime mover for capture.

1 Like