logo
pub fn process_float(
    ticks: i32,
    input_buffer: &[f32],
    output_buffer: &mut [f32]
)
Expand description

Processes the audio buffer of f32 in place through the loaded pd patch.

The processing order is like the following, input_buffer -> libpd -> output_buffer.

Call this in your audio callback.

Examples

use libpd_rs::process::process_float;
use libpd_rs::block_size;

let output_channels = 2;
// ...
// After initializing audio and opening a patch file then in the audio callback..

// We can imagine that these are the buffers which has been handed to us by the audio callback.
let input_buffer = [0.0_f32; 512];
let mut output_buffer = [0.0_f32; 1024];

let buffer_size = output_buffer.len() as i32;
let pd_ticks: i32 = buffer_size / (block_size() * output_channels);

process_float(pd_ticks, &input_buffer, &mut output_buffer);
// Or if you wish,
// the input buffer can also be an empty slice if you're not going to use any inputs.
process_float(pd_ticks, &[], &mut output_buffer);

Panics

This function may panic for multiple reasons, first of all there is a mutex lock used internally and also it processes buffers in place so there are possibilities of segfaults. Use with care.