Skip to content

Commit 3111eda

Browse files
committed
Fix audio monitor indexing issue when toggling while acquisition is active
1 parent c65db66 commit 3111eda

3 files changed

Lines changed: 30 additions & 6 deletions

File tree

Source/Processors/AudioNode/AudioNode.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,16 @@ void AudioNode::updateBufferSize()
7575
void AudioNode::setChannel(const DataChannel* ch)
7676
{
7777

78-
int channelNum = getDataChannelIndex(ch->getSourceIndex(), ch->getSourceNodeID(), ch->getSubProcessorIdx());
78+
int channelNum;
79+
80+
try
81+
{
82+
channelNum = audioDataChannelMap.at(ch->getCurrentNodeID()).at(ch->getCurrentNodeChannelIdx());
83+
}
84+
catch (...)
85+
{
86+
channelNum = -1;
87+
}
7988

8089
std::cout << "Audio node setting channel to " << channelNum << std::endl;
8190

@@ -249,7 +258,7 @@ void AudioNode::process(AudioSampleBuffer& buffer)
249258

250259
for (int i = 0; i < buffer.getNumChannels()-2; i++) // cycle through them all
251260
{
252-
261+
253262
if (dataChannelArray[i]->isMonitored())
254263
{
255264
tempBuffer->clear();
@@ -476,6 +485,14 @@ void AudioNode::updateRecordChannelIndexes()
476485
{
477486
//Keep the nodeIDs of the original processor from each channel comes from
478487
updateChannelIndexes(false);
488+
//and update the internal map
489+
audioDataChannelMap.clear();
490+
unsigned int nChans = dataChannelArray.size();
491+
for (int i = 0; i < nChans; i++)
492+
{
493+
DataChannel* ch = dataChannelArray[i];
494+
audioDataChannelMap[ch->getCurrentNodeID()][ch->getCurrentNodeChannelIdx()] = i;
495+
}
479496
}
480497

481498
// ==========================================================

Source/Processors/AudioNode/AudioNode.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ class AudioNode : public GenericProcessor
158158
// Temporary buffer for data
159159
ScopedPointer<AudioSampleBuffer> tempBuffer;
160160

161+
//private map for datachannels with info relative to multiple processors
162+
std::unordered_map<uint16, std::map<uint16, int>> audioDataChannelMap;
163+
161164
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(AudioNode);
162165

163166
};

Source/Processors/GenericProcessor/GenericProcessor.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,10 @@ void GenericProcessor::updateChannelIndexes(bool updateNodeID)
405405
dataChannelMap.clear();
406406
eventChannelMap.clear();
407407
spikeChannelMap.clear();
408-
409-
for (int i = 0; i < dataChannelArray.size(); i++)
408+
unsigned int nChans;
409+
410+
nChans = dataChannelArray.size();
411+
for (int i = 0; i < nChans; i++)
410412
{
411413
DataChannel* channel = dataChannelArray[i];
412414
if (updateNodeID)
@@ -419,7 +421,8 @@ void GenericProcessor::updateChannelIndexes(bool updateNodeID)
419421
uint32 sourceID = getProcessorFullId(channel->getSourceNodeID(), channel->getSubProcessorIdx());
420422
dataChannelMap[sourceID][channel->getSourceIndex()] = i;
421423
}
422-
for (int i = 0; i < eventChannelArray.size(); i++)
424+
nChans = eventChannelArray.size();
425+
for (int i = 0; i < nChans; i++)
423426
{
424427
EventChannel* channel = eventChannelArray[i];
425428
if (updateNodeID)
@@ -432,7 +435,8 @@ void GenericProcessor::updateChannelIndexes(bool updateNodeID)
432435
uint32 sourceID = getProcessorFullId(channel->getSourceNodeID(), channel->getSubProcessorIdx());
433436
eventChannelMap[sourceID][channel->getSourceIndex()] = i;
434437
}
435-
for (int i = 0; i < spikeChannelArray.size(); i++)
438+
nChans = spikeChannelArray.size();
439+
for (int i = 0; i < nChans; i++)
436440
{
437441
SpikeChannel* channel = spikeChannelArray[i];
438442
if (updateNodeID)

0 commit comments

Comments
 (0)