Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

OK, now the start of the audio scope...
Goto page 1, 2, 3, 4  Next
 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
Bazza
LXF regular


Joined: Sat Mar 21, 2009 11:16 am
Posts: 1477
Location: Loughborough

PostPosted: Tue Jan 15, 2013 9:38 pm    Post subject: OK, now the start of the audio scope... Reply with quote

Hi guys and gals...

This is the starter of the shell script audio scope...

The shebang is definitive this time and not a comment...

It is just a simple scan of a graticule using a random number...

Those prepared to test give it a whirl and pass preliminary comments...

Ignore the cursor being shown I have a way of removing if necessary...

The next stage will be using /dev/dsp to grab from the mic input or internal mic...

Watch for 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 ) ]
      # IMPORTANT! The display must be inverted because of the way a terminal plots its characters...
      vert=$[ ( 19 - $vert ) ]
      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

_________________
73...

Bazza, G0LCU...

Team AMIGA...
Back to top
View user's profile Send private message
roseway
LXF regular


Joined: Thu Jan 18, 2007 2:27 pm
Posts: 446

PostPosted: Wed Jan 16, 2013 7:57 am    Post subject: Reply with quote

Well, it works, but the Os used for plotting the curves didn't make for a very clear display. It would perhaps be better with fat dots or something of that nature.
_________________
Eric
Back to top
View user's profile Send private message
Bazza
LXF regular


Joined: Sat Mar 21, 2009 11:16 am
Posts: 1477
Location: Loughborough

PostPosted: Wed Jan 16, 2013 10:02 am    Post subject: Reply with quote

Hi roseway...

Thanks a mill'...

I am really appreciative of you guys testing on various linux platforms...

This is just a taster, the "o"s were just as a proof test. The graticule display WILL be in a different colour to the plotted _graph_. Anything I post in the near future will be proof of concept only...

The next one will need /dev/dsp so if anyone is interested in the next level then check you have /dev/dsp "installed"...
_________________
73...

Bazza, G0LCU...

Team AMIGA...
Back to top
View user's profile Send private message
guy
LXF regular


Joined: Thu Apr 07, 2005 1:07 pm
Posts: 1071
Location: Worcestershire

PostPosted: Wed Jan 16, 2013 9:36 pm    Post subject: Reply with quote

Yeah.

The o's were too far apart to give any real sense of a continuous curve. Hoping that's down to the random coordinate generator.

Can you explain about /dev/dsp and the quote marks around "installed"?
_________________
Cheers,
Guy
The eternal help vampire
Back to top
View user's profile Send private message
johnhudson
LXF regular


Joined: Wed Aug 03, 2005 2:37 pm
Posts: 871

PostPosted: Wed Jan 16, 2013 9:40 pm    Post subject: Reply with quote

No problem seeing the o's in KDE Konsole but curve not always obvious because of distances/speed of writing; took about 4.5 secs to plot on a 1.8GHz processor.
Back to top
View user's profile Send private message
Bazza
LXF regular


Joined: Sat Mar 21, 2009 11:16 am
Posts: 1477
Location: Loughborough

PostPosted: Wed Jan 16, 2013 10:53 pm    Post subject: Reply with quote

Hi guy...

http://www.linuxformat.com/forums/viewtopic.php?t=13336

Hi JH...

This is proof of concept ATM. If it works then that is all I want.

The next upload will be pseudo-real time access from /dev/dsp.

The limitation of /dev/dsp is that by default it samples at 8KHz to 8 bit depth and mono so do not expect anything wondrous...

EDIT: Speed is not important as I deliberately slowed it down so that it could seen working correctly...
_________________
73...

Bazza, G0LCU...

Team AMIGA...
Back to top
View user's profile Send private message
Bazza
LXF regular


Joined: Sat Mar 21, 2009 11:16 am
Posts: 1477
Location: Loughborough

PostPosted: Fri Jan 18, 2013 6:37 pm    Post subject: Update 1, 18-01-2013, AudioScope... Reply with quote

This is an update.

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

Any takers want to try it out and give me any constructive tips...

TIA...

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)
#
# Set window size down to 66 x 24...
printf "\x1B[8;24;66t"

display()
{
   # Set foregound and background graticule colours and foreground and background other window colours.
   printf "\x1B[0;30;46m"
   clear
   graticule="+-------+-------+-------+---[\x1B[0;37;46mDISPLAY\x1B[0;30;46m]---+-------+-------+--------+\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"
   graticule=$graticule"\x1B[0;37;40m+------------------------[STATUS WINDOW]-------------------------+\n"
   graticule=$graticule"|     \$VER: AudioScope.sh_Version_0.00.10_PD_B.Walker_G0LCU.     |\n"
   graticule=$graticule"+-----------------------[COMMAND  WINDOW]------------------------+\n"
   graticule=$graticule"| COMMAND:- Press Ctrl-C to stop the scan...                     |\n"
   graticule=$graticule"|                                                                |\n"
   graticule=$graticule"+----------------------------------------------------------------+"
   printf "$graticule"
   # Set colours for plot.
   printf "\x1B[1;31;46m"
}

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 ) ]
      # IMPORTANT! The display must be inverted because of the way a terminal plots its characters...
      vert=$[ ( 19 - $vert ) ]
      printf "\x1B["$vert";"$horiz"f*"
   done
   printf "\x1B[22;45f\x1B[0;37;40"
   sleep 1
done

_________________
73...

Bazza, G0LCU...

Team AMIGA...
Back to top
View user's profile Send private message
guy
LXF regular


Joined: Thu Apr 07, 2005 1:07 pm
Posts: 1071
Location: Worcestershire

PostPosted: Fri Jan 18, 2013 8:54 pm    Post subject: Reply with quote

works fine.

I think that it will be important to interpolate between points, where they are spaced apart vertically. Otherwise, higher frequencies appear as a visually random scatter of stars, and the trace even at mid-frequencies will be broken into irregular "dashes".

I'd suggest that for each new point, you start drawing one step offset (up or down as required) from the previous point, and draw a vertical line of stars to the new point. Or of course, if the points are level then don't!

Red on blue/green is not easily legible. Yellow on blue/green would be much better for me.
_________________
Cheers,
Guy
The eternal help vampire
Back to top
View user's profile Send private message
johnhudson
LXF regular


Joined: Wed Aug 03, 2005 2:37 pm
Posts: 871

PostPosted: Fri Jan 18, 2013 9:21 pm    Post subject: Reply with quote

It works and the text is helpful BUT

the * is barely visible - the o's were much clearer

it appears to write the plot instantaneously rather than as if it were a line moving across the screen as in the previous example.
Back to top
View user's profile Send private message
Bazza
LXF regular


Joined: Sat Mar 21, 2009 11:16 am
Posts: 1477
Location: Loughborough

PostPosted: Fri Jan 18, 2013 11:10 pm    Post subject: Reply with quote

Hi guy...

The interpolation will come as linear. As this progresses then I might make the whole user definable - colours, type of plotting character etc...

Hi jh...

The colours will remain FTTb but I have taken note of both comments. As for the instantaneous effect that is because I removed the sleep 0.05 delay... This will be how it will be displayed in reality. I am looking at SoX for the grabbing tool as it supposedly is platform independent.

Thanks to both for risking your machines.

The next snippet will use /dev/dsp and demo mode defaulting to demo mode until you edit the file and rerun. I have to assume that your systems have it as a device...

The limitation of /dev/dsp is 8KHz sampling speed, mono, 8 bit depth. This is where the binary transfer file uploaded recently will come into play... This will be the timebase... ;o)

Again many thanks you guys...
_________________
73...

Bazza, G0LCU...

Team AMIGA...
Back to top
View user's profile Send private message
Bazza
LXF regular


Joined: Sat Mar 21, 2009 11:16 am
Posts: 1477
Location: Loughborough

PostPosted: Mon Mar 11, 2013 8:36 pm    Post subject: Reply with quote

Hi all...

Well I was able to carry on with this little enterprise...

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

There is 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...

Watch for 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)

# Change demo value to 1 to access /dev/dsp for "storage" AudioScope facility...
demo=0
vert=12
horiz=5
subscript=0

display()
{
   # Set foregound and background graticule colours and foreground and background other window colours.
   printf "\x1B[0;36;44m"
   clear
   graticule="   +-------+-------+-------+-------[\x1B[0;37;44mDISPLAY\x1B[0;36;44m]-------+-------+-------+--------+   \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"
   graticule=$graticule"\x1B[0;37;40m   +---------------------------[COMMAND  WINDOW]----------------------------+   \n"
   graticule=$graticule"   | COMMAND:- Press Ctrl-C to stop the scan...                             |   \n"
   graticule=$graticule"   |                                                                        |   \n"
   graticule=$graticule"   +----------------------------[STATUS WINDOW]-----------------------------+   \n"
   graticule=$graticule"   |         \$VER: AudioScope.sh_Version_0.00.12_PD_B.Walker_G0LCU.         |   \n"
   graticule=$graticule"   +------------------------------------------------------------------------+   " 
   printf "$graticule"
   # Set colours for plot.
   printf "\x1B[1;37;44m"
}

while true
do
   display
   horiz=5
   vert=12
   subscript=0
   if [ $demo -eq 1 ]
   then
      dd if=/dev/dsp of=/tmp/waveform.raw bs=8000 count=1
      # scan_start=0
      # scan_jump=1
      # scan_finish=$[ ( $scan_jump * 64 ) ]
   fi
   if [ $demo -eq -1 ]
   then
      /Users/barrywalker/Downloads/sox-14.4.0/sox -q -V0 -d -t raw -r 44100 -b 8 -c 1 -e unsigned-integer -> /tmp/waveform.raw trim 0 00:01
   fi
   for horiz in {5..76}
   do
      if [ $demo -eq 0 ]
      then
         # 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 ) ]
      fi
      if [ $demo -ne 0 ]
      then
         vert=`hexdump -n1 -s$subscript -v -e '1/1 "%u"' /tmp/waveform.raw`
         vert=$[ ( ( $vert / 16 ) + 2 ) ]
         subscript=$[ ( $subscript + 1 ) ]
      fi
      
      # IMPORTANT! The display must be inverted because of the way a terminal plots its characters...
      vert=$[ ( 19 - $vert ) ]
      printf "\x1B["$vert";"$horiz"f*"
   done
   printf "\x1B[20;48f\x1B[0;37;40m"
   sleep 1
done

_________________
73...

Bazza, G0LCU...

Team AMIGA...
Back to top
View user's profile Send private message
guy
LXF regular


Joined: Thu Apr 07, 2005 1:07 pm
Posts: 1071
Location: Worcestershire

PostPosted: Mon Mar 11, 2013 9:10 pm    Post subject: Reply with quote

Much easier on the eyeballs.

Unfortunately I have nothing that can give a real signal, and precious little understanding of the system resources, so am ducking out of the interesting bit.
_________________
Cheers,
Guy
The eternal help vampire
Back to top
View user's profile Send private message
Bazza
LXF regular


Joined: Sat Mar 21, 2009 11:16 am
Posts: 1477
Location: Loughborough

PostPosted: Tue Mar 12, 2013 1:29 pm    Post subject: Reply with quote

Thanks Guy...

The next upload will have the grabbing part put into a "function", (already done in fact), and then I will start on the timebase...

I have also tested the simple Linux grabbing part on Debian and it works...
_________________
73...

Bazza, G0LCU...

Team AMIGA...
Back to top
View user's profile Send private message
Bazza
LXF regular


Joined: Sat Mar 21, 2009 11:16 am
Posts: 1477
Location: Loughborough

PostPosted: Wed Mar 13, 2013 9:55 pm    Post subject: Reply with quote

This is a new updated version of the AudioScope with limited scans which can be from single shot storage to pseudo-continuous.

Beware when altering any values as there is NO error detection as yet.

Now starting to create _functions_ as this becomes more mature...

Code:

#!/bin/bash
#
# AudioScopeDisplay.sh

# Change demo value of 0 to 1 to access /dev/dsp for "storage" AudioScope facility, OR, -1 to use SoX...
demo=0
count=0
number=0
char=""
vert=12
horiz=9
graticule=""
# Scan retraces...
scan=1
scanloops=10
# Timebase variables...
subscript=0
# IMPORTANT!!! There is NO error checking yet so be careful with your choice of values...
# scan_start is from 0 to (length of file - 64)...
scan_start=0
# scan_jump is from 1 to (length of file / 64)...
scan_jump=1
# scan_finish is not used yet...
scan_finish=$[ ( $scan_jump * 64 ) ]

# Screen display setup function.
display()
{
   # Set foregound and background graticule colours and foreground and background other window colours.
   printf "\x1B[0;36;44m"
   clear
   graticule="       +-------+-------+-------+---[\x1B[0;37;44mDISPLAY\x1B[0;36;44m]---+-------+-------+--------+       \n"
   graticule=$graticule"       |       |       |       |       +       |       |       |        |       \n"
   graticule=$graticule"       |       |       |       |       +       |       |       |        |       \n"
   graticule=$graticule"       |       |       |       |       +       |       |       |        |       \n"
   graticule=$graticule"       +-------+-------+-------+-------+-------+-------+-------+--------+ <     \n"
   graticule=$graticule"       |       |       |       |       +       |       |       |        |       \n"
   graticule=$graticule"       |       |       |       |       +       |       |       |        |       \n"
   graticule=$graticule"       |       |       |       |       +       |       |       |        |       \n"
   graticule=$graticule"     0 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+--+ <     \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" \x1B[0;37;40m+-----------------------------[COMMAND  WINDOW]------------------------------+\x1B[0;37;44m \n"
   graticule=$graticule" \x1B[0;37;40m| COMMAND:- Running in default DEMO mode...                                  |\x1B[0;37;44m \n"
   graticule=$graticule" \x1B[0;37;40m|                                                                            |\x1B[0;37;44m \n"
   graticule=$graticule" \x1B[0;37;40m+------------------------------[STATUS WINDOW]-------------------------------+\x1B[0;37;44m \n"
   graticule=$graticule" \x1B[0;37;40m|           \$VER: AudioScope.sh_Version_0.00.14_PD_B.Walker_G0LCU.           |\x1B[0;37;44m \n"
   graticule=$graticule" \x1B[0;37;40m+----------------------------------------------------------------------------+\x1B[0;37;44m " 
   printf "$graticule"
   # Set colours for plot.
   printf "\x1B[1;37;44m"
}

# Pick which method to store the waveform.
waveform()
{
   > /tmp/waveform.raw
   chmod 766 /tmp/waveform.raw
   # Demo mode, generate 2000 bytes of random data...
   if [ $demo -eq 0 ]
   then
      char=""
      for count in {0..1999}
      do
         number=$[ ( $RANDOM % ( 256 ) ) ]
         char=`printf '\\\\x'"%02x" $number`
         printf "$char" >> /tmp/waveform.raw
      done
   fi
   # Using the aging(/old) /dev/dsp device, mono, 8 bits per sample and 8KHz sampling rate, 8000 bytes of data...
   if [ $demo -eq 1 ]
   then
      # This uses the oss-compat installation from your distro's repository...
      dd if=/dev/dsp of=/tmp/waveform.raw bs=8000 count=1
   fi
   # The main means of obtaining the data, using SoX, (Sound eXcahnge) from http://sox.sourceforge.net ...
   if [ $demo -eq -1 ]
   then
      # Change the absolute address for your location of "sox"...
      /Users/barrywalker/Downloads/sox-14.4.0/sox -q -V0 -d -t raw -r 48000 -b 8 -c 1 -e unsigned-integer -> /tmp/waveform.raw trim 0 00:01
   fi
}

# Plot the points inside the window...
plot()
{
   subscript=$scan_start
   for horiz in {9..72}
   do
      vert=`hexdump -n1 -s$subscript -v -e '1/1 "%u"' /tmp/waveform.raw`
      vert=$[ ( ( $vert / 16 ) + 2 ) ]
      subscript=$[ ( $subscript + $scan_jump ) ]
      # IMPORTANT! The display must be inverted because of the way a terminal plots its characters...
      vert=$[ ( 19 - $vert ) ]
      printf "\x1B["$vert";"$horiz"f*"
   done
}

# Do an initial screen set up...
display

# This is the main loop...
while true
do
   for scan in $( seq 1 $scanloops )
   do
      waveform
      display
      plot
      # Remember to do all the status reports using the line below as a separate _function_.
      # Temporarily set the cursor outside of the plotting window.
      printf "\x1B[20;46f\x1B[0;37;40m"
   done
   break
done

_________________
73...

Bazza, G0LCU...

Team AMIGA...
Back to top
View user's profile Send private message
Bazza
LXF regular


Joined: Sat Mar 21, 2009 11:16 am
Posts: 1477
Location: Loughborough

PostPosted: Sat Mar 16, 2013 12:36 pm    Post subject: Shell script AudioScope latest update... Reply with quote

Hi guys and gals...

It is now beginning to take shape...

There is now the start of the program's command line stuff...

Commented out is the shell script problem _cured_ for my needs.

IF this part is uncommented and run then a sinewave test signal runs in parallel with the scope and injecting this to the input of the scope and also setting the input and output levels you can see it working...

Next job is a, (within limits), calibrated timebase...

Code:

#!/bin/bash
#
# AudioScope.sh
# At this point I will include and say thank you to "Corona688", a member of http://www.unix.com for his input...

# The lines below, from ">" to "xterm", will generate a new shell script and execute it in a new xterm terminal...
# Just EDIT out the comments and then EDIT the line pointing to the correct </full/path/to/sox/play> to use it.
# It assumes that you have SoX installed. When this script is run it generates a 1KHz sinewave in a separate window
# that lasts for 8 seconds. Just press ENTER when this window is active and it will repeat again. To quit this script
# and close the window just press Ctrl-C. This generator will be needed for the calibration of some timebase ranges.
#> /tmp/1KHz-Test.sh
#chmod 777 /tmp/1KHz-Test.sh
#printf '#!/bin/bash\n' >> /tmp/1KHz-Test.sh
#printf '> /tmp/sinewave.raw\n' >> /tmp/1KHz-Test.sh
#printf 'data="\\\\x80\\\\x26\\\\x00\\\\x26\\\\x7F\\\\xD9\\\\xFF\\\\xD9"\n' >> /tmp/1KHz-Test.sh
#printf 'for waveform in {0..4095}\n' >> /tmp/1KHz-Test.sh
#printf 'do\n' >> /tmp/1KHz-Test.sh
#printf '        printf "$data" >> /tmp/sinewave.raw\n' >> /tmp/1KHz-Test.sh
#printf 'done\n' >> /tmp/1KHz-Test.sh
#printf 'while true\n' >> /tmp/1KHz-Test.sh
#printf 'do\n' >> /tmp/1KHz-Test.sh
#printf '        /full/path/to/sox/play -b 8 -r 8000 -e unsigned-integer /tmp/sinewave.raw\n' >> /tmp/1KHz-Test.sh
#printf '        read -p "Press ENTER to rerun OR Ctrl-C to quit:- " -e kbinput\n' >> /tmp/1KHz-Test.sh
#printf 'done\n' >> /tmp/1KHz-Test.sh
#sleep 1
#xterm -e /tmp/1khz-Test.sh &

# Change demo value of 0 to 1 to access /dev/dsp for "storage" AudioScope facility, OR, 2 to use SoX...
demo=0
hold=1
count=0
number=0
char=""
vert=12
horiz=9
kbinput=""
status=1
graticule="Public Domain, 2013, B.Walker, G0LCU."
# Scan retraces...
scan=1
scanloops=10
# Timebase variables...
subscript=0
# IMPORTANT!!! There is NO error checking yet so be careful with your choice of values...
# scan_start is from 0 to (length of file - 64)...
scan_start=0
# scan_jump is from 1 to (length of file / 64)...
scan_jump=1
# scan_finish is not used yet...
scan_finish=$[ ( $scan_jump * 64 ) ]

# Screen display setup function.
display()
{
   # Set foregound and background graticule colours and foreground and background other window colours.
   printf "\x1B[0;36;44m"
   clear
   graticule="       +-------+-------+-------+---[\x1B[0;37;44mDISPLAY\x1B[0;36;44m]---+-------+-------+--------+       \n"
   graticule=$graticule"       |       |       |       |       +       |       |       |        |       \n"
   graticule=$graticule"       |       |       |       |       +       |       |       |        |       \n"
   graticule=$graticule"       |       |       |       |       +       |       |       |        |       \n"
   graticule=$graticule"       +-------+-------+-------+-------+-------+-------+-------+--------+ <     \n"
   graticule=$graticule"       |       |       |       |       +       |       |       |        |       \n"
   graticule=$graticule"       |       |       |       |       +       |       |       |        |       \n"
   graticule=$graticule"       |       |       |       |       +       |       |       |        |       \n"
   graticule=$graticule"     0 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+--+ <     \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" \x1B[0;37;40m+-----------------------------[COMMAND  WINDOW]------------------------------+\x1B[0;37;44m \n"
   graticule=$graticule" \x1B[0;37;40m| COMMAND:-                                                                  |\x1B[0;37;44m \n"
   graticule=$graticule" \x1B[0;37;40m+------------------------------[STATUS WINDOW]-------------------------------+\x1B[0;37;44m \n"
   graticule=$graticule" \x1B[0;37;40m| Stopped...                                                                 |\x1B[0;37;44m \n"
   graticule=$graticule" \x1B[0;37;40m|           \$VER: AudioScope.sh_Version_0.00.16_PD_B.Walker_G0LCU.           |\x1B[0;37;44m \n"
   graticule=$graticule" \x1B[0;37;40m+----------------------------------------------------------------------------+\x1B[0;37;44m " 
   printf "$graticule"
   # Set colours for plot.
   printf "\x1B[1;37;44m"
}

# Pick which method to store the waveform on the fly.
waveform()
{
   > /tmp/waveform.raw
   chmod 766 /tmp/waveform.raw
   # Demo mode, generate 2000 bytes of random data...
   if [ $demo -eq 0 ]
   then
      char=""
      for count in {0..1999}
      do
         number=$[ ( $RANDOM % ( 256 ) ) ]
         char=`printf '\\\\x'"%02x" $number`
         printf "$char" >> /tmp/waveform.raw
      done
   fi
   # Using the aging(/old) /dev/dsp device, mono, 8 bits per sample and 8KHz sampling rate, 8000 bytes of data...
   if [ $demo -eq 1 ]
   then
      # This uses the oss-compat installation from your distro's repository...
      dd if=/dev/dsp of=/tmp/waveform.raw bs=8000 count=1
   fi
   # The main means of obtaining the data, using SoX, (Sound eXcahnge) from http://sox.sourceforge.net ...
   if [ $demo -eq 2 ]
   then
      # Change the absolute address for your location of "sox"...
      /Users/barrywalker/Downloads/sox-14.4.0/sox -q -V0 -d -t raw -r 48000 -b 8 -c 1 -e unsigned-integer -> /tmp/waveform.raw trim 0 00:01
   fi
}

# Plot the points inside the window...
plot()
{
   subscript=$scan_start
   for horiz in {9..72}
   do
      vert=`hexdump -n1 -s$subscript -v -e '1/1 "%u"' /tmp/waveform.raw`
      vert=$[ ( ( $vert / 16 ) + 2 ) ]
      subscript=$[ ( $subscript + $scan_jump ) ]
      # IMPORTANT! The display must be inverted because of the way a terminal plots its characters...
      vert=$[ ( 19 - $vert ) ]
      printf "\x1B["$vert";"$horiz"f*"
   done
}

# this is the information line _parser_...
statusline()
{
   printf "\x1B[22;3f\x1B[0;37;40m                                                                            \x1B[22;4f"
   if [ $status -eq 0 ]
   then
      printf "Stopped..."
   fi
   if [ $status -eq 1 ]
   then
      printf "Running $scan of $scanloops scans..."
   fi
   if [ $status -eq 2 ]
   then
      printf "Running in single shot storage mode..."
   fi
   # Cursor pointer...
   printf "\x1B[20;14f"
}

# All keyboard commands appear here when the scanning stops; there will be lots of them to make subtle changes...
# NOTE:- Uppercase ASCII text ONLY. This eliminates any numerical typos that can occur. It also means anything
# within reason that is typed which is wrong wil be ignored and not cause an error report...
kbcommands()
{
   status=0
   read -p "Press <CR> to (re)run, HELP or QUIT<CR> " -e kbinput
   if [ "$kbinput" == "" ]
   then
      status=1
   fi
   if [ "$kbinput" == "RUN" ]
   then
      status=1
      hold=1
   fi
   if [ "$kbinput" == "HOLD" ]
   then
      status=2
      hold=0
   fi
   if [ "$kbinput" == "QUIT" ]
   then
      status=255
      break
   fi
   if [ "$kbinput" == "HELP" ]
   then
      status=0
      scanloops=1
      commandhelp
   fi
   if [ "$kbinput" == "DEMO" ]
   then
      status=1
      scanloops=10
      demo=0
   fi
   if [ "$kbinput" == "DSP" ]
   then
      status=1
      scanloops=1
      demo=1
   fi
   if [ "$kbinput" == "SOX" ]
   then
      status=1
      scanloops=1
      demo=2
   fi
   if [ "$kbinput" == "ONE" ]
   then
      status=0
      scanloops=1
   fi
   if [ "$kbinput" == "TEN" ]
   then
      status=0
      scanloops=10
   fi
   if [ "$kbinput" == "HUNDRED" ]
   then
      status=0
      scanloops=100
   fi
}

# Help clears the screen to the startup defaults prints command line help...
commandhelp()
{
   status=2
   hold=0
   printf "\x1B[0m"
   clear
   printf "CURRENT COMMANDS AVAILABLE:-\n\n"
   printf "<CR> ............................................... Reruns the scan(s) again.\n"
   printf "RUN<CR> ........................... Reruns the scan(s) always with real grabs.\n"
   printf "QUIT<CR> .................................................. Quits the program.\n"
   printf "HELP<CR> .............................................. This help as required.\n"
   printf "HOLD<CR> ...................................... Switch to pseudo-storage mode.\n"
   printf "DEMO<CR> ................................ Switch capture to default DEMO mode.\n"
   printf "DSP<CR> ............................... Switch capture to Linux /dev/dsp mode.\n"
   printf "SOX<CR> ................ Switch capture to multi-platform SOund eXchange mode.\n"
   printf "ONE<CR> ....................................... Sets the number of scans to 1.\n"
   printf "TEN<CR> ...................................... Sets the number of scans to 10.\n"
   printf "HUNDRED<CR> ................................. Sets the number of scans to 100.\n"
   printf "\n"
   read -p "Press <CR> to continue:- " -e kbinput
   display
   statusline
   sleep 1
}

# Do an initial screen set up...
display
statusline

# This is the main loop...
while true
do
   if [ $hold -eq 0 ]
   then
      scanloops=1
   fi
   for scan in $( seq 1 $scanloops )
   do
      # hold determines a new scan or retrace of an existing scan...
      if [ $hold -eq 1 ]
      then
         waveform
      fi
      display
      plot
      # Temporarily set the cursor outside of the plotting window.
      printf "\x1B[20;14f\x1B[0;37;40m"
      statusline
   done
   status=0
   statusline
   kbcommands
done

# Getout and cleanup...
if [ $status -eq 255 ]
then
   printf "\x1B[0m"
   clear
   reset
fi
printf "\nProgram terminated...\n\nTerminal reset back to startup defaults...\n\n"

_________________
73...

Bazza, G0LCU...

Team AMIGA...
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Goto page 1, 2, 3, 4  Next
Page 1 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast