Skip to content

Commit 0ad9827

Browse files
committed
Wait for non-empty buffers before starting recording
Eliminates zero-padding in continuous data files
1 parent 2a80471 commit 0ad9827

4 files changed

Lines changed: 33 additions & 9 deletions

File tree

Source/Plugins/BinaryWriter/BinaryRecording.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ void BinaryRecording::openFiles(File rootFolder, int experimentNumber, int recor
161161
Array<uint32> procIDs;
162162
for (int i = 0; i < nChans; i++)
163163
{
164+
if (i == 0)
165+
std::cout << "Start timestamp: " << getTimestamp(i) << std::endl;
164166
m_startTS.add(getTimestamp(i));
165167
}
166168

Source/Plugins/BinaryWriter/SequentialBlockFile.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ bool SequentialBlockFile::writeChannel(uint64 startPos, int channel, int16* data
9999
int samplesToWrite = jmin((nSamples - writtenSamples), (m_samplesPerBlock - startIdx));
100100
for (int i = 0; i < samplesToWrite; i++)
101101
{
102+
//if (writtenSamples == 0 && *(data + dataIdx) == 0)
103+
//{
104+
// std::cout << "Found a zero." << std::endl;
105+
// break;
106+
//}
107+
102108
*(blockPtr + startMemPos + channel + i*m_nChannels) = *(data + dataIdx);
103109
dataIdx++;
104110
}

Source/Processors/RecordNode/RecordNode.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ float RecordNode::getFreeSpace() const
448448

449449
void RecordNode::handleEvent(const EventChannel* eventInfo, const MidiMessage& event, int samplePosition)
450450
{
451-
if (true)
451+
if (isRecording)
452452
{
453453

454454
if ((*(event.getRawData()+0) & 0x80) == 0) // saving flag > 0 (i.e., event has not already been processed)
@@ -476,6 +476,8 @@ void RecordNode::process(AudioSampleBuffer& buffer)
476476
// FIRST: cycle through events -- extract the TTLs and the timestamps
477477
checkForEvents();
478478

479+
bool noEmptyBuffers = true;
480+
479481
if (isRecording)
480482
{
481483
// SECOND: write channel data
@@ -484,20 +486,33 @@ void RecordNode::process(AudioSampleBuffer& buffer)
484486
{
485487
int realChan = channelMap[chan];
486488
int nSamples = getNumSamples(realChan);
487-
int timestamp = getTimestamp(realChan);
488-
m_dataQueue->writeChannel(buffer, chan, realChan, nSamples, timestamp);
489+
490+
if (nSamples == 0)
491+
noEmptyBuffers = false;
489492
}
490493

491-
// std::cout << nSamples << " " << samplesWritten << " " << blockIndex << std::endl;
492-
if (!setFirstBlock)
494+
if (noEmptyBuffers || setFirstBlock)
493495
{
494-
m_recordThread->setFirstBlockFlag(true);
495-
setFirstBlock = true;
496+
for (int chan = 0; chan < recordChans; ++chan)
497+
{
498+
int realChan = channelMap[chan];
499+
int nSamples = getNumSamples(realChan);
500+
int timestamp = getTimestamp(realChan);
501+
m_dataQueue->writeChannel(buffer, chan, realChan, nSamples, timestamp);
502+
}
503+
if (!setFirstBlock)
504+
{
505+
506+
m_recordThread->setFirstBlockFlag(true);
507+
setFirstBlock = true;
508+
}
496509
}
510+
511+
// std::cout << nSamples << " " << samplesWritten << " " << blockIndex << std::endl;
512+
497513

498514
}
499515

500-
501516
}
502517

503518
void RecordNode::registerProcessor(const GenericProcessor* sourceNode)

Source/Processors/RecordNode/RecordThread.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,14 @@ void RecordThread::run()
8383
wait(1);
8484
}
8585

86-
//2-Open Files
86+
//2-Open Files
8787
if (!threadShouldExit())
8888
{
8989
m_cleanExit = false;
9090
closeEarly = false;
9191
Array<int64> timestamps;
9292
m_dataQueue->getTimestampsForBlock(0, timestamps);
93+
9394
EVERY_ENGINE->updateTimestamps(timestamps);
9495
EVERY_ENGINE->openFiles(m_rootFolder, m_experimentNumber, m_recordingNumber);
9596
}

0 commit comments

Comments
 (0)