1
0
Fork 0

Add an output slices field to Buffer

This commit is contained in:
Robbert van der Helm 2022-03-01 15:00:32 +01:00
parent 6ded3d6f11
commit a58c796fc0
2 changed files with 13 additions and 13 deletions

View file

@ -143,8 +143,8 @@ 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 as_raw_vec(&mut self) -> &mut Vec<&'a mut [f32]> { pub unsafe fn with_raw_vec(&mut self, update: impl FnOnce(&mut Vec<&'a mut [f32]>)) {
&mut self.output_slices update(&mut self.output_slices);
} }
} }
@ -200,11 +200,12 @@ mod miri {
fn repeated_access() { fn repeated_access() {
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 {
let slices = unsafe { buffer.as_raw_vec() }; buffer.with_raw_vec(|output_slices| {
let (first_channel, other_channels) = real_buffers.split_at_mut(1); let (first_channel, other_channels) = real_buffers.split_at_mut(1);
*slices = vec![&mut first_channel[0], &mut other_channels[0]]; *output_slices = vec![&mut first_channel[0], &mut other_channels[0]];
} })
};
for samples in buffer.iter_mut() { for samples in buffer.iter_mut() {
for sample in samples { for sample in samples {

View file

@ -19,7 +19,6 @@ use super::inner::WrapperInner;
use super::util::{VstPtr, BYPASS_PARAM_HASH, BYPASS_PARAM_ID}; use super::util::{VstPtr, BYPASS_PARAM_HASH, BYPASS_PARAM_ID};
use super::view::WrapperView; use super::view::WrapperView;
use crate::param::internals::ParamPtr; use crate::param::internals::ParamPtr;
use crate::param::range::Range;
use crate::param::Param; use crate::param::Param;
use crate::plugin::{BufferConfig, BusConfig, NoteEvent, ProcessStatus, Vst3Plugin}; use crate::plugin::{BufferConfig, BusConfig, NoteEvent, ProcessStatus, Vst3Plugin};
use crate::wrapper::state::{ParamValue, State}; use crate::wrapper::state::{ParamValue, State};
@ -699,8 +698,9 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
self.inner self.inner
.output_buffer .output_buffer
.write() .write()
.as_raw_vec() .with_raw_vec(|output_slices| {
.resize_with(bus_config.num_output_channels as usize, || &mut []); output_slices.resize_with(bus_config.num_output_channels as usize, || &mut [])
});
// Also store this for later, so we can reinitialize the plugin after restoring state // Also store this for later, so we can reinitialize the plugin after restoring state
self.inner.current_buffer_config.store(Some(buffer_config)); self.inner.current_buffer_config.store(Some(buffer_config));
@ -829,8 +829,7 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
// This vector has been reallocated to contain enough slices as there are output // This vector has been reallocated to contain enough slices as there are output
// channels // channels
let mut output_buffer = self.inner.output_buffer.write(); let mut output_buffer = self.inner.output_buffer.write();
{ output_buffer.with_raw_vec(|output_slices| {
let output_slices = output_buffer.as_raw_vec();
nih_debug_assert_eq!(num_output_channels, output_slices.len()); nih_debug_assert_eq!(num_output_channels, output_slices.len());
for (output_channel_idx, output_channel_slice) in for (output_channel_idx, output_channel_slice) in
output_slices.iter_mut().enumerate() output_slices.iter_mut().enumerate()
@ -843,7 +842,7 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
data.num_samples as usize, data.num_samples as usize,
); );
} }
} });
// Most hosts process data in place, in which case we don't need to do any copying // Most hosts process data in place, in which case we don't need to do any copying
// ourselves. If the pointers do not alias, then we'll do the copy here and then the // ourselves. If the pointers do not alias, then we'll do the copy here and then the