确定哪些频率对应于aurioTouch示例应用程序x轴 [英] Determining what frequencies correspond to the x axis in aurioTouch sample application
问题描述
我在看 aurioTouch样本应用的iPhone SDK。它有当您选择FFT选项实施了基本频谱分析仪。其中一个应用缺少的东西是X轴标签(即频率标签)。
I'm looking at the aurioTouch sample application for the iPhone SDK. It has a basic spectrum analyzer implemented when you choose the "FFT" option. One of the things the app is lacking is X axis labels (i.e. the frequency labels).
在<一个href=\"https://developer.apple.com/iphone/library/sample$c$c/aurioTouch/Listings/Classes_aurioTouchAppDelegate_mm.html#//apple_ref/doc/uid/DTS40007770-Classes_aurioTouchAppDelegate_mm-DontLinkElementID_6\"相对=nofollow> aurioTouchAppDelegate.mm 文件中,在函数 - (无效)drawOscilloscope
在行652,它具有以下code:
In the aurioTouchAppDelegate.mm file, in the function - (void)drawOscilloscope
at line 652, it has the following code:
if (displayMode == aurioTouchDisplayModeOscilloscopeFFT)
{
if (fftBufferManager->HasNewAudioData())
{
if (fftBufferManager->ComputeFFT(l_fftData))
[self setFFTData:l_fftData length:fftBufferManager->GetNumberFrames() / 2];
else
hasNewFFTData = NO;
}
if (hasNewFFTData)
{
int y, maxY;
maxY = drawBufferLen;
for (y=0; y<maxY; y++)
{
CGFloat yFract = (CGFloat)y / (CGFloat)(maxY - 1);
CGFloat fftIdx = yFract * ((CGFloat)fftLength);
double fftIdx_i, fftIdx_f;
fftIdx_f = modf(fftIdx, &fftIdx_i);
SInt8 fft_l, fft_r;
CGFloat fft_l_fl, fft_r_fl;
CGFloat interpVal;
fft_l = (fftData[(int)fftIdx_i] & 0xFF000000) >> 24;
fft_r = (fftData[(int)fftIdx_i + 1] & 0xFF000000) >> 24;
fft_l_fl = (CGFloat)(fft_l + 80) / 64.;
fft_r_fl = (CGFloat)(fft_r + 80) / 64.;
interpVal = fft_l_fl * (1. - fftIdx_f) + fft_r_fl * fftIdx_f;
interpVal = CLAMP(0., interpVal, 1.);
drawBuffers[0][y] = (interpVal * 120);
}
cycleOscilloscopeLines();
}
}
从我的理解中,code,这部分是用来决定绘制在UI的每个频率,幅度。我的问题是我怎么能确定哪些频率每次迭代(或是
值)内重presents的为
循环。
From my understanding, this part of the code is what is used to decide which magnitude to draw for each frequency in the UI. My question is how can I determine what frequency each iteration (or y
value) represents inside the for
loop.
例如,如果我想知道的幅度是什么6kHz的,我想加入类似下面的一行:
For example, if I want to know what the magnitude is for 6kHz, I'm thinking of adding a line similar to the following:
if (yValueRepresentskHz(y, 6))
NSLog(@"The magnitude for 6kHz is %f", (interpVal * 120));
的请注意,尽管他们选择使用的变量名称是
,从我的理解,它实际上重新presents x轴的频谱分析仪的可视化图形,而 drawBuffers值[0] [Y]
重新presents y轴。的
Please note that although they chose to use the variable name y
, from what I understand, it actually represents the x-axis in the visual graph of the spectrum analyzer, and the value of the drawBuffers[0][y]
represents the y-axis.
推荐答案
我相信,它使用每个仓的频率由
I believe that the frequency of each bin it is using is given by
yFract * hwSampleRate * .5
我相当肯定,你需要.5因为yFract是总fftLength的一小部分和FFT的最后一仓与采样率的一半相对应。因此,你可以不喜欢
I'm fairly certain that you need the .5 because yFract is a fraction of the total fftLength and the last bin of the FFT corresponds with half of the sampling rate. Thus, you could do something like
NSLog(@"The magnitude for %f Hz is %f.", (yFract * hwSampleRate * .5), (interpVal * 120));
希望这有助于至少你指出正确的方向。
Hopefully that helps to point you in the right direction at least.
这篇关于确定哪些频率对应于aurioTouch示例应用程序x轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!