Some comment improvement and cleanup

This commit is contained in:
Anne de Jong 2022-07-25 22:29:42 +02:00
parent 6a006e27f9
commit da99618fc3
3 changed files with 121 additions and 120 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.16)
project(LASP LANGUAGES CXX)
project(LASP LANGUAGES C CXX)
# To allow linking to static libs from other directories
cmake_policy(SET CMP0079 NEW)
@ -10,10 +10,6 @@ include("BuildType")
include("QueryPythonForPybind11")
# Generate stubs for the Python module
option(WITH_PY_STUBS
"Generate Python stub files (.pyi) for the Python module." On)
# Find the pybind11 package
find_pybind11_python_first()
@ -50,7 +46,6 @@ find_package(BLAS REQUIRED)
add_definitions(-DLASP_MAX_NFFT=33554432) # 2**25
# ####################################### End of user-adjustable variables section
include(OSSpecific)

View File

@ -32,25 +32,25 @@ void fillRtAudioDeviceInfo(vector<DeviceInfo> &devinfolist) {
// "Our device info struct"
DeviceInfo d;
switch (api) {
case RtAudio::LINUX_ALSA:
d.api = rtaudioAlsaApi;
break;
case RtAudio::LINUX_PULSE:
d.api = rtaudioPulseaudioApi;
break;
case RtAudio::WINDOWS_WASAPI:
d.api = rtaudioWasapiApi;
break;
case RtAudio::WINDOWS_DS:
d.api = rtaudioDsApi;
break;
case RtAudio::WINDOWS_ASIO:
d.api = rtaudioAsioApi;
break;
default:
cerr << "Not implemented RtAudio API, skipping." << endl;
continue;
break;
case RtAudio::LINUX_ALSA:
d.api = rtaudioAlsaApi;
break;
case RtAudio::LINUX_PULSE:
d.api = rtaudioPulseaudioApi;
break;
case RtAudio::WINDOWS_WASAPI:
d.api = rtaudioWasapiApi;
break;
case RtAudio::WINDOWS_DS:
d.api = rtaudioDsApi;
break;
case RtAudio::WINDOWS_ASIO:
d.api = rtaudioAsioApi;
break;
default:
cerr << "Not implemented RtAudio API, skipping." << endl;
continue;
break;
}
d.device_name = devinfo.name;
@ -80,7 +80,7 @@ void fillRtAudioDeviceInfo(vector<DeviceInfo> &devinfolist) {
}
/* if (formats & RTAUDIO_SINT32) { */
/* d.availableDataTypes.push_back(DataTypeDescriptor::DataType::dtype_int24);
*/
*/
/* } */
if (formats & RTAUDIO_SINT32) {
d.availableDataTypes.push_back(
@ -105,7 +105,7 @@ void fillRtAudioDeviceInfo(vector<DeviceInfo> &devinfolist) {
}
static int mycallback(void *outputBuffer, void *inputBuffer, unsigned int nFrames,
double streamTime, RtAudioStreamStatus status, void *userData);
double streamTime, RtAudioStreamStatus status, void *userData);
static void myerrorcallback(RtAudioError::Type, const string &errorText);
@ -122,91 +122,91 @@ class RtAudioDaq : public Daq {
std::atomic<StreamStatus> _streamStatus{};
public:
public:
RtAudioDaq(const DeviceInfo &devinfo, const DaqConfiguration &config)
: Daq(devinfo, config),
rtaudio(static_cast<RtAudio::Api>(devinfo.api.api_specific_subcode)),
nFramesPerBlock(Daq::framesPerBlock()) {
: Daq(devinfo, config),
rtaudio(static_cast<RtAudio::Api>(devinfo.api.api_specific_subcode)),
nFramesPerBlock(Daq::framesPerBlock()) {
DEBUGTRACE_ENTER;
DEBUGTRACE_ENTER;
// 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.
if (duplexMode()) {
throw runtime_error("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 = getHighestInChannel() + 1;
if (inParams->nChannels < 1) {
throw runtime_error("Invalid input number of channels");
// 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.
if (duplexMode()) {
throw runtime_error("RtAudio backend cannot run in duplex mode.");
}
inParams->firstChannel = 0;
inParams->deviceId = devinfo.api_specific_devindex;
assert(!monitorOutput);
} else {
std::unique_ptr<RtAudio::StreamParameters> inParams, outParams;
outParams = std::make_unique<RtAudio::StreamParameters>();
if (neninchannels() > 0) {
outParams->nChannels = getHighestOutChannel() + 1;
if (outParams->nChannels < 1) {
throw runtime_error("Invalid output number of channels");
inParams = std::make_unique<RtAudio::StreamParameters>();
// +1 to get the count.
inParams->nChannels = getHighestInChannel() + 1;
if (inParams->nChannels < 1) {
throw runtime_error("Invalid input number of channels");
}
inParams->firstChannel = 0;
inParams->deviceId = devinfo.api_specific_devindex;
} else {
outParams = std::make_unique<RtAudio::StreamParameters>();
outParams->nChannels = getHighestOutChannel() + 1;
if (outParams->nChannels < 1) {
throw runtime_error("Invalid output number of channels");
}
outParams->firstChannel = 0;
outParams->deviceId = devinfo.api_specific_devindex;
}
outParams->firstChannel = 0;
outParams->deviceId = devinfo.api_specific_devindex;
RtAudio::StreamOptions streamoptions;
streamoptions.flags = RTAUDIO_HOG_DEVICE | RTAUDIO_NONINTERLEAVED;
streamoptions.numberOfBuffers = 2;
streamoptions.streamName = "RtAudio stream";
streamoptions.priority = 0;
RtAudioFormat format;
using Dtype = DataTypeDescriptor::DataType;
const Dtype dtype = dataType();
switch (dtype) {
case Dtype::dtype_fl32:
format = RTAUDIO_FLOAT32;
break;
case Dtype::dtype_fl64:
format = RTAUDIO_FLOAT64;
break;
case Dtype::dtype_int8:
format = RTAUDIO_SINT8;
break;
case Dtype::dtype_int16:
format = RTAUDIO_SINT16;
break;
case Dtype::dtype_int32:
format = RTAUDIO_SINT32;
break;
default:
throw runtime_error("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);
}
RtAudio::StreamOptions streamoptions;
streamoptions.flags = RTAUDIO_HOG_DEVICE | RTAUDIO_NONINTERLEAVED;
streamoptions.numberOfBuffers = 2;
streamoptions.streamName = "RtAudio stream";
streamoptions.priority = 0;
RtAudioFormat format;
using Dtype = DataTypeDescriptor::DataType;
const Dtype dtype = dataType();
switch (dtype) {
case Dtype::dtype_fl32:
format = RTAUDIO_FLOAT32;
break;
case Dtype::dtype_fl64:
format = RTAUDIO_FLOAT64;
break;
case Dtype::dtype_int8:
format = RTAUDIO_SINT8;
break;
case Dtype::dtype_int16:
format = RTAUDIO_SINT16;
break;
case Dtype::dtype_int32:
format = RTAUDIO_SINT32;
break;
default:
throw runtime_error("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);
}
virtual void start(InDaqCallback inCallback,
OutDaqCallback outCallback) override {
OutDaqCallback outCallback) override {
DEBUGTRACE_ENTER;
@ -219,7 +219,7 @@ public:
// Logical XOR
if (inCallback && outCallback) {
throw runtime_error("Either input or output stream possible for RtAudio. "
"Stream duplex mode not provided.");
"Stream duplex mode not provided.");
}
if (inCallback) {
@ -236,6 +236,7 @@ public:
"Output callback given, but stream does not provide output data");
}
}
rtaudio.startStream();
// If we are here, we are running without errors.
@ -251,12 +252,16 @@ public:
if (getStreamStatus().runningOK()) {
rtaudio.stopStream();
}
StreamStatus s = _streamStatus;
s.isRunning = false;
s.errorType = StreamStatus::StreamError::noError;
_streamStatus = s;
}
int streamCallback(void *outputBuffer, void *inputBuffer,
unsigned int nFrames, double streamTime,
unsigned int nFrames, double streamTime,
RtAudioStreamStatus status) {
RtAudioStreamStatus status) {
/* DEBUGTRACE_ENTER; */
@ -268,20 +273,21 @@ public:
StreamStatus stat = _streamStatus;
stat.errorType = e;
stat.isRunning = false;
_streamStatus = stat;
rval = 1;
};
switch (status) {
case RTAUDIO_INPUT_OVERFLOW:
stopWithError(se::inputXRun);
return 1;
break;
case RTAUDIO_OUTPUT_UNDERFLOW:
stopWithError(se::outputXRun);
return 1;
break;
default:
break;
case RTAUDIO_INPUT_OVERFLOW:
stopWithError(se::inputXRun);
return 1;
break;
case RTAUDIO_OUTPUT_UNDERFLOW:
stopWithError(se::outputXRun);
return 1;
break;
default:
break;
}
const auto &dtype_descr = DataTypeDescriptor();
@ -291,7 +297,7 @@ public:
us sw = dtype_descr.sw;
if (nFrames != nFramesPerBlock) {
cerr << "RtAudio backend error: nFrames does not match block size!"
<< endl;
<< endl;
stopWithError(se::logicError);
return 1;
}
@ -303,7 +309,7 @@ public:
for (int ch = getLowestInChannel(); ch <= getHighestInChannel(); ch++) {
if (inchannel_config.at(ch).enabled) {
ptrs.push_back(&static_cast<uint8_t *>(
inputBuffer)[sw * ninchannels * ch * nFramesPerBlock]);
inputBuffer)[sw * ninchannels * ch * nFramesPerBlock]);
}
}
DaqData d{neninchannels, nFramesPerBlock, dtype};
@ -326,7 +332,7 @@ public:
for (int ch = 0; ch <= getHighestOutChannel(); ch++) {
if (outchannel_config.at(ch).enabled) {
ptrs.push_back(&static_cast<uint8_t *>(
outputBuffer)[sw * nenoutchannels * ch * nFramesPerBlock]);
outputBuffer)[sw * nenoutchannels * ch * nFramesPerBlock]);
}
}
DaqData d{nenoutchannels, nFramesPerBlock, dtype};
@ -354,7 +360,7 @@ public:
};
std::unique_ptr<Daq> createRtAudioDevice(const DeviceInfo &devinfo,
const DaqConfiguration &config) {
const DaqConfiguration &config) {
return std::make_unique<RtAudioDaq>(devinfo, config);
}
@ -362,7 +368,7 @@ void myerrorcallback(RtAudioError::Type, const string &errorText) {
cerr << "RtAudio backend stream error: " << errorText << endl;
}
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(
outputBuffer, inputBuffer, nFrames, streamTime, status);

View File

@ -6,4 +6,4 @@ add_library(fftpack
# Ling fft to math
target_link_libraries(fftpack PRIVATE m)
interface_include_directories(fftpack .)
target_include_directories(fftpack PUBLIC .)