@@ -96,14 +96,20 @@ void PluginProcessor::prepareToPlay(const double sample_rate, const int samples_
9696 static_cast <juce::uint32>(samples_per_block),
9797 2
9898 };
99- float_buffer_.setSize (4 , samples_per_block);
100- float_buffer_.clear ();
101- float_side_pointers_[0 ] = float_buffer_.getWritePointer (2 );
102- float_side_pointers_[1 ] = float_buffer_.getWritePointer (3 );
103- double_buffer_.setSize (2 , samples_per_block);
104- double_side_pointers_[0 ] = double_buffer_.getWritePointer (0 );
105- double_side_pointers_[1 ] = double_buffer_.getWritePointer (1 );
106- double_buffer_.clear ();
99+ const auto buffer_size = static_cast <size_t >(samples_per_block);
100+
101+ float_buffer_[0 ].resize (buffer_size);
102+ float_buffer_[1 ].resize (buffer_size);
103+ float_buffer_[2 ].resize (buffer_size);
104+ float_buffer_[3 ].resize (buffer_size);
105+ float_side_pointers_[0 ] = float_buffer_[2 ].data ();
106+ float_side_pointers_[1 ] = float_buffer_[3 ].data ();
107+
108+ double_buffer_[0 ].resize (buffer_size);
109+ double_buffer_[1 ].resize (buffer_size);
110+ double_side_pointers_[0 ] = double_buffer_[0 ].data ();
111+ double_side_pointers_[1 ] = double_buffer_[1 ].data ();
112+
107113 compressor_controller_.prepare (spec);
108114 // determine current channel layout
109115 const auto *main_bus = getBus (true , 0 );
@@ -154,13 +160,14 @@ bool PluginProcessor::isBusesLayoutSupported(const BusesLayout &layouts) const {
154160
155161void PluginProcessor::processBlock (juce::AudioBuffer<float > &buffer, juce::MidiBuffer &) {
156162 juce::ScopedNoDenormals no_denormals;
157- if (buffer.getNumSamples () == 0 ) return ; // ignore empty blocks
163+ if (buffer.getNumSamples () == 0 ) { return ; } // ignore empty blocks
158164 const auto c_use_ext_side = use_ext_side_.load (std::memory_order::relaxed);
159165 const auto buffer_size = static_cast <size_t >(buffer.getNumSamples ());
160166 switch (channel_layout_) {
161167 case ChannelLayout::kMain1Aux0 : {
168+ if (buffer.getNumChannels () < 1 ) { return ; }
162169 main_pointers_[0 ] = buffer.getWritePointer (0 );
163- main_pointers_[1 ] = float_buffer_. getWritePointer ( 1 );
170+ main_pointers_[1 ] = float_buffer_[ 1 ]. data ( );
164171 zldsp::vector::copy (main_pointers_[1 ], main_pointers_[0 ], buffer_size);
165172
166173 zldsp::vector::copy<double , float >(double_side_pointers_, main_pointers_, buffer_size);
@@ -171,8 +178,9 @@ void PluginProcessor::processBlock(juce::AudioBuffer<float> &buffer, juce::MidiB
171178 break ;
172179 }
173180 case ChannelLayout::kMain1Aux1 : {
181+ if (buffer.getNumChannels () < 2 ) { return ; }
174182 main_pointers_[0 ] = buffer.getWritePointer (0 );
175- main_pointers_[1 ] = float_buffer_. getWritePointer ( 1 );
183+ main_pointers_[1 ] = float_buffer_[ 1 ]. data ( );
176184 zldsp::vector::copy (main_pointers_[1 ], main_pointers_[0 ], buffer_size);
177185
178186 if (c_use_ext_side) {
@@ -188,8 +196,9 @@ void PluginProcessor::processBlock(juce::AudioBuffer<float> &buffer, juce::MidiB
188196 break ;
189197 }
190198 case ChannelLayout::kMain1Aux2 : {
199+ if (buffer.getNumChannels () < 3 ) { return ; }
191200 main_pointers_[0 ] = buffer.getWritePointer (0 );
192- main_pointers_[1 ] = float_buffer_. getWritePointer ( 1 );
201+ main_pointers_[1 ] = float_buffer_[ 1 ]. data ( );
193202 zldsp::vector::copy (main_pointers_[1 ], main_pointers_[0 ], buffer_size);
194203
195204 if (c_use_ext_side) {
@@ -205,6 +214,7 @@ void PluginProcessor::processBlock(juce::AudioBuffer<float> &buffer, juce::MidiB
205214 break ;
206215 }
207216 case ChannelLayout::kMain2Aux0 : {
217+ if (buffer.getNumChannels () < 2 ) { return ; }
208218 main_pointers_[0 ] = buffer.getWritePointer (0 );
209219 main_pointers_[1 ] = buffer.getWritePointer (1 );
210220
@@ -216,6 +226,7 @@ void PluginProcessor::processBlock(juce::AudioBuffer<float> &buffer, juce::MidiB
216226 break ;
217227 }
218228 case ChannelLayout::kMain2Aux1 : {
229+ if (buffer.getNumChannels () < 3 ) { return ; }
219230 main_pointers_[0 ] = buffer.getWritePointer (0 );
220231 main_pointers_[1 ] = buffer.getWritePointer (1 );
221232
@@ -232,6 +243,7 @@ void PluginProcessor::processBlock(juce::AudioBuffer<float> &buffer, juce::MidiB
232243 break ;
233244 }
234245 case ChannelLayout::kMain2Aux2 : {
246+ if (buffer.getNumChannels () < 4 ) { return ; }
235247 main_pointers_[0 ] = buffer.getWritePointer (0 );
236248 main_pointers_[1 ] = buffer.getWritePointer (1 );
237249
0 commit comments