Skip to content

Commit 49fdb50

Browse files
committed
Supress FIFO fill percentages below 5%, which are expected after increasing write block size
1 parent 2b716d1 commit 49fdb50

6 files changed

Lines changed: 54 additions & 17 deletions

File tree

Source/Processors/RecordNode/DataQueue.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,18 @@ float DataQueue::writeAllChannels (const AudioBuffer<float>& buffer,
279279
}
280280

281281
// Return usage from last channel (all should be the same)
282-
const float usage = 1.0f - (float) m_fifos[m_numChans - 1]->getFreeSpace() / (float) m_fifos[m_numChans - 1]->getTotalSize();
282+
return getFifoUsage();
283+
}
284+
285+
float DataQueue::getFifoUsage() const
286+
{
287+
const float freeSpace = (float) m_fifos[m_numChans - 1]->getFreeSpace();
288+
const float totalSize = (float) m_fifos[m_numChans - 1]->getTotalSize();
289+
290+
const float usage = 1.0f - (freeSpace / totalSize);
291+
292+
//LOGC ("DataQueue::getFifoUsage: usage = ", usage, " (free: ", freeSpace, ", total: ", totalSize, ")");
293+
283294
return usage;
284295
}
285296

Source/Processors/RecordNode/DataQueue.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ class DataQueue
121121
/** Fills the sample number buffer for the stream */
122122
void fillSampleNumbers (int index, int size, int64 sampleNumber);
123123

124+
/** Returns the fraction of the FIFO currently in use */
125+
float getFifoUsage() const;
126+
124127
int lastIdx;
125128

126129
OwnedArray<AbstractFifo> m_fifos;

Source/Processors/RecordNode/RecordNode.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,7 @@ void RecordNode::startRecording()
928928
}
929929

930930
recordThread->setFileComponents (rootFolder, experimentNumber, recordingNumber);
931+
recordThread->openFiles();
931932
recordThread->startThread (Thread::Priority::highest);
932933

933934
if (settingsNeeded)

Source/Processors/RecordNode/RecordNodeEditor.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,31 @@ StreamMonitor::StreamMonitor (RecordNode* rn, uint64 id)
120120
selectedChannels = 0;
121121
totalChannels = rn->getDataStream (streamId)->getChannelCount();
122122

123-
startTimerHz (10);
123+
startTimerHz (5);
124124
}
125125

126126
StreamMonitor::~StreamMonitor() {}
127127

128128
void StreamMonitor::timerCallback()
129129
{
130130
if (((RecordNode*) processor)->recordThread->isThreadRunning())
131-
setFillPercentage (((RecordNode*) processor)->fifoUsage[streamId]);
131+
{
132+
float fifoUsage = ((RecordNode*) processor)->fifoUsage[streamId];
133+
134+
// Scale the fill percentage to reduce noise from expected low values:
135+
// - Values <= 5% are displayed as 0%
136+
// - Values between 5% and 10% are scaled to 0-10%
137+
// - Values above 10% are displayed linearly
138+
float scaledUsage;
139+
if (fifoUsage <= 0.05f)
140+
scaledUsage = 0.0f;
141+
else if (fifoUsage <= 0.10f)
142+
scaledUsage = (fifoUsage - 0.05f) * 2.0f; // Maps 0.05-0.10 to 0.0-0.10
143+
else
144+
scaledUsage = fifoUsage;
145+
146+
setFillPercentage (scaledUsage);
147+
}
132148
else
133149
setFillPercentage (0.0);
134150
}

Source/Processors/RecordNode/RecordThread.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,8 @@ void RecordThread::setFirstBlockFlag (bool state)
9696
this->notify();
9797
}
9898

99-
void RecordThread::run()
99+
void RecordThread::openFiles()
100100
{
101-
spikesReceived = 0;
102-
spikesWritten = 0;
103-
104101
// Initialize per-channel sample numbers
105102
sampleNumbers.clear();
106103
for (int chan = 0; chan < m_numChannels; ++chan)
@@ -114,17 +111,23 @@ void RecordThread::run()
114111
m_perStreamTimestampIdxs.resize (numStreams);
115112
m_perStreamSampleNumbers.resize (numStreams, 0);
116113

117-
bool closeEarly = true;
118-
119-
//1-Open Files
120-
m_cleanExit = false;
121-
closeEarly = false;
122-
Array<int64> initSampleNumbers;
123-
124114
m_engine->openFiles (m_rootFolder, m_experimentNumber, m_recordingNumber);
125115

126116
if (recordNode != nullptr)
127117
recordNode->notifyRecordThreadFilesOpened();
118+
}
119+
120+
void RecordThread::run()
121+
{
122+
// 1-Initialize counters
123+
spikesReceived = 0;
124+
spikesWritten = 0;
125+
126+
bool closeEarly = false;
127+
int numStreams = recordNode->getNumDataStreams();
128+
129+
m_cleanExit = false;
130+
Array<int64> initSampleNumbers;
128131

129132
//2-Wait until the first block has arrived, so we can align the timestamps
130133
bool isWaiting = false;
@@ -137,7 +140,7 @@ void RecordThread::run()
137140
wait (1);
138141
}
139142

140-
// Get initial sample numbers from each stream's queue
143+
// 3 - Get initial sample numbers from each stream's queue
141144
int globalChan = 0;
142145
for (int streamIdx = 0; streamIdx < numStreams; streamIdx++)
143146
{
@@ -165,12 +168,12 @@ void RecordThread::run()
165168
}
166169
m_engine->updateLatestSampleNumbers (initSampleNumbers);
167170

168-
//3-Normal loop
171+
//4 - Normal loop
169172
while (! threadShouldExit())
170173
writeData (m_minWriteSamples, m_maxWriteSamples, BLOCK_MAX_WRITE_EVENTS, BLOCK_MAX_WRITE_SPIKES);
171174

172175
//LOGD(__FUNCTION__, " Exiting record thread");
173-
//4-Before closing the thread, try to write the remaining samples
176+
//5 - Before closing the thread, try to write the remaining samples
174177

175178
LOGD ("Closing all files");
176179

Source/Processors/RecordNode/RecordThread.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class RecordThread : public Thread
7272
/** Sets the pointers to the data queues (one per stream), event queue, and spike queue */
7373
void setQueuePointers (OwnedArray<DataQueue>* dataQueues, EventMsgQueue* events, SpikeMsgQueue* spikes);
7474

75+
/** Opens files prior to starting recording */
76+
void openFiles();
77+
7578
/** Runs the thread */
7679
void run() override;
7780

0 commit comments

Comments
 (0)