LASP 1.0
Library for Acoustic Signal Processing
Loading...
Searching...
No Matches
lasp_daqconfig.h
Go to the documentation of this file.
1#pragma once
2#include "lasp_config.h"
3#include "lasp_types.h"
4#include <map>
5#include <vector>
6
11using std::string;
12using std::to_string;
13
14using boolvec = std::vector<bool>;
15using dvec = std::vector<double>;
16using usvec = std::vector<us>;
17
22public:
27 enum class DataType {
28 dtype_fl32 = 0,
29 dtype_fl64 = 1,
30 dtype_int8 = 2,
31 dtype_int16 = 3,
32 dtype_int32 = 4
33 };
34
38 string name;
42 unsigned sw;
47
52
58 operator DataType() { return dtype; }
59
68 bool operator==(const DataTypeDescriptor &o) noexcept {
69 return dtype == o.dtype;
70 }
71};
72
74 .name = "32-bits floating point",
75 .sw = 4,
76 .is_floating = true,
79 .name = "64-bits floating point",
80 .sw = 8,
81 .is_floating = true,
84 .name = "8-bits integer",
85 .sw = 1,
86 .is_floating = false,
89 .name = "16-bits integer",
90 .sw = 2,
91 .is_floating = false,
94 .name = "32-bits integer",
95 .sw = 4,
96 .is_floating = false,
98
99const std::map<DataTypeDescriptor::DataType, const DataTypeDescriptor>
107
114class DaqApi {
115public:
116 string apiname = "Invalid API";
117 int apicode = -1;
119
124 bool operator==(const DaqApi &other) const {
125 return (apiname == other.apiname && apicode == other.apicode &&
127 }
128 operator string() const { return apiname; }
129 static std::vector<DaqApi> getAvailableApis();
130};
131
132#if LASP_HAS_ULDAQ == 1
133const us LASP_ULDAQ_APICODE = 0;
134const DaqApi uldaqapi("UlDaq", 0);
135#endif
136#if LASP_HAS_RTAUDIO == 1
137#include "RtAudio.h"
138const us LASP_RTAUDIO_APICODE = 1;
139const DaqApi rtaudioAlsaApi("RtAudio Linux ALSA", 1, RtAudio::Api::LINUX_ALSA);
140const DaqApi rtaudioPulseaudioApi("RtAudio Linux Pulseaudio", LASP_RTAUDIO_APICODE,
141 RtAudio::Api::LINUX_PULSE);
142const DaqApi rtaudioWasapiApi("RtAudio Windows Wasapi", LASP_RTAUDIO_APICODE,
143 RtAudio::Api::WINDOWS_WASAPI);
144const DaqApi rtaudioDsApi("RtAudio Windows DirectSound", LASP_RTAUDIO_APICODE,
145 RtAudio::Api::WINDOWS_DS);
146const DaqApi rtaudioAsioApi("RtAudio Windows ASIO", LASP_RTAUDIO_APICODE,
147 RtAudio::Api::WINDOWS_ASIO);
148#endif
149#if LASP_HAS_PORTAUDIO == 1
150const us LASP_PORTAUDIO_APICODE = 2;
151const DaqApi portaudioApi("PortAudio Linux ALSA", LASP_PORTAUDIO_APICODE, 0);
152#endif
153
154class DeviceInfo;
155
162
163public:
168
170
174 bool enabled = false;
175
176 string name = "";
182 double sensitivity = 1;
187 bool IEPEEnabled = false;
191 bool ACCouplingMode = false;
195 int rangeIndex = 0;
200
207
216 bool operator==(const DaqChannel &other) const {
217 return other.name == name && other.sensitivity == sensitivity &&
218 other.qty == qty;
219 }
220};
221
226public:
232 std::string toTOML() const;
233
241 static DaqConfiguration fromTOML(const std::string &toml);
242
248
252 std::vector<DaqChannel> inchannel_config;
253
262 std::vector<DaqChannel>
263 enabledInChannels(const bool include_monitor = true) const;
264
268 std::vector<DaqChannel> outchannel_config;
269
273 int sampleRateIndex = 0; //
274
279
285
290 bool monitorOutput = false;
291
298 DaqConfiguration(const DeviceInfo &deviceinfo);
299
301
311 bool match(const DeviceInfo &devinfo) const;
312
320 int getHighestEnabledInChannel() const;
328 int getHighestEnabledOutChannel() const;
329
337 int getLowestEnabledInChannel() const;
345 int getLowestEnabledOutChannel() const;
346
352 void setAllInputEnabled(bool val) {
353 for (auto &ch : inchannel_config) {
354 ch.enabled = val;
355 }
356 }
357
363 void setAllOutputEnabled(bool val) {
364 for (auto &ch : outchannel_config) {
365 ch.enabled = val;
366 }
367 }
368};
Class that specifies API related information. An API configuration is part of the DAQConfiguration an...
bool operator==(const DaqApi &other) const
unsigned api_specific_subcode
DaqApi(string apiname, unsigned apicode, unsigned api_specific_subcode=0)
static std::vector< DaqApi > getAvailableApis()
string apiname
Stores channel configuration data for each channel. I.e. the physical quantity measured,...
Qty
Possible physical quantities that are recorded.
bool operator==(const DaqChannel &other) const
Compare two channels to eachother. They are equal when the name, sensitivity and quantity are the sam...
double sensitivity
The conversion between recorded physical unit and stored / outputed number, i.e. Number/Volt or Numbe...
double digitalHighPassCutOn
Whether to enable a digital high pass on the signal before passing the result in case of input,...
bool IEPEEnabled
For input-only: enable IEPE constant current power supply for this channel. Only for hardware that is...
int rangeIndex
Index in possible ranges for input / output.
bool ACCouplingMode
Whether to enable HW AC-coupling for this channel.
Qty qty
The physical quantity that is inputed / outputed.
bool enabled
Whether the channel is enabled.
Configuration of a DAQ device.
static DaqConfiguration fromTOML(const std::string &toml)
Load in a DAQConfiguration from TOML.
std::vector< DaqChannel > enabledInChannels(const bool include_monitor=true) const
Return list of enabled input channels.
int framesPerBlockIndex
The index in the array of frames per block that can be used for the device.
int dataTypeIndex
Required datatype for output, should be present in the list.
std::vector< DaqChannel > inchannel_config
Channel configuration for input channels.
bool monitorOutput
If set to true and if the device has this capability, the output channels are added as input channels...
int getHighestEnabledOutChannel() const
Get the highest channel number from the list of enabled output channels.
int getHighestEnabledInChannel() const
Get the enabled highest channel number from the list of enabled input channels.
string device_name
The internal device name this DAQ configuration applies to.
std::string toTOML() const
Export the class to TOML markup language.
int sampleRateIndex
Index in list of sample rates that are available for the device.
int getLowestEnabledInChannel() const
Get the lowest channel number from the list of enabled input channels.
std::vector< DaqChannel > outchannel_config
Channel configuration for output channels.
void setAllInputEnabled(bool val)
Set all input channels to enabled / disabled state.
bool match(const DeviceInfo &devinfo) const
Check to see whether the DAQ configuration matches with the device. This means, some basic checks are...
int getLowestEnabledOutChannel() const
Get the lowest channel number from the list of enabled output channels.
void setAllOutputEnabled(bool val)
Set all output channels to enabled / disabled state.
Descriptor for data types containing more detailed information.
bool operator==(const DataTypeDescriptor &o) noexcept
Compare two data type descriptors. Returns true if the DataType enumerator is the same.
unsigned sw
Sample width of a single sample, in bytes.
string name
Name of the datatype.
bool is_floating
Whether the datatype is a floating point Y/N.
DataType
Basic data types coming from a DAQ that we can deal with. The naming will be self-explainging.
DataType dtype
The number from the enumeration.
Structure containing device info parameters.
std::vector< us > usvec
const DataTypeDescriptor dtype_desc_fl64
const DataTypeDescriptor dtype_desc_fl32
std::vector< double > dvec
const std::map< DataTypeDescriptor::DataType, const DataTypeDescriptor > dtype_map
const DataTypeDescriptor dtype_desc_int16
const DataTypeDescriptor dtype_desc_int32
const DataTypeDescriptor dtype_desc_int8
std::vector< bool > boolvec
size_t us
We often use boolean values.
Definition lasp_types.h:29