From 9005bda017515c8698e4dc7c8d33df18a12b1bcd Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - ASCEE" Date: Sun, 23 May 2021 10:15:48 -0700 Subject: [PATCH] Fixed some bugs. Lrftubes is temporarily disabled on this branch --- CMakeLists.txt | 10 +++++++--- lasp/CMakeLists.txt | 2 +- lasp/c/CMakeLists.txt | 1 + lasp/c/lasp_pyarray.h | 6 +++++- lasp/c/lasp_sosfilterbank.c | 5 +++-- lasp/device/CMakeLists.txt | 2 +- lasp/device/lasp_cppdaq.h | 3 ++- lasp/device/lasp_cpprtaudio.cpp | 14 ++++++++++---- lasp/lasp_avstream.py | 15 ++++++++------- lasp/lasp_imptube.py | 6 +++--- 10 files changed, 41 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 89785c6..790bcf1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,7 @@ endif(LASP_FLOAT STREQUAL "double") # ##################### END Cmake variables converted to a macro set(Python_ADDITIONAL_VERSIONS "3.8") +set(python_version_windll "38") # #################### Setting definitions and debug-specific compilation flags # General make flags @@ -80,11 +81,14 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") message("Building for Windows") include_directories( ..\\rtaudio - C:\\mingw\\include\\OpenBLAS + C:\\mingw\\mingw64\\include\\OpenBLAS + link_directories(C:\\Users\\User\\miniconda3\\Library\\include) ) add_definitions(-DMS_WIN64) - link_directories(C:\\mingw\\lib) - link_directories(C:\\mingw\\bin) + link_directories(C:\\mingw\\mingw64\\lib) + LINK_DIRECTORIES(C:\\Users\\User\\miniconda3) + link_directories(C:\\mingw\\mingw64\\bin) + link_directories(C:\\mingw\\mingw64\\bin) link_directories(..\\rtaudio) link_directories(C:\\Users\\User\\Miniconda3) add_definitions(-DHAS_RTAUDIO_WIN_WASAPI_API) diff --git a/lasp/CMakeLists.txt b/lasp/CMakeLists.txt index 8a827ad..5760574 100644 --- a/lasp/CMakeLists.txt +++ b/lasp/CMakeLists.txt @@ -17,5 +17,5 @@ set_source_files_properties(wrappers.c PROPERTIES COMPILE_FLAGS "${CMAKE_C_FLAGS cython_add_module(wrappers wrappers.pyx) target_link_libraries(wrappers lasp_lib) if(win32) -target_link_libraries(wrappers python37) +target_link_libraries(wrappers python${python_version_windll}) endif(win32) diff --git a/lasp/c/CMakeLists.txt b/lasp/c/CMakeLists.txt index a68d4ef..d1d5b3d 100644 --- a/lasp/c/CMakeLists.txt +++ b/lasp/c/CMakeLists.txt @@ -17,6 +17,7 @@ add_library(lasp_lib lasp_mq.c lasp_siggen.c lasp_worker.c + lasp_nprocs.c lasp_dfifo.c lasp_firfilterbank.c lasp_sosfilterbank.c diff --git a/lasp/c/lasp_pyarray.h b/lasp/c/lasp_pyarray.h index 6690c9c..cbe8792 100644 --- a/lasp/c/lasp_pyarray.h +++ b/lasp/c/lasp_pyarray.h @@ -68,7 +68,11 @@ static inline PyObject *data_to_ndarray(void *data, int n_rows, int n_cols, // Note that in general it was disadvised to build all C code with MinGW on // Windows. We do it anyway, see if we find any problems on the way. PyObject *capsule = PyCapsule_New(data, "data destructor", capsule_cleanup); - PyArray_SetBaseObject(arr, capsule); + int res = PyArray_SetBaseObject(arr, capsule); + if(res != 0) { + fprintf(stderr, "Failed to set base object of array!"); + return NULL; + } #endif /* fprintf(stderr, "============Ownership transfer================\n"); */ PyArray_ENABLEFLAGS(arr, NPY_OWNDATA); diff --git a/lasp/c/lasp_sosfilterbank.c b/lasp/c/lasp_sosfilterbank.c index 7e237cb..e3c652d 100644 --- a/lasp/c/lasp_sosfilterbank.c +++ b/lasp/c/lasp_sosfilterbank.c @@ -2,7 +2,8 @@ #include "lasp_sosfilterbank.h" #include "lasp_mq.h" #include "lasp_worker.h" -#include +#include "lasp_nprocs.h" + typedef struct Sosfilterbank { @@ -89,7 +90,7 @@ Sosfilterbank* Sosfilterbank_create( vd_free(&imp_response); us nthreads; - us nprocs = (us) get_nprocs(); + us nprocs = getNumberOfProcs(); if(nthreads_ == 0) { nthreads = min(max(nprocs/2,1), filterbank_size); diff --git a/lasp/device/CMakeLists.txt b/lasp/device/CMakeLists.txt index 320d528..cec4915 100644 --- a/lasp/device/CMakeLists.txt +++ b/lasp/device/CMakeLists.txt @@ -11,7 +11,7 @@ if(LASP_ULDAQ) list(PREPEND cpp_daq_linklibs uldaq) endif() if(win32) - list(APPEND cpp_daq_linklibs python) + list(APPEND cpp_daq_linklibs python${python_version_windll}) endif(win32) add_library(cpp_daq ${cpp_daq_files}) diff --git a/lasp/device/lasp_cppdaq.h b/lasp/device/lasp_cppdaq.h index 2264dad..c238c12 100644 --- a/lasp/device/lasp_cppdaq.h +++ b/lasp/device/lasp_cppdaq.h @@ -50,11 +50,12 @@ const DataType dtype_invalid; const DataType dtype_fl32("32-bits floating point", 4, true); const DataType dtype_fl64("64-bits floating point", 8, true); const DataType dtype_int8("8-bits integers", 1, false); +const DataType dtype_int24("24-bits integers", 1, false); const DataType dtype_int16("16-bits integers", 2, false); const DataType dtype_int32("32-bits integers", 4, false); const std::vector dataTypes = { - dtype_int8, dtype_int16, dtype_int32, dtype_fl32, dtype_fl64, + dtype_int8, dtype_int16,dtype_int24, dtype_int32, dtype_fl32, dtype_fl64, }; class DaqApi { diff --git a/lasp/device/lasp_cpprtaudio.cpp b/lasp/device/lasp_cpprtaudio.cpp index 4805252..8a77d01 100644 --- a/lasp/device/lasp_cpprtaudio.cpp +++ b/lasp/device/lasp_cpprtaudio.cpp @@ -5,10 +5,7 @@ #include #include #if MS_WIN64 -// #include -// #include typedef uint8_t u_int8_t; - #endif using std::atomic; @@ -24,7 +21,10 @@ void fillRtAudioDeviceInfo(vector &devinfolist) { for(us devno = 0; devno< count;devno++) { RtAudio::DeviceInfo devinfo = rtaudio.getDeviceInfo(devno); - + if(!devinfo.probed) { + // Device capabilities not successfully probed. Continue to next + continue; + } DeviceInfo d; switch(api){ case RtAudio::LINUX_ALSA: @@ -71,12 +71,18 @@ void fillRtAudioDeviceInfo(vector &devinfolist) { if(formats & RTAUDIO_SINT16) { d.availableDataTypes.push_back(dtype_int16); } + if(formats & RTAUDIO_SINT32) { + d.availableDataTypes.push_back(dtype_int24); + } if(formats & RTAUDIO_SINT32) { d.availableDataTypes.push_back(dtype_fl32); } if(formats & RTAUDIO_FLOAT64) { d.availableDataTypes.push_back(dtype_fl64); } + if(d.availableDataTypes.size() == 0) { + std::cerr << "RtAudio: No data types found in device!" << endl; + } d.prefDataTypeIndex = d.availableDataTypes.size() - 1; diff --git a/lasp/lasp_avstream.py b/lasp/lasp_avstream.py index 8beb4b4..58f24d9 100644 --- a/lasp/lasp_avstream.py +++ b/lasp/lasp_avstream.py @@ -109,8 +109,10 @@ class AudioStream: """ logging.debug('AudioStream()') - self.running = Atomic(False) - self.aframectr = Atomic(0) + # self.running = Atomic(False) + # self.aframectr = Atomic(0) + self.running = False + self.aframectr = 0 self.avtype = avtype self.siggen_activated = Atomic(False) @@ -144,17 +146,16 @@ class AudioStream: blocksize=self.daq.nFramesPerBlock, dtype=self.daq.getNumpyDataType(), ) - self.running <<= True + self.running = True def streamCallback(self, indata, outdata, nframes): """ This is called (from a separate thread) for each block of audio data. """ - if not self.running(): + if not self.running: return 1 - - self.aframectr += 1 + self.aframectr += 1 rv = self.processCallback(self, indata, outdata) if rv != 0: @@ -282,7 +283,7 @@ class AvStreamProcess(mp.Process): except Exception as e: self.sendAllQueues( - StreamMsg.streamError, avtype, "Error starting stream {str(e)}" + StreamMsg.streamError, avtype, f"Error starting stream {str(e)}" ) return diff --git a/lasp/lasp_imptube.py b/lasp/lasp_imptube.py index f32ec44..8a00a89 100644 --- a/lasp/lasp_imptube.py +++ b/lasp/lasp_imptube.py @@ -6,12 +6,12 @@ Author: J.A. de Jong - ASCEE Description: Two-microphone impedance tube methods """ __all__ = ['TwoMicImpedanceTube'] -from lrftubes import Air +# from lrftubes import Air from .lasp_measurement import Measurement from numpy import pi, sqrt, exp import numpy as np from scipy.interpolate import UnivariateSpline -from lrftubes import PrsDuct +# from lrftubes import PrsDuct from functools import lru_cache class TwoMicImpedanceTube: @@ -23,7 +23,7 @@ class TwoMicImpedanceTube: fl: float = None, fu: float = None, periodic_method=False, - mat= Air(), + # mat= Air(), D_imptube = 50e-3, thermoviscous = True, **kwargs):