使用核心音频实现后处理低通滤波器
我已经使用基于时间的值实现了一个基本的低通滤波器。这没问题,但是尝试找到正确的时间片是猜测工作,并且会根据不同的输入音频文件给出不同的结果。这是我现在所拥有的:
- (void)processDataWithInBuffer:(const int16_t *)buffer outBuffer:(int16_t *)outBuffer sampleCount:(int)len {
BOOL positive;
for(int i = 0; i < len; i++) {
positive = (buffer[i] >= 0);
currentFilteredValueOfSampleAmplitude = LOWPASSFILTERTIMESLICE * (float)abs(buffer[i]) + (1.0 - LOWPASSFILTERTIMESLICE) * previousFilteredValueOfSampleAmplitude;
previousFilteredValueOfSampleAmplitude = currentFilteredValueOfSampleAmplitude;
outBuffer[i] = currentFilteredValueOfSampleAmplitude * (positive ? 1 : -1);
}
}
我可以做什么来将此代码转换为允许我将特定赫兹频率降低特定分贝级别的代码?
I have implemented a rudimentary low-pass filter using a time based value. This is ok, but trying to find the correct time slice is guess work, and gives different results based on different input audio files. Here is what I have now:
- (void)processDataWithInBuffer:(const int16_t *)buffer outBuffer:(int16_t *)outBuffer sampleCount:(int)len {
BOOL positive;
for(int i = 0; i < len; i++) {
positive = (buffer[i] >= 0);
currentFilteredValueOfSampleAmplitude = LOWPASSFILTERTIMESLICE * (float)abs(buffer[i]) + (1.0 - LOWPASSFILTERTIMESLICE) * previousFilteredValueOfSampleAmplitude;
previousFilteredValueOfSampleAmplitude = currentFilteredValueOfSampleAmplitude;
outBuffer[i] = currentFilteredValueOfSampleAmplitude * (positive ? 1 : -1);
}
}
What can I do to convert this code into code that will allow me to cut frequencies over a certain hz by a certain db level?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我强烈推荐c 中的数字食谱。除此之外,我不确定我能帮助你。
当您设计滤波器时,您需要根据频率计算该滤波器的系数,因此您几乎需要一个类来处理它,而不仅仅是一个函数。
这是 C++ 中的内容,但它应该可以帮助您入门。抱歉我无法提供具体答案。
I strongly recommend numerical recipes in c. Outside of that, I'm not sure I can help you.
When you design a filter, you need to calculate the coefficients of that filter based on the frequency so you almost need a class to handle it, not just a function.
This is in C++ but it should get you started. Sorry I can't provide a concrete answer.
您拥有的是 IIR 滤波器,为了获得更多控制,我建议使用 FIR 滤波器,它更容易计算系数。我创建了一个窗口函数:
y = sin (x * width) / (sin (x) * windowWidth)
其中 windowWidth 是窗口宽度的样本数,x 的范围为 -2 * PI为 2 * PI,带宽:
带宽 = 2 * 频率 * n /sampleRate;
这将创建一个数字数组,您可以将其应用于以要输出的样本为中心的一系列样本。您可以对每个样本进行迭代。
我总结了我自己的代码来执行此操作,因为原始代码相当粗糙。
What you have is an IIR filter, and for more control I'd suggest using a FIR filter, which is easier to calculate the coefficients for. I create a window function that is:
y = sin (x * bandwidth) / (sin (x) * windowWidth)
where windowWidth is how many samples wide your window is, x ranges from -2 * PI to 2 * PI, and bandwidth:
bandwidth = 2 * frequency * n / sampleRate;
This creates an array of numbers which you apply to a range of samples centered around the one you want to output. You iterate this over every sample.
I've summarized my own code for doing this, since the original code is rather crufty.
我使用交互式过滤器设计器实现了一个过滤器。
以下是一些示例代码,已集成: https://github.com/davidcairns/MediaPlayerDemo
I implemented a filter using the interactive filter designer.
Here's some sample code, with it integrated: https://github.com/davidcairns/MediaPlayerDemo