The Start Of A Simple Audio Scope Shell Script... | Unix Linux Forums | Shell Programming and Scripting

  Unix/Linux Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

The Start Of A Simple Audio Scope Shell Script...

Shell Programming and Scripting


Tags
audio, audioscope, oscilloscope, scope

Unix or Linux Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-15-2013
wisecracker's Unix or Linux Image
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 6 March 2015, 3:17 AM EST
Location: Loughborough
Posts: 745
Thanks: 165
Thanked 170 Times in 137 Posts
The Start Of A Simple Audio Scope Shell Script...

This is a DEMO shell script to generate a simple graticule and plot inside it...

Apologies for any typos...

it is another building block along with my other two shell uploads recently to start a semi_serious project of an Terminal_AudioScope...

The fist upload I posted recently was to show how to animate colours, the second was to be able to manipulate a known bainary file to become a timebase and now this simple display...

The next upload will be a simple working unit using "/dev/dsp" for Linux through either the internal micrphone or the external mic input... The limitations of this device is that by default it samples at 8KHz, to 8 bit depth, mono, so don't expect anything wondrous...

There is a FLAW in this DEMO. It is NOT a bug! What is it? ;o)

You need to know how the console or terminal works to find it... <big wink>

Be aware of wordwrapping, etc...


Code:
#!/bin/bash
#
# AudioScopeDisplay.sh
# 
# This method can also be used for a simple kids level Analogue Data_logger/Transient_Recorder
# Cannot use "setterm -cursor off" as Mac OSX 10.7.5 has not got "setterm", thought of another way for the Macbook Pro... ;o)
#
# $VER: AudioScopeDisplay.sh_Version_0.00.01_Public_Domain_B.Walker_G0LCU.

display()
{
	clear
	graticule="+-------+-------+-------+-------+-------+-------+-------+--------+\n"
	graticule=$graticule"|       |       |       |       +       |       |       |        |\n"
	graticule=$graticule"|       |       |       |       +       |       |       |        |\n"
	graticule=$graticule"|       |       |       |       +       |       |       |        |\n"
	graticule=$graticule"+-------+-------+-------+-------+-------+-------+-------+--------+\n"
	graticule=$graticule"|       |       |       |       +       |       |       |        |\n"
	graticule=$graticule"|       |       |       |       +       |       |       |        |\n"
	graticule=$graticule"|       |       |       |       +       |       |       |        |\n"
	graticule=$graticule"+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+--+\n"
	graticule=$graticule"|       |       |       |       +       |       |       |        |\n"
	graticule=$graticule"|       |       |       |       +       |       |       |        |\n"
	graticule=$graticule"|       |       |       |       +       |       |       |        |\n"
	graticule=$graticule"+-------+-------+-------+-------+-------+-------+-------+--------+\n"
	graticule=$graticule"|       |       |       |       +       |       |       |        |\n"
	graticule=$graticule"|       |       |       |       +       |       |       |        |\n"
	graticule=$graticule"|       |       |       |       +       |       |       |        |\n"
	graticule=$graticule"|       |       |       |       +       |       |       |        |\n"
	graticule=$graticule"+-------+-------+-------+-------+-------+-------+-------+--------+\n"
	printf "$graticule"
}

while true
do
	display
	for horiz in {2..65}
	do
		# 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=$[ ( $RANDOM % ( 256 / 16 ) + 2 ) ]
		# There IS a FLAW here at _printf_, NOTE, not a bug! What is it? ;o)
		printf "\x1B["$vert";"$horiz"fo"
		# Slow it down so you can see it working...
		sleep 0.05
	done
	printf "\x1B[20;1f"
	sleep 1
done

Enjoy finding simple solutions to often very difficult problems... ;o)

Bazza, G0LCU...

EDIT: Changed the shebang line; many thanks to Scrutinizer...

Last edited by wisecracker; 01-15-2013 at 04:31 PM..
Sponsored Links
    #2  
Old Unix and Linux 01-15-2013
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is online now Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 6 March 2015, 11:00 AM EST
Location: Amsterdam
Posts: 9,976
Thanks: 321
Thanked 2,593 Times in 2,319 Posts
One little problem with the script is that the shebang on line 1 is not correct in two ways:

Code:
# !/bin/sh

There is a space between # and ! so it does not function as a shebang, but as a comment.

And also the script is clearly a bash script, not a sh script, so the shebang should be
Code:
#!/bin/bash

for example..
Sponsored Links
    #3  
Old Unix and Linux 01-15-2013
wisecracker's Unix or Linux Image
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 6 March 2015, 3:17 AM EST
Location: Loughborough
Posts: 745
Thanks: 165
Thanked 170 Times in 137 Posts
Hi Scrutinizer...

Thanks for the info...

I hadn't noticed the space. Will correct next time. And I check the code on DEFAULT terminals/shells on many Linux flavours as well is this Macbook Pro, (which just happens to be bash)...

If it did not work for you then I would gladly have a description of the error and I will correct if possible accordingly...

If it did work then your shell/terminal would be of interest too...

Again thanks for the info...

Bazza, G0LCU...

EDIT: BTW That was not the flaw... ;o)
    #4  
Old Unix and Linux 01-15-2013
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is online now Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 6 March 2015, 11:00 AM EST
Location: Amsterdam
Posts: 9,976
Thanks: 321
Thanked 2,593 Times in 2,319 Posts
Simple example. If the interactive shell is ksh for example, then your script will not run correctly:

Code:
$ ksh
$ ./AudioScopeDisplay.sh
./AudioScopeDisplay.sh: line 10: syntax error at line 41: `(' unexpected
$

If you use the correct shebang, then it will run.

Also if you use #!/bin/sh on Ubuntu for example, it will not work...
On other linux distributions #!/bin/sh calls bash --posix which also will not always work like bash.
If you use a shebang then it should call the shell that the script is supposed to work with..

Last edited by Scrutinizer; 01-15-2013 at 04:43 PM..
The Following User Says Thank You to Scrutinizer For This Useful Post:
wisecracker (01-15-2013)
Sponsored Links
    #5  
Old Unix and Linux 01-15-2013
wisecracker's Unix or Linux Image
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 6 March 2015, 3:17 AM EST
Location: Loughborough
Posts: 745
Thanks: 165
Thanked 170 Times in 137 Posts
Hi Scrutinizer...

I went offline and tried various shells from this Macbook Pro and found the "ksh" error...

Thanks for pointing it out, and edited the code...

I like being corrected and log it down in the old grey matter... ;o)

"sh" worked OK, as did "csh"...

Although an amateur, and old, I learn very quickly... ;o)

Cheers...

Bazza, G0LCU...
Sponsored Links
    #6  
Old Unix and Linux 01-18-2013
wisecracker's Unix or Linux Image
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 6 March 2015, 3:17 AM EST
Location: Loughborough
Posts: 745
Thanks: 165
Thanked 170 Times in 137 Posts
Update 1, 18-01-2013, AudioScope continued...

This is the next stage...

It alters the size of the Terminal window down in size from 80 x 24 to 66 x 24...

Now in colour and has pseudo-windows for a status line and a command line...

The plotting delay is now removed...

/dev/dsp will be accessed next to give e pseudo-realtime scan...

Any takers want to try it out and pass on any constructive tips...

TIA...

(Watch for wordwrapping, etc.)

Bazza, G0LCU...
Attached Files
File Type: sh 00011.sh (3.1 KB, 13 views)

Last edited by wisecracker; 07-14-2013 at 05:19 AM.. Reason: Code is now an attachment.
Sponsored Links
    #7  
Old Unix and Linux 03-11-2013
wisecracker's Unix or Linux Image
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 6 March 2015, 3:17 AM EST
Location: Loughborough
Posts: 745
Thanks: 165
Thanked 170 Times in 137 Posts
Hi all...

A real sample can now be displayed using SoX and the internal microphone of a netbook, laptop, etc...

Just download and install "SoX" command line _sound_(exchange)_system_...

There is also a line using /dev/dsp in default 8000KHz sampling speed but I haven't tested it yet...

You will have to change the "demo" variable from 0 to 1 for /dev/dsp or -1 for SoX. If you use SoX then change the pointer to the correct absolute address of your install...

Colours changed and decided on going back to the default 80 x 24 Terminal size...
Attached Files
File Type: sh 00012.sh (4.2 KB, 15 views)

Last edited by wisecracker; 07-14-2013 at 05:24 AM.. Reason: Code now an attachment.
Sponsored Links
Unix or Linux Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
The scope of the shell/perl script is to read the input text file. Validate the expiry date of each casmo Shell Programming and Scripting 5 04-21-2011 12:06 PM
Scope of Shell Programming and scripting malikshahid85 What is on Your Mind? 2 09-02-2010 01:38 PM
scope of a Variable inside shell script vij_krr Shell Programming and Scripting 4 11-02-2009 07:37 AM
simple shell - how to get a parameter typed in a shell script cmitulescu Shell Programming and Scripting 4 01-09-2009 08:45 PM
problem with shell variable's scope cjjoy Shell Programming and Scripting 2 01-04-2009 11:25 AM



All times are GMT -4. The time now is 12:00 PM.