diff --git a/lasp/device/lasp_cppdaq.cpp b/lasp/device/lasp_cppdaq.cpp index b37a1f4..b0a21b6 100644 --- a/lasp/device/lasp_cppdaq.cpp +++ b/lasp/device/lasp_cppdaq.cpp @@ -154,14 +154,6 @@ Daq::Daq(const DeviceInfo &devinfo, const DaqConfiguration &config) throw runtime_error( "Output monitoring only possible when output is enabled"); } - // Some sanity checks - if (eninchannels.size() != 4) { - throw runtime_error("Invalid length of enabled inChannels vector"); - } - - if (enoutchannels.size() != 1) { - throw runtime_error("Invalid length of enabled outChannels vector"); - } } diff --git a/lasp/device/lasp_cpprtaudio.cpp b/lasp/device/lasp_cpprtaudio.cpp index cacad49..6168659 100644 --- a/lasp/device/lasp_cpprtaudio.cpp +++ b/lasp/device/lasp_cpprtaudio.cpp @@ -193,6 +193,13 @@ class AudioDaq: public Daq { void start(SafeQueue *inqueue, SafeQueue *outqueue) { + this->inqueue = inqueue; + this->outqueue = outqueue; + if(monitorOutput) { + this->outDelayqueue = new SafeQueue(); + + } + if(isRunning()){ throw runtime_error("Stream already running"); } @@ -209,6 +216,7 @@ class AudioDaq: public Daq { } void stop() { + if(!isRunning()) { cerr << "Stream is already stopped" << endl; } @@ -216,6 +224,9 @@ class AudioDaq: public Daq { assert(rtaudio); rtaudio->stopStream(); } + if(inqueue) delete inqueue; + if(outqueue) delete outqueue; + if(outDelayqueue) delete outDelayqueue; } bool isRunning() const {return (rtaudio && rtaudio->isStreamRunning());} diff --git a/lasp/device/lasp_daq.pyx b/lasp/device/lasp_daq.pyx index ac59afd..99f0418 100644 --- a/lasp/device/lasp_daq.pyx +++ b/lasp/device/lasp_daq.pyx @@ -3,6 +3,7 @@ from .lasp_deviceinfo cimport DeviceInfo from .lasp_daqconfig cimport DaqConfiguration from cpython.ref cimport PyObject,Py_INCREF, Py_DECREF +import numpy as np from .lasp_device_common import AvType __all__ = ['Daq'] diff --git a/lasp/lasp_avstream.py b/lasp/lasp_avstream.py index 46156cc..14a7b16 100644 --- a/lasp/lasp_avstream.py +++ b/lasp/lasp_avstream.py @@ -59,9 +59,6 @@ class AvStream: self.input_sensitivity = np.asarray(self.input_sensitivity) - # Fill in numpy data type, and sample width - datatype = daqconfig.dataTypeIndex - # Counters for the number of frames that have been coming in self._aframectr = Atomic(0) self._vframectr = Atomic(0) @@ -88,6 +85,7 @@ class AvStream: self._daq = Daq(device, daqconfig) self.blocksize = self._daq.nFramesPerBlock self.samplerate = self._daq.samplerate + self.dtype = self._daq.getNumpyDataType() def nCallbacks(self): """Returns the current number of installed callbacks.""" @@ -164,27 +162,23 @@ class AvStream: # the output buffer to zero noutput_cb = len(self._callbacks[AvType.audio_output]) - shouldhaveoutput = (self.avtype == AvType.audio_output or - self.daqconfig.duplex_mode) - - if noutput_cb == 0 and shouldhaveoutput and outdata is not None: - outdata[:, :] = 0 - # Loop over callbacks if outdata is not None: - for cb in self._callbacks[AvType.audio_output]: - try: - cb(indata, outdata, self._aframectr()) - except Exception as e: - print(e) - return 2 + try: + if len(self._callbacks[AvType.audio_output]) == 0: + outdata[:, :] = 0 + for cb in self._callbacks[AvType.audio_output]: + cb(indata, outdata, self._aframectr()) + except Exception as e: + print(e) + return 2 if indata is not None: - for cb in self._callbacks[AvType.audio_input]: - try: - cb(indata, outdata, self._aframectr()) - except Exception as e: - print(e) - return 1 + try: + for cb in self._callbacks[AvType.audio_input]: + cb(indata, outdata, self._aframectr()) + except Exception as e: + print(e) + return 1 return 0 if self._running else 1 @@ -199,8 +193,8 @@ class AvStream: self._vframectr <<= 0 self._video_started <<= False - self._audiobackend.stop() - self._audiobackend = None + self._daq.stop() + self._daq = None def isRunning(self): return self._running() diff --git a/lasp/lasp_record.py b/lasp/lasp_record.py index 82f98f6..bcf9461 100644 --- a/lasp/lasp_record.py +++ b/lasp/lasp_record.py @@ -37,7 +37,7 @@ class Recording: if stream.avtype != AvType.audio_input: raise RuntimeError('Stream does not have any input channels') self.blocksize = stream.blocksize - self.samplerate = stream.input_samplerate + self.samplerate = stream.samplerate self._running = Atomic(False) self._running_cond = Condition() self.rectime = rectime @@ -81,7 +81,7 @@ class Recording: self._ad = f.create_dataset('audio', (1, stream.blocksize, nchannels), - dtype=stream.input_numpy_dtype, + dtype=stream.dtype, maxshape=(None, stream.blocksize, nchannels), compression='gzip' @@ -96,7 +96,7 @@ class Recording: compression='gzip' ) - f.attrs['samplerate'] = stream.input_samplerate + f.attrs['samplerate'] = stream.samplerate f.attrs['nchannels'] = nchannels f.attrs['blocksize'] = stream.blocksize f.attrs['sensitivity'] = stream.input_sensitivity