Sponsored Content
Top Forums Programming My first PERL incarnation... Audio Oscillograph Post 303037917 by wisecracker on Saturday 17th of August 2019 01:46:38 PM
Old 08-17-2019
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...

Code:
#!/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)
This User Gave Thanks to wisecracker For This Post:
 

6 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Audio HELP Please!

I know about next to nothing, and I am trying to play an audio file on HP-UX 10.2 (743i) every time I try to use the ‘/opt/audio/bin/AudioCP &' command I get an error message that says “Unable to access audio hardware.” I checked the man page on audio, and both Aserver and rpcd are running. Am I... (4 Replies)
Discussion started by: Matt
4 Replies

2. UNIX for Dummies Questions & Answers

playing audio

Hi all, I play audio through the web browser and it plays ok on windows. When i try the same thing on unix i get the error message "sh: /usr/local/bin/sox: not found. I've tried 'locate sox' and can't seem to find it. Is there some way I can change the browser settings so they play the audio... (3 Replies)
Discussion started by: molli_81
3 Replies

3. UNIX for Advanced & Expert Users

Audio-Text in Unix

Hello all, Could anyone help to me :as to how can i record an audio file in unix and convert it into a text . Or anything with audio recording to get started would help . thanks, (3 Replies)
Discussion started by: phantom308
3 Replies

4. UNIX for Dummies Questions & Answers

Audio Problem

Hi I recently installed BT 5 Gnome on my Asus laptop running on Intel HD graphics. I've been having problems with audio, at first I experienced the basic problem that was solved by adding pulse audio to the starting programs. This allowed me to open Sound preferences but I still have no sound.... (0 Replies)
Discussion started by: edreeso
0 Replies

5. Slackware

Problems with audio recording in Audacity 2.0.5. Slackware64 14.1; Intel HD Audio.

I'm trying to record audio using Audacity 2.0.5 installed from SlackBuilds. My system is 64-bit Slackware 14.1 and a sound card is Intel HD Audio. I didn't change my sound system to OSS. (Default sound system in Slackware 14.1 is ALSA, isn't it?) First, I set Internal Microphone slider in KMix... (2 Replies)
Discussion started by: qzxcvbnm
2 Replies

6. OS X (Apple)

An Audio Function Generator...

Ok guys, gals and geeks... As from today I am starting to learn awk in earnest doing something totally different. I am going to create a pseudo-Audio_Function Generator centred around OSX 10.11.x minimum. The code below is a tester to see what the possibilities are. All waveforms will be... (11 Replies)
Discussion started by: wisecracker
11 Replies
All times are GMT -4. The time now is 07:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy