Bugfix in RtAudio. Almost working properly

This commit is contained in:
Anne de Jong 2020-11-07 21:36:05 +01:00
parent 3d188281ab
commit f301e3d5f9
4 changed files with 54 additions and 45 deletions

View File

@ -30,17 +30,17 @@ typedef vector<us> usvec;
typedef std::lock_guard<std::mutex> mutexlock; typedef std::lock_guard<std::mutex> mutexlock;
class DataType { class DataType {
public: public:
string name; string name;
unsigned sw; unsigned sw;
bool is_floating; bool is_floating;
DataType(const char *name, unsigned sw, bool is_floating) DataType(const char *name, unsigned sw, bool is_floating)
: name(name), sw(sw), is_floating(is_floating) {} : name(name), sw(sw), is_floating(is_floating) {}
DataType() : name("invalid data type"), sw(0), is_floating(false) {} DataType() : name("invalid data type"), sw(0), is_floating(false) {}
bool operator==(const DataType &o) { bool operator==(const DataType &o) {
return (name == o.name && sw == o.sw && is_floating == o.is_floating); return (name == o.name && sw == o.sw && is_floating == o.is_floating);
} }
}; };
const DataType dtype_invalid; const DataType dtype_invalid;
@ -51,25 +51,25 @@ const DataType dtype_int16("16-bits integers", 2, false);
const DataType dtype_int32("32-bits integers", 4, false); const DataType dtype_int32("32-bits integers", 4, false);
const std::vector<DataType> dataTypes = { const std::vector<DataType> dataTypes = {
dtype_int8, dtype_int16, dtype_int32, dtype_fl32, dtype_fl64, dtype_int8, dtype_int16, dtype_int32, dtype_fl32, dtype_fl64,
}; };
class DaqApi { class DaqApi {
public: public:
string apiname = "Invalid API"; string apiname = "Invalid API";
int apicode = -1; int apicode = -1;
unsigned api_specific_subcode = 0; unsigned api_specific_subcode = 0;
DaqApi(string apiname, unsigned apicode, unsigned api_specific_subcode = 0) DaqApi(string apiname, unsigned apicode, unsigned api_specific_subcode = 0)
: apiname(apiname), apicode(apicode), : apiname(apiname), apicode(apicode),
api_specific_subcode(api_specific_subcode) {} api_specific_subcode(api_specific_subcode) {}
DaqApi() {} DaqApi() {}
bool operator==(const DaqApi &other) const { bool operator==(const DaqApi &other) const {
return (apiname == other.apiname && apicode == other.apicode && return (apiname == other.apiname && apicode == other.apicode &&
api_specific_subcode == other.api_specific_subcode); api_specific_subcode == other.api_specific_subcode);
} }
static vector<DaqApi> getAvailableApis(); static vector<DaqApi> getAvailableApis();
}; };
#ifdef HAS_ULDAQ_API #ifdef HAS_ULDAQ_API

View File

@ -160,7 +160,7 @@ class AudioDaq: public Daq {
} }
try { try {
rtaudio = new RtAudio((RtAudio::Api) devinfo.api_specific_devindex); rtaudio = new RtAudio((RtAudio::Api) devinfo.api.api_specific_subcode);
if(!rtaudio) { if(!rtaudio) {
throw runtime_error("RtAudio allocation failed"); throw runtime_error("RtAudio allocation failed");
} }
@ -177,6 +177,8 @@ class AudioDaq: public Daq {
); );
} catch(...) { } catch(...) {
if(rtaudio) delete rtaudio; if(rtaudio) delete rtaudio;
if(instreamparams) delete instreamparams;
if(outstreamparams) delete outstreamparams;
throw; throw;
} }
if(monitorOutput) { if(monitorOutput) {
@ -224,16 +226,22 @@ class AudioDaq: public Daq {
assert(rtaudio); assert(rtaudio);
rtaudio->stopStream(); rtaudio->stopStream();
} }
if(inqueue) delete inqueue; if(inqueue) {
if(outqueue) delete outqueue; inqueue = nullptr;
if(outDelayqueue) delete outDelayqueue; }
if(outqueue) {
outqueue = nullptr;
}
if(outDelayqueue) {
delete outDelayqueue;
outDelayqueue = nullptr;
}
} }
bool isRunning() const {return (rtaudio && rtaudio->isStreamRunning());} bool isRunning() const {return (rtaudio && rtaudio->isStreamRunning());}
~AudioDaq() { ~AudioDaq() {
assert(rtaudio); assert(rtaudio);
if(rtaudio->isStreamRunning()) { if(isRunning()) {
stop(); stop();
} }
if(rtaudio->isStreamOpen()) { if(rtaudio->isStreamOpen()) {

View File

@ -192,12 +192,14 @@ public:
outqueue = NULL; outqueue = NULL;
inqueue = NULL; inqueue = NULL;
if (inbuffer) if (inbuffer) {
delete inbuffer; delete inbuffer;
if (outbuffer) inbuffer = nullptr;
}
if (outbuffer) {
delete outbuffer; delete outbuffer;
outbuffer = NULL; outbuffer = nullptr;
inbuffer = NULL; }
} }
friend void threadfcn(DT9837A *); friend void threadfcn(DT9837A *);

View File

@ -285,23 +285,22 @@ cdef class Daq:
if sd.inQueue: if sd.inQueue:
# If waiting in the input queue, hereby we let it run. # If waiting in the input queue, hereby we let it run.
sd.inQueue.enqueue(NULL) sd.inQueue.enqueue(NULL)
# printf('Joining thread...\n')
# HERE WE SHOULD RELEASE THE GIL, as exiting the thread function sd.thread.join()
# will require the GIL, which is locked by this thread! del sd.thread
sd.thread.join() sd.thread = NULL
# printf('Thread joined!\n')
del sd.thread if sd.inQueue:
sd.thread = NULL while not sd.inQueue.empty():
free(sd.inQueue.dequeue())
del sd.inQueue
if sd.outQueue: if sd.outQueue:
while not sd.outQueue.empty(): while not sd.outQueue.empty():
free(sd.outQueue.dequeue()) free(sd.outQueue.dequeue())
del sd.outQueue del sd.outQueue
if sd.inQueue: sd.outQueue = NULL
while not sd.inQueue.empty(): fprintf(stderr, "End cleanup stream queues...\n")
free(sd.inQueue.dequeue())
del sd.inQueue
fprintf(stderr, "End cleanup stream queues...\n")
if sd.pyCallback: if sd.pyCallback:
Py_DECREF(<object> sd.pyCallback) Py_DECREF(<object> sd.pyCallback)