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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting The Start Of A Simple Audio Scope Shell Script...
# 1  
Old 01-15-2013
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..
# 2  
Old 01-15-2013
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..
# 3  
Old 01-15-2013
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 01-15-2013
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..
This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 01-15-2013
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...
# 6  
Old 01-18-2013
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...

Last edited by wisecracker; 07-14-2013 at 05:19 AM.. Reason: Code is now an attachment.
# 7  
Old 03-11-2013
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...

Last edited by wisecracker; 07-14-2013 at 05:24 AM.. Reason: Code now an attachment.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. OS X (Apple)

A simple variable frequency sinewave audio generator.

Hi all... Well I have not been inactive but working out how to make OSX 10.14.x command line audio player have a variable sample rate. This is a back door as afplay does not have a sample rate flag unlike aplay for ALSA, in Linux flavours. This is a DEMO only but a derivative of it will... (2 Replies)
Discussion started by: wisecracker
2 Replies

2. Shell Programming and Scripting

Generate 10000 unique audio file of 2MB each using shell script.

Hi, I want 10000+ unique Audio file of approx 2MB each. How can i generate numerous audio files using shell script. Any tool, command or suggestions are welcome. If i give one audio seed file then can we create numerous unique files with same seed file? Any help is highly appreciable.... (11 Replies)
Discussion started by: sushil.kumar
11 Replies

3. OS X (Apple)

Python script to do simple audio capture...

This site is the first to get this snippet. It will capture an audio recording of any time length within the limits of OSX's QuickTime Player's capablility... A shell script derivative of this will be used as a further capture for CygWin's AudioScope.sh. Thoroughly read ALL the comments in... (0 Replies)
Discussion started by: wisecracker
0 Replies

4. UNIX for Dummies Questions & Answers

unable to start shell script

Hi, Pleasse could someone advise why i'm getting this error below - No such file or directory dev6:$ ls -ltr ReleaseManagement.sh -rwxr-xr-x 1 dev fix 4830 Aug 22 11:13 ReleaseManagement.sh dev6:$ ./ReleaseManagement.sh : No such file or directory dev6:$ thank you (2 Replies)
Discussion started by: venhart
2 Replies

5. Shell Programming and Scripting

The scope of the shell/perl script is to read the input text file. Validate the expiry date of each

The scope of the shell/perl script is to read the input text file. Validate the expiry date of each certificate and send the mail to the user. The user takes action to add the new certificate to the storage file and user owns the responsibility to update the input text file with the new certificate... (5 Replies)
Discussion started by: casmo
5 Replies

6. What is on Your Mind?

Scope of Shell Programming and scripting

Hi all, I want to know what is the scope and job status of shell Programming and scripting. Does it have any attractive jobs? (2 Replies)
Discussion started by: malikshahid85
2 Replies

7. Shell Programming and Scripting

Help with stop/start Shell Script.

Hi All, I would like to develop a shell script for stop & start an application server (1-4) on Solaris box. Here are the user requirements for this task. 1. User will input the option which server they wish to stop. 2. Will clear cache files from specific location. 3. ... (1 Reply)
Discussion started by: venga
1 Replies

8. Shell Programming and Scripting

scope of a Variable inside shell script

hi all, i'm using the following script, Status=1 Function_do () { while read line; do if ; then #echo $line if ; then Status=0 echo " LINKINK ERROR " fi fi done < ldd.log } Function_do (4 Replies)
Discussion started by: vij_krr
4 Replies

9. Shell Programming and Scripting

simple shell - how to get a parameter typed in a shell script

Hi, I am new to unix and using linux 7.2. I would like to create a script that would make it easyer for me to run my java programms. At the moment I have to type java myJavaprogram I am trying to write a script that will allow me to type something like this "myscript myJavaprogram" or maybe... (4 Replies)
Discussion started by: cmitulescu
4 Replies

10. Shell Programming and Scripting

problem with shell variable's scope

Hi, I am stuck while developing a shell sub-routine which checks the log file for "success" or "failure". The subroutine reads the log file and checks for key word "success", if found it set the variable (found=1). It returns success or failure based on this variable. My problem is, I can... (2 Replies)
Discussion started by: cjjoy
2 Replies
Login or Register to Ask a Question