Saturday, March 18, 2006

Plot a wav file - wav2png

#!/bin/sh
#usage: wav2png.sh file.wav


BASE=${1%.wav}
PNG=$BASE.png
WAV=$BASE.wav
DAT=$BASE.dat

#echo $BASE,$PNG,$WAV,$DAT
sox $WAV $DAT
grep -v '^;' $DAT >$DAT.clean
FREQ=`head -1 $DAT|tr -d ';'`

echo -e "set terminal png;set title '$FREQ';set output '$PNG'; plot '$DAT.clean'" |gnuplot

6 comments:

  1. Hi Doug. Wondering if you can help us out on a wav2png php project? Feel free to contact me : nrgATtelenetDOTbe

    ReplyDelete
  2. Anonymous7:51 PM

    Thanks. it still works fine under Ben Nanonote.

    ReplyDelete
  3. Anonymous8:01 PM

    works just fine under Ben Nanonote. I will include this file to Ben Nanonote release if you don't mind. thanks

    ReplyDelete
  4. Cool, go for it :)

    ReplyDelete
  5. Hey,

    I'd recommend, that you check out https://github.com/beschulz/wav2png/. It's written in C++ and thus very light on CPU and memory. It builds and runs on Linux and Mac OS X (command line and GUI).

    Hope it will be of use to anyone.

    Cheers
    -- Benjamin

    ReplyDelete
  6. Thanks Benjamin - it works perfect

    Just tested today on a LAMPP install under Ubuntu 14.04

    Compiled and placed the binary file on localhost but it was a bit tricky to get the job done - from exec() we must specify the libpng location at least on Ubuntu - probably you can fix that on your Git leading text by explaining to Ubuntu users > Ubuntu use some exotic locations for some standard LSB libs - to get it work with Ubuntu you must export library path.

    PHP Example:

    $cmd = "export LD_LIBRARY_PATH=/usr/lib/i386-linux-gnu; ./wav2png --foreground-color=ffb400aa --background-color=2e4562ff -o myfile.png myfile.wav"; passthru($cmd);

    therefore to get things done in Ubuntu , you must prefix your script with:

    export LD_LIBRARY_PATH=/usr/lib/i386-linux-gnu;

    other distros use the standard place /usr/lib ..therefore no problem

    -----------

    about speed - wow - very fast

    ReplyDelete