Skip to content

Commit 33c3d76

Browse files
committed
Add subprocessor support to Binary format
1 parent 3515c94 commit 33c3d76

3 files changed

Lines changed: 51 additions & 9 deletions

File tree

Source/Plugins/BinaryWriter/BinaryRecording.cpp

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,52 @@ void BinaryRecording::openFiles(File rootFolder, int experimentNumber, int recor
4949
//Open channel files
5050
int nProcessors = getNumRecordedProcessors();
5151

52-
for (int i = 0; i < nProcessors; i++)
52+
m_channelIndexes.insertMultiple(0, 0, getNumRecordedChannels());
53+
m_fileIndexes.insertMultiple(0, 0, getNumRecordedChannels());
54+
55+
int lastId = 0;
56+
for (int proc = 0; proc < nProcessors; proc++)
5357
{
54-
const RecordProcessorInfo& pInfo = getProcessorInfo(i);
55-
File datFile(basepath + "_" + String(pInfo.processorId) + "_" + String(recordingNumber) + ".dat");
56-
ScopedPointer<SequentialBlockFile> bFile = new SequentialBlockFile(pInfo.recordedChannels.size(), samplesPerBlock);
57-
if (bFile->openFile(datFile))
58-
m_DataFiles.add(bFile.release());
58+
const RecordProcessorInfo& pInfo = getProcessorInfo(proc);
59+
int recChans = pInfo.recordedChannels.size();
60+
61+
for (int chan = 0; chan < recChans; chan++)
62+
{
63+
int recordedChan = pInfo.recordedChannels[chan];
64+
int realChan = getRealChannel(recordedChan);
65+
const DataChannel* channelInfo = getDataChannel(realChan);
66+
int sourceId = channelInfo->getSourceNodeID();
67+
int sourceSubIdx = channelInfo->getSubProcessorIdx();
68+
int nInfoArrays = m_dataChannels.size();
69+
bool found = false;
70+
for (int i = lastId; i < nInfoArrays; i++)
71+
{
72+
if (sourceId == m_dataChannels.getReference(i)[0]->getSourceNodeID() && sourceSubIdx == m_dataChannels.getReference(i)[0]->getSubProcessorIdx())
73+
{
74+
m_channelIndexes.set(recordedChan, m_dataChannels.getReference(i).size());
75+
m_fileIndexes.set(recordedChan, i);
76+
m_dataChannels.getReference(i).add(getDataChannel(realChan));
77+
found = true;
78+
break;
79+
}
80+
}
81+
if (!found)
82+
{
83+
File datFile(basepath + "_" + String(pInfo.processorId) + "_" + String(sourceId) + "." + String(sourceSubIdx) + "_" + String(recordingNumber) + ".dat");
84+
ScopedPointer<SequentialBlockFile> bFile = new SequentialBlockFile(pInfo.recordedChannels.size(), samplesPerBlock);
85+
if (bFile->openFile(datFile))
86+
m_DataFiles.add(bFile.release());
87+
else
88+
m_DataFiles.add(nullptr);
89+
90+
ContinuousGroup newGroup;
91+
newGroup.add(getDataChannel(realChan));
92+
m_dataChannels.add(newGroup);
93+
m_fileIndexes.set(recordedChan, nInfoArrays);
94+
m_channelIndexes.set(recordedChan, 0);
95+
96+
}
97+
}
5998
}
6099
int nChans = getNumRecordedChannels();
61100
//Origin Timestamp
@@ -130,7 +169,7 @@ void BinaryRecording::writeData(int writeChannel, int realChannel, const float*
130169
FloatVectorOperations::copyWithMultiply(m_scaledBuffer.getData(), buffer, multFactor, size);
131170
AudioDataConverters::convertFloatToInt16LE(m_scaledBuffer.getData(), m_intBuffer.getData(), size);
132171

133-
m_DataFiles[getProcessorFromChannel(writeChannel)]->writeChannel(getTimestamp(writeChannel)-m_startTS[writeChannel],getChannelNumInProc(writeChannel),m_intBuffer.getData(),size);
172+
m_DataFiles[m_fileIndexes[writeChannel]]->writeChannel(getTimestamp(writeChannel)-m_startTS[writeChannel],m_channelIndexes[writeChannel],m_intBuffer.getData(),size);
134173
}
135174

136175
//Code below is copied from OriginalRecording, so it's not as clean as newer one

Source/Plugins/BinaryWriter/BinaryRecording.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace BinaryRecordingEngine
5656
static RecordEngineManager* getEngineManager();
5757

5858
private:
59-
59+
typedef Array<const DataChannel*> ContinuousGroup;
6060
void openSpikeFile(String basepath, int spikeIndex, int recordingNumber);
6161
String generateSpikeHeader(const SpikeChannel* elec);
6262
String generateEventHeader();
@@ -71,6 +71,9 @@ namespace BinaryRecordingEngine
7171
int m_bufferSize;
7272

7373
OwnedArray<SequentialBlockFile> m_DataFiles;
74+
Array<unsigned int> m_channelIndexes;
75+
Array<unsigned int> m_fileIndexes;
76+
Array<ContinuousGroup> m_dataChannels;
7477

7578
FILE* eventFile;
7679
FILE* messageFile;

Source/Plugins/NWBFormat/NWBRecording.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
int lastId = 0;
6060
for (int proc = 0; proc < recProcs; proc++)
6161
{
62-
const RecordProcessorInfo procInfo = getProcessorInfo(proc);
62+
const RecordProcessorInfo& procInfo = getProcessorInfo(proc);
6363
int recChans = procInfo.recordedChannels.size();
6464
for (int chan = 0; chan < recChans; chan++)
6565
{

0 commit comments

Comments
 (0)