音频均衡器在Ruby中 [英] Audio Equalizer in Ruby

查看:231
本文介绍了音频均衡器在Ruby中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作的红宝石(当然,打...),试图创建一些有用的音频工具。没有什么活,而不是像MIDI合成或真人过滤器或MP3播放器。我想提出是打开一个.wav文件简单的工具,修改它,并保存它。我有一个好发生器(方波,正弦波,噪声,三角波,锯齿波,等等等等!)。我有与我很舒服的信封过滤器。我有一个很好的颤音(自动包过滤器)。

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.

你知道如何在红宝石(preferably)?实现参数均衡器

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

推荐答案

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

Sounds like a fun project.

您可以通过在样本模糊实施的低通滤波器和高通其他简单的数学(不记得那是什么目前)

You can implement low-pass filters by "blurring" across samples, and high-pass by other simple maths (can't remember what that is at the moment)

不过,如果您正在使用的音频工作,你最终还是会希望信号转换到频域和背部。这样做的最好的开放源码库是FFTW3,并有一个Ruby的宝石 fftw3 绑定 - 它与 narray 如果您洁具尚未使用,你应该考虑无论如何,因为它会在操纵个别样本的1000阵列表现非常好,这

However, if you are working with audio, you will eventually want to convert signals to frequency domain and back. The best open-source library for this is FFTW3, and there is a Ruby binding in the gem fftw3 - it works with narray which if you ware not already using you should consider anyway since it will perform very well on manipulating arrays of 1000s of individual samples.

要开始转换到频域:

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 . . .

抱歉,这并不是一个全功能件code的,但我希望给你足够的指针去发挥!

Sorry this is not a full-featured piece of code, but hopefully gives you enough pointers to go play!

这篇关于音频均衡器在Ruby中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆