@@ -31,12 +31,12 @@ using namespace LfpViewer;
3131LfpDisplayNode::LfpDisplayNode ()
3232 : GenericProcessor (" LFP Viewer" )
3333 , displayGain (1 )
34- , bufferLength (10 .0f )
34+ , bufferLength (1 .0f )
3535 , abstractFifo (100 )
3636{
3737 setProcessorType (PROCESSOR_TYPE_SINK);
3838
39- displayBuffer = new AudioSampleBuffer (8 , 100 );
39+ displayBuffer. reset ( new AudioSampleBuffer (8 , 100 ) );
4040
4141 const int heapSize = 5000 ;
4242 arrayOfOnes = new float [heapSize];
@@ -83,6 +83,12 @@ void LfpDisplayNode::updateSettings()
8383
8484 numSubprocessors = numChannelsInSubprocessor.size ();
8585
86+ displayBuffers.resize (numSubprocessors, std::make_shared<AudioSampleBuffer> (8 , 100 ));
87+
88+ displayBufferIndices.resize (numSubprocessors);
89+
90+ channelIndices.resize (numSubprocessors);
91+
8692 if (numChannelsInSubprocessor.find (subprocessorToDraw) == numChannelsInSubprocessor.end ())
8793 {
8894 // subprocessor to draw does not exist
@@ -188,10 +194,13 @@ float LfpDisplayNode::getSubprocessorSampleRate(uint32 subprocId)
188194
189195bool LfpDisplayNode::resizeBuffer ()
190196{
191- int nSamples = (int )getSubprocessorSampleRate (subprocessorToDraw) * bufferLength;
197+ LfpDisplayEditor * ed = (LfpDisplayEditor*)getEditor ();
198+ allSubprocessors = ed->getInputSubprocessors ();
199+
200+ /* int nSamples = (int)getSubprocessorSampleRate(subprocessorToDraw) * bufferLength;
192201 int nInputs = getNumSubprocessorChannels();
193202
194- std::cout << " Resizing buffer. Samples: " << nSamples << " , Inputs: " << nInputs << std::endl;
203+ // std::cout << "Resizing buffer. Samples: " << nSamples << ", Inputs: " << nInputs << std::endl;
195204
196205 if (nSamples > 0 && nInputs > 0)
197206 {
@@ -202,13 +211,46 @@ bool LfpDisplayNode::resizeBuffer()
202211 displayBufferIndex.clear();
203212 displayBufferIndex.insertMultiple(0, 0, nInputs + 1);
204213
214+ //return true;
215+ }*/
216+ // else
217+ // {
218+ // return false;
219+ // }
220+
221+ int totalResized = 0 ;
222+
223+ for (int cs = 0 ; cs < numSubprocessors ; cs++)
224+ {
225+ int nSamples = (int )getSubprocessorSampleRate (allSubprocessors[cs]) * bufferLength;
226+ int nInputs = numChannelsInSubprocessor[allSubprocessors[cs]];
227+
228+ std::cout << " Resizing buffer for Subprocessor " << allSubprocessors[cs] << " . Samples: " << nSamples << " , Inputs: " << nInputs << std::endl;
229+
230+ if (nSamples > 0 && nInputs > 0 )
231+ {
232+ // abstractFifo.setTotalSize(nSamples);
233+ displayBuffers[cs]->setSize (nInputs + 1 , nSamples); // add extra channel for TTLs
234+ displayBuffers[cs]->clear ();
235+
236+ displayBufferIndices[cs].clear ();
237+ displayBufferIndices[cs].insert (displayBufferIndices[cs].end (), nInputs + 1 , 0 );
238+
239+ channelIndices.clear ();
240+
241+ totalResized++;
242+ }
243+ }
244+
245+
246+ if (totalResized == numSubprocessors)
247+ {
205248 return true ;
206249 }
207250 else
208251 {
209252 return false ;
210253 }
211-
212254}
213255
214256
@@ -396,7 +438,7 @@ void LfpDisplayNode::process (AudioSampleBuffer& buffer)
396438 {
397439 ScopedLock displayLock (displayMutex);
398440
399- if (true )
441+ if (false )
400442 {
401443 initializeEventChannels ();
402444 checkForEvents (); // see if we got any TTL events
@@ -406,10 +448,13 @@ void LfpDisplayNode::process (AudioSampleBuffer& buffer)
406448 if (true )
407449 {
408450 int channelIndex = -1 ;
451+ channelIndices.insertMultiple (0 , -1 , numSubprocessors);
452+ uint32 subProcId = 0 ;
453+ int cs = -1 ;
409454
410455 for (int chan = 0 ; chan < buffer.getNumChannels (); ++chan)
411456 {
412- if (getDataSubprocId (chan) == subprocessorToDraw)
457+ /* if (getDataSubprocId(chan) == subprocessorToDraw)
413458 {
414459 channelIndex++;
415460 const int samplesLeft = displayBuffer->getNumSamples() - displayBufferIndex[channelIndex];
@@ -446,7 +491,48 @@ void LfpDisplayNode::process (AudioSampleBuffer& buffer)
446491
447492 displayBufferIndex.set(channelIndex, extraSamples);
448493 }
494+ }*/
495+
496+ subProcId = getDataSubprocId (chan);
497+ cs = allSubprocessors.indexOf (subProcId);
498+
499+ channelIndices.set (cs, channelIndices[cs] + 1 );
500+
501+ const int samplesLeft = displayBuffers[cs]->getNumSamples () - displayBufferIndices[cs][channelIndices[cs]];
502+ const int nSamples = getNumSamples (chan);
503+
504+ if (nSamples < samplesLeft)
505+ {
506+ displayBuffers[cs]->copyFrom (channelIndices[cs], // destChannel
507+ displayBufferIndices[cs][channelIndices[cs]], // destStartSample
508+ buffer, // source
509+ chan, // source channel
510+ 0 , // source start sample
511+ nSamples); // numSamples
512+
513+ displayBufferIndices[cs].insert (displayBufferIndices[cs].begin () + channelIndices[cs], displayBufferIndices[cs][channelIndices[cs]] + nSamples);
449514 }
515+ else
516+ {
517+ const int extraSamples = nSamples - samplesLeft;
518+
519+ displayBuffers[cs]->copyFrom (channelIndices[cs], // destChannel
520+ displayBufferIndices[cs][channelIndices[cs]], // destStartSample
521+ buffer, // source
522+ chan, // source channel
523+ 0 , // source start sample
524+ samplesLeft); // numSamples
525+
526+ displayBuffers[cs]->copyFrom (channelIndices[cs], // destChannel
527+ 0 , // destStartSample
528+ buffer, // source
529+ chan, // source channel
530+ samplesLeft, // source start sample
531+ extraSamples); // numSamples
532+
533+ displayBufferIndices[cs].insert (displayBufferIndices[cs].begin () + channelIndices[cs], extraSamples);
534+ }
535+
450536 }
451537 }
452538 }
0 commit comments