Skip to content

Commit d5ed1fc

Browse files
committed
Add 2D arrays to correctly track both Neuropixels 2e probes
1 parent b2bb962 commit d5ed1fc

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

Source/Devices/Neuropixels2e.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@ Neuropixels2e::Neuropixels2e(std::string name, std::string hubName, const oni_de
3030
INeuropixel(NeuropixelsV2eValues::numberOfSettings, NeuropixelsV2eValues::numberOfShanks)
3131
{
3232
probeSN.fill(0);
33+
frameCount.fill(0);
34+
sampleNumber.fill(0);
3335

3436
for (int i = 0; i < NeuropixelsV2eValues::numberOfSettings; i++)
3537
{
3638
defineMetadata(settings[i].get(), NeuropixelsV2eValues::numberOfShanks);
3739
}
3840

39-
for (int i = 0; i < numFrames; i++)
40-
eventCodes[i] = 0;
41+
for (int i = 0; i < NumberOfProbes; i++)
42+
eventCodes[i].fill(0);
4143
}
4244

4345
Neuropixels2e::~Neuropixels2e()
@@ -495,8 +497,8 @@ uint64_t Neuropixels2e::getProbeSN(uint8_t probeSelect)
495497

496498
void Neuropixels2e::startAcquisition()
497499
{
498-
sampleNumber = 0;
499-
frameCount = 0;
500+
frameCount.fill(0);
501+
sampleNumber.fill(0);
500502
}
501503

502504
void Neuropixels2e::stopAcquisition()
@@ -535,8 +537,8 @@ void Neuropixels2e::processFrames()
535537
uint16_t probeIndex = *(dataPtr + 4);
536538
uint16_t* amplifierData = dataPtr + 9;
537539

538-
sampleNumbers[frameCount] = sampleNumber;
539-
timestamps[frameCount] = deviceContext->convertTimestampToSeconds(frame->time);
540+
sampleNumbers[probeIndex][frameCount[probeIndex]] = sampleNumber[probeIndex]++;
541+
timestamps[probeIndex][frameCount[probeIndex]] = deviceContext->convertTimestampToSeconds(frame->time);
540542

541543
for (int i = 0; i < FramesPerSuperFrame; i++)
542544
{
@@ -546,18 +548,17 @@ void Neuropixels2e::processFrames()
546548
{
547549
const size_t channelIndex = rawToChannel[j][i];
548550

549-
samples[channelIndex * numFrames + frameCount] =
551+
samples[probeIndex][channelIndex * numFrames + frameCount[probeIndex]] =
550552
(float)(*(amplifierData + adcIndices[j] + adcDataOffset)) * gainCorrection[probeIndex];
551553
}
552554
}
553555

554-
frameCount++;
555-
sampleNumber++;
556+
frameCount[probeIndex]++;
556557

557-
if (frameCount >= numFrames)
558+
if (frameCount[probeIndex] >= numFrames)
558559
{
559-
amplifierBuffer[probeIndex]->addToBuffer(samples.data(), sampleNumbers, timestamps, eventCodes, numFrames);
560-
frameCount = 0;
560+
amplifierBuffer[probeIndex]->addToBuffer(samples[probeIndex].data(), sampleNumbers[probeIndex].data(), timestamps[probeIndex].data(), eventCodes[probeIndex].data(), numFrames);
561+
frameCount[probeIndex] = 0;
561562
}
562563

563564
oni_destroy_frame(frame);

Source/Devices/Neuropixels2e.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ namespace OnixSourcePlugin
124124
static const int numFrames = 10;
125125
static const int numSamples = numberOfChannels * numFrames;
126126

127-
std::array<float, numSamples> samples;
127+
std::array<std::array<float, numSamples>, NumberOfProbes> samples {};
128128

129-
int64 sampleNumbers[numFrames];
130-
double timestamps[numFrames];
131-
uint64 eventCodes[numFrames];
129+
std::array<std::array<int64_t, numFrames>, NumberOfProbes> sampleNumbers {};
130+
std::array<std::array<double, numFrames>, NumberOfProbes> timestamps {};
131+
std::array<std::array<uint64_t, numFrames>, NumberOfProbes> eventCodes {};
132132

133-
int frameCount = 0;
134-
int sampleNumber = 0;
133+
std::array<int, NumberOfProbes> frameCount;
134+
std::array<int64_t, NumberOfProbes> sampleNumber;
135135

136136
std::unique_ptr<I2CRegisterContext> serializer;
137137
std::unique_ptr<I2CRegisterContext> deserializer;

0 commit comments

Comments
 (0)