how convert audio file such aiff svg using gnuplot? used sox (sound exchange) convert .aiff .dat, can load in gnuplot.
i did similar to:
set terminal svg set output "test.svg" plot "test.dat"
i svg file, dots / or lot of x. how connect dots?
to draw lines between points, use
plot "test.dat" lines
or keep point markers lines, use
plot "test.dat" linespoints
so example becomes
set terminal svg set output "test.svg" plot "test.dat" lines
further tips:
don't consider every sample:
with large files may find useful plot every nth sample "every n". make plot faster generate , yield smaller (but less detailed) svg file.
e.g.
plot "test.dat" every 100 lines
ignore .dat file header:
if sox-produced .dat file has lines of introductory metadata, such as
; sample rate 44100 ; channels 2
you can add following have gnuplot consider lines comments , ignore them.
set datafile commentschars ";"
this save having pre-process .dat file in order remove lines before gnuplot chokes on them.
plot both left , right channels of stereo audio:
if you're working stereo file, want see both channels.
we can use "multiplot" lay out following 2 plots (of left right channel) 1 above other on shared x-axis, many sound-editing programs do.
set multiplot layout 2,1 plot "test.dat" using 1:2 lines plot "" using 1:3 lines
the 1:2 , 1:3 instruct gnuplot columns of dat file use x , y sources. i'm assuming stereo .dat file produced sox looks mine does, columns - 1: time since beginning of first sample - 2: normalized sample value of left channel - 3: normalized sample value of right channel
example snippet:
10.840113 0.20101929 0.17840576 10.840136 0.26062012 0.14831543 10.840159 0.23779297 0.13146973
putting together: here's script puts of above together. if don't have stereo data file try with, you'll want remove plot of 1:3 , multiplot setting.
#!/usr/bin/env gnuplot set datafile commentschars ";" set terminal svg set output "test.svg" set multiplot layout 2,1 plot "test.dat" using 1:2 every 100 lines plot "" using 1:3 every 100 lines unset multiplot
prettification
finally, i've tweaked script presentation (borrowing heavily excellent "gnuplot in action" book philipp k. janert):
#!/usr/bin/env gnuplot set datafile commentschars ";" set terminal svg set output "test.svg" set multiplot layout 2,1 set ylabel "sample value" set bmargin 0 set format x "" set ytics -0.8,0.2 set key bottom plot "test.dat" using 1:2 every 100 lines lc rgbcolor "#a0a0b0" title "left channel" set xlabel "time (s)" set bmargin set tmargin 0 set format x "%g" set ytics -1.0,0.2,0.8 set key top plot "" using 1:3 every 100 lines lc rgbcolor "#a0a0b0" title "right channel" unset multiplot
here's example output (albeit png):
how make .dat file
for following along @ home, can use sox generate .dat file audio file following command:
sox input.wav output.dat
big file warning: converting 10 seconds of stereo audio @ 40khz produce 25mb output file.
Comments
Post a Comment