<分区>
我正在尝试弄清楚如何从我从麦克风接收到的特定值中获取移动平均值。我有一个 frequencyChangedWithValue
函数调用我的测量方法。这意味着我在一秒钟内获得了高达 10 次的频率变化值。我现在感兴趣的是如何从所有这些变化的值中得出一个平均数。我该怎么做?
代码
- (void)frequencyChangedWithValue:(float)newFrequency{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
self.currentFrequency = newFrequency;
[self performSelectorInBackground:@selector(filterFrequencyToGetBeats) withObject:nil];
[pool drain];
pool = nil;
}
- (void) filterFrequencyToGetBeats {
if (self.currentFrequency > 1000 && pointInTime % 2 == 0)
{
tm_start = mach_absolute_time();
pointInTime = pointInTime + 1;
}
else
if (self.currentFrequency > 1000 && pointInTime % 2 == 1)
{
pointInTime = pointInTime + 1;
tm_end = mach_absolute_time();
tm_elapsed = tm_end - tm_start;
mach_timebase_info(&info);
tm_nanoSeconds = tm_elapsed * info.numer / info.denom;
tm_milliSeconds = tm_nanoSeconds / (1000000);
tm_seconds = (tm_milliSeconds/1000);
fflush(stdout);
printf ( "| allocateAudio: %5lld milliseconds, (%12lld nano seconds)\n", tm_milliSeconds, tm_nanoSeconds );
}
}