Skip to content

Commit 23d4bb1

Browse files
committed
Restrict batch writes to the Binary engine
1 parent d3445ca commit 23d4bb1

2 files changed

Lines changed: 41 additions & 16 deletions

File tree

Source/Processors/RecordNode/RecordThread.cpp

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ RecordThread::RecordThread (RecordNode* parentNode, RecordEngine* engine) : Thre
4242
m_maxWriteSamples = m_minWriteSamples;
4343
}
4444

45+
if (m_engine == nullptr || ! m_engine->getEngineId().equalsIgnoreCase ("BINARY"))
46+
{
47+
useBatchWrites = false;
48+
LOGD ("[RecordThread] Batch writes disabled - using single-sample writes for compatibility with engines other than BINARY");
49+
}
50+
4551
LOGD ("RecordThread initialized with MIN_WRITE_SAMPLES=", m_minWriteSamples, " MAX_WRITE_SAMPLES=", m_maxWriteSamples);
4652
}
4753

@@ -52,6 +58,17 @@ RecordThread::~RecordThread()
5258
void RecordThread::setEngine (RecordEngine* engine)
5359
{
5460
m_engine = engine;
61+
62+
if (m_engine == nullptr || ! m_engine->getEngineId().equalsIgnoreCase ("BINARY"))
63+
{
64+
useBatchWrites = false;
65+
LOGD ("[RecordThread] Batch writes disabled - using single-sample writes for compatibility with engines other than BINARY");
66+
}
67+
else
68+
{
69+
useBatchWrites = true;
70+
LOGD ("[RecordThread] Batch writes enabled for engine: ", m_engine->getEngineId());
71+
}
5572
}
5673

5774
void RecordThread::setFileComponents (File rootFolder, int experimentNumber, int recordingNumber)
@@ -268,7 +285,7 @@ void RecordThread::writeData (int minSamples,
268285
const double* timestamps = timestampBuffer.getReadPointer (0, bufferIndex);
269286

270287
// Use batch write if we have multiple channels, otherwise use single-channel write
271-
if (batchSize > 1)
288+
if (batchSize > 1 && useBatchWrites)
272289
{
273290
m_engine->writeContinuousDataBatch (
274291
m_batchWriteChannels.data(),
@@ -279,14 +296,17 @@ void RecordThread::writeData (int minSamples,
279296
numSamples,
280297
streamIdx);
281298
}
282-
else if (batchSize == 1)
299+
else
283300
{
284-
m_engine->writeContinuousData (
285-
m_batchWriteChannels[0],
286-
m_batchRealChannels[0],
287-
m_batchDataPtrs[0],
288-
timestamps,
289-
numSamples);
301+
for (int i = 0; i < batchSize; ++i)
302+
{
303+
m_engine->writeContinuousData (
304+
m_batchWriteChannels[i],
305+
m_batchRealChannels[i],
306+
m_batchDataPtrs[i],
307+
timestamps,
308+
numSamples);
309+
}
290310
}
291311

292312
// Handle wrap-around (size2) if present
@@ -317,7 +337,7 @@ void RecordThread::writeData (int minSamples,
317337

318338
const double* timestamps2 = timestampBuffer.getReadPointer (0, bufferIndex2);
319339

320-
if (batchSize > 1)
340+
if (batchSize > 1 && useBatchWrites)
321341
{
322342
m_engine->writeContinuousDataBatch (
323343
m_batchWriteChannels.data(),
@@ -328,14 +348,17 @@ void RecordThread::writeData (int minSamples,
328348
numSamples2,
329349
streamIdx);
330350
}
331-
else if (batchSize == 1)
351+
else
332352
{
333-
m_engine->writeContinuousData (
334-
m_batchWriteChannels[0],
335-
m_batchRealChannels[0],
336-
m_batchDataPtrs[0],
337-
timestamps2,
338-
numSamples2);
353+
for (int i = 0; i < batchSize; ++i)
354+
{
355+
m_engine->writeContinuousData (
356+
m_batchWriteChannels[i],
357+
m_batchRealChannels[i],
358+
m_batchDataPtrs[i],
359+
timestamps2,
360+
numSamples2);
361+
}
339362
}
340363
}
341364
}

Source/Processors/RecordNode/RecordThread.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ class RecordThread : public Thread
136136
int m_minWriteSamples; // Minimum samples before writing
137137
int m_maxWriteSamples; // Maximum samples per write batch
138138

139+
bool useBatchWrites { true }; // Whether to use batch writes for continuous data
140+
139141
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (RecordThread);
140142
};
141143

0 commit comments

Comments
 (0)