Skip to content

Commit b0b851a

Browse files
committed
Fix issues writing spikes to disk
1 parent 2641db8 commit b0b851a

5 files changed

Lines changed: 26 additions & 33 deletions

File tree

Source/Plugins/BinaryWriter/BinaryRecording.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,17 +417,22 @@ void BinaryRecording::writeSpike(int electrodeIndex, const SpikeEvent* spike)
417417
*reinterpret_cast<uint16*>(spikeBuffer.getData() + 40) = channel->getSampleRate();
418418

419419
int ptrIdx = 0;
420+
uint16* dataIntPtr = reinterpret_cast<uint16*>(spikeBuffer.getData() + 42);
421+
const float* spikeDataPtr = spike->getDataPointer();
420422
for (int i = 0; i < numChannels; i++)
421423
{
422-
float scaleFactor = 1 / (float(0x7fff) * channel->getChannelBitVolts(i));
423-
FloatVectorOperations::copyWithMultiply(m_scaledBuffer + ptrIdx, spike->getDataPointer(i), scaleFactor, chanSamples);
424-
ptrIdx += chanSamples;
424+
const float bitVolts = channel->getChannelBitVolts(i);
425+
for (int j = 0; j < chanSamples; j++)
426+
{
427+
*(dataIntPtr + ptrIdx) = uint16(*(spikeDataPtr + ptrIdx) / bitVolts + 32768);
428+
ptrIdx++;
429+
}
425430
}
426-
AudioDataConverters::convertFloatToInt16LE(m_scaledBuffer, (spikeBuffer.getData() + 42), totalSamples);
427431
ptrIdx = totalSamples * 2 + 42;
428432
for (int i = 0; i < numChannels; i++)
429433
{
430-
*reinterpret_cast<float*>(spikeBuffer.getData() + ptrIdx) = channel->getGain();
434+
//To get the same value as the original version
435+
*reinterpret_cast<float*>(spikeBuffer.getData() + ptrIdx) = (int)(1.0f / channel->getChannelBitVolts(i)) * 1000;
431436
ptrIdx += sizeof(float);
432437
}
433438
for (int i = 0; i < numChannels; i++)

Source/Processors/Channel/InfoObjects.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -416,16 +416,6 @@ Array<sourceChannelInfo> SpikeChannel::getSourceChannelInfo() const
416416
return m_sourceInfo;
417417
}
418418

419-
void SpikeChannel::setGain(float gain)
420-
{
421-
m_gain = gain;
422-
}
423-
424-
float SpikeChannel::getGain() const
425-
{
426-
return m_gain;
427-
}
428-
429419
void SpikeChannel::setNumSamples(unsigned int preSamples, unsigned int postSamples)
430420
{
431421
m_numPreSamples = preSamples;

Source/Processors/Channel/InfoObjects.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,6 @@ class PLUGIN_API SpikeChannel :
358358
/** Returns an array with info about the channels from which the spikes originate */
359359
Array<sourceChannelInfo> getSourceChannelInfo() const;
360360

361-
/** Sets the electrode gain */
362-
void setGain(float gain);
363-
364-
/** Gets the electrode gain */
365-
float getGain() const;
366-
367361
/** Sets the number of samples, pre and post peak */
368362
void setNumSamples(unsigned int preSamples, unsigned int postSamples);
369363

@@ -399,7 +393,6 @@ class PLUGIN_API SpikeChannel :
399393
private:
400394
const ElectrodeTypes m_type;
401395
Array<sourceChannelInfo> m_sourceInfo;
402-
float m_gain{ 1.0f };
403396
unsigned int m_numPreSamples{ 8 };
404397
unsigned int m_numPostSamples{ 32 };
405398
Array<float> m_channelBitVolts;

Source/Processors/FileReader/FileReader.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,13 @@ String FileReader::getFile() const
218218

219219
void FileReader::updateSettings()
220220
{
221-
// if (!input) return;
221+
if (!input) return;
222222

223-
// for (int i=0; i < currentNumChannels; i++)
224-
// {
225-
// channels[i]->bitVolts = channelInfo[i].bitVolts;
226-
// channels[i]->name = channelInfo[i].name;
227-
// }
223+
for (int i=0; i < currentNumChannels; i++)
224+
{
225+
dataChannelArray[i]->setBitVolts(channelInfo[i].bitVolts);
226+
dataChannelArray[i]->setName(channelInfo[i].name);
227+
}
228228
}
229229

230230

Source/Processors/RecordNode/OriginalRecording.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -676,17 +676,22 @@ void OriginalRecording::writeSpike(int electrodeIndex, const SpikeEvent* spike)
676676
*reinterpret_cast<uint16*>(spikeBuffer.getData() + 40) = channel->getSampleRate();
677677

678678
int ptrIdx = 0;
679+
uint16* dataIntPtr = reinterpret_cast<uint16*>(spikeBuffer.getData() + 42);
680+
const float* spikeDataPtr = spike->getDataPointer();
679681
for (int i = 0; i < numChannels; i++)
680682
{
681-
float scaleFactor = 1 / (float(0x7fff) * channel->getChannelBitVolts(i));
682-
FloatVectorOperations::copyWithMultiply(continuousDataFloatBuffer + ptrIdx, spike->getDataPointer(i), scaleFactor, chanSamples);
683-
ptrIdx += chanSamples;
683+
const float bitVolts = channel->getChannelBitVolts(i);
684+
for (int j = 0; j < chanSamples; j++)
685+
{
686+
*(dataIntPtr + ptrIdx) = uint16(*(spikeDataPtr + ptrIdx) / bitVolts + 32768);
687+
ptrIdx++;
688+
}
684689
}
685-
AudioDataConverters::convertFloatToInt16LE(continuousDataFloatBuffer, (spikeBuffer.getData() + 42), totalSamples);
686690
ptrIdx = totalSamples * 2 + 42;
687691
for (int i = 0; i < numChannels; i++)
688692
{
689-
*reinterpret_cast<float*>(spikeBuffer.getData() + ptrIdx) = channel->getGain();
693+
//To get the same value as the original version
694+
*reinterpret_cast<float*>(spikeBuffer.getData() + ptrIdx) = (int)(1.0f / channel->getChannelBitVolts(i)) * 1000;
690695
ptrIdx += sizeof(float);
691696
}
692697
for (int i = 0; i < numChannels; i++)

0 commit comments

Comments
 (0)