104 lines
2.8 KiB
C++
104 lines
2.8 KiB
C++
/* #define DEBUGTRACE_ENABLED */
|
|
#include "debugtrace.hpp"
|
|
#include "lasp_daqconfig.h"
|
|
|
|
#include "lasp_daq.h"
|
|
#if LASP_HAS_ULDAQ == 1
|
|
#include "lasp_uldaq.h"
|
|
#endif
|
|
#if LASP_HAS_RTAUDIO == 1
|
|
#include "lasp_rtaudiodaq.h"
|
|
#endif
|
|
using std::runtime_error;
|
|
|
|
Daq::~Daq() { DEBUGTRACE_ENTER; }
|
|
|
|
std::unique_ptr<Daq> Daq::createDaq(const DeviceInfo &devinfo,
|
|
const DaqConfiguration &config) {
|
|
DEBUGTRACE_ENTER;
|
|
|
|
#if LASP_HAS_ULDAQ == 1
|
|
if (devinfo.api.apicode == LASP_ULDAQ_APICODE) {
|
|
return createUlDaqDevice(devinfo, config);
|
|
}
|
|
#endif
|
|
#if LASP_HAS_RTAUDIO == 1
|
|
// See lasp_daqconfig.h:114 ALSA, up to
|
|
if (devinfo.api.apicode == LASP_RTAUDIO_APICODE) {
|
|
return createRtAudioDevice(devinfo, config);
|
|
}
|
|
#endif
|
|
throw std::runtime_error(string("Unable to match Device API: ") +
|
|
devinfo.api.apiname);
|
|
}
|
|
|
|
Daq::Daq(const DeviceInfo &devinfo, const DaqConfiguration &config)
|
|
: DaqConfiguration(config), DeviceInfo(devinfo) {
|
|
DEBUGTRACE_ENTER;
|
|
|
|
if (!hasInternalOutputMonitor && monitorOutput) {
|
|
throw std::runtime_error(
|
|
"Output monitor flag set, but device does not have output monitor");
|
|
}
|
|
|
|
if (!config.match(devinfo)) {
|
|
throw std::runtime_error("DaqConfiguration does not match device info");
|
|
}
|
|
if (neninchannels(false) > ninchannels) {
|
|
throw std::runtime_error(
|
|
"Number of enabled input channels is higher than device capability");
|
|
}
|
|
if (nenoutchannels() > noutchannels) {
|
|
throw std::runtime_error(
|
|
"Number of enabled output channels is higher than device capability");
|
|
}
|
|
}
|
|
|
|
double Daq::samplerate() const {
|
|
DEBUGTRACE_ENTER;
|
|
return availableSampleRates.at(sampleRateIndex);
|
|
}
|
|
|
|
DataTypeDescriptor::DataType Daq::dataType() const {
|
|
return availableDataTypes.at(dataTypeIndex);
|
|
}
|
|
const DataTypeDescriptor &Daq::dtypeDescr() const {
|
|
return dtype_map.at(dataType());
|
|
}
|
|
|
|
double Daq::inputRangeForChannel(us ch) const {
|
|
if (!(ch < ninchannels)) {
|
|
throw runtime_error("Invalid channel number");
|
|
}
|
|
return availableInputRanges.at(inchannel_config[ch].rangeIndex);
|
|
}
|
|
|
|
us Daq::neninchannels(bool include_monitorchannel) const {
|
|
boolvec eninchannels = this->eninchannels(include_monitorchannel);
|
|
return std::count(eninchannels.cbegin(), eninchannels.cend(), true);
|
|
}
|
|
|
|
us Daq::nenoutchannels() const {
|
|
boolvec enchannels = this->enoutchannels();
|
|
return std::count(enchannels.cbegin(), enchannels.cend(), true);
|
|
}
|
|
|
|
boolvec Daq::eninchannels(bool include_monitor) const {
|
|
boolvec res;
|
|
if (hasInternalOutputMonitor && include_monitor) {
|
|
res.push_back(monitorOutput);
|
|
}
|
|
|
|
for (auto &ch : inchannel_config) {
|
|
res.push_back(ch.enabled);
|
|
}
|
|
return res;
|
|
}
|
|
boolvec Daq::enoutchannels() const {
|
|
boolvec res;
|
|
for (auto &ch : outchannel_config) {
|
|
res.push_back(ch.enabled);
|
|
}
|
|
return res;
|
|
}
|