1
0
Fork 0

Rename Buffer::with_raw_vec to set_slices

This commit is contained in:
Robbert van der Helm 2023-01-05 15:36:04 +01:00
parent 11d9476a5f
commit 19be530ba3
6 changed files with 24 additions and 24 deletions
src

View file

@ -117,7 +117,7 @@ impl<'a> Buffer<'a> {
/// The stored slices must point to live data when this object is passed to the plugins' process /// The stored slices must point to live data when this object is passed to the plugins' process
/// function. The rest of this object also assumes all channel lengths are equal. Panics will /// function. The rest of this object also assumes all channel lengths are equal. Panics will
/// likely occur if this is not the case. /// likely occur if this is not the case.
pub unsafe fn with_raw_vec(&mut self, update: impl FnOnce(&mut Vec<&'a mut [f32]>)) { pub unsafe fn set_slices(&mut self, update: impl FnOnce(&mut Vec<&'a mut [f32]>)) {
update(&mut self.output_slices); update(&mut self.output_slices);
} }
} }
@ -131,7 +131,7 @@ mod miri {
let mut real_buffers = vec![vec![0.0; 512]; 2]; let mut real_buffers = vec![vec![0.0; 512]; 2];
let mut buffer = Buffer::default(); let mut buffer = Buffer::default();
unsafe { unsafe {
buffer.with_raw_vec(|output_slices| { buffer.set_slices(|output_slices| {
let (first_channel, other_channels) = real_buffers.split_at_mut(1); let (first_channel, other_channels) = real_buffers.split_at_mut(1);
*output_slices = vec![&mut first_channel[0], &mut other_channels[0]]; *output_slices = vec![&mut first_channel[0], &mut other_channels[0]];
}) })
@ -159,7 +159,7 @@ mod miri {
let mut real_buffers = vec![vec![0.0; 512]; 2]; let mut real_buffers = vec![vec![0.0; 512]; 2];
let mut buffer = Buffer::default(); let mut buffer = Buffer::default();
unsafe { unsafe {
buffer.with_raw_vec(|output_slices| { buffer.set_slices(|output_slices| {
let (first_channel, other_channels) = real_buffers.split_at_mut(1); let (first_channel, other_channels) = real_buffers.split_at_mut(1);
*output_slices = vec![&mut first_channel[0], &mut other_channels[0]]; *output_slices = vec![&mut first_channel[0], &mut other_channels[0]];
}) })

View file

@ -1788,7 +1788,7 @@ impl<P: ClapPlugin> Wrapper<P> {
wrapper wrapper
.output_buffer .output_buffer
.borrow_mut() .borrow_mut()
.with_raw_vec(|output_slices| { .set_slices(|output_slices| {
output_slices.resize_with(bus_config.num_output_channels as usize, || &mut []) output_slices.resize_with(bus_config.num_output_channels as usize, || &mut [])
}); });
@ -1812,7 +1812,7 @@ impl<P: ClapPlugin> Wrapper<P> {
Buffer::default, Buffer::default,
); );
for buffer in aux_input_buffers.iter_mut() { for buffer in aux_input_buffers.iter_mut() {
buffer.with_raw_vec(|channel_slices| { buffer.set_slices(|channel_slices| {
channel_slices channel_slices
.resize_with(bus_config.aux_input_busses.num_channels as usize, || { .resize_with(bus_config.aux_input_busses.num_channels as usize, || {
&mut [] &mut []
@ -1827,7 +1827,7 @@ impl<P: ClapPlugin> Wrapper<P> {
Buffer::default, Buffer::default,
); );
for buffer in aux_output_buffers.iter_mut() { for buffer in aux_output_buffers.iter_mut() {
buffer.with_raw_vec(|channel_slices| { buffer.set_slices(|channel_slices| {
channel_slices channel_slices
.resize_with(bus_config.aux_output_busses.num_channels as usize, || { .resize_with(bus_config.aux_output_busses.num_channels as usize, || {
&mut [] &mut []
@ -1989,7 +1989,7 @@ impl<P: ClapPlugin> Wrapper<P> {
// flags? // flags?
let mut output_buffer = wrapper.output_buffer.borrow_mut(); let mut output_buffer = wrapper.output_buffer.borrow_mut();
let mut buffer_is_valid = false; let mut buffer_is_valid = false;
output_buffer.with_raw_vec(|output_slices| { output_buffer.set_slices(|output_slices| {
// Buffers for zero-channel plugins like note effects should always be allowed // Buffers for zero-channel plugins like note effects should always be allowed
buffer_is_valid = output_slices.is_empty(); buffer_is_valid = output_slices.is_empty();
@ -2095,7 +2095,7 @@ impl<P: ClapPlugin> Wrapper<P> {
// If the host passes weird data then we need to be very sure that there are // If the host passes weird data then we need to be very sure that there are
// no dangling references to previous data // no dangling references to previous data
buffer.with_raw_vec(|slices| slices.fill_with(|| &mut [])); buffer.set_slices(|slices| slices.fill_with(|| &mut []));
continue; continue;
} }
@ -2113,7 +2113,7 @@ impl<P: ClapPlugin> Wrapper<P> {
)); ));
} }
buffer.with_raw_vec(|slices| { buffer.set_slices(|slices| {
for (channel_slice, channel_storage) in for (channel_slice, channel_storage) in
slices.iter_mut().zip(storage.iter_mut()) slices.iter_mut().zip(storage.iter_mut())
{ {
@ -2148,12 +2148,12 @@ impl<P: ClapPlugin> Wrapper<P> {
// If the host passes weird data then we need to be very sure that there are // If the host passes weird data then we need to be very sure that there are
// no dangling references to previous data // no dangling references to previous data
buffer.with_raw_vec(|slices| slices.fill_with(|| &mut [])); buffer.set_slices(|slices| slices.fill_with(|| &mut []));
continue; continue;
} }
let block_len = block_end - block_start; let block_len = block_end - block_start;
buffer.with_raw_vec(|slices| { buffer.set_slices(|slices| {
for (channel_idx, channel_slice) in slices.iter_mut().enumerate() { for (channel_idx, channel_slice) in slices.iter_mut().enumerate() {
*channel_slice = std::slice::from_raw_parts_mut( *channel_slice = std::slice::from_raw_parts_mut(
(*(*host_output).data32.add(channel_idx)).add(block_start) (*(*host_output).data32.add(channel_idx)).add(block_start)

View file

@ -325,7 +325,7 @@ impl Cpal {
]; ];
let mut buffer = Buffer::default(); let mut buffer = Buffer::default();
unsafe { unsafe {
buffer.with_raw_vec(|output_slices| { buffer.set_slices(|output_slices| {
// Pre-allocate enough storage, the pointers are set in the data callback because // Pre-allocate enough storage, the pointers are set in the data callback because
// `channels` will have been moved between now and the next callback // `channels` will have been moved between now and the next callback
output_slices.resize_with(channels.len(), || &mut []); output_slices.resize_with(channels.len(), || &mut []);
@ -344,7 +344,7 @@ impl Cpal {
// Things may have been moved in between callbacks, so these pointers need to be set up // Things may have been moved in between callbacks, so these pointers need to be set up
// again on each invocation // again on each invocation
unsafe { unsafe {
buffer.with_raw_vec(|output_slices| { buffer.set_slices(|output_slices| {
for (output_slice, channel) in output_slices.iter_mut().zip(channels.iter_mut()) for (output_slice, channel) in output_slices.iter_mut().zip(channels.iter_mut())
{ {
// SAFETY: `channels` is no longer used directly after this, and it outlives // SAFETY: `channels` is no longer used directly after this, and it outlives

View file

@ -33,7 +33,7 @@ impl Backend for Dummy {
]; ];
let mut buffer = Buffer::default(); let mut buffer = Buffer::default();
unsafe { unsafe {
buffer.with_raw_vec(|output_slices| { buffer.set_slices(|output_slices| {
// SAFETY: `channels` is no longer used directly after this // SAFETY: `channels` is no longer used directly after this
*output_slices = channels *output_slices = channels
.iter_mut() .iter_mut()

View file

@ -40,7 +40,7 @@ impl Backend for Jack {
let mut buffer = Buffer::default(); let mut buffer = Buffer::default();
unsafe { unsafe {
buffer.with_raw_vec(|output_slices| { buffer.set_slices(|output_slices| {
output_slices.resize_with(self.outputs.lock().len(), || &mut []); output_slices.resize_with(self.outputs.lock().len(), || &mut []);
}) })
} }
@ -104,7 +104,7 @@ impl Backend for Jack {
// And the buffer's slices need to point to the JACK output ports // And the buffer's slices need to point to the JACK output ports
unsafe { unsafe {
buffer.with_raw_vec(|output_slices| { buffer.set_slices(|output_slices| {
for (output_slice, output) in output_slices.iter_mut().zip(outputs.iter_mut()) { for (output_slice, output) in output_slices.iter_mut().zip(outputs.iter_mut()) {
// SAFETY: This buffer is only read from after in this callback, and the // SAFETY: This buffer is only read from after in this callback, and the
// reference passed to `cb` cannot outlive that function call // reference passed to `cb` cannot outlive that function call

View file

@ -402,7 +402,7 @@ impl<P: Vst3Plugin> IComponent for Wrapper<P> {
self.inner self.inner
.output_buffer .output_buffer
.borrow_mut() .borrow_mut()
.with_raw_vec(|output_slices| { .set_slices(|output_slices| {
output_slices output_slices
.resize_with(bus_config.num_output_channels as usize, || &mut []) .resize_with(bus_config.num_output_channels as usize, || &mut [])
}); });
@ -429,7 +429,7 @@ impl<P: Vst3Plugin> IComponent for Wrapper<P> {
Buffer::default, Buffer::default,
); );
for buffer in aux_input_buffers.iter_mut() { for buffer in aux_input_buffers.iter_mut() {
buffer.with_raw_vec(|channel_slices| { buffer.set_slices(|channel_slices| {
channel_slices.resize_with( channel_slices.resize_with(
bus_config.aux_input_busses.num_channels as usize, bus_config.aux_input_busses.num_channels as usize,
|| &mut [], || &mut [],
@ -444,7 +444,7 @@ impl<P: Vst3Plugin> IComponent for Wrapper<P> {
Buffer::default, Buffer::default,
); );
for buffer in aux_output_buffers.iter_mut() { for buffer in aux_output_buffers.iter_mut() {
buffer.with_raw_vec(|channel_slices| { buffer.set_slices(|channel_slices| {
channel_slices.resize_with( channel_slices.resize_with(
bus_config.aux_output_busses.num_channels as usize, bus_config.aux_output_busses.num_channels as usize,
|| &mut [], || &mut [],
@ -1324,7 +1324,7 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
// we'll skip the process function. // we'll skip the process function.
let mut output_buffer = self.inner.output_buffer.borrow_mut(); let mut output_buffer = self.inner.output_buffer.borrow_mut();
let mut buffer_is_valid = false; let mut buffer_is_valid = false;
output_buffer.with_raw_vec(|output_slices| { output_buffer.set_slices(|output_slices| {
// Buffers for zero-channel plugins like note effects should always be allowed // Buffers for zero-channel plugins like note effects should always be allowed
buffer_is_valid = output_slices.is_empty(); buffer_is_valid = output_slices.is_empty();
@ -1416,7 +1416,7 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
// If the host passes weird data then we need to be very sure that there are // If the host passes weird data then we need to be very sure that there are
// no dangling references to previous data // no dangling references to previous data
buffer.with_raw_vec(|slices| slices.fill_with(|| &mut [])); buffer.set_slices(|slices| slices.fill_with(|| &mut []));
continue; continue;
} }
@ -1435,7 +1435,7 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
)); ));
} }
buffer.with_raw_vec(|slices| { buffer.set_slices(|slices| {
for (channel_slice, channel_storage) in for (channel_slice, channel_storage) in
slices.iter_mut().zip(storage.iter_mut()) slices.iter_mut().zip(storage.iter_mut())
{ {
@ -1470,12 +1470,12 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
// If the host passes weird data then we need to be very sure that there are // If the host passes weird data then we need to be very sure that there are
// no dangling references to previous data // no dangling references to previous data
buffer.with_raw_vec(|slices| slices.fill_with(|| &mut [])); buffer.set_slices(|slices| slices.fill_with(|| &mut []));
continue; continue;
} }
let block_len = block_end - block_start; let block_len = block_end - block_start;
buffer.with_raw_vec(|slices| { buffer.set_slices(|slices| {
for (channel_idx, channel_slice) in slices.iter_mut().enumerate() { for (channel_idx, channel_slice) in slices.iter_mut().enumerate() {
*channel_slice = std::slice::from_raw_parts_mut( *channel_slice = std::slice::from_raw_parts_mut(
(*(*host_output).buffers.add(channel_idx)).add(block_start) (*(*host_output).buffers.add(channel_idx)).add(block_start)