Skip to content

Commit ea2212a

Browse files
authored
Merge pull request #4 from labstreaminglayer/fix_unsigned_int
Fix unsigned int bug when pushing integers instead of floats
2 parents 8b63533 + acff53e commit ea2212a

7 files changed

Lines changed: 21 additions & 17 deletions

File tree

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Streams analog input data from [Measurement Computing](https://www.mccdaq.com/)
66

77
- Continuous hardware-paced acquisition via `ulAInScan` (no dropped samples)
88
- **Scaled mode**: calibrated voltage output as `cf_float32`
9-
- **Raw mode**: integer ADC counts matching device resolution (`cf_int16` for 12/16-bit, `cf_int32` for 18/24-bit)
9+
- **Raw mode**: integer ADC counts matching device resolution (`cf_int16` for 12/16-bit, `cf_int32` for 18/24-bit), offset by the midpoint (0V = 0).
1010
- LSL stream metadata includes voltage range, resolution, and scaling coefficients for offline reconstruction
1111
- Automatic FIFO overrun recovery (restarts scan transparently on USB scheduling delays)
1212
- Per-device capability queries: supported voltage ranges, resolution, max scan rate
@@ -145,7 +145,7 @@ Options:
145145
--high-chan N High channel (default: 5)
146146
-r, --rate RATE Sample rate in Hz (default: 16384)
147147
--range VALUE Voltage range (uldaq Range enum value, default: auto)
148-
--raw Output raw integer ADC counts instead of scaled voltage
148+
--raw Output raw integer ADC instead of scaled voltage
149149
```
150150

151151
Examples:
@@ -160,7 +160,7 @@ MCCOutletCLI --list-ranges -d 0
160160
# Stream 6 channels at 16384 Hz (scaled voltage)
161161
MCCOutletCLI -d 0 --low-chan 0 --high-chan 5 --rate 16384
162162

163-
# Stream raw ADC counts
163+
# Stream raw ADC integers
164164
MCCOutletCLI --raw --device-name USB-1608FS
165165

166166
# Use a config file
@@ -192,14 +192,14 @@ Outputs calibrated voltage as `cf_float32`. Channel units are volts (`V`).
192192

193193
### Raw Mode (`--raw`)
194194

195-
Outputs uncalibrated ADC counts. The LSL channel format is selected based on the device's ADC resolution:
195+
Outputs uncalibrated ADC offset by midpoint (0=0). The LSL channel format is selected based on the device's ADC resolution:
196196

197-
| ADC Resolution | LSL Format | Value Range |
198-
|----------------|-------------|---------------------|
199-
| 12-bit | `cf_int16` | 0 - 4095 |
200-
| 16-bit | `cf_int16` | 0 - 65535 |
201-
| 18-bit | `cf_int32` | 0 - 262143 |
202-
| 24-bit | `cf_int32` | 0 - 16777215 |
197+
| ADC Resolution | LSL Format | Value Range |
198+
|----------------|-------------|-----------------------|
199+
| 12-bit | `cf_int16` | -2048 - 2047 |
200+
| 16-bit | `cf_int16` | -32768 - 32767 |
201+
| 18-bit | `cf_int32` | -116072 - 116071 |
202+
| 24-bit | `cf_int32` | -83886078 - 83886077 |
203203

204204
### Stream Metadata
205205

src/cli/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void printUsage(const char* program_name) {
3939
<< " --high-chan N High channel (default: 7)\n"
4040
<< " -r, --rate RATE Sample rate in Hz (default: 44100)\n"
4141
<< " --range VALUE Voltage range (uldaq Range enum value, default: auto)\n"
42-
<< " --raw Output raw integer ADC counts instead of scaled voltage\n"
42+
<< " --raw Output raw integer ADC integers instead of scaled voltage\n"
4343
<< "\n"
4444
<< "Examples:\n"
4545
<< " " << program_name << " --list-devices\n"

src/core/include/mccoutlet/Config.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct AppConfig {
2121
int high_channel = 5;
2222
double sample_rate = 16384.0;
2323
int range = -1; ///< uldaq Range enum value, -1 = auto-select first
24-
bool scaled = true; ///< true = calibrated voltage, false = raw ADC counts
24+
bool scaled = true; ///< true = calibrated voltage, false = raw ADC integers
2525
};
2626

2727
class ConfigManager {

src/core/include/mccoutlet/Device.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class MCCDevice : public IDevice {
112112
int high_channel = 7;
113113
double sample_rate = 44100.0;
114114
int range = -1; ///< uldaq Range enum value, -1 = auto-select first
115-
bool scaled = true; ///< true = calibrated voltage (float), false = raw ADC counts (int)
115+
bool scaled = true; ///< true = calibrated voltage (float), false = raw ADC (int)
116116
};
117117

118118
using StatusCallback = std::function<void(const std::string& message, bool is_error)>;

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
}

src/gui/MainWindow.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180
</item>
181181
<item>
182182
<property name="text">
183-
<string>Raw (Integer Counts)</string>
183+
<string>Raw (Integer)</string>
184184
</property>
185185
</item>
186186
</widget>

0 commit comments

Comments
 (0)