2

I am working (well, playing...) in ruby, attempting to create some useful audio tools. Not anything live, not something like a midi synthesizer or live action filters or an mp3 player. What I am making are simple tools that open a .wav file, modify it, and save it. I have good generators (square, sine, noise, triangular, sawtooth, etc... and more!). I have an envelope filter with which I am comfortable. I have a good tremolo (automatic envelope filter).

The closest thing I have to a low-pass, high-pass or parametric equalizer is a tremolo that runs into the audio range... basically turning the frequency up until the tremolo is in the audio frequency range. It's an interesting sound.

Do you know how to implement a parametric equalizer in ruby (preferably)?

4

1 に答える 1

2

楽しいプロジェクトのようですね。

サンプル全体を「ぼかす」ことでローパス フィルターを実装し、他の単純な数学でハイパス フィルターを実装できます (現時点ではそれが何であるか思い出せません)。

ただし、オーディオを扱っている場合は、最終的に信号を周波数ドメインに変換して元に戻す必要があります。これに最適なオープンソース ライブラリは FFTW3 であり、gem に Ruby バインディングがあります。これfftw3で動作しnarrayます。まだ使用していない場合は、何千もの個々のサンプルの配列を操作する際に非常にうまく機能するため、とにかく検討する必要があります。

周波数ドメインへの変換を開始するには:

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 に答える