PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Shell audio oscilloscope journey
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Shell audio oscilloscope journey

Réponse
 
LinkBack Outils de la discussion
Vieux 19/04/2008, 23h06   #1
BruXy
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Shell audio oscilloscope journey

----------------------------------------------------------------
Written by BruXy http://bruxy.regnet.cz/texty/audioscope.txt
----------------------------------------------------------------

There was an idea at the beginning. It should not be
a problem to made a simple audio oscilloscope in BASH!

For recording can be used sound card also know as /dev/dsp in
the system. You can simply record a 5 second of sound using:

dd if=/dev/dsp of=audio.raw bs=8k count=5

And play it with:

cat audio.raw > /dev/dsp

My next work continued on visualisation using hexdump and
printf. After few minutes the first version was born:

dd if=/dev/dsp bs=1 | hexdump -v -e'1/1 "%u\n"'|(
while read s;do s=$((s/3))rintf "%*c\n" $s x;done)

So take you microphone, copy-paste these two lines to your
console or terminal emulator and watch the waves! You may notice
a small delay, because I/O operation with stdout is not very
fast. I wanted to introduce this invention into the World and I
posted it on IRCNet channel #linux.cz. After an extensive
testing we have made second version:

hexdump -v -e '1/2 "%u\n"'</dev/dsp|(while read
s; do s=$((s>>10)); printf "%*c\n" $s x;done)

Indeed there is still same problem, the x-beam is moving from
top to bottom of terminal. We was talking about the way to
display audio waves horizontally and after few minutes a man
with nickname sd` released his improvement:

clear; hexdump -v -e '1/1 "%u\n"'</dev/dsp|(while read \
s; do c=$(((c+1)%COLUMNS));s=$((s*LINES/255));echo -ne \
"\e[${u[c]};${c}H \e[${s};${c}Hx" ; u[c]=$s ; done )

Turnover of line scan is done using terminal escape sequences.
The meaning of important escape sequences is:

\e[2J is a clear screen command
\e[${s}d move to row ${s}

Look into man console_codes for further details.

I cannot leave this challenge unheard! And there is a fully
graphical version:

while true; do echo -e "P5\n256 512\n255" > o.pgm;i=0; dd \
if=/dev/dsp bs=1024 count=1 | hexdump -v -e '1/2 "%u\n"' |\
(while read s;do s=$((s>>8));if [ $i -ge 512 ];then exit;fi;
printf "%*c" $s z;s=$((256-s))rintf "%*c" $s A;i=$((i+1));
done)>>o.pgm;(display -rotate 90 o.pgm &);sleep 1; killall \
display; done #(c) 2008 BruXy #

And how did you spend your Saturday evening? :-)
  Réponse avec citation
Vieux 20/04/2008, 20h00   #2
Laurianne Gardeux
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Shell audio oscilloscope journey [how did you spend yourSaturday evening?]

Le Sun, 20 Apr 2008 00:06:22 +0200, BruXy a écrit:

> ...
> There was an idea at the beginning. It should not be
> a problem to made a simple audio oscilloscope in BASH!
> ...
> clear; hexdump -v -e '1/1 "%u\n"'</dev/dsp|(while read \
> s; do c=$(((c+1)%COLUMNS));s=$((s*LINES/255));echo -ne \
> "\e[${u[c]};${c}H \e[${s};${c}Hx" ; u[c]=$s ; done )
> ...
> I cannot leave this challenge unheard! And there is a fully
> graphical version:
>
> while true; do echo -e "P5\n256 512\n255" > o.pgm;i=0; dd \
> if=/dev/dsp bs=1024 count=1 | hexdump -v -e '1/2 "%u\n"' |\
> (while read s;do s=$((s>>8));if [ $i -ge 512 ];then exit;fi;
> printf "%*c" $s z;s=$((256-s))rintf "%*c" $s A;i=$((i+1));
> done)>>o.pgm;(display -rotate 90 o.pgm &);sleep 1; killall \
> display; done #(c) 2008 BruXy #


Cool, thanks a lot! Now y can watch my music.

> And how did you spend your Saturday evening? :-)


this way:

----------------------------------------------------------

#!/bin/bash

# show numbers of blocks, bytes, directories and files in a directory
# (c) 2006, 2008 by Laurianne Gardeux, GPL
# usage: $0 path
# bugs: filenames ending with ":" are ignored, ...

if [ $# = 0 ]; then
echo "$(basename $0): enter path!"
exit
fi

mkdir -p $HOME/tmp
TMPFILE=$HOME/tmp/ordnergewicht

ls -lRAsp $1 | grep -v ^$ | grep -v \:$ > $TMPFILE

awk ' \
{ sum1 += $1 } \
{ sum2 += $6 } \
END { print sum1, "blocks", "\n" sum2, "bytes" } \
' < $TMPFILE

echo "$(grep \/$ $TMPFILE | wc -l) directories
$(grep -v \/$ $TMPFILE | grep -v ^'total ' | wc -l) files"

rm $TMPFILE

exit

---------------------------------------------------------
bash on GNU-Linux
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 08h38.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08663 seconds with 10 queries