AVAudioEngineManualRenderingBlock

Type Alias AVAudioEngineManualRenderingBlock 

Source
pub type AVAudioEngineManualRenderingBlock = *mut DynBlock<dyn Fn(AVAudioFrameCount, NonNull<AudioBufferList>, *mut i32) -> AVAudioEngineManualRenderingStatus>;
Available on crate features AVAudioEngine and AVAudioTypes and block2 and objc2-core-audio-types only.
Expand description

Block to render the engine when operating in manual rendering mode

Parameter numberOfFrames: The number of PCM sample frames to be rendered

Parameter outBuffer: The PCM buffer to which the engine must render the audio. The buffer pointers (outBuffer->mBuffers[x].mData) may be null on entry, in which case the block will render into a memory it owns and modify the mData pointers to point to that memory. The block is responsible for preserving the validity of that memory until it is next called to render, or AVAudioEngine(stop) is called.

Parameter outError: On exit, if an error occurs during rendering, a description of the error (see AVAudioEngineManualRenderingError for the possible errors)

Returns: One of the status codes from AVAudioEngineManualRenderingStatus. Irrespective of the returned status code, on exit, the output buffer’s mDataByteSize (outBuffer->mBuffers[x].mDataByteSize) will indicate the number of PCM data bytes rendered by the engine.

Use this if you want to render the engine from a realtime context when it is operating in the manual rendering mode. See AVAudioEngine(manualRenderingBlock) for details.

Note that when using AVAudioEngine manual rendering with AVAudioEngineManualRenderingModeRealtime, calling into the engine or related classes from a non-realtime thread (e.g. for setting or getting node properties), can cause AVAudioEngineManualRenderingBlock on the IO thread to return AVAudioEngineManualRenderingStatusCannotDoInCurrentContext.

This is because interacting with some of these properties requires synchronization between the realtime and calling threads.

In such a case, the client could implement their own synchronization between their realtime and non-realtime threads and retry calling AVAudioEngineManualRenderingBlock.

See also Apple’s documentation