mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-17 00:44:19 +00:00
VST2 Hosting: Always ensure that the buffer passed to the plug-in has at least the maximum number of channels that the VST2 plug-in supports
This commit is contained in:
parent
201a85acd7
commit
78c8fcbda1
1 changed files with 55 additions and 12 deletions
|
|
@ -864,7 +864,15 @@ struct VSTPluginInstance : public AudioPluginInstance,
|
|||
dispatch (plugInOpcodeSetSampleFloatType, 0, (pointer_sized_int) vstPrecision, 0, 0);
|
||||
}
|
||||
|
||||
tempBuffer.setSize (jmax (1, vstEffect->numInputChannels), samplesPerBlockExpected);
|
||||
auto maxChannels = jmax (1, jmax (vstEffect->numInputChannels, vstEffect->numOutputChannels));
|
||||
|
||||
tmpBufferFloat .setSize (maxChannels, samplesPerBlockExpected);
|
||||
tmpBufferDouble.setSize (maxChannels, samplesPerBlockExpected);
|
||||
|
||||
channelBufferFloat .calloc (static_cast<size_t> (maxChannels));
|
||||
channelBufferDouble.calloc (static_cast<size_t> (maxChannels));
|
||||
|
||||
outOfPlaceBuffer.setSize (jmax (1, vstEffect->numOutputChannels), samplesPerBlockExpected);
|
||||
|
||||
if (! isPowerOn)
|
||||
setPower (true);
|
||||
|
|
@ -891,7 +899,13 @@ struct VSTPluginInstance : public AudioPluginInstance,
|
|||
setPower (false);
|
||||
}
|
||||
|
||||
tempBuffer.setSize (1, 1);
|
||||
channelBufferFloat.free();
|
||||
tmpBufferFloat.setSize (0, 0);
|
||||
|
||||
channelBufferDouble.free();
|
||||
tmpBufferDouble.setSize (0, 0);
|
||||
|
||||
outOfPlaceBuffer.setSize (1, 1);
|
||||
incomingMidi.clear();
|
||||
|
||||
midiEventsToSend.freeEvents();
|
||||
|
|
@ -909,13 +923,13 @@ struct VSTPluginInstance : public AudioPluginInstance,
|
|||
void processBlock (AudioBuffer<float>& buffer, MidiBuffer& midiMessages) override
|
||||
{
|
||||
jassert (! isUsingDoublePrecision());
|
||||
processAudio (buffer, midiMessages);
|
||||
processAudio (buffer, midiMessages, tmpBufferFloat, channelBufferFloat);
|
||||
}
|
||||
|
||||
void processBlock (AudioBuffer<double>& buffer, MidiBuffer& midiMessages) override
|
||||
{
|
||||
jassert (isUsingDoublePrecision());
|
||||
processAudio (buffer, midiMessages);
|
||||
processAudio (buffer, midiMessages, tmpBufferDouble, channelBufferDouble);
|
||||
}
|
||||
|
||||
bool supportsDoublePrecisionProcessing() const override
|
||||
|
|
@ -1462,12 +1476,19 @@ private:
|
|||
CriticalSection lock;
|
||||
bool wantsMidiMessages = false, initialised = false, isPowerOn = false;
|
||||
mutable StringArray programNames;
|
||||
AudioBuffer<float> tempBuffer;
|
||||
AudioBuffer<float> outOfPlaceBuffer;
|
||||
|
||||
CriticalSection midiInLock;
|
||||
MidiBuffer incomingMidi;
|
||||
VSTMidiEventList midiEventsToSend;
|
||||
VstTimingInformation vstHostTime;
|
||||
|
||||
AudioBuffer<float> tmpBufferFloat;
|
||||
HeapBlock<float*> channelBufferFloat;
|
||||
|
||||
AudioBuffer<double> tmpBufferDouble;
|
||||
HeapBlock<double*> channelBufferDouble;
|
||||
|
||||
static pointer_sized_int handleCanDo (const char* name)
|
||||
{
|
||||
static const char* canDos[] = { "supplyIdle",
|
||||
|
|
@ -1648,9 +1669,12 @@ private:
|
|||
|
||||
//==============================================================================
|
||||
template <typename FloatType>
|
||||
void processAudio (AudioBuffer<FloatType>& buffer, MidiBuffer& midiMessages)
|
||||
void processAudio (AudioBuffer<FloatType>& buffer, MidiBuffer& midiMessages,
|
||||
AudioBuffer<FloatType>& tmpBuffer,
|
||||
HeapBlock<FloatType*>& channelBuffer)
|
||||
{
|
||||
auto numSamples = buffer.getNumSamples();
|
||||
auto numSamples = buffer.getNumSamples();
|
||||
auto numChannels = buffer.getNumChannels();
|
||||
|
||||
if (initialised)
|
||||
{
|
||||
|
|
@ -1729,7 +1753,26 @@ private:
|
|||
|
||||
_clearfp();
|
||||
|
||||
invokeProcessFunction (buffer, numSamples);
|
||||
// always ensure that the buffer is at least as large as the maximum number of channels
|
||||
auto maxChannels = jmax (vstEffect->numInputChannels, vstEffect->numOutputChannels);
|
||||
auto channels = channelBuffer.getData();
|
||||
|
||||
if (numChannels < maxChannels)
|
||||
{
|
||||
if (numSamples > tmpBuffer.getNumSamples())
|
||||
tmpBuffer.setSize (tmpBuffer.getNumChannels(), numSamples);
|
||||
|
||||
tmpBuffer.clear();
|
||||
}
|
||||
|
||||
for (int ch = 0; ch < maxChannels; ++ch)
|
||||
channels[ch] = (ch < numChannels ? buffer.getWritePointer (ch) : tmpBuffer.getWritePointer (ch));
|
||||
|
||||
{
|
||||
AudioBuffer<FloatType> processBuffer (channels, maxChannels, numSamples);
|
||||
|
||||
invokeProcessFunction (processBuffer, numSamples);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1757,14 +1800,14 @@ private:
|
|||
}
|
||||
else
|
||||
{
|
||||
tempBuffer.setSize (vstEffect->numOutputChannels, sampleFrames);
|
||||
tempBuffer.clear();
|
||||
outOfPlaceBuffer.setSize (vstEffect->numOutputChannels, sampleFrames);
|
||||
outOfPlaceBuffer.clear();
|
||||
|
||||
vstEffect->processAudioFunction (vstEffect, buffer.getArrayOfWritePointers(),
|
||||
tempBuffer.getArrayOfWritePointers(), sampleFrames);
|
||||
outOfPlaceBuffer.getArrayOfWritePointers(), sampleFrames);
|
||||
|
||||
for (int i = vstEffect->numOutputChannels; --i >= 0;)
|
||||
buffer.copyFrom (i, 0, tempBuffer.getReadPointer (i), sampleFrames);
|
||||
buffer.copyFrom (i, 0, outOfPlaceBuffer.getReadPointer (i), sampleFrames);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue