Skip to content

Commit

Permalink
LADSPA: Fix crash with mono to stereo
Browse files Browse the repository at this point in the history
  • Loading branch information
tedfelix committed Mar 26, 2024
1 parent 810a6b3 commit f640f1c
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/sound/LADSPAPluginInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ namespace Rosegarden
{


// Allocate enough for a mono plugin on a stereo track in case we switch
// from mono to stereo.
// Allocate enough for two instances of a mono to stereo plugin. That
// would have 2 ins and 4 outs.
// See setIdealChannelCount().
// ??? Can this be larger than 2? If so we'll need to check
// m_audioPortsIn.size() and m_audioPortsOut.size().
static constexpr size_t maxBuffers = 2ul;
// ??? Is there a situation where we would need more than 4?
static constexpr size_t maxBuffers = 4ul;

LADSPAPluginInstance::LADSPAPluginInstance(
PluginFactory *factory,
Expand Down Expand Up @@ -322,18 +321,29 @@ LADSPAPluginInstance::connectPorts()

size_t inbuf = 0, outbuf = 0;

// For each instance...
for (std::vector<LADSPA_Handle>::iterator hi = m_instanceHandles.begin();
hi != m_instanceHandles.end();
++hi) {

// For each audio in...
for (size_t i = 0; i < m_audioPortsIn.size(); ++i) {
if (inbuf > maxBuffers - 1) {
RG_WARNING << "connectPorts(): Not enough in buffers." << m_instrument << m_position;
break;
}
m_descriptor->connect_port(*hi,
m_audioPortsIn[i],
m_inputBuffers[inbuf]);
++inbuf;
}

// For each audio out...
for (size_t i = 0; i < m_audioPortsOut.size(); ++i) {
if (outbuf > maxBuffers - 1) {
RG_WARNING << "connectPorts(): Not enough out buffers." << m_instrument << m_position;
break;
}
m_descriptor->connect_port(*hi,
m_audioPortsOut[i],
m_outputBuffers[outbuf]);
Expand Down

0 comments on commit f640f1c

Please sign in to comment.