IIR 梳状滤波器帮助

发布于 2024-10-19 01:01:56 字数 1684 浏览 1 评论 0原文

Reverb.m

    #define D 1000

        OSStatus MusicPlayerCallback(
        void* inRefCon,
        AudioUnitRenderActionFlags * ioActionFlags, 
        const AudioTimeStamp * inTimeStamp,
        UInt32 inBusNumber,
        UInt32 inNumberFrames
        AudioBufferList * ioData){

MusicPlaybackState *musicPlaybackState = (MusicPlaybackState*) inRefCon;

                //Sample Rate 44.1    
                float a0,a1; 
                double y0, sampleinp;

                    //Delay Gain 
                    a0 = 1; 
                    a1 = 0.5; 

                for (int i = 0; i< ioData->mNumberBuffers; i++){
                AudioBuffer buffer = ioData->mBuffers[i];
                SIn16 *outSampleBuffer = buffer.mData;    
                    for (int j = 0; j < inNumberFrames*2; j++) {  

                            //Delay Left Channel 

                            sampleinp = *musicPlaybackState->samplePtr++; 

                    /* IIR equation of Comb Filter 
                     y[n] = (a*x[n])+ (b*x[n-D]) 
                    */ 

        y0 = (a0*sampleinp) + (a1*sampleinp-D);

                            outSample[j] = fmax(fmin(y0, 32767.0), -32768.0);  


                            j++;            

                    //Delay Right Channel 

        sampleinp = *musicPlaybackState->samplePtr++;

                           y0 = (a0*sampleinp) + (a1*sampleinp-D);

                            outSample[j] = fmax(fmin(y0, 32767.0), -32768.0);  


                        } 
                    } 

                }

好吧,我得到了很多信息,但我在实现它时遇到了困难。有人可以帮忙吗,这可能是我很容易忘记的事情。它只是正常播放,有一点增强,但没有延迟。

Reverb.m

    #define D 1000

        OSStatus MusicPlayerCallback(
        void* inRefCon,
        AudioUnitRenderActionFlags * ioActionFlags, 
        const AudioTimeStamp * inTimeStamp,
        UInt32 inBusNumber,
        UInt32 inNumberFrames
        AudioBufferList * ioData){

MusicPlaybackState *musicPlaybackState = (MusicPlaybackState*) inRefCon;

                //Sample Rate 44.1    
                float a0,a1; 
                double y0, sampleinp;

                    //Delay Gain 
                    a0 = 1; 
                    a1 = 0.5; 

                for (int i = 0; i< ioData->mNumberBuffers; i++){
                AudioBuffer buffer = ioData->mBuffers[i];
                SIn16 *outSampleBuffer = buffer.mData;    
                    for (int j = 0; j < inNumberFrames*2; j++) {  

                            //Delay Left Channel 

                            sampleinp = *musicPlaybackState->samplePtr++; 

                    /* IIR equation of Comb Filter 
                     y[n] = (a*x[n])+ (b*x[n-D]) 
                    */ 

        y0 = (a0*sampleinp) + (a1*sampleinp-D);

                            outSample[j] = fmax(fmin(y0, 32767.0), -32768.0);  


                            j++;            

                    //Delay Right Channel 

        sampleinp = *musicPlaybackState->samplePtr++;

                           y0 = (a0*sampleinp) + (a1*sampleinp-D);

                            outSample[j] = fmax(fmin(y0, 32767.0), -32768.0);  


                        } 
                    } 

                }

Ok, I got a lot of info but I'm having trouble implementing it. Can someone help, it's probably something really easy i'm forgeting. It's just playing back as normal with a little boost but no delays.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故笙诉离歌 2024-10-26 01:01:56

您对 x0[] 变量的处理看起来不正确 - 按照您的方式,左通道和右通道将混合在一起。您分配给左声道的 x0[j],然后
用右通道数据覆盖x0[j]。因此延迟信号x0[jD]
始终对应于右通道,延迟的左通道数据丢失。

您没有说您的采样率是多少,但对于典型的音频应用程序,
三个样本的延迟可能不会产生太大的听觉效果。在 44.1 ksamp/秒时,
使用 3 个样本延迟时,滤波器响应的波峰和波谷将位于
14,700 Hz 的倍数。您将得到的只是音频中的单个峰值
范围,在频谱的一部分,几乎没有任何功率(假设
信号是语音或音乐)。

Your treatment of the x0[] variables doesn't look right -- the way you have it, the left and right channels will be intermingled. You assign to x0[j] for the left channel, then
overwrite x0[j] with the right channel data. So the delayed signal x0[j-D] will
always correspond to the right channel, with the delayed left channel data being lost.

You didn't say what your sample rate is, but for a typical audio application, a
three-sample delay might not have much of an audible effect. At 44.1 ksamp/sec,
with a 3-sample delay the peaks and troughs of the filter response will be at
multiples of 14,700 Hz. All you'll get is a single peak in the audio frequency
range, in a part of the spectrum where there's hardly any power (assuming the
signal is speech or music).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文