A PaStreamCallback is a high-priority function responsible for processing audio data. Because it runs in a real-time context, you must adhere to strict constraints to avoid audio glitches:
- Do NOT allocate memory.
- Do NOT access the file system.
- Do NOT call blocking library functions or any functions with unpredictable execution times.
- Do NOT call any PortAudio API functions from within the callback (except
Pa_GetStreamCpuLoad()).
Callback Signature & Parameters:
input/output: Arrays of interleaved samples, or an array of buffer pointers if paNonInterleaved was requested.frameCount: Number of sample frames to process.timeInfo: Timestamps for ADC capture, DAC output, and callback invocation.statusFlags: Indicates if buffers were inserted or dropped due to underflow/overflow.userData: A user-supplied pointer for synthesis data or state.
Return Values (PaStreamCallbackResult):
paContinue (0): Keep the stream running.paComplete: Finish the stream after all generated buffers are played (useful for soundfile players).paAbort: Finish the stream as soon as possible.
Note: The callback must always fill the entire output buffer regardless of the return value.
pub type PaStreamCallback =
::std::option::Option<unsafe extern "C" fn(
input: *const ::std::os::raw::c_void,
output: *mut ::std::os::raw::c_void,
frameCount: ::std::os::raw::c_ulong,
timeInfo: *const PaStreamCallbackTimeInfo,
statusFlags: PaStreamCallbackFlags,
userData: *mut ::std::os::raw::c_void
) -> ::std::os::raw::c_int>;