Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Streams analog input data from [Measurement Computing](https://www.mccdaq.com/)

- Continuous hardware-paced acquisition via `ulAInScan` (no dropped samples)
- **Scaled mode**: calibrated voltage output as `cf_float32`
- **Raw mode**: integer ADC counts matching device resolution (`cf_int16` for 12/16-bit, `cf_int32` for 18/24-bit)
- **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).
- LSL stream metadata includes voltage range, resolution, and scaling coefficients for offline reconstruction
- Automatic FIFO overrun recovery (restarts scan transparently on USB scheduling delays)
- Per-device capability queries: supported voltage ranges, resolution, max scan rate
Expand Down Expand Up @@ -145,7 +145,7 @@ Options:
--high-chan N High channel (default: 5)
-r, --rate RATE Sample rate in Hz (default: 16384)
--range VALUE Voltage range (uldaq Range enum value, default: auto)
--raw Output raw integer ADC counts instead of scaled voltage
--raw Output raw integer ADC instead of scaled voltage
```

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

# Stream raw ADC counts
# Stream raw ADC integers
MCCOutletCLI --raw --device-name USB-1608FS

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

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

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

| ADC Resolution | LSL Format | Value Range |
|----------------|-------------|---------------------|
| 12-bit | `cf_int16` | 0 - 4095 |
| 16-bit | `cf_int16` | 0 - 65535 |
| 18-bit | `cf_int32` | 0 - 262143 |
| 24-bit | `cf_int32` | 0 - 16777215 |
| ADC Resolution | LSL Format | Value Range |
|----------------|-------------|-----------------------|
| 12-bit | `cf_int16` | -2048 - 2047 |
| 16-bit | `cf_int16` | -32768 - 32767 |
| 18-bit | `cf_int32` | -116072 - 116071 |
| 24-bit | `cf_int32` | -83886078 - 83886077 |

### Stream Metadata

Expand Down
2 changes: 1 addition & 1 deletion src/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void printUsage(const char* program_name) {
<< " --high-chan N High channel (default: 7)\n"
<< " -r, --rate RATE Sample rate in Hz (default: 44100)\n"
<< " --range VALUE Voltage range (uldaq Range enum value, default: auto)\n"
<< " --raw Output raw integer ADC counts instead of scaled voltage\n"
<< " --raw Output raw integer ADC integers instead of scaled voltage\n"
<< "\n"
<< "Examples:\n"
<< " " << program_name << " --list-devices\n"
Expand Down
2 changes: 1 addition & 1 deletion src/core/include/mccoutlet/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct AppConfig {
int high_channel = 5;
double sample_rate = 16384.0;
int range = -1; ///< uldaq Range enum value, -1 = auto-select first
bool scaled = true; ///< true = calibrated voltage, false = raw ADC counts
bool scaled = true; ///< true = calibrated voltage, false = raw ADC integers
};

class ConfigManager {
Expand Down
2 changes: 1 addition & 1 deletion src/core/include/mccoutlet/Device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class MCCDevice : public IDevice {
int high_channel = 7;
double sample_rate = 44100.0;
int range = -1; ///< uldaq Range enum value, -1 = auto-select first
bool scaled = true; ///< true = calibrated voltage (float), false = raw ADC counts (int)
bool scaled = true; ///< true = calibrated voltage (float), false = raw ADC (int)
};

using StatusCallback = std::function<void(const std::string& message, bool is_error)>;
Expand Down
8 changes: 6 additions & 2 deletions src/core/src/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,11 @@ bool MCCDevice::getDataInt32(std::vector<int32_t>& buffer, double& timestamp) {
size_t read_offset =
(static_cast<size_t>(scans_read_) * channelCount) % total_buffer_elements;

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

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

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

scans_read_ += available;
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/LSLOutlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ LSLOutlet::LSLOutlet(const DeviceInfo& info)
double full_scale = std::pow(2.0, info.resolution_bits);
double span = info.range_max - info.range_min;
double slope = span / full_scale;
double offset = info.range_min;
double offset = (info.range_min + info.range_max) / 2.0;
acq.append_child_value("scaling_slope", std::to_string(slope));
acq.append_child_value("scaling_offset", std::to_string(offset));
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
</item>
<item>
<property name="text">
<string>Raw (Integer Counts)</string>
<string>Raw (Integer)</string>
</property>
</item>
</widget>
Expand Down
Loading