From 7153096552bf797fb686ff31d9bb7971390cc57f Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Wed, 19 May 2021 16:33:27 +0200 Subject: [PATCH] Fixed several bugs. Most serious one is a segfault for a stream without input. --- CMakeLists.txt | 2 +- lasp/device/lasp_daq.pyx | 10 ++++++---- lasp/lasp_avstream.py | 5 +++++ test/CMakeLists.txt | 6 ++++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f229c0..74082fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ option(LASP_RTAUDIO "Compile with RtAudio Daq backend" ON) option(LASP_ULDAQ "Compile with UlDaq backend" ON) option(LASP_DEBUG "Compile in debug mode" ON) option(LASP_FFTW_BACKEND "Compile with FFTW fft backend" ON) -option(LAS_FFTPACK_BACKEND "Compile with Fftpack fft backend" OFF) +option(LASP_FFTPACK_BACKEND "Compile with Fftpack fft backend" OFF) if(LASP_PARALLEL) add_definitions(-DLASP_MAX_NUM_THREADS=30) diff --git a/lasp/device/lasp_daq.pyx b/lasp/device/lasp_daq.pyx index ff9fcc5..4200153 100644 --- a/lasp/device/lasp_daq.pyx +++ b/lasp/device/lasp_daq.pyx @@ -93,10 +93,12 @@ cdef void audioCallbackPythonThreadFunction(void* voidsd) nogil: # print(f'Number of input channels: {ninchannels}') # print(f'Number of out channels: {noutchannels}') # fprintf(stderr, 'Sleep time: %d us\n', sleeptime_us) - for i in range(nblocks_buffer): - outbuffer = malloc(sizeof(double)*nBytesPerChan*noutchannels) - memset(outbuffer, 0, sizeof(double)*nBytesPerChan*noutchannels) - sd.outQueue.enqueue( outbuffer) + + if sd.outQueue: + for i in range(nblocks_buffer): + outbuffer = malloc(sizeof(double)*nBytesPerChan*noutchannels) + memset(outbuffer, 0, sizeof(double)*nBytesPerChan*noutchannels) + sd.outQueue.enqueue( outbuffer) sd.ready.store(True) while not sd.stopThread.load(): diff --git a/lasp/lasp_avstream.py b/lasp/lasp_avstream.py index 88299e6..6c1253c 100644 --- a/lasp/lasp_avstream.py +++ b/lasp/lasp_avstream.py @@ -107,6 +107,7 @@ class AudioStream: processCallback: callback function that will be called from a different thread, with arguments (AudioStream, in """ + logging.debug('AudioStream()') self.running = Atomic(False) self.aframectr = Atomic(0) @@ -130,6 +131,10 @@ class AudioStream: self.daq = Daq(device, daqconfig) en_in_ch = daqconfig.getEnabledInChannels(include_monitor=True) en_out_ch = daqconfig.getEnabledOutChannels() + if en_in_ch == 0 and en_out_ch == 0: + raise RuntimeError('No enabled input / output channels') + + logging.debug('Ready to start device...') samplerate = self.daq.start(self.streamCallback) self.streammetadata = StreamMetaData( diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 15442c7..f077ccc 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -11,5 +11,7 @@ target_link_libraries(test_fft lasp_lib) target_link_libraries(test_workers lasp_lib) target_link_libraries(test_math lasp_lib) -add_executable(test_uldaq test_uldaq.cpp) -target_link_libraries(test_uldaq cpp_daq) +if(LASP_ULDAQ) + add_executable(test_uldaq test_uldaq.cpp) + target_link_libraries(test_uldaq cpp_daq) +endif(LASP_ULDAQ)