Skip to content

Commit da8f411

Browse files
committed
In int mode, data from DAQ are counts but LSL expects signed ints, so we subtract the midpoint.
1 parent 8b63533 commit da8f411

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/core/src/Device.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,11 @@ bool MCCDevice::getDataInt32(std::vector<int32_t>& buffer, double& timestamp) {
537537
size_t read_offset =
538538
(static_cast<size_t>(scans_read_) * channelCount) % total_buffer_elements;
539539

540+
const int64_t mid = 1LL << (capabilities_.resolution_bits - 1);
540541
for (size_t i = 0; i < num_elements; ++i) {
541-
buffer[i] = static_cast<int32_t>(
542+
auto raw = static_cast<int64_t>(
542543
scan_buffer_[(read_offset + i) % total_buffer_elements]);
544+
buffer[i] = static_cast<int32_t>(raw - mid);
543545
}
544546

545547
scans_read_ += available;
@@ -581,9 +583,11 @@ bool MCCDevice::getDataInt16(std::vector<int16_t>& buffer, double& timestamp) {
581583
size_t read_offset =
582584
(static_cast<size_t>(scans_read_) * channelCount) % total_buffer_elements;
583585

586+
const int32_t mid = 1 << (capabilities_.resolution_bits - 1);
584587
for (size_t i = 0; i < num_elements; ++i) {
585-
buffer[i] = static_cast<int16_t>(
588+
auto raw = static_cast<int32_t>(
586589
scan_buffer_[(read_offset + i) % total_buffer_elements]);
590+
buffer[i] = static_cast<int16_t>(raw - mid);
587591
}
588592

589593
scans_read_ += available;

src/core/src/LSLOutlet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ LSLOutlet::LSLOutlet(const DeviceInfo& info)
4040
double full_scale = std::pow(2.0, info.resolution_bits);
4141
double span = info.range_max - info.range_min;
4242
double slope = span / full_scale;
43-
double offset = info.range_min;
43+
double offset = (info.range_min + info.range_max) / 2.0;
4444
acq.append_child_value("scaling_slope", std::to_string(slope));
4545
acq.append_child_value("scaling_offset", std::to_string(offset));
4646
}

0 commit comments

Comments
 (0)