【发布时间】:2014-08-05 12:28:42
【问题描述】:
我正在尝试构建一个 iOS 7 应用程序来检测声音/歌曲音高(或频率),对于example: 349.23Hz, 392.00Hz, 440.00Hz......
所以,我下载了“自动关联”项目(这是一个音乐家的 ket http://musicianskit.com/developer.php),我在 iOS 7 模拟器上运行它,它工作正常,“汉宁 fft 窗口”具有价值(不是 NaN),并且终于可以得到频率了。
但是,它在 iPhone 设备上不起作用,它在“汉宁 fft 窗口”中没有任何价值。 谁能看看 Kevin Murphy 的这些类,并告诉我如何修改它们以在 iPhone 设备(而不是 iOS 模拟器)上工作? 非常感谢~
我在下面粘贴了我的代码:
// PitchDetector.m
-(id) initWithSampleRate: (float) rate lowBoundFreq: (int) low hiBoundFreq: (int) hi andDelegate: (id<PitchDetectorDelegate>) initDelegate {
self.lowBoundFrequency = low;
self.hiBoundFrequency = hi;
self.sampleRate = rate;
self.delegate = initDelegate;
bufferLength = self.sampleRate/self.lowBoundFrequency;
hann = (float*) malloc(sizeof(float)*bufferLength);
// applied the Hanning windows, the 'hann' is the Hanning fft Window
vDSP_hann_window(hann, bufferLength, vDSP_HANN_NORM);
sampleBuffer = (SInt16*) malloc(512);
samplesInSampleBuffer = 0;
result = (float*) malloc(sizeof(float)*bufferLength);
return self;
}
-(void) performWithNumFrames: (NSNumber*) numFrames;
{
int n = numFrames.intValue;
float freq = 0;
SInt16 *samples = sampleBuffer;
int returnIndex = 0;
float sum;
bool goingUp = false;
float normalize = 0;
for(int i = 0; i<n; i++) {
sum = 0;
for(int j = 0; j<n; j++) {
//here I found the hann[j] is NaN. seems doesn't have value in hann('hann' is the Hanning fft Window)
//if hann[j] is Not a Number (NaN), the value of sum also to be NaN.
sum += (samples[j]*samples[j+i])*hann[j];
}
if(i ==0 ) normalize = sum;
result[i] = sum/normalize;
}
......
......
}
【问题讨论】:
-
我遇到了类似的问题。尚未查明原因。
标签: ios iphone signal-processing fft accelerate-framework