@@ -31,7 +31,7 @@ using namespace LfpViewer;
3131LfpDisplayNode::LfpDisplayNode ()
3232 : GenericProcessor (" LFP Viewer" )
3333 , displayGain (1 )
34- , bufferLength (1 .0f )
34+ , bufferLength (10 .0f )
3535 , abstractFifo (100 )
3636{
3737 setProcessorType (PROCESSOR_TYPE_SINK);
@@ -197,28 +197,32 @@ bool LfpDisplayNode::resizeBuffer()
197197
198198 int totalResized = 0 ;
199199
200- for (int cs = 0 ; cs < numSubprocessors ; cs++)
201- {
202- int nSamples = (int )getSubprocessorSampleRate (allSubprocessors[cs]) * bufferLength;
203- int nInputs = numChannelsInSubprocessor[allSubprocessors[cs]];
200+ if (true )
201+ {
202+ ScopedLock displayLock (displayMutex);
204203
205- std::cout << " Resizing buffer for Subprocessor " << allSubprocessors[cs] << " . Samples: " << nSamples << " , Inputs: " << nInputs << std::endl;
204+ for (int currSubproc = 0 ; currSubproc < numSubprocessors ; currSubproc++)
205+ {
206+ int nSamples = (int )getSubprocessorSampleRate (allSubprocessors[currSubproc]) * bufferLength;
207+ int nInputs = numChannelsInSubprocessor[allSubprocessors[currSubproc]];
206208
207- if (nSamples > 0 && nInputs > 0 )
208- {
209- abstractFifo.setTotalSize (nSamples);
210- displayBuffers[cs]->setSize (nInputs + 1 , nSamples); // add extra channel for TTLs
211- displayBuffers[cs]->clear ();
209+ std::cout << " Resizing buffer for Subprocessor " << allSubprocessors[currSubproc] << " . Samples: " << nSamples << " , Inputs: " << nInputs << std::endl;
212210
213- displayBufferIndices[cs].clear ();
214- displayBufferIndices[cs].insert (displayBufferIndices[cs].end (), nInputs + 1 , 0 );
211+ if (nSamples > 0 && nInputs > 0 )
212+ {
213+ abstractFifo.setTotalSize (nSamples);
214+ displayBuffers[currSubproc]->setSize (nInputs + 1 , nSamples); // add extra channel for TTLs
215+ displayBuffers[currSubproc]->clear ();
215216
216- channelIndices.clear ();
217+ displayBufferIndices[currSubproc].clear ();
218+ displayBufferIndices[currSubproc].insert (displayBufferIndices[currSubproc].end (), nInputs + 1 , 0 );
217219
218- totalResized++;
219- }
220- }
220+ channelIndices.clear ();
221221
222+ totalResized++;
223+ }
224+ }
225+ }
222226
223227 if (totalResized == numSubprocessors)
224228 {
@@ -400,7 +404,7 @@ void LfpDisplayNode::finalizeEventChannels()
400404 newIdx = nSamples - samplesLeft;
401405 }
402406
403- displayBufferIndices[i]. insert (displayBufferIndices[i]. begin () + chan, newIdx) ;
407+ displayBufferIndices[i][chan] = newIdx;
404408 }
405409}
406410
@@ -426,48 +430,48 @@ void LfpDisplayNode::process (AudioSampleBuffer& buffer)
426430 int channelIndex = -1 ;
427431 channelIndices.insertMultiple (0 , -1 , numSubprocessors);
428432 uint32 subProcId = 0 ;
429- int cs = -1 ;
433+ int currSubproc = -1 ;
430434
431435 for (int chan = 0 ; chan < buffer.getNumChannels (); ++chan)
432436 {
433437 subProcId = getDataSubprocId (chan);
434- cs = allSubprocessors.indexOf (subProcId);
438+ currSubproc = allSubprocessors.indexOf (subProcId);
435439
436- channelIndices.set (cs , channelIndices[cs ] + 1 );
440+ channelIndices.set (currSubproc , channelIndices[currSubproc ] + 1 );
437441
438- const int samplesLeft = displayBuffers[cs ]->getNumSamples () - displayBufferIndices[cs ][channelIndices[cs ]];
442+ const int samplesLeft = displayBuffers[currSubproc ]->getNumSamples () - displayBufferIndices[currSubproc ][channelIndices[currSubproc ]];
439443 const int nSamples = getNumSamples (chan);
440444
441445 if (nSamples < samplesLeft)
442446 {
443- displayBuffers[cs ]->copyFrom (channelIndices[cs ], // destChannel
444- displayBufferIndices[cs ][channelIndices[cs ]], // destStartSample
447+ displayBuffers[currSubproc ]->copyFrom (channelIndices[currSubproc ], // destChannel
448+ displayBufferIndices[currSubproc ][channelIndices[currSubproc ]], // destStartSample
445449 buffer, // source
446450 chan, // source channel
447451 0 , // source start sample
448452 nSamples); // numSamples
449453
450- displayBufferIndices[cs]. insert (displayBufferIndices[cs]. begin () + channelIndices[cs], displayBufferIndices[cs ][channelIndices[cs ]] + nSamples) ;
454+ displayBufferIndices[currSubproc][ channelIndices[currSubproc]] = displayBufferIndices[currSubproc ][channelIndices[currSubproc ]] + nSamples;
451455 }
452456 else
453457 {
454458 const int extraSamples = nSamples - samplesLeft;
455459
456- displayBuffers[cs ]->copyFrom (channelIndices[cs ], // destChannel
457- displayBufferIndices[cs ][channelIndices[cs ]], // destStartSample
460+ displayBuffers[currSubproc ]->copyFrom (channelIndices[currSubproc ], // destChannel
461+ displayBufferIndices[currSubproc ][channelIndices[currSubproc ]], // destStartSample
458462 buffer, // source
459463 chan, // source channel
460464 0 , // source start sample
461465 samplesLeft); // numSamples
462466
463- displayBuffers[cs ]->copyFrom (channelIndices[cs ], // destChannel
467+ displayBuffers[currSubproc ]->copyFrom (channelIndices[currSubproc ], // destChannel
464468 0 , // destStartSample
465469 buffer, // source
466470 chan, // source channel
467471 samplesLeft, // source start sample
468472 extraSamples); // numSamples
469473
470- displayBufferIndices[cs]. insert (displayBufferIndices[cs]. begin () + channelIndices[cs], extraSamples) ;
474+ displayBufferIndices[currSubproc][ channelIndices[currSubproc]] = extraSamples;
471475 }
472476
473477 }
0 commit comments