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.
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.
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.
加载中,请稍侯......
精彩评论