2

我在 ruby​​ 中工作(嗯,玩......),试图创建一些有用的音频工具。不是现场直播,不是像 midi 合成器或现场动作过滤器或 mp3 播放器之类的东西。我正在制作的是打开一个 .wav 文件、修改它并保存它的简单工具。我有很好的发电机(正方形、正弦、噪声、三角形、锯齿等......等等!)。我有一个我觉得很舒服的包络滤波器。我有一个很好的颤音(自动包络滤波器)。

我最接近低通、高通或参数均衡器的是一个进入音频范围的颤音……基本上把频率调高,直到颤音在音频范围内。这是一个有趣的声音。

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

4

1 回答 1

2

听起来是个有趣的项目。

您可以通过跨样本“模糊”来实现低通滤波器,并通过其他简单的数学来实现高通(现在不记得那是什么了)

但是,如果您正在处理音频,您最终会希望将信号转换为频域并返回。最好的开源库是 FFTW3,并且 gem 中有一个 Ruby 绑定fftw3-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 . . .

抱歉,这不是一段功能齐全的代码,但希望能给你足够的指导去玩!

于 2013-03-20T16:18:48.230 回答