开发者

Can I limit the inNumberFrames passed by iOS in AURenderCallback function?

I created custom audio player class which use AudioUnit and ExtAudioFile. In my class I prepared my own render callback function such like

OSStatus MyAURenderCallack (
   void                        *inRefCon,
   AudioUnitRenderActionFlags  *ioActionFlags,
   const AudioTimeStamp        *inTimeStamp,
   UInt32                      inBusNumber,
   UInt32                      inNumberFrames,
   AudioBufferList             *ioData
);

When my application is foreground, parameter inNumberFrames passed by OS is always 512 or 1024, and my player works well.

But when the iOS device slept, inNumberFrames becomes 4096, and my player doesn't work because it couldn't prepar开发者_JAVA百科e so much frames one time.

It is difficult to improve frame preparing process, because it heavily use extAudioFileRead function, which is hard to accelerate.

So, I want to restrict inNumberFrames from becoming bigger than 1024.

Can I make it?


As @sbooth noted, you should really be writing to disk in another thread. If not, this puts a real stress on your application's main thread, which should be focused on delivering audio without dropouts.

But to directly answer your question: no, you cannot directly tell the OS an exact number of frames to use for the blocksize. You can advise it to use a certain latency, which combined with the requested sample rate will give you a ballpark blocksize. However, there is no guarantee that iOS will give you this blocksize back.

However, your best bet here is to make your algorithm work with arbitrary blocksizes. Unless you are doing something like convolution, it should generally be easier with larger blocksizes. So if you are having trouble at 4096, you should probably profile your code and see what the underlying problem is.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜