Small comment change
This commit is contained in:
parent
0c0a86dc64
commit
f4c4a883c6
@ -38,32 +38,32 @@ void fillRtAudioDeviceInfo(vector<DeviceInfo> &devinfolist) {
|
|||||||
// "Our device info struct"
|
// "Our device info struct"
|
||||||
DeviceInfo d;
|
DeviceInfo d;
|
||||||
switch (api) {
|
switch (api) {
|
||||||
case RtAudio::LINUX_ALSA:
|
case RtAudio::LINUX_ALSA:
|
||||||
d.api = rtaudioAlsaApi;
|
d.api = rtaudioAlsaApi;
|
||||||
break;
|
break;
|
||||||
case RtAudio::LINUX_PULSE:
|
case RtAudio::LINUX_PULSE:
|
||||||
d.api = rtaudioPulseaudioApi;
|
d.api = rtaudioPulseaudioApi;
|
||||||
break;
|
break;
|
||||||
case RtAudio::WINDOWS_WASAPI:
|
case RtAudio::WINDOWS_WASAPI:
|
||||||
d.api = rtaudioWasapiApi;
|
d.api = rtaudioWasapiApi;
|
||||||
break;
|
break;
|
||||||
case RtAudio::WINDOWS_DS:
|
case RtAudio::WINDOWS_DS:
|
||||||
d.api = rtaudioDsApi;
|
d.api = rtaudioDsApi;
|
||||||
break;
|
break;
|
||||||
case RtAudio::WINDOWS_ASIO:
|
case RtAudio::WINDOWS_ASIO:
|
||||||
d.api = rtaudioAsioApi;
|
d.api = rtaudioAsioApi;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
cerr << "Not implemented RtAudio API, skipping." << endl;
|
cerr << "Not implemented RtAudio API, skipping." << endl;
|
||||||
continue;
|
continue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
d.device_name = devinfo.name;
|
d.device_name = devinfo.name;
|
||||||
d.api_specific_devindex = devno;
|
d.api_specific_devindex = devno;
|
||||||
|
|
||||||
/// We overwrite the default sample rate with the 48 kHz value, which
|
/// When 48k is available we overwrite the default sample rate with the 48
|
||||||
/// is our preffered rate.
|
/// kHz value, which is our preffered rate,
|
||||||
bool rate_48k_found = false;
|
bool rate_48k_found = false;
|
||||||
|
|
||||||
for (us j = 0; j < devinfo.sampleRates.size(); j++) {
|
for (us j = 0; j < devinfo.sampleRates.size(); j++) {
|
||||||
@ -72,13 +72,13 @@ void fillRtAudioDeviceInfo(vector<DeviceInfo> &devinfolist) {
|
|||||||
|
|
||||||
d.availableSampleRates.push_back((double)rate_int);
|
d.availableSampleRates.push_back((double)rate_int);
|
||||||
|
|
||||||
if(!rate_48k_found) {
|
if (!rate_48k_found) {
|
||||||
|
|
||||||
if (devinfo.preferredSampleRate == rate_int) {
|
if (devinfo.preferredSampleRate == rate_int) {
|
||||||
d.prefSampleRateIndex = j;
|
d.prefSampleRateIndex = j;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(rate_int == 48000) {
|
if (rate_int == 48000) {
|
||||||
d.prefSampleRateIndex = j;
|
d.prefSampleRateIndex = j;
|
||||||
rate_48k_found = true;
|
rate_48k_found = true;
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ void fillRtAudioDeviceInfo(vector<DeviceInfo> &devinfolist) {
|
|||||||
}
|
}
|
||||||
/* if (formats & RTAUDIO_SINT24) { *1/ */
|
/* if (formats & RTAUDIO_SINT24) { *1/ */
|
||||||
/* d.availableDataTypes.push_back(DataTypeDescriptor::DataType::dtype_int24);
|
/* d.availableDataTypes.push_back(DataTypeDescriptor::DataType::dtype_int24);
|
||||||
*/
|
*/
|
||||||
/* } */
|
/* } */
|
||||||
if (formats & RTAUDIO_SINT32) {
|
if (formats & RTAUDIO_SINT32) {
|
||||||
d.availableDataTypes.push_back(
|
d.availableDataTypes.push_back(
|
||||||
@ -126,8 +126,8 @@ void fillRtAudioDeviceInfo(vector<DeviceInfo> &devinfolist) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int mycallback(void *outputBuffer, void *inputBuffer,
|
static int mycallback(void *outputBuffer, void *inputBuffer,
|
||||||
unsigned int nFrames, double streamTime,
|
unsigned int nFrames, double streamTime,
|
||||||
RtAudioStreamStatus status, void *userData);
|
RtAudioStreamStatus status, void *userData);
|
||||||
|
|
||||||
static void myerrorcallback(RtAudioError::Type, const string &errorText);
|
static void myerrorcallback(RtAudioError::Type, const string &errorText);
|
||||||
|
|
||||||
@ -144,101 +144,101 @@ class RtAudioDaq : public Daq {
|
|||||||
|
|
||||||
std::atomic<StreamStatus> _streamStatus{};
|
std::atomic<StreamStatus> _streamStatus{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RtAudioDaq(const DeviceInfo &devinfo, const DaqConfiguration &config)
|
RtAudioDaq(const DeviceInfo &devinfo, const DaqConfiguration &config)
|
||||||
: Daq(devinfo, config),
|
: Daq(devinfo, config),
|
||||||
rtaudio(static_cast<RtAudio::Api>(devinfo.api.api_specific_subcode)),
|
rtaudio(static_cast<RtAudio::Api>(devinfo.api.api_specific_subcode)),
|
||||||
nFramesPerBlock(Daq::framesPerBlock()) {
|
nFramesPerBlock(Daq::framesPerBlock()) {
|
||||||
|
|
||||||
DEBUGTRACE_ENTER;
|
DEBUGTRACE_ENTER;
|
||||||
|
|
||||||
// We make sure not to run RtAudio in duplex mode. This seems to be buggy
|
// We make sure not to run RtAudio in duplex mode. This seems to be buggy
|
||||||
// and untested. Better to use a hardware-type loopback into the system.
|
// and untested. Better to use a hardware-type loopback into the system.
|
||||||
if (duplexMode()) {
|
if (duplexMode()) {
|
||||||
throw rte("RtAudio backend cannot run in duplex mode.");
|
throw rte("RtAudio backend cannot run in duplex mode.");
|
||||||
|
}
|
||||||
|
assert(!monitorOutput);
|
||||||
|
|
||||||
|
std::unique_ptr<RtAudio::StreamParameters> inParams, outParams;
|
||||||
|
|
||||||
|
if (neninchannels() > 0) {
|
||||||
|
|
||||||
|
inParams = std::make_unique<RtAudio::StreamParameters>();
|
||||||
|
|
||||||
|
// +1 to get the count.
|
||||||
|
inParams->nChannels = getHighestEnabledInChannel() + 1;
|
||||||
|
if (inParams->nChannels < 1) {
|
||||||
|
throw rte("Invalid input number of channels");
|
||||||
}
|
}
|
||||||
assert(!monitorOutput);
|
inParams->firstChannel = 0;
|
||||||
|
inParams->deviceId = devinfo.api_specific_devindex;
|
||||||
|
|
||||||
std::unique_ptr<RtAudio::StreamParameters> inParams, outParams;
|
} else {
|
||||||
|
|
||||||
if (neninchannels() > 0) {
|
outParams = std::make_unique<RtAudio::StreamParameters>();
|
||||||
|
|
||||||
inParams = std::make_unique<RtAudio::StreamParameters>();
|
outParams->nChannels = getHighestEnabledOutChannel() + 1;
|
||||||
|
if (outParams->nChannels < 1) {
|
||||||
// +1 to get the count.
|
throw rte("Invalid output number of channels");
|
||||||
inParams->nChannels = getHighestEnabledInChannel() + 1;
|
|
||||||
if (inParams->nChannels < 1) {
|
|
||||||
throw rte("Invalid input number of channels");
|
|
||||||
}
|
|
||||||
inParams->firstChannel = 0;
|
|
||||||
inParams->deviceId = devinfo.api_specific_devindex;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
outParams = std::make_unique<RtAudio::StreamParameters>();
|
|
||||||
|
|
||||||
outParams->nChannels = getHighestEnabledOutChannel() + 1;
|
|
||||||
if (outParams->nChannels < 1) {
|
|
||||||
throw rte("Invalid output number of channels");
|
|
||||||
}
|
|
||||||
outParams->firstChannel = 0;
|
|
||||||
outParams->deviceId = devinfo.api_specific_devindex;
|
|
||||||
}
|
|
||||||
|
|
||||||
RtAudio::StreamOptions streamoptions;
|
|
||||||
streamoptions.flags = RTAUDIO_HOG_DEVICE | RTAUDIO_NONINTERLEAVED;
|
|
||||||
|
|
||||||
streamoptions.numberOfBuffers = 2;
|
|
||||||
streamoptions.streamName = "LASP RtAudio DAQ stream";
|
|
||||||
streamoptions.priority = 0;
|
|
||||||
|
|
||||||
RtAudioFormat format;
|
|
||||||
using Dtype = DataTypeDescriptor::DataType;
|
|
||||||
const Dtype dtype = dataType();
|
|
||||||
switch (dtype) {
|
|
||||||
case Dtype::dtype_fl32:
|
|
||||||
DEBUGTRACE_PRINT("Datatype float32");
|
|
||||||
format = RTAUDIO_FLOAT32;
|
|
||||||
break;
|
|
||||||
case Dtype::dtype_fl64:
|
|
||||||
DEBUGTRACE_PRINT("Datatype float64");
|
|
||||||
format = RTAUDIO_FLOAT64;
|
|
||||||
break;
|
|
||||||
case Dtype::dtype_int8:
|
|
||||||
DEBUGTRACE_PRINT("Datatype int8");
|
|
||||||
format = RTAUDIO_SINT8;
|
|
||||||
break;
|
|
||||||
case Dtype::dtype_int16:
|
|
||||||
DEBUGTRACE_PRINT("Datatype int16");
|
|
||||||
format = RTAUDIO_SINT16;
|
|
||||||
break;
|
|
||||||
case Dtype::dtype_int32:
|
|
||||||
DEBUGTRACE_PRINT("Datatype int32");
|
|
||||||
format = RTAUDIO_SINT32;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw rte("Invalid data type specified for DAQ stream.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy here, as it is used to return the *actual* number of frames per
|
|
||||||
// block.
|
|
||||||
unsigned int nFramesPerBlock_copy = nFramesPerBlock;
|
|
||||||
|
|
||||||
// Final step: open the stream.
|
|
||||||
rtaudio.openStream(outParams.get(), inParams.get(), format,
|
|
||||||
static_cast<us>(samplerate()), &nFramesPerBlock_copy,
|
|
||||||
mycallback, (void *)this, &streamoptions,
|
|
||||||
&myerrorcallback);
|
|
||||||
|
|
||||||
if (nFramesPerBlock_copy != nFramesPerBlock) {
|
|
||||||
throw rte("Got different number of frames per block back from RtAudio "
|
|
||||||
"backend. Do not know what to do");
|
|
||||||
}
|
}
|
||||||
|
outParams->firstChannel = 0;
|
||||||
|
outParams->deviceId = devinfo.api_specific_devindex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RtAudio::StreamOptions streamoptions;
|
||||||
|
streamoptions.flags = RTAUDIO_HOG_DEVICE | RTAUDIO_NONINTERLEAVED;
|
||||||
|
|
||||||
|
streamoptions.numberOfBuffers = 2;
|
||||||
|
streamoptions.streamName = "LASP RtAudio DAQ stream";
|
||||||
|
streamoptions.priority = 0;
|
||||||
|
|
||||||
|
RtAudioFormat format;
|
||||||
|
using Dtype = DataTypeDescriptor::DataType;
|
||||||
|
const Dtype dtype = dataType();
|
||||||
|
switch (dtype) {
|
||||||
|
case Dtype::dtype_fl32:
|
||||||
|
DEBUGTRACE_PRINT("Datatype float32");
|
||||||
|
format = RTAUDIO_FLOAT32;
|
||||||
|
break;
|
||||||
|
case Dtype::dtype_fl64:
|
||||||
|
DEBUGTRACE_PRINT("Datatype float64");
|
||||||
|
format = RTAUDIO_FLOAT64;
|
||||||
|
break;
|
||||||
|
case Dtype::dtype_int8:
|
||||||
|
DEBUGTRACE_PRINT("Datatype int8");
|
||||||
|
format = RTAUDIO_SINT8;
|
||||||
|
break;
|
||||||
|
case Dtype::dtype_int16:
|
||||||
|
DEBUGTRACE_PRINT("Datatype int16");
|
||||||
|
format = RTAUDIO_SINT16;
|
||||||
|
break;
|
||||||
|
case Dtype::dtype_int32:
|
||||||
|
DEBUGTRACE_PRINT("Datatype int32");
|
||||||
|
format = RTAUDIO_SINT32;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw rte("Invalid data type specified for DAQ stream.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy here, as it is used to return the *actual* number of frames per
|
||||||
|
// block.
|
||||||
|
unsigned int nFramesPerBlock_copy = nFramesPerBlock;
|
||||||
|
|
||||||
|
// Final step: open the stream.
|
||||||
|
rtaudio.openStream(outParams.get(), inParams.get(), format,
|
||||||
|
static_cast<us>(samplerate()), &nFramesPerBlock_copy,
|
||||||
|
mycallback, (void *)this, &streamoptions,
|
||||||
|
&myerrorcallback);
|
||||||
|
|
||||||
|
if (nFramesPerBlock_copy != nFramesPerBlock) {
|
||||||
|
throw rte("Got different number of frames per block back from RtAudio "
|
||||||
|
"backend. Do not know what to do");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
virtual void start(InDaqCallback inCallback,
|
virtual void start(InDaqCallback inCallback,
|
||||||
OutDaqCallback outCallback) override final {
|
OutDaqCallback outCallback) override final {
|
||||||
|
|
||||||
DEBUGTRACE_ENTER;
|
DEBUGTRACE_ENTER;
|
||||||
|
|
||||||
@ -251,7 +251,7 @@ class RtAudioDaq : public Daq {
|
|||||||
// Logical XOR
|
// Logical XOR
|
||||||
if (inCallback && outCallback) {
|
if (inCallback && outCallback) {
|
||||||
throw rte("Either input or output stream possible for RtAudio. "
|
throw rte("Either input or output stream possible for RtAudio. "
|
||||||
"Stream duplex mode not provided.");
|
"Stream duplex mode not provided.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (neninchannels() > 0) {
|
if (neninchannels() > 0) {
|
||||||
@ -294,7 +294,7 @@ class RtAudioDaq : public Daq {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int streamCallback(void *outputBuffer, void *inputBuffer,
|
int streamCallback(void *outputBuffer, void *inputBuffer,
|
||||||
unsigned int nFrames, RtAudioStreamStatus status) {
|
unsigned int nFrames, RtAudioStreamStatus status) {
|
||||||
|
|
||||||
DEBUGTRACE_ENTER;
|
DEBUGTRACE_ENTER;
|
||||||
|
|
||||||
@ -311,16 +311,16 @@ class RtAudioDaq : public Daq {
|
|||||||
};
|
};
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case RTAUDIO_INPUT_OVERFLOW:
|
case RTAUDIO_INPUT_OVERFLOW:
|
||||||
stopWithError(se::inputXRun);
|
stopWithError(se::inputXRun);
|
||||||
return 1;
|
return 1;
|
||||||
break;
|
break;
|
||||||
case RTAUDIO_OUTPUT_UNDERFLOW:
|
case RTAUDIO_OUTPUT_UNDERFLOW:
|
||||||
stopWithError(se::outputXRun);
|
stopWithError(se::outputXRun);
|
||||||
return 1;
|
return 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto &dtype_descr = dtypeDescr();
|
const auto &dtype_descr = dtypeDescr();
|
||||||
@ -331,7 +331,7 @@ class RtAudioDaq : public Daq {
|
|||||||
us sw = dtype_descr.sw;
|
us sw = dtype_descr.sw;
|
||||||
if (nFrames != nFramesPerBlock) {
|
if (nFrames != nFramesPerBlock) {
|
||||||
cerr << "RtAudio backend error: nFrames does not match block size!"
|
cerr << "RtAudio backend error: nFrames does not match block size!"
|
||||||
<< endl;
|
<< endl;
|
||||||
stopWithError(se::logicError);
|
stopWithError(se::logicError);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -347,7 +347,7 @@ class RtAudioDaq : public Daq {
|
|||||||
for (us ch = ch_min; ch <= ch_max; ch++) {
|
for (us ch = ch_min; ch <= ch_max; ch++) {
|
||||||
if (inchannel_config.at(ch).enabled) {
|
if (inchannel_config.at(ch).enabled) {
|
||||||
byte_t *ptr =
|
byte_t *ptr =
|
||||||
static_cast<byte_t *>(inputBuffer) + sw * i * nFramesPerBlock;
|
static_cast<byte_t *>(inputBuffer) + sw * i * nFramesPerBlock;
|
||||||
DEBUGTRACE_PRINT((us)ptr);
|
DEBUGTRACE_PRINT((us)ptr);
|
||||||
ptrs.push_back(ptr);
|
ptrs.push_back(ptr);
|
||||||
}
|
}
|
||||||
@ -377,7 +377,7 @@ class RtAudioDaq : public Daq {
|
|||||||
if (outchannel_config.at(ch).enabled) {
|
if (outchannel_config.at(ch).enabled) {
|
||||||
|
|
||||||
ptrs.push_back(static_cast<byte_t *>(outputBuffer) +
|
ptrs.push_back(static_cast<byte_t *>(outputBuffer) +
|
||||||
sw * i * nFramesPerBlock);
|
sw * i * nFramesPerBlock);
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@ -405,7 +405,7 @@ class RtAudioDaq : public Daq {
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<Daq> createRtAudioDevice(const DeviceInfo &devinfo,
|
std::unique_ptr<Daq> createRtAudioDevice(const DeviceInfo &devinfo,
|
||||||
const DaqConfiguration &config) {
|
const DaqConfiguration &config) {
|
||||||
return std::make_unique<RtAudioDaq>(devinfo, config);
|
return std::make_unique<RtAudioDaq>(devinfo, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,7 +413,7 @@ void myerrorcallback(RtAudioError::Type, const string &errorText) {
|
|||||||
cerr << "RtAudio backend stream error: " << errorText << endl;
|
cerr << "RtAudio backend stream error: " << errorText << endl;
|
||||||
}
|
}
|
||||||
int mycallback(void *outputBuffer, void *inputBuffer, unsigned int nFrames,
|
int mycallback(void *outputBuffer, void *inputBuffer, unsigned int nFrames,
|
||||||
double streamTime, RtAudioStreamStatus status, void *userData) {
|
double streamTime, RtAudioStreamStatus status, void *userData) {
|
||||||
|
|
||||||
return static_cast<RtAudioDaq *>(userData)->streamCallback(
|
return static_cast<RtAudioDaq *>(userData)->streamCallback(
|
||||||
outputBuffer, inputBuffer, nFrames, status);
|
outputBuffer, inputBuffer, nFrames, status);
|
||||||
|
Loading…
Reference in New Issue
Block a user