我有以下一段音频代码,我认为它可以很好地在加速框架中使用 vDSP。
// --- get pointers for buffer lists
float* left = (float*)audio->mBuffers[0].mData;
float* right = numChans == 2 ? (float*)audio->mBuffers[1].mData : NULL;
float dLeftAccum = 0.0;
float dRightAccum = 0.0;
float fMix = 0.25; // -12dB HR per note
// --- the frame processing loop
for(UInt32 frame=0; frame<inNumberFrames; ++frame)
{
// --- zero out for each trip through loop
dLeftAccum = 0.0;
dRightAccum = 0.0;
float dLeft = 0.0;
float dRight = 0.0;
// --- synthesize and accumulate each note's sample
for(int i=0; i<MAX_VOICES; i++)
{
// --- render
if(m_pVoiceArray[i])
m_pVoiceArray[i]->doVoice(dLeft, dRight);
// --- accumulate and scale
dLeftAccum += fMix*(float)dLeft;
dRightAccum += fMix*(float)dRight;
}
// --- accumulate in output buffers
// --- mono
left[frame] = (float)dLeftAccum;
// --- stereo
if(right) right[frame] = (float)dRightAccum;
}
// needed???
// mAbsoluteSampleFrame += inNumberFrames;
return noErr;
因此我修改它以使用 vDSP,在帧块的末尾乘以 fMix。
// --- the frame processing loop
for(UInt32 frame=0; frame<inNumberFrames; ++frame)
{
// --- zero out for each trip through loop
dLeftAccum = 0.0;
dRightAccum = 0.0;
float dLeft = 0.0;
float dRight = 0.0;
// --- synthesize and accumulate each note's sample
for(int i=0; i<MAX_VOICES; i++)
{
// --- render
if(m_pVoiceArray[i])
m_pVoiceArray[i]->doVoice(dLeft, dRight);
// --- accumulate and scale
dLeftAccum += (float)dLeft;
dRightAccum += (float)dRight;
}
// --- accumulate in output buffers
// --- mono
left[frame] = (float)dLeftAccum;
// --- stereo
if(right) right[frame] = (float)dRightAccum;
}
vDSP_vsmul(left, 1, &fMix, left, 1, inNumberFrames);
vDSP_vsmul(right, 1, &fMix, right, 1, inNumberFrames);
// needed???
// mAbsoluteSampleFrame += inNumberFrames;
return noErr;
但是,我的 CPU 使用率仍然保持不变。我认为在这里使用 vDSP 没有明显的好处。我这样做正确吗?非常感谢。
对矢量操作还是陌生的,对我来说放轻松:)
如果我应该做一些明显的优化(在加速框架之外),请随时向我指出,谢谢!