Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IOS中的吉他调谐器:Goertzel算法不';6个字符串中的2个不能工作_Ios_Core Audio_Frequency_Goertzel Algorithm - Fatal编程技术网

IOS中的吉他调谐器:Goertzel算法不';6个字符串中的2个不能工作

IOS中的吉他调谐器:Goertzel算法不';6个字符串中的2个不能工作,ios,core-audio,frequency,goertzel-algorithm,Ios,Core Audio,Frequency,Goertzel Algorithm,我试图在IOS 8中实现一个吉他调谐器,我从s.o.那里得到了一些代码。s.o.已经实现了它:它处理Goertzel算法,该算法在短期内比较固定频率的大小-如srings E-a-D-G-B-E所定义的-这里是放置在CoreAudio回调方法中的例程: int currentString(SInt16 *samples, int N) { int note0 = 82; int note1 = 110; int note2 = 147; int note3 = 196; int note4 =

我试图在IOS 8中实现一个吉他调谐器,我从s.o.那里得到了一些代码。s.o.已经实现了它:它处理Goertzel算法,该算法在短期内比较固定频率的大小-如srings E-a-D-G-B-E所定义的-这里是放置在CoreAudio回调方法中的例程:

int currentString(SInt16 *samples, int N) {

int note0 = 82;
int note1 = 110;
int note2 = 147;
int note3 = 196;
int note4 = 247;
int note5 = 330;

int offset = 0.5;


double results[6];
// filter for the six strings
results[0] = (goertzelFilter(samples, note0+offset, N) +goertzelFilter(samples, note0, N) + goertzelFilter(samples, note0-offset, N))/3.0;

results[1] = (goertzelFilter(samples, note1+offset, N) +goertzelFilter(samples, note1, N) + goertzelFilter(samples, note1-offset, N))/3.0;

results[2] = (goertzelFilter(samples, note2+offset, N) +goertzelFilter(samples, note2, N) + goertzelFilter(samples, note2-offset, N))/3.0;

results[3] = (goertzelFilter(samples, note3+offset, N) +goertzelFilter(samples, note3, N) + goertzelFilter(samples, note3-offset, N))/3.0;

results[4] = (goertzelFilter(samples, note4+offset, N) +goertzelFilter(samples, note4, N) + goertzelFilter(samples, note4-offset, N))/3.0;

results[5] = (goertzelFilter(samples, note5+offset, N) +goertzelFilter(samples, note5, NN) + goertzelFilter(samples, note5-offset, N))/3.0;


int maxInd = -1;
double maxVal = 0.0;

for (int i=0; i<6; i++) {
    if (results[i] > maxVal) {

        if (i==0)
            NSLog(@"String %d - value: %f", i+1, results[i]);

        maxVal = results[i];
        maxInd = i;
    }
}

// if all levels are quite low, return -1
if (maxVal < 1) {
    maxInd = -1;
}
return maxInd;
}
int-currentString(SInt16*示例,int-N){
int note0=82;
int note1=110;
int note2=147;
int note3=196;
int note4=247;
int note5=330;
整数偏移=0.5;
双重结果[6];
//筛选六个字符串
结果[0]=(goertzelFilter(样本,note0+偏移量,N)+goertzelFilter(样本,note0,N)+goertzelFilter(样本,note0偏移量,N))/3.0;
结果[1]=(goertzelFilter(样本,注1+偏移量,N)+goertzelFilter(样本,注1,N)+goertzelFilter(样本,注1偏移量,N))/3.0;
结果[2]=(goertzelFilter(样本,note2+偏移量,N)+goertzelFilter(样本,note2,N)+goertzelFilter(样本,note2偏移量,N))/3.0;
结果[3]=(goertzelFilter(样本,注3+偏移量,N)+goertzelFilter(样本,注3,N)+goertzelFilter(样本,注3偏移量,N))/3.0;
结果[4]=(goertzelFilter(样本,注释4+偏移量,N)+goertzelFilter(样本,注释4,N)+goertzelFilter(样本,注释4偏移量,N))/3.0;
结果[5]=(goertzelFilter(样本,注5+偏移量,N)+goertzelFilter(样本,注5,NN)+goertzelFilter(样本,注5偏移量,N))/3.0;
int maxInd=-1;
双maxVal=0.0;
对于(int i=0;i maxVal){
如果(i==0)
NSLog(@“字符串%d-值:%f”,i+1,结果[i]);
maxVal=结果[i];
maxInd=i;
}
}
//如果所有级别都很低,则返回-1
if(maxVal<1){
maxInd=-1;
}
返回maxInd;
}
但是,此类例程仅适用于较低的字符串“D-G-B-E”。 对于E-和D-字符串,我得到了错误的结果,我相信这种行为与泛音有关,因为它们似乎比搜索到的强-可能低“E”的泛音为“A”或“D”,振幅更大

我的问题:s.o.是否遇到过类似的问题?解决了吗?Goertzel是正确的算法,还是FFT或卷积是更好的解决方案

最后这里是我使用的Goertzel算法:

double goertzelFilter(SInt16* samples, double freq, int N) {
double s_prev = 0.0;
double s_prev2 = 0.0;
double coeff,normalizedfreq,power,s;
int i;
normalizedfreq = freq / 44100;
coeff = 2*cos(2*M_PI*normalizedfreq);
for (i=0; i<N; i++) {
    s = samples[i] + coeff * s_prev - s_prev2;
    s_prev2 = s_prev;
    s_prev = s;
}
power = s_prev2*s_prev2+s_prev*s_prev-coeff*s_prev*s_prev2;
return power;
}
double goertzelFilter(SInt16*样本,双频,整数N){
双s_prev=0.0;
双s_prev2=0.0;
双系数,标准化频率,功率,s;
int i;
标准化频率=频率/44100;
系数=2*cos(2*M_PI*normalizedfreq);

对于(i=0;iGoertzel算法测量特定频率下的能量,而不是音高(这是一种不同的心理声学现象).许多弦乐器和声音产生的最强频谱频率可能是泛音或谐波,而不是基音频率,而频谱频率是Goertzel滤波器看到的而不是基音


对于低频弦音,尝试使用基音检测/估计算法(如自相关、ASDF、AMDF、RAPT、YAAPT等),而不是使用Goertzel滤波器(或简单的DFT幅度)来估计基音的存在。

非常感谢,hotpaw2-我已经尝试了AMDF,它工作得非常好!