lasp/lasp/device/lasp_daqconfig.cpp

98 lines
2.6 KiB
C++

#include "lasp_daqconfig.h"
#include "lasp_deviceinfo.h"
#include <algorithm>
#include <cassert>
#define MAX_DEV_COUNT_PER_API 20
using std::vector;
vector<DaqApi> DaqApi::getAvailableApis() {
vector<DaqApi> apis;
apis.resize(6);
#if LASP_HAS_ULDAQ == 1
apis.at(uldaqapi.apicode) = uldaqapi;
#endif
#if LASP_HAS_RTAUDIO == 1
apis.at(rtaudioAlsaApi.apicode) = rtaudioAlsaApi;
apis.at(rtaudioPulseaudioApi.apicode) = rtaudioPulseaudioApi;
apis.at(rtaudioWasapiApi.apicode) = rtaudioWasapiApi;
apis.at(rtaudioDsApi.apicode) = rtaudioDsApi;
apis.at(rtaudioAsioApi.apicode) = rtaudioAsioApi;
#endif
return apis;
}
DaqConfiguration::DaqConfiguration(const DeviceInfo &device) {
api = device.api;
device_name = device.device_name;
eninchannels.resize(device.ninchannels, false);
enoutchannels.resize(device.noutchannels, false);
inchannel_sensitivities.resize(device.ninchannels, 1.0);
inchannel_metadata.resize(device.ninchannels, "");
for (us i = 0; i < eninchannels.size(); i++) {
std::stringstream chname;
chname << "Unnamed input channel " << i;
inchannel_names.push_back(chname.str());
}
outchannel_metadata.resize(device.noutchannels, "");
outchannel_sensitivities.resize(device.noutchannels, 1.0);
for (us i = 0; i < enoutchannels.size(); i++) {
std::stringstream chname;
chname << "Unnamed output channel " << i;
outchannel_names.push_back(chname.str());
}
sampleRateIndex = device.prefSampleRateIndex;
dataTypeIndex = device.prefDataTypeIndex;
framesPerBlockIndex = device.prefFramesPerBlockIndex;
monitorOutput = false;
inputIEPEEnabled.resize(device.ninchannels, false);
inputACCouplingMode.resize(device.ninchannels, false);
inputRangeIndices.resize(device.ninchannels, device.prefInputRangeIndex);
assert(match(device));
}
bool DaqConfiguration::match(const DeviceInfo &dev) const {
return (dev.device_name == device_name && dev.api == api);
}
int DaqConfiguration::getHighestInChannel() const {
for (int i = eninchannels.size() - 1; i > -1; i--) {
if (eninchannels.at(i))
return i;
}
return -1;
}
int DaqConfiguration::getHighestOutChannel() const {
for (us i = enoutchannels.size() - 1; i >= 0; i--) {
if (enoutchannels.at(i))
return i;
}
return -1;
}
int DaqConfiguration::getLowestInChannel() const {
for (us i = 0; i < eninchannels.size(); i++) {
if (eninchannels.at(i))
return i;
}
return -1;
}
int DaqConfiguration::getLowestOutChannel() const {
for (us i = 0; i < enoutchannels.size(); i++) {
if (enoutchannels.at(i))
return i;
}
return -1;
}