@@ -87,14 +87,26 @@ impl ScratchBuffers {
87
87
self . moves . reserve ( in_out_channels) ;
88
88
}
89
89
90
+ /// Set up buffer pointers for the processor given a VST3 `ProcessData` struct.
91
+ ///
92
+ /// This method is responsible for detecting if any of the buffers for an input bus are aliased
93
+ /// by a output buffer and, if so, copying those inputs to scratch buffers. It is also
94
+ /// responsible for detecting if separate input and output buffers have been passed for an
95
+ /// in-out bus and copying those inputs to the corresponding outputs.
96
+ ///
97
+ /// This method will return `Err` if the channel counts do not match the current layout or if
98
+ /// the buffer's length exceeds the maximum buffer size. It will return `Ok(None)` if the
99
+ /// buffer's length is 0, as hosts are not guaranteed to provide the correct number of inputs
100
+ /// and outputs in that case, and we don't need to construct a `Buffers` object as we will be
101
+ /// calling `Processor::flush` instead of `Processor::process`.
90
102
pub unsafe fn get_buffers (
91
103
& mut self ,
92
104
buses : & [ BusInfo ] ,
93
105
input_bus_map : & [ usize ] ,
94
106
output_bus_map : & [ usize ] ,
95
107
config : & Config ,
96
108
data : & ProcessData ,
97
- ) -> Result < Buffers , ( ) > {
109
+ ) -> Result < Option < Buffers > , ( ) > {
98
110
let len = data. numSamples as usize ;
99
111
if len > config. max_buffer_size {
100
112
return Err ( ( ) ) ;
@@ -103,7 +115,7 @@ impl ScratchBuffers {
103
115
let mut scratch = & mut self . buffers [ ..] ;
104
116
105
117
if len == 0 {
106
- return Ok ( self . get_empty_buffers ( ) ) ;
118
+ return Ok ( None ) ;
107
119
}
108
120
109
121
let input_count = data. numInputs as usize ;
@@ -242,11 +254,8 @@ impl ScratchBuffers {
242
254
243
255
self . output_ptrs . clear ( ) ;
244
256
245
- Ok ( Buffers :: from_raw_parts ( & self . data , & self . ptrs , 0 , len) )
246
- }
247
-
248
- pub fn get_empty_buffers ( & mut self ) -> Buffers {
249
- self . ptrs . fill ( NonNull :: dangling ( ) . as_ptr ( ) ) ;
250
- unsafe { Buffers :: from_raw_parts ( & self . data , & self . ptrs , 0 , 0 ) }
257
+ Ok ( Some ( Buffers :: from_raw_parts (
258
+ & self . data , & self . ptrs , 0 , len,
259
+ ) ) )
251
260
}
252
261
}
0 commit comments