@@ -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
0 commit comments