我正在用 ruby 工作(很好,正在玩...),试图创建一些有用的音频工具。没有任何直播,没有像Midi合成器或现场 Action 过滤器或mp3播放器之类的东西。我正在做的是打开.wav文件,对其进行修改并保存的简单工具。我有很好的发电机(正方形,正弦波,噪声,三角形,锯齿形,等等!)。我有一个舒适的信封过滤器。我有一个好的颤音(自动包络滤波器)。
我最接近低通,高通或参数均衡器的是一个颤音,它进入了音频范围……基本上将频率调高,直到颤音在音频范围内。这是一种有趣的声音。
您知道如何在 ruby 中实现参数均衡器吗?
最佳答案
听起来像是一个有趣的项目。
您可以通过对样本进行“模糊处理”来实现低通滤波器,而可以通过其他简单的数学运算来实现高通(不记得目前的含义)
但是,如果您使用的是音频,则最终将需要将信号转换到频域并返回。最好的开源库是FFTW3,gem fftw3
中有一个Ruby绑定(bind)-它可与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 . . .
抱歉,这不是功能齐全的代码,但希望能为您提供足够的指针来玩!