在Go中的信号处理

huangapple go评论92阅读模式
英文:

Signal Processing in Go

问题

我想到了一个音频项目的想法,Go语言似乎是实现它的有用语言。然而,它需要能够对输入的音频应用滤波器,而Go似乎没有任何音频处理包。我可以使用cgo调用C代码,但我找到的每个信号处理库都使用C++类,而cgo无法处理。看起来libsox可能适用。还有其他的吗?

libsox可以提供什么以及我所需要的是将输入的音频流分成频带。如果我可以在只读取文件一次的情况下完成这个操作,那就太好了!我不确定libsox是否能够做到这一点。

英文:

I have come up with an idea for an audio project and it looks like Go is a useful language for implementing it. However, it requires the ability to apply filters to incoming audio, and Go doesn't appear to have any sort of audio processing package. I can use cgo to call C code, but every signal processing library I find uses C++ classes which cgo cannot handle. It looks like libsox may work. Are there any others?

What libsox can provide and what I need is to take an incoming audio stream and divide it into frequency bands. If I can do this while only reading the file once, then bonus! I am not sure if libsox can do this.

答案1

得分: 2

如果你想使用C++库,你可以尝试使用SWIG,但你需要从Subversion中获取它。下一个发布版本(2.0.1)将是第一个支持Go的版本。根据我的经验,Go的支持还有些不完善,但是我尝试封装的库非常庞大。

另外,你仍然可以通过cgo创建自己的绑定,使用与SWIG相同的方法,但这将是痛苦而乏味的。基本思路是首先创建一个C包装器,然后让cgo创建一个围绕你的C包装器的Go包装器。

不过,我对信号处理或libsox一无所知。抱歉。

英文:

If you want to use a C++ library you could try SWIG, but you'll have to get it out of Subversion. The next release (2.0.1) will be the first released version to support Go. In my experience the Go support is still a little rough, but then again the library I tried to wrap is a monster.

Alternatively, you could still create your own bindings through cgo using the same method SWIG does, but it will be painful and tedious. The basic idea is that you first create a C wrapper, then let cgo create a Go wrapper around your C wrapper.

I don't know anything about signal processing or libsox, though. Sorry.

答案2

得分: 1

有一个相对较新的项目叫做ZikiChombo,目前包含一些针对音频的基本DSP功能,可以在这里查看。

该项目的DSP部分在其路线图中包含了滤波器,但目前还没有实现。另一方面,一些用于实现滤波器的基础设施,如实数FFT和块卷积,已经存在。这意味着如果您想要FIR滤波器,并且可以通过其他方式计算系数,您可以在zc中通过卷积以实时处理声音。

基本滤波器设计支持(FIR,Biquad),例如使用理想滤波器作为起点,将是zc的下一步。有许多小型独立的开源项目用于基本和更高级的FIR和IIR滤波器设计,其中最著名的是Iowa Hills,它可能比一个更大的项目更容易计算Go之外的滤波器系数。

更高级的滤波器,如Butterworth滤波器和基于多项式求解和双线性变换的滤波器,将需要更多时间来实现。

还有一些与滤波相关的软件定义无线电Golang项目,抱歉我没有相关链接,但搜索一下这个主题可能会找到它们。

最后,还有一个gonum的Fourier包,它也提供了FFT功能。

因此,Go在这个领域正在发展一些有趣且潜力巨大的东西,但与较旧的项目相比(这些项目主要使用C/C++,或者通过numpy等Python包装器),还有很长的路要走。

英文:

There is a relatively new project called ZikiChombo
which contains so far some basic DSP functionality geared toward audio, see here

The dsp part of the project has filters on its roadmap, but they are not yet there. On the other hand some infrastructure for implementing filters, such as real fft and block convolution is there. Meaning that if you want FIRs, and can compute the coefficients by some other means, you can run them via convolution in zc currently with sound in real time.

Basic filtering design support (FIR,Biquad), for example using an ideal filter as a starting point will be the next step for zc. There are numerous small self-contained open source projects for basic and more advanced FIR and IIR filter design, most notably Iowa Hills which might be more accessible than a larger project to compute filter coefficients outside of Go.

More advanced filtering such as Butterworth, and filters based on polynomial solving and the bilinear transform will take more time for zc.

There is also some software defined radio Golang projects with some code related to filtering, sorry don't have the links offhand but a search for the topic may lead you to them.

Finally, there is a gonum Fourier package which also supplies fft.

So Go is growing some interesting and potentially stuff in this domain, but still has quite a ways to go compared to older projects (which are mostly in C/C++, or perhaps with a Python wrapper via numpy for example).

答案3

得分: 0

我正在使用这个纯Go语言的仓库来进行傅里叶变换,效果很好。

https://github.com/mjibson/go-dsp

只需将FFT调用提供给以下代码:

import (
    "github.com/mjibson/go-dsp/fft" //  https://github.com/mjibson/go-dsp
)

var audio_wave []float64
// ... 现在用你的音频PCM样本填充audio_wave

var complex_fft []complex128

// 输入时域...输出等间距频率区间的频域
complex_fft = fft.FFTReal(audio_wave)
英文:

I am using this pure golang repo to perform Fourier Transforms with good effect

https://github.com/mjibson/go-dsp

just supply the FFT call with a

import (
    "github.com/mjibson/go-dsp/fft" //  https://github.com/mjibson/go-dsp
)

var audio_wave []float64
// ... now populate audio_wave with your audio PCM samples

var complex_fft []complex128

// input time domain ... output frequency domain of equally spaced freq bins 
complex_fft = fft.FFTReal(audio_wave) 

huangapple
  • 本文由 发表于 2010年8月26日 00:14:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/3567988.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定