【发布时间】:2011-11-04 16:01:37
【问题描述】:
我在核心音频回调中非常频繁地调用一个函数以将 eq 应用于我的音频样本。在仪器时间曲线中测量的这种方法中,我得到了非常奇怪的性能结果。
我已经完成了 3 次测试。第一个调用该函数并仅返回一个零值。 Instruments 将其报告为 1%。
inline AudioUnitSampleType LowPassProcess (struct EQEffect *obj , AudioUnitSampleType input)
{
return 0;
}
第二个测试实际上是通过访问包含 eq 参数的结构体在函数中进行 EQ 计算。
执行此操作时,仪器将其报告为 *40%* !
struct globaldata
{
float cutoff;
float fs;
float f;
float q;
float scale;
AudioUnitSampleType low;
AudioUnitSampleType high;
AudioUnitSampleType band;
AudioUnitSampleType notch;
};
struct globaldata global;
inline AudioUnitSampleType LowPassProcess (struct EQEffect *obj , AudioUnitSampleType input)
{
global.low= global.low + (global.f * global.band);
global.high= global.scale * input -global.low - global.q * global.band;
global.band = global.f * global.high +global.band;
global.notch = global.high + global.low;
return global.low;
};
最后我尝试再次调用该函数,但在这种情况下没有访问 EQ 结构,但仍然执行相同数量的计算。
执行此操作时,仪器报告为 7 %
struct globaldata
{
float cutoff;
float fs;
float f;
float q;
float scale;
AudioUnitSampleType low;
AudioUnitSampleType high;
AudioUnitSampleType band;
AudioUnitSampleType notch;
};
struct globaldata global;
inline AudioUnitSampleType LowPassProcess (struct EQEffect *obj , AudioUnitSampleType input)
{
float x =10+(50*8);
float y = ((10 *5) -50)- (6*40);
float z=10 *(6+9);
float j=60+0;
return 0;
};
所以我的问题是,为什么当我对结构成员执行计算时,我的函数执行时间要长 5 倍,而当我只对变量执行计算时,执行时间要少得多?
【问题讨论】:
-
您的测试似乎有缺陷。在最后一种情况下,编译器将能够在编译时计算所有四个结果,因此您只需在函数调用中进行 4 次赋值。
标签: c core-audio