Skip to content

Commit 8100835

Browse files
committed
Add always-0 reference channel.
1 parent e83d1ff commit 8100835

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

src/core/src/EGIAmpClient.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -801,11 +801,13 @@ void EGIAmpClient::readPacketFormat2() {
801801
physioChannelCount = 32;
802802
}
803803

804-
emitChannelCount(nChannels + physioChannelCount);
804+
// +1 for Cz reference channel (always zero, appended to EEG data)
805+
int eegChannelCount = nChannels + 1;
806+
emitChannelCount(eegChannelCount + physioChannelCount);
805807

806808
// Create LSL outlet for EEG (+ Physio if connected)
807809
std::string streamName = config_.streamName();
808-
streamer_.createOutlet(streamName, nChannels, physioChannelCount, 0,
810+
streamer_.createOutlet(streamName, eegChannelCount, physioChannelCount, 0,
809811
config_.sampleRate, config_.serverAddress, details_,
810812
config_.nativeFormat);
811813

@@ -904,7 +906,7 @@ void EGIAmpClient::readPacketFormat2() {
904906
std::string streamName = config_.streamName();
905907
int physioChCount = (physioConnectionStatus_ == 3) ? 32 :
906908
(physioConnectionStatus_ > 0) ? 16 : 0;
907-
streamer_.createOutlet(streamName, nChannels, physioChCount, 0,
909+
streamer_.createOutlet(streamName, nChannels + 1, physioChCount, 0,
908910
config_.sampleRate, config_.serverAddress, details_,
909911
config_.nativeFormat);
910912
dinStreamer_.createDINOutlet(streamName + "_DIN", config_.serverAddress);
@@ -954,11 +956,12 @@ void EGIAmpClient::readPacketFormat2() {
954956
if (config_.nativeFormat) {
955957
// Native format: push raw int32 ADC counts
956958
std::vector<int32_t> rawSamples;
957-
rawSamples.reserve(nChannels + physioChannels);
959+
rawSamples.reserve(nChannels + 1 + physioChannels);
958960

959961
for (int ch = 0; ch < nChannels; ch++) {
960962
rawSamples.push_back(packet.eegData[ch]);
961963
}
964+
rawSamples.push_back(0); // Cz reference channel
962965

963966
// Add PIB1 channels (if port 1 connected: status 1 or 3)
964967
if (physioConnectionStatus_ & 0x01) {
@@ -978,12 +981,13 @@ void EGIAmpClient::readPacketFormat2() {
978981
} else {
979982
// Default: convert to float microvolts
980983
std::vector<float> eegSamples;
981-
eegSamples.reserve(nChannels + physioChannels);
984+
eegSamples.reserve(nChannels + 1 + physioChannels);
982985

983986
for (int ch = 0; ch < nChannels; ch++) {
984987
eegSamples.push_back(static_cast<float>(packet.eegData[ch]) *
985988
details_.scalingFactor);
986989
}
990+
eegSamples.push_back(0.0f); // Cz reference channel
987991

988992
// Add PIB1 channels (if port 1 connected: status 1 or 3)
989993
// Channels 1-8 use negative scaling, 9-16 use positive scaling
@@ -1298,25 +1302,27 @@ void EGIAmpClient::readPacketFormat1() {
12981302

12991303
emitStatus(std::string("Sensor: ") + netCodeName(details_.netCode) + "\n");
13001304
emitSensor(details_.netCode);
1301-
emitChannelCount(nChannels);
1305+
// +1 for Cz reference channel
1306+
emitChannelCount(nChannels + 1);
13021307

13031308
// Create LSL outlet (no Physio16 or DIN support for PacketFormat1)
13041309
// Note: PacketFormat1 (NA300) already provides float data, so nativeFormat
13051310
// doesn't apply - we always use float for Format1
13061311
std::string streamName = config_.streamName();
1307-
streamer_.createOutlet(streamName, nChannels, 0, 0,
1312+
streamer_.createOutlet(streamName, nChannels + 1, 0, 0,
13081313
config_.sampleRate, config_.serverAddress, details_,
13091314
false); // Format1 is always float
13101315
}
13111316

13121317
// Convert endianness and accumulate sample
13131318
std::vector<float> sample;
1314-
sample.reserve(nChannels);
1319+
sample.reserve(nChannels + 1);
13151320
for (int i = 0; i < nChannels; i++) {
13161321
float val = packet.eeg[i];
13171322
big_to_native_inplace(val);
13181323
sample.push_back(val);
13191324
}
1325+
sample.push_back(0.0f); // Cz reference channel
13201326
chunk.push_back(std::move(sample));
13211327
}
13221328

src/core/src/LSLStreamer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ void LSLStreamer::createOutlet(const std::string& streamName, int eegChannelCoun
163163
lsl::xml_element ref = desc.append_child("reference");
164164
ref.append_child_value("label", "Cz");
165165
ref.append_child_value("subtracted", "Yes");
166+
ref.append_child_value("included_in_stream", "Yes");
166167

167168
// =========================================================================
168169
// Channel metadata

0 commit comments

Comments
 (0)