Audio 在gnuplot中绘制音频数据

Audio 在gnuplot中绘制音频数据,audio,gnuplot,Audio,Gnuplot,如何使用gnuplot将音频文件(如aiff)转换为svg?我使用sox(声音交换)将.aiff转换成.dat,现在可以在gnuplot中加载 我做了类似的事情: set terminal svg set output "test.svg" plot "test.dat" 我得到一个svg文件,但只有点/或很多x。 如何连接点?要在点之间绘制线,请使用 plot "test.dat" with lines 或者,要保留点标记和线,请使用 plot "test.dat" with linesp

如何使用gnuplot将音频文件(如aiff)转换为svg?我使用sox(声音交换)将.aiff转换成.dat,现在可以在gnuplot中加载

我做了类似的事情:

set terminal svg
set output "test.svg"
plot "test.dat"
我得到一个svg文件,但只有点/或很多x。
如何连接点?

要在点之间绘制线,请使用

plot "test.dat" with lines
或者,要保留点标记和线,请使用

plot "test.dat" with linespoints
所以你的例子变成了

set terminal svg    
set output "test.svg"
plot "test.dat" with lines
更多提示:

<强>不要考虑每一个样本:< /强>

对于大文件,您可能会发现仅用“每n个”绘制每n个样本很有用。这将使绘图的生成速度大大加快,还将生成更小(但不太详细)的svg文件

e、 g

忽略.dat文件头:

如果您的sox生成的.dat文件包含一些介绍性元数据行,例如

; Sample Rate 44100
; Channels 2

你可以添加下面的GNUTRAP,考虑这些行注释并忽略它们。< /P>

set datafile commentschars ";"
这将使您无需预处理.dat文件,以便在gnuplot阻塞这些行之前删除它们

同时绘制立体声音频的左声道和右声道:

如果使用的是立体声文件,则可能希望同时看到两个频道

我们可以使用“multiplot”在一个共享的x轴上一个接一个地布置以下两个图(左声道和右声道),就像许多声音编辑程序所做的那样

set multiplot layout 2,1
plot "test.dat" using 1:2 with lines
plot ""         using 1:3 with lines
1:2和1:3指示gnuplot将dat文件的哪些列用作x和y源。我假设你的sox生成的stereo.dat文件看起来和我的一样,其中列用于 -1:自第一个样本开始的时间 -2:左通道的标准化采样值 -3:右通道的标准化采样值

示例代码段:

   10.840113       0.20101929      0.17840576 
   10.840136       0.26062012      0.14831543 
   10.840159       0.23779297      0.13146973 
把它放在一起: 下面是一个脚本,它将上述所有内容放在一起。如果您没有立体声数据文件来尝试此操作,则需要删除1:3的打印和多点打印设置

#!/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 with lines
plot ""         using 1:3 every 100 with lines
unset multiplot
美化

最后,我调整了演示文稿的脚本(大量借用了Philipp K.Janert的优秀“gnuplot in action”一书):

下面是一个示例输出(尽管是png):

如何制作.dat文件

对于在家中跟随的任何人,您可以使用sox通过以下命令从音频文件生成.dat文件:

sox input.wav output.dat

大文件警告:在40kHz下仅转换10秒的立体声音频将产生25Mb的输出文件。

注意,您也可以直接绘制二进制数据:

set terminal svg
set output "test.svg"
plot '< sox test.aiff -t s32 -' binary format='%int32' using 0:1 with lines
设置终端svg
设置输出“test.svg”
使用带行的0:1绘制“
我只是想记录这一点——我一直在寻找Linux命令行音频波形查看器,它可以从命令行调用,输入原始二进制文件,并且可以在命令行上指定数据格式

Audacity可以导入原始数据,但只能从GUI导入(无法通过其命令行选项指定原始数据文件格式);而wave查看器喜欢
gwave
gtkwave
,或者可以读取正确的
.wav
,或者基于SPICE的格式

多亏了,现在我知道我可以使用
gnuplot
。下面是一个示例命令行,它将原始二进制数据解释为16位立体声:

gnuplot -p -e "set terminal x11 ; set multiplot layout 2,1 ; plot 0 ls 2, 'data.raw' binary format='%int16%int16' using 0:1 with lines ls 1; plot 0 ls 2, 'data.raw' binary format='%int16%int16' using 0:2 with lines ls 1 ; unset multiplot"
。。。或者分成几行:

gnuplot -p -e "set terminal x11 ; set multiplot layout 2,1 ; \
plot 0 ls 2, 'data.raw' binary format='%int16%int16' using 0:1 with lines ls 1; \
plot 0 ls 2, 'data.raw' binary format='%int16%int16' using 0:2 with lines ls 1; \
unset multiplot"
请注意:

  • 如果要从shell命令输出,则只应使用管道
    “<…”
    ——如果您有文件(如上所述),则不要使用管道(否则将拒绝获得权限)
  • 注意:格式
    “%int16%int16”
    将导致字节流“分组”为2个字节,表示列(通道)1,接下来的2个字节表示列(通道)2,接下来的2个字节再次表示列1,依此类推。。。见(也相关:)
  • 最后,使用两个独立的
    绘图
    ,一个
    使用0:1
    ,另一个
    使用0:2
    ,我们可以得到一个典型的波形渲染(如公认的答案所示)-一个通道高于另一个通道
  • 由于上面使用了
    --persist
    选项,
    gnuplot
    将退出,而(
    x11
    wxt
    )窗口将保持不变,因此,与该窗口的典型
    gnuplot
    交互将不起作用

无论如何,很高兴我发现了这一点,这将节省我不少时间,我想
:)

现在我在创建.svg文件后遇到了一个解析错误。例如,我可以在Safari中读取该文件,但不能在Adobe Illustrator中读取。在Safari中打开文件后,浏览器告诉我发生了“第47列第1857行错误:文档末尾的额外内容”。我刚刚创建了一个postscript eps文件。再次感谢。请注意,当“跳过”样本或在大文件上运行时,大多数视觉显示将采用样本范围的rms和最小/最大值,而不是跳过样本(因为这会造成明显的不一致。)@Neilb有没有办法只获取峰值。我做了
sox input.wav output.dat
。我还有
sox input.wav-n stat-freq
输出。我不知道如何处理这些问题。你的建议对我帮助很大
gnuplot -p -e "set terminal x11 ; set multiplot layout 2,1 ; plot 0 ls 2, 'data.raw' binary format='%int16%int16' using 0:1 with lines ls 1; plot 0 ls 2, 'data.raw' binary format='%int16%int16' using 0:2 with lines ls 1 ; unset multiplot"
gnuplot -p -e "set terminal x11 ; set multiplot layout 2,1 ; \
plot 0 ls 2, 'data.raw' binary format='%int16%int16' using 0:1 with lines ls 1; \
plot 0 ls 2, 'data.raw' binary format='%int16%int16' using 0:2 with lines ls 1; \
unset multiplot"