gpt4 book ai didi

iphone - 峰值滤波器有咔哒声和爆裂声

转载 作者:可可西里 更新时间:2023-11-01 04:28:16 32 4
gpt4 key购买 nike

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


MusicPlaybackState *musicPlaybackState = (MusicPlaybackState*) inRefCon;

double sampleinp;

double A,omega,sn,cs,alpha,Bandwidth;

double dbGain;

double a0,a1,a2,b0,b1,b2;

dbGain = 1.0;

A=pow(10.0,dbGain/40.0);

Bandwidth = 2.0;

omega=2 * M_PI * 800.0/44100.0;

sn=sin(omega);

cs=cos(omega);

alpha=sn*sinh(((M_LN2/2)*Bandwidth*omega)/sn);


//Peak Filter Biquad

b0 =1.0 + alpha * A;

b1 = (-2.0 * cs);

b2 = 1.0 - alpha * A;

a0 = 1.0 + (alpha /A);

a1 = -2.0 * cs;

a2 = 1.0 - (alpha /A);



double b0a0, b1a0, b2a0, a1a0, a2a0;

double static x1;

double static x2;

double static y1;

double static y2;


b0a0=b0/a0;

b1a0=b1/a0;

b2a0=b2/a0;

a1a0=a1/a0;

a2a0=a2/a0;


for (int i = 0 ; i < ioData->mNumberBuffers; i++){


AudioBuffer buffer = ioData->mBuffers[i];
AudioSampleType *outSample = buffer.mData;

for (int j = 0; j < inNumberFrames*2; j++){

sampleinp = *musicPlaybackState->samplePtr++;

outSample[j] = b0a0 * sampleinp +
b1a0 * x1 +
b2a0 * x2 -
a1a0 * y1 -
a2a0 * y2;


x2=x1;
x1=sampleinp;

y2=y1;
y1=outSample[j];

}}





return noErr;
}

有点击/弹出问题。有人请帮助......我不知道我做错了什么。这是在 Xcode 中使用 Objective-C 中的 C。我尝试制作 Coeff Global 和 Static 但没有成功。使用的音频文件是 .caf 我试过 .wav 但还是不行....

谢谢,对于普遍的求救声感到抱歉。我是这个网站的新手。我想在我的应用程序中添加一个峰值过滤器,但每次我使用 slider 或将增益保持在 1 时,我都会听到爆裂声和咔哒声。似乎一切都在那里,并且就保持以前的样本等而言正常工作。当改变频率或带宽时,我也会得到某种类型的相位。几个月来我一直在研究 dsp,我很困惑,我认为这是 Objective-C 的问题和一个小的用户错误。将样本更改为 SInt32 时它似乎消失了,但在更改频率时左声道消失了。

Dsp.h

typedef struct { 

void* audioData;

UInt32 audioDataByteCount;

SInt16 *samplePtr;

} MusicPlaybackState;

最佳答案

根据 hotpaw2 的回答,这是您的过滤器响应的图表:

from pylab import *
import scipy.signal as signal

def biquad_peak(omega, gain_db, bandwidth):
sn = sin(omega)
cs = cos(omega)
alpha = sn * sinh(log(2) / 2 * bandwidth * omega / sn)
gain_sqrt = 10.0 ** (gain_db / 40.0)

# feed-forward coefficients
b0 = 1.0 + alpha * gain_sqrt
b1 = -2.0 * cs
b2 = 1.0 - alpha * gain_sqrt
# feedback coefficients
a0 = 1.0 + (alpha / gain_sqrt)
a1 = -2.0 * cs
a2 = 1.0 - (alpha / gain_sqrt)
# normalize by a0
B = array([b0, b1, b2]) / a0
A = array([a0, a1, a2]) / a0
return B, A

omega = 2 * pi * 800.0 / 44100.0
gain_db = 1.0
bandwidth = 2.0

B, A = biquad_peak(omega, gain_db, bandwidth)
w, H = signal.freqz(B, A)
f = w / pi * 22050.0
plot(f, abs(H), 'r')
gain = 10.0 ** (gain_db / 20.0)
print "Gain:", gain
plot(f, gain*ones(len(f)), 'b--'); grid()

biquad peak filter response

峰值增益设置为 1.1220184543(即 1 dB)。您可以看到滤波器如何使大部分可听范围的增益大于 1。

编辑 2:如果这是用于可调 EQ,则由用户设置避免失真的增益。另外,我怀疑您描述的极端问题是由典型音轨在窄带上 1 dB 的轻微增益引起的。我认为这是因为您的音频具有交错的立体声数据。这些 channel 中的每一个都需要单独过滤。我已经尝试修改您的嵌套循环来完成此任务:

a0 = 1.0 + alpha / A; 
a1 = -2.0 * cs / a0;
a2 = (1.0 - alpha / A) / a0;
b0 = (1.0 + alpha * A) / a0;
b1 = -2.0 * cs / a0;
b2 = (1.0 - alpha * A) / a0;

double static x11, x12, x21, x22;
double static y11, y12, y21, y22;
double x0, y0;

for (int i = 0; i < ioData->mNumberBuffers; i++) {

AudioBuffer buffer = ioData->mBuffers[i];
AudioSampleType *outSample = buffer.mData;

for (int j = 0; j < inNumberFrames*2; j++) {

/* x0 is in the range of SInt16: -32768 to 32767 */

x0 = *musicPlaybackState->samplePtr++;

y0 = b0 * x0 +
b1 * x11 +
b2 * x12 -
a1 * y11 -
a2 * y12;

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

x12 = x11;
x11 = x0;
y12 = y11;
y11 = y0
j++;

x0 = *musicPlaybackState->samplePtr++;

y0 = b0 * x0 +
b1 * x21 +
b2 * x22 -
a1 * y21 -
a2 * y22;

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

x22 = x21;
x21 = x0;
y22 = y21;
y21 = y0;
}
}

关于iphone - 峰值滤波器有咔哒声和爆裂声,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4840492/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com