Add an output slices field to Buffer
This commit is contained in:
parent
6ded3d6f11
commit
a58c796fc0
|
@ -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
|
||||
/// function. The rest of this object also assumes all channel lengths are equal. Panics will
|
||||
/// likely occur if this is not the case.
|
||||
pub unsafe fn as_raw_vec(&mut self) -> &mut Vec<&'a mut [f32]> {
|
||||
&mut self.output_slices
|
||||
pub unsafe fn with_raw_vec(&mut self, update: impl FnOnce(&mut Vec<&'a mut [f32]>)) {
|
||||
update(&mut self.output_slices);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,11 +200,12 @@ mod miri {
|
|||
fn repeated_access() {
|
||||
let mut real_buffers = vec![vec![0.0; 512]; 2];
|
||||
let mut buffer = Buffer::default();
|
||||
{
|
||||
let slices = unsafe { buffer.as_raw_vec() };
|
||||
let (first_channel, other_channels) = real_buffers.split_at_mut(1);
|
||||
*slices = vec![&mut first_channel[0], &mut other_channels[0]];
|
||||
}
|
||||
unsafe {
|
||||
buffer.with_raw_vec(|output_slices| {
|
||||
let (first_channel, other_channels) = real_buffers.split_at_mut(1);
|
||||
*output_slices = vec![&mut first_channel[0], &mut other_channels[0]];
|
||||
})
|
||||
};
|
||||
|
||||
for samples in buffer.iter_mut() {
|
||||
for sample in samples {
|
||||
|
|
|
@ -19,7 +19,6 @@ use super::inner::WrapperInner;
|
|||
use super::util::{VstPtr, BYPASS_PARAM_HASH, BYPASS_PARAM_ID};
|
||||
use super::view::WrapperView;
|
||||
use crate::param::internals::ParamPtr;
|
||||
use crate::param::range::Range;
|
||||
use crate::param::Param;
|
||||
use crate::plugin::{BufferConfig, BusConfig, NoteEvent, ProcessStatus, Vst3Plugin};
|
||||
use crate::wrapper::state::{ParamValue, State};
|
||||
|
@ -699,8 +698,9 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
|
|||
self.inner
|
||||
.output_buffer
|
||||
.write()
|
||||
.as_raw_vec()
|
||||
.resize_with(bus_config.num_output_channels as usize, || &mut []);
|
||||
.with_raw_vec(|output_slices| {
|
||||
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
|
||||
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
|
||||
// channels
|
||||
let mut output_buffer = self.inner.output_buffer.write();
|
||||
{
|
||||
let output_slices = output_buffer.as_raw_vec();
|
||||
output_buffer.with_raw_vec(|output_slices| {
|
||||
nih_debug_assert_eq!(num_output_channels, output_slices.len());
|
||||
for (output_channel_idx, output_channel_slice) in
|
||||
output_slices.iter_mut().enumerate()
|
||||
|
@ -843,7 +842,7 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
|
|||
data.num_samples as usize,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 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
|
||||
|
|
Loading…
Reference in a new issue