Created
June 27, 2025 10:36
-
-
Save JonnieCache/157bfb26bb220191f0e2e0159f9cf59f to your computer and use it in GitHub Desktop.
nih block => fundsp buffer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn process(&mut self, mut block: Block) { | |
let (left, right, frames) = unsafe { | |
let p_left = block.get_unchecked_mut(0) as *mut [f32]; | |
let p_right = block.get_unchecked_mut(1) as *mut [f32]; | |
assert_ne!( | |
p_left, p_right, | |
"host gave the same buffer for both channels" | |
); | |
// SAFETY: host guarantees 2 non-overlapping channels | |
let frames = (*p_left).len(); | |
let left = &mut *p_left; | |
let right = &mut *p_right; | |
debug_assert_eq!(frames, right.len()); | |
(left, right, frames) | |
}; | |
for chunk_start in (0..frames).step_by(MAX_BLOCK_SIZE) { | |
let chunk_end = Num::min(chunk_start + MAX_BLOCK_SIZE, frames); | |
let chunk_size = chunk_end - chunk_start; | |
{ | |
let mut in_buf = self.buf_in.buffer_mut(); | |
in_buf.channel_f32_mut(0)[..chunk_size] | |
.copy_from_slice(&left[chunk_start..chunk_end]); | |
in_buf.channel_f32_mut(1)[..chunk_size] | |
.copy_from_slice(&right[chunk_start..chunk_end]); | |
} | |
self.graph.process( | |
chunk_size, | |
&self.buf_in.buffer_ref(), | |
&mut self.buf_out.buffer_mut(), | |
); | |
left[chunk_start..chunk_end] | |
.copy_from_slice(&self.buf_out.channel_f32(0)[..chunk_size]); | |
right[chunk_start..chunk_end] | |
.copy_from_slice(&self.buf_out.channel_f32(1)[..chunk_size]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment