Implementing a post-processed low-pass filter using core audio

风流意气都作罢 提交于 2019-12-21 21:45:23

问题


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?


回答1:


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.




回答2:


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.




回答3:


I implemented a filter using the interactive filter designer.

Here's some sample code, with it integrated: https://github.com/davidcairns/MediaPlayerDemo



来源:https://stackoverflow.com/questions/4162504/implementing-a-post-processed-low-pass-filter-using-core-audio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!