Ruby中的音频均衡器

时间:2013-03-20 15:46:20

标签: ruby audio filter wav equalizer

我在红宝石中工作(好吧,玩......),尝试创建一些有用的音频工具。没有任何东西,不像midi合成器或真人动作过滤器或MP3播放器。我正在制作的是打开.wav文件,修改它并保存它的简单工具。我有很好的发电机(方形,正弦,噪音,三角形,锯齿形......等等!)。我有一个信封过滤器,我很舒服。我有一个很好的颤音(自动信封滤波器)。

我对低通,高通或参数均衡器最接近的是颤音,它在音频范围内运行...基本上将频率调高,直到颤音处于音频频率范围内。这是一个有趣的声音。

你知道如何在ruby(最好)中实现参数均衡器吗?

1 个答案:

答案 0 :(得分:2)

听起来像一个有趣的项目。

您可以通过跨样本“模糊”实现低通滤波器,并通过其他简单的数学实现高通(不记得此刻的内容)

但是,如果您正在处理音频,最终您希望将信号转换为频域并返回。最好的开源库是FFTW3,并且gem fftw3中有一个Ruby绑定 - 它与narray一起使用,如果你还没有使用它,你应该考虑,因为它会表现得很好很好地操纵1000个单个样本的数组。

开始转换到频域:

require 'narray'
require 'fftw3'


# You'll need to feed in real-world data in audio_segment 
# This generates white noise -1.0 to 1.0
audio_segment = 2.0 * ( NArray.float(1024).random() - 0.5 )

# To avoid edges of the window looking like high-frequency changes, 
# you need to apply a window function. This is just a multiplier for  each sampel point
# Look up Hann window on Wikipedia, the maths is very simple.
# hann_window is a simple 1024 NArray of floats, and you can re-use the same one each time 
audio_window = audio_segment * hann_window

# This does FFT magic
frequency_domain_window = FFTW3.fft(audio_window, -1)

# What you do next depends on the processing you need to do. Typically you'll want to
# re-normalise the data (as FFTW doesn't do that for you)
frequency_domain_window *= 1.0/1024

# This is a very crude "notch filter" that reduces amplitude of some mid frequencies
frequency_domain_window[100..200] *= 0.3

#  Convert back to samples in time (but we still are in a Hann window)
processed_audio_window = (FFTW3.ifft( frequency_domain_window, 0 )).real


# Next you need to do an inverse of the Hann window


# After then you'll want to step forward say 256 samples, and repeat the process
# whilst averaging windows together where they overlap . . .

对不起,这不是一个功能齐全的代码片段,但希望能给你足够的指示去玩!