diff --git a/Source/Plugins/BinaryWriter/BinaryRecording.cpp b/Source/Plugins/BinaryWriter/BinaryRecording.cpp index b13ee7123bd6925ccf8da8a50c6e527ac44d8de2..3e3f5dd1d9911c472ad9710b9b78827e2babaa1a 100644 --- a/Source/Plugins/BinaryWriter/BinaryRecording.cpp +++ b/Source/Plugins/BinaryWriter/BinaryRecording.cpp @@ -504,8 +504,8 @@ void BinaryRecording::writeData(int writeChannel, int realChannel, const float* double multFactor = 1 / (float(0x7fff) * getDataChannel(realChannel)->getBitVolts()); FloatVectorOperations::copyWithMultiply(m_scaledBuffer.getData(), buffer, multFactor, size); AudioDataConverters::convertFloatToInt16LE(m_scaledBuffer.getData(), m_intBuffer.getData(), size); - - m_DataFiles[m_fileIndexes[writeChannel]]->writeChannel(getTimestamp(writeChannel)-m_startTS[writeChannel],m_channelIndexes[writeChannel],m_intBuffer.getData(),size); + int fileIndex = m_fileIndexes[writeChannel]; + m_DataFiles[fileIndex]->writeChannel(getTimestamp(writeChannel) - m_startTS[writeChannel], m_channelIndexes[writeChannel], m_intBuffer.getData(), size); if (m_channelIndexes[writeChannel] == 0) { @@ -515,7 +515,8 @@ void BinaryRecording::writeData(int writeChannel, int realChannel, const float* { m_tsBuffer[i] = (baseTS + i); } - m_dataTimestampFiles[m_fileIndexes[writeChannel]]->writeData(m_tsBuffer, size*sizeof(int64)); + m_dataTimestampFiles[fileIndex]->writeData(m_tsBuffer, size*sizeof(int64)); + m_dataTimestampFiles[fileIndex]->increaseRecordCount(size); } } @@ -576,12 +577,14 @@ void BinaryRecording::writeEvent(int eventIndex, const MidiMessage& event) chanFile->writeData(&chan, sizeof(uint16)); } writeEventMetaData(ev.get(), rec->metaDataFile); + increaseEventCounts(rec); } void BinaryRecording::writeTimestampSyncText(uint16 sourceID, uint16 sourceIdx, int64 timestamp, float, String text) { text.paddedRight(' ', 256); m_syncTextFile->writeData(text.toUTF8(), 256); + m_syncTextFile->increaseRecordCount(); } @@ -593,7 +596,7 @@ void BinaryRecording::writeSpike(int electrodeIndex, const SpikeEvent* spike) uint16 spikeChannel = m_spikeChannelIndexes[electrodeIndex]; int totalSamples = channel->getTotalSamples() * channel->getNumChannels(); - + if (totalSamples > m_bufferSize) //Shouldn't happen, and if it happens it'll be slow, but better this than crashing. Will be reset on file close and reset. { @@ -629,8 +632,16 @@ void BinaryRecording::writeSpike(int electrodeIndex, const SpikeEvent* spike) uint16 sortedID = spike->getSortedID(); sortedFile->writeData(&sortedID, sizeof(uint16)); + increaseEventCounts(rec); +} - writeEventMetaData(spike, rec->metaDataFile); +void BinaryRecording::increaseEventCounts(EventRecording* rec) +{ + rec->mainFile->increaseRecordCount(); + rec->timestampFile->increaseRecordCount(); + if (rec->extraFile) rec->extraFile->increaseRecordCount(); + if (rec->channelFile) rec->channelFile->increaseRecordCount(); + if (rec->metaDataFile) rec->metaDataFile->increaseRecordCount(); } RecordEngineManager* BinaryRecording::getEngineManager() diff --git a/Source/Plugins/BinaryWriter/BinaryRecording.h b/Source/Plugins/BinaryWriter/BinaryRecording.h index e0493fac8926f7fff26d2a5e95ecf37fe586fcef..d70f8a3a9f31bdcf9fc503419577d126dafa10b9 100644 --- a/Source/Plugins/BinaryWriter/BinaryRecording.h +++ b/Source/Plugins/BinaryWriter/BinaryRecording.h @@ -84,6 +84,7 @@ namespace BinaryRecordingEngine NpyFile* createEventMetadataFile(const MetaDataEventObject* channel, String fileName, DynamicObject* jsonObject); void createChannelMetaData(const MetaDataInfoObject* channel, DynamicObject* jsonObject); void writeEventMetaData(const MetaDataEvent* event, NpyFile* file); + void increaseEventCounts(EventRecording* rec); static String jsonTypeValue(BaseType type); SpikeMode m_spikeMode;