Skip to content

Instantly share code, notes, and snippets.

@s-leroux
Last active April 12, 2018 10:59
Show Gist options
  • Save s-leroux/84766d3063ef3642c2904e0bf772b7b9 to your computer and use it in GitHub Desktop.
Save s-leroux/84766d3063ef3642c2904e0bf772b7b9 to your computer and use it in GitHub Desktop.
A crude script to obtain a graphical representation of a stereo sound waveform.
#!/bin/bash
INFILE="$1"
OUTFILE="$2"
DATFILE="${INFILE}.dat"
SVGFILE="${INFILE}.svg"
sox "${INFILE}" "${DATFILE}"
gnuplot << EOF
# set terminal pngcairo size 750,400 enhanced font 'Verdana,10'
# set output "${OUTFILE}"
set terminal svg size 750,600 fname 'Verdana, Helvetica, Arial, sans-serif' fsize '12'
set output "${SVGFILE}"
set border linewidth 1.5
set tics nomirror out
set style line 11 lc rgb '#808080' lt 1 lw 2
set style line 12 lc rgb '#808080' lt 1 lw 1 dt "."
set xzeroaxis ls 12
set border 3 back ls 11
set nokey
set style line 1 lc rgb '#000000' lt 1 lw 2 ps 1.5
set style line 2 lc rgb '#ad0000' lt 1 lw 2 ps 1.5
set yrange [-1:+1]
set multiplot layout 3,1 rowsfirst
set xlabel "left channel"
plot "${DATFILE}" using 1:2 title "left channel" with lines ls 1
set xlabel "right channel"
plot "${DATFILE}" using 1:3 title "right channel" with lines ls 2
set xlabel "left-right"
plot "${DATFILE}" using 1:(\$2-\$3) title "left-right" with lines ls 2
unset multiplot
EOF
inkscape --export-png="${OUTFILE}" --export-background=white "${SVGFILE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment