diff --git a/.gitignore b/.gitignore index b6323ee..a19ddef 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ resources_rc.py .spyproject test/test_uldaq lasp/device/lasp_daq.cxx +lasp/c/lasp_config.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7351fae..f7c2342 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,39 +1,45 @@ -cmake_minimum_required (VERSION 3.0) +cmake_minimum_required (VERSION 3.1) # To allow linking to static libs from other directories cmake_policy(SET CMP0079 NEW) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/lasp/cmake") +include("BuildType") + # This is used for code completion in vim set(CMAKE_EXPORT_COMPILE_COMMANDS=ON) project(LASP LANGUAGES C CXX) # Whether we want to use blas yes or no -set(LASP_USE_BLAS TRUE) -# set(LASP_USE_BLAS FALSE) - -set(LASP_FLOAT double) -# set(LASP_FLOAT float) - +option(LASP_USE_BLAS "Use external blas library for math" ON) +option(LASP_ARM "Compile subset of code for ARM real time (Bela board)" OFF) +option(LASP_DOUBLE_PRECISION "Compile as double precision floating point" ON) option(LASP_PARALLEL "Parallel processing" ON) -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(LASP_FFTPACK_BACKEND "Compile with Fftpack fft backend" OFF) +option(LASP_HAS_RTAUDIO "Compile with RtAudio Daq backend" ON) +option(LASP_HAS_ULDAQ "Compile with UlDaq backend" ON) +set(LASP_MAX_NUM_CHANNELS 16 CACHE STRING "Maximum number of audio channels that is compiled in in code") +set(LASP_MAX_NUM_THREADS 30 CACHE STRING "The maximum number of simultaneous threads in parallel processing") +set(LASP_TRACERNAME "defaulttracer" CACHE STRING "Name of tracer variable containing level") +set(LASP_FFT_BACKEND "FFTW" CACHE STRING "FFT Library backend") +set_property(CACHE LASP_FFT_BACKEND PROPERTY STRINGS "FFTW" "FFTPack" "None") + +if(CMAKE_BUILD_TYPE STREQUAL Debug) + set(LASP_DEBUG True) +else() + set(LASP_DEBUG False) +endif() if(LASP_PARALLEL) -add_definitions(-DLASP_MAX_NUM_THREADS=30) -add_definitions(-D_REENTRANT) + add_definitions(-D_REENTRANT) + set(LASP_THREADING_LIBRARIES pthread) +else() + set(LASP_THREADING_LIBRARIES "") endif() -if(LASP_RTAUDIO) - add_definitions(-DHAS_RTAUDIO_API) -endif() -if(LASP_ULDAQ) - add_definitions(-DHAS_ULDAQ_API) +if(LASP_USE_BLAS) + find_package(BLAS REQUIRED) endif() -add_definitions(-DLASP_MAX_NUM_CHANNELS=80) # Reasonable maximum to the nfft size, at 48kHz this is 700s of data... add_definitions(-DLASP_MAX_NFFT=33554432) # 2**25 @@ -42,101 +48,75 @@ add_definitions(-DLASP_MAX_NFFT=33554432) # 2**25 set(CMAKE_CXX_STANDARD 11) set(CMAKE_C_STANDARD 11) -# ############### Choose an fft backend here -if(((LASP_FFTW_BACKEND AND LASP_FFTPACK_BACKEND) OR ((NOT (LASP_FFTPACK_BACKEND) AND (NOT LASP_FFTW_BACKEND))))) - message(FATAL_ERROR "Either FFTW or Fftpack backend should be chosen. Please disable one of them") -endif() - -if(LASP_FFTW_BACKEND) +if(LASP_FFT_BACKEND STREQUAL "FFTW") find_library(FFTW_LIBRARY NAMES fftw3 fftw) - set(FFTW_LIBRARIES "${FFTW_LIBRARY}") - set(LASP_FFT_LIBRARY "${FFTW_LIBRARIES}") - add_definitions(-DLASP_FFT_BACKEND_FFTW) -elseif(LASP_FFTPACK_BACKEND) - add_definitions(-DLASP_FFT_BACKEND_FFTPACK) - set(LASP_FFT_LIBRARY "fftpack") + set(FFT_LIBRARIES "${FFTW_LIBRARY}") +elseif(LASP_FFT_BACKEND STREQUAL "FFTPack") + include_directories(fftpack) + set(FFT_LIBRARIES fftpack) + add_subdirectory(fftpack) endif() -if(LASP_FLOAT STREQUAL "double") - add_definitions(-DLASP_FLOAT=64) - add_definitions(-DLASP_DOUBLE_PRECISION) -else() - # TODO: This has not been tested for a long time. - add_definitions(-DLASP_FLOAT=32) - add_definitions(-DLASP_SINGLE_PRECISION) -endif(LASP_FLOAT STREQUAL "double") - - # ##################### END Cmake variables converted to a macro -set(Python_ADDITIONAL_VERSIONS "3.8") -set(python_version_windll "38") +# set(Python_ADDITIONAL_VERSIONS "3.8") +# set(python_version_windll "38") # #################### Setting definitions and debug-specific compilation flags # General make flags -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -Wall -Wextra -Wno-type-limits \ +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-type-limits \ -Werror=implicit-function-declaration -Wno-unused-parameter \ -Werror=return-type") if(CMAKE_SYSTEM_NAME STREQUAL "Windows") set(win32 true) - set(home $ENV{USERPROFILE}) - # set(miniconda_dir ${home}\\Miniconda3) - - message("Building for Windows") - include_directories( - ..\\rtaudio - C:\\mingw\\mingw64\\include\\OpenBLAS - link_directories(${home}\\miniconda3\\Library\\include) - ) - set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH} $miniconda_dir\\Lib\\cmake") - # include( - add_definitions(-DMS_WIN64) - link_directories(C:\\mingw\\mingw64\\lib) - link_directories(C:\\mingw\\mingw64\\bin) - link_directories(..\\rtaudio) - link_directories(${home}\\Miniconda3) + set(home $ENV{USERPROFILE}) + # set(miniconda_dir ${home}\\Miniconda3) + + message("Building for Windows") + include_directories( + ..\\rtaudio + C:\\mingw\\mingw64\\include\\OpenBLAS + link_directories(${home}\\miniconda3\\Library\\include) + ) + set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH} $miniconda_dir\\Lib\\cmake") + # include( + add_definitions(-DMS_WIN64) + link_directories(C:\\mingw\\mingw64\\lib) + link_directories(C:\\mingw\\mingw64\\bin) + link_directories(..\\rtaudio) + link_directories(${home}\\Miniconda3) add_definitions(-DHAS_RTAUDIO_WIN_WASAPI_API) else() # Linux compile set(win32 false) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -Werror=incompatible-pointer-types") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -Werror=incompatible-pointer-types") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") include_directories(/usr/local/include/rtaudio) include_directories(/usr/include/rtaudio) link_directories(/usr/local/lib) # This should become optional later on, and be added to the windows list as # well. - + endif(CMAKE_SYSTEM_NAME STREQUAL "Windows") set(CYTHON_FLAGS "--fast-fail") if(LASP_DEBUG) - set(TRACERNAME LASPTracer) set(LASP_DEBUG_CYTHON=True) - set(CMAKE_BUILD_TYPE Debug) message("Building debug code") - set(CMAKE_BUILD_TYPE Debug) - add_definitions(-DLASP_DEBUG=1) - add_definitions(-DTRACERNAME=${TRACERNAME}) - add_definitions(-DDEBUG) - add_definitions(-DTRACER=1) # This will produce html files # set(CYTHON_ANNOTATE ON) # Add the __FILENAME__ macro # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'") else() message("Building LASP for release") - set(CMAKE_BUILD_TYPE Release) set(LASP_DEBUG_CYTHON=False) set(CYTHON_ANNOTATE OFF) set(CYTHON_NO_DOCSTRINGS ON) # Strip unnecessary symbols # set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--gc-sections") # set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--gc-sections") - - add_definitions(-DTRACER=0 -DNDEBUG) endif(LASP_DEBUG) # The last argument here takes care of calling SIGABRT when an integer overflow @@ -155,14 +135,6 @@ set(CMAKE_C_FLAGS_DEBUG "-g" ) set(CMAKE_C_FLAGS_RELEASE "-O2 -mfpmath=sse -march=x86-64 -mtune=native \ -fdata-sections -ffunction-sections -fomit-frame-pointer -finline-functions") -# set(CMAKE_C_FLAGS_RELEASE "-O2 -march=native -mtune=native -fomit-frame-pointer") - -if(LASP_USE_BLAS) - add_definitions(-DLASP_USE_BLAS=1) -else() - add_definitions(-DLASP_USE_BLAS=0) -endif(LASP_USE_BLAS) - # ############################# End compilation flags @@ -171,10 +143,10 @@ find_package(PythonLibs REQUIRED ) find_package(PythonInterp REQUIRED) if(LASP_FFTPACK_BACKEND) -add_subdirectory(fftpack) -include_directories( - fftpack - ) + add_subdirectory(fftpack) + include_directories( + fftpack + ) endif() include_directories( diff --git a/lasp/CMakeLists.txt b/lasp/CMakeLists.txt index 5760574..8c8e445 100644 --- a/lasp/CMakeLists.txt +++ b/lasp/CMakeLists.txt @@ -1,4 +1,3 @@ - configure_file(config.pxi.in config.pxi) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") set(CYTHON_EXECUTABLE "cython3") @@ -15,7 +14,7 @@ add_subdirectory(device) set_source_files_properties(wrappers.c PROPERTIES COMPILE_FLAGS "${CMAKE_C_FLAGS} ${CYTHON_EXTRA_C_FLAGS}") cython_add_module(wrappers wrappers.pyx) -target_link_libraries(wrappers lasp_lib) +target_link_libraries(wrappers lasp_lib ${LASP_THREADING_LIBRARIES}) if(win32) target_link_libraries(wrappers python${python_version_windll}) endif(win32) diff --git a/lasp/c/CMakeLists.txt b/lasp/c/CMakeLists.txt index d1d5b3d..ff86eb5 100644 --- a/lasp/c/CMakeLists.txt +++ b/lasp/c/CMakeLists.txt @@ -1,3 +1,4 @@ +configure_file(lasp_config.h.in lasp_config.h) if(!LASP_DEBUG) SET_SOURCE_FILES_PROPERTIES(lasp_sosfilterbank.c PROPERTIES COMPILE_FLAGS -O3) SET_SOURCE_FILES_PROPERTIES(lasp_slm.c PROPERTIES COMPILE_FLAGS -O3) @@ -26,6 +27,4 @@ add_library(lasp_lib lasp_eq.c ) - - -target_link_libraries(lasp_lib ${LASP_FFT_LIBRARY} openblas pthread) +target_link_libraries(lasp_lib ${FFT_LIBRARIES} ${BLAS_LIBRARIES}) diff --git a/lasp/c/lasp_alg.h b/lasp/c/lasp_alg.h index b26daf0..bc41074 100644 --- a/lasp/c/lasp_alg.h +++ b/lasp/c/lasp_alg.h @@ -8,6 +8,7 @@ #pragma once #ifndef LASP_ALG_H #define LASP_ALG_H +#include "lasp_config.h" #include "lasp_mat.h" /** diff --git a/lasp/c/lasp_assert.c b/lasp/c/lasp_assert.c index f8aea2f..3105e36 100644 --- a/lasp/c/lasp_assert.c +++ b/lasp/c/lasp_assert.c @@ -5,6 +5,7 @@ // Description: // ////////////////////////////////////////////////////////////////////// +#include "lasp_config.h" #include "lasp_assert.h" #ifdef LASP_DEBUG diff --git a/lasp/c/lasp_config.h.in b/lasp/c/lasp_config.h.in new file mode 100644 index 0000000..a0d3840 --- /dev/null +++ b/lasp/c/lasp_config.h.in @@ -0,0 +1,53 @@ +// lasp_config.h +// +// Author: J.A. de Jong - ASCEE +// +// Description: Basic configuration compiler macro definitions, coming from +// cmake configuration. The file is configured using the configure_file() +// cmake macro. +#pragma once +#ifndef LASP_CONFIG_H +#define LASP_CONFIG_H + +/* Debug flag */ +#cmakedefine01 LASP_DEBUG +#if LASP_DEBUG == 1 +#define TRACER 1 +#define TRACERNAME @LASP_TRACERNAME@ +#else +#define TRACER 0 +#endif + + +/* Type of fft backend */ +#define FFTW 1 +#define FFTPack 2 +#define None 0 +#cmakedefine LASP_FFT_BACKEND @LASP_FFT_BACKEND@ +#cmakedefine LASP_HAS_RTAUDIO +#cmakedefine LASP_HAS_ULDAQ +#cmakedefine01 LASP_DOUBLE_PRECISION +#cmakedefine01 LASP_USE_BLAS + +/* Single / double precision */ +#ifdef LASP_DOUBLE_PRECISION +#define LASP_FLOAT 64 +#else +#define LASP_FLOAT 32 +#endif + +/* Serial / parallel computation */ +#cmakedefine LASP_PARALLEL +#ifdef LASP_PARALLEL +#cmakedefine LASP_MAX_NUM_THREADS @LASP_MAX_NUM_THREADS@ +#endif // LASP_PARALLEL + +/* Audio-specific */ +#cmakedefine LASP_MAX_NUM_CHANNELS @LASP_MAX_NUM_CHANNELS@ + +/* Platform-specific */ +#ifdef _WIN32 +#define MS_WIN64 +#endif + +#endif // LASP_CONFIG_H diff --git a/lasp/c/lasp_fft.c b/lasp/c/lasp_fft.c index 6324010..f238083 100644 --- a/lasp/c/lasp_fft.c +++ b/lasp/c/lasp_fft.c @@ -6,17 +6,18 @@ // ////////////////////////////////////////////////////////////////////// #define TRACERPLUS (-5) +#include "lasp_types.h" +#include "lasp_config.h" #include "lasp_tracer.h" #include "lasp_fft.h" -#include "lasp_types.h" -#ifdef LASP_FFT_BACKEND_FFTPACK +#if LASP_FFT_BACKEND == FFTPack #include "fftpack.h" typedef struct Fft_s { us nfft; vd fft_work; // Storage memory for fftpack } Fft_s; -#elif defined LASP_FFT_BACKEND_FFTW +#elif LASP_FFT_BACKEND == FFTW #include typedef struct Fft_s { @@ -26,12 +27,13 @@ typedef struct Fft_s { c* complex_storage; d* real_storage; } Fft_s; - +#else +#error "Cannot compile lasp_ffc.c, no FFT backend specified" #endif void load_fft_wisdom(const char* wisdom) { -#ifdef LASP_FFT_BACKEND_FFTPACK -#elif defined LASP_FFT_BACKEND_FFTW +#if LASP_FFT_BACKEND == FFTPack +#elif LASP_FFT_BACKEND == FFTW if(wisdom) { int rv= fftw_import_wisdom_from_string(wisdom); if(rv != 1) { @@ -42,9 +44,9 @@ void load_fft_wisdom(const char* wisdom) { } char* store_fft_wisdom() { -#ifdef LASP_FFT_BACKEND_FFTPACK +#if LASP_FFT_BACKEND == FFTPack return NULL; -#elif defined LASP_FFT_BACKEND_FFTW +#elif LASP_FFT_BACKEND == FFTW return fftw_export_wisdom_to_string(); #endif } @@ -60,12 +62,12 @@ Fft* Fft_create(const us nfft) { fft->nfft = nfft; -#ifdef LASP_FFT_BACKEND_FFTPACK +#if LASP_FFT_BACKEND == FFTPack /* Initialize foreign fft lib */ fft->fft_work = vd_alloc(2*nfft+15); npy_rffti(nfft,getvdval(&fft->fft_work,0)); check_overflow_vx(fft->fft_work); -#elif defined LASP_FFT_BACKEND_FFTW +#elif LASP_FFT_BACKEND == FFTW fft->complex_storage = fftw_malloc(sizeof(c) * (nfft/2 + 1)); fft->real_storage = fftw_malloc(sizeof(d) * nfft); @@ -88,9 +90,9 @@ Fft* Fft_create(const us nfft) { void Fft_free(Fft* fft) { fsTRACE(15); dbgassert(fft,NULLPTRDEREF); -#ifdef LASP_FFT_BACKEND_FFTPACK +#if LASP_FFT_BACKEND == FFTPack vd_free(&fft->fft_work); -#elif defined LASP_FFT_BACKEND_FFTW +#elif LASP_FFT_BACKEND == FFTW fftw_free(fft->complex_storage); fftw_free(fft->real_storage); fftw_destroy_plan(fft->forward_plan); @@ -116,7 +118,7 @@ void Fft_ifft_single(const Fft* fft,const vc* freqdata,vd* result) { d* result_ptr = getvdval(result,0); -#ifdef LASP_FFT_BACKEND_FFTPACK +#if LASP_FFT_BACKEND == FFTPack d* freqdata_ptr = (d*) getvcval(freqdata,0); /* Copy freqdata, to fft_result. */ d_copy(&result_ptr[1],&freqdata_ptr[2],nfft-1,1,1); @@ -187,7 +189,7 @@ void Fft_fft_single(const Fft* fft,const vd* timedata,vc* result) { " result array"); -#ifdef LASP_FFT_BACKEND_FFTPACK +#if LASP_FFT_BACKEND == FFTPack d* result_ptr = (d*) getvcval(result,0); /* Fftpack stores the data a bit strange, the resulting array diff --git a/lasp/c/lasp_math_raw.c b/lasp/c/lasp_math_raw.c index 196895a..02385f2 100644 --- a/lasp/c/lasp_math_raw.c +++ b/lasp/c/lasp_math_raw.c @@ -7,10 +7,16 @@ ////////////////////////////////////////////////////////////////////// #define TRACERPLUS (-5) #include "lasp_math_raw.h" -#if LASP_USE_BLAS +#if LASP_USE_BLAS == 1 #include #endif +#ifdef __MKL_CBLAS_H__ +/* Symbol not present in MKL blas */ +#define blasint CBLAS_INDEX +#else +#endif + void d_elem_prod_d(d res[], const d arr1[], const d arr2[], @@ -101,7 +107,7 @@ void c_hadamard(c res[], #endif /* LASP_DEBUG */ - #if LASP_DOUBLE_PRECISION + #if LASP_DOUBLE_PRECISION == 1 #define elem_prod_fun cblas_zgbmv #else #define elem_prod_fun cblas_cgbmv diff --git a/lasp/c/lasp_math_raw.h b/lasp/c/lasp_math_raw.h index c707cd7..ed91b87 100644 --- a/lasp/c/lasp_math_raw.h +++ b/lasp/c/lasp_math_raw.h @@ -8,6 +8,7 @@ #pragma once #ifndef LASP_MATH_RAW_H #define LASP_MATH_RAW_H +#include "lasp_config.h" #include "lasp_assert.h" #include "lasp_tracer.h" #include "lasp_types.h" @@ -16,12 +17,13 @@ #if LASP_USE_BLAS == 1 #include + #elif LASP_USE_BLAS == 0 #else #error "LASP_USE_BLAS should be set to either 0 or 1" #endif -#ifdef LASP_DOUBLE_PRECISION +#if LASP_DOUBLE_PRECISION == 1 #define c_real creal #define c_imag cimag #define d_abs fabs @@ -73,9 +75,9 @@ static const d number_pi = 3.141592653589793238462643383279502884197169399375105 * @param size */ static inline void d_set(d to[],d val,us size) { - for(us i=0;ib?a:b; + return a>b?a:b; } @@ -114,12 +116,12 @@ static inline d d_max(const d a,const d b) { * @return the dot product */ static inline c cd_dot(const c a[],const d b[],us size){ - c result = 0; - us i; - for(i=0;i max) max=a[i]; - } - return max; + us i; + d max = a[0]; + for(i=1;i max) max=a[i]; + } + return max; } /** * Compute the minimum of an array @@ -357,12 +372,12 @@ static inline d darray_max(const d a[],us size){ * @return minimum */ static inline d d_min(const d a[],us size){ - us i; - d min = a[0]; - for(i=1;i min) min=a[i]; - } - return min; + us i; + d min = a[0]; + for(i=1;i min) min=a[i]; + } + return min; } /** @@ -372,18 +387,18 @@ static inline d d_min(const d a[],us size){ * @param size Size of array */ static inline d d_norm(const d a[],us size){ - #if LASP_USE_BLAS == 1 - return cblas_dnrm2(size,a,1); - #else - d norm = 0; - us i; - for(i=0;i -#ifdef LASP_DOUBLE_PRECISION +#include "lasp_types.h" +#if LASP_DOUBLE_PRECISION == 1 #define LASP_NUMPY_FLOAT_TYPE NPY_FLOAT64 #define LASP_NUMPY_COMPLEX_TYPE NPY_COMPLEX128 #else @@ -31,7 +32,16 @@ static inline void capsule_cleanup(PyObject *capsule) { #endif -static inline PyObject *data_to_ndarray(void *data, int n_rows, int n_cols, +/** + * Create a numpy array from a raw data pointer. + * + * @param data pointer to data, assumes d* for data + * @param transfer_ownership If set to true, Numpy array will be responsible + * for freeing the data. + * + * @return Numpy array + */ +static inline PyObject *data_to_ndarray(d *data, int n_rows, int n_cols, int typenum, bool transfer_ownership, bool F_contiguous) { diff --git a/lasp/c/lasp_sosfilterbank.h b/lasp/c/lasp_sosfilterbank.h index b38309c..6950627 100644 --- a/lasp/c/lasp_sosfilterbank.h +++ b/lasp/c/lasp_sosfilterbank.h @@ -8,6 +8,7 @@ #pragma once #ifndef LASP_FILTERBANK_H #define LASP_FILTERBANK_H +#include "lasp_config.h" #include "lasp_types.h" #include "lasp_mat.h" diff --git a/lasp/c/lasp_tracer.c b/lasp/c/lasp_tracer.c index f122a77..bb3bf06 100644 --- a/lasp/c/lasp_tracer.c +++ b/lasp/c/lasp_tracer.c @@ -3,8 +3,9 @@ // last-edit-by: J.A. de Jong // // Description: -// +// Debug tracing code implementation ////////////////////////////////////////////////////////////////////// +#include "lasp_config.h" #if TRACER == 1 #include #include "lasp_tracer.h" diff --git a/lasp/c/lasp_tracer.h b/lasp/c/lasp_tracer.h index 1db54d6..f767168 100644 --- a/lasp/c/lasp_tracer.h +++ b/lasp/c/lasp_tracer.h @@ -6,8 +6,9 @@ // Basic tracing code for debugging. ////////////////////////////////////////////////////////////////////// #pragma once -#ifndef ASCEE_TRACER_H -#define ASCEE_TRACER_H +#ifndef LASP_TRACER_H +#define LASP_TRACER_H +#include "lasp_config.h" #include "lasp_types.h" #include #include @@ -226,5 +227,5 @@ void uvartrace_impl(const char* pos,int line,const char* varname,size_t var); #endif // ######################################## TRACER ==1 -#endif // ASCEE_TRACER_H +#endif // LASP_TRACER_H ////////////////////////////////////////////////////////////////////// diff --git a/lasp/c/lasp_types.h b/lasp/c/lasp_types.h index c8b17be..bb29d90 100644 --- a/lasp/c/lasp_types.h +++ b/lasp/c/lasp_types.h @@ -9,7 +9,9 @@ #pragma once #ifndef LASP_TYPES_H #define LASP_TYPES_H +#include "lasp_config.h" #include + // // Branch prediction performance improvement #if !defined(islikely) && defined(__GNUC__) && !defined(LASP_DEBUG) #define islikely(x) __builtin_expect(!!(x), 1) @@ -20,30 +22,41 @@ #endif // !defined(likely) /// We often use boolean values +#ifndef __cplusplus #include // true, false #include -#include +#endif typedef size_t us; /* Size type I always use */ // To change the whole code to 32-bit floating points, change this to // float. #if LASP_FLOAT == 32 typedef float d; /* Shortcut for double */ -typedef float complex c; #elif LASP_FLOAT == 64 typedef double d; /* Shortcut for double */ -typedef double complex c; #else #error LASP_FLOAT should be either 32 or 64 #endif +#include +#ifdef __cplusplus +typedef std::complex c; +#else +#if LASP_FLOAT == 32 +typedef float complex c; +#else +typedef double complex c; +#endif +#endif + + /// I need these numbers so often, that they can be in the global /// namespace. -#define SUCCESS 0 -#define INTERRUPTED (-3) -#define MALLOC_FAILED (-1) -#define FAILURE -2 +#define LASP_SUCCESS 0 +#define LASP_INTERRUPTED (-3) +#define LASP_MALLOC_FAILED (-1) +#define LASP_FAILURE (-2) #endif // LASP_TYPES_H diff --git a/lasp/c/lasp_window.c b/lasp/c/lasp_window.c index 00cd797..9f11123 100644 --- a/lasp/c/lasp_window.c +++ b/lasp/c/lasp_window.c @@ -104,7 +104,7 @@ int window_create(const WindowType wintype,vd* result,d* win_pow) { *win_pow = signal_power(result); feTRACE(15); - return SUCCESS; + return LASP_SUCCESS; } diff --git a/lasp/cmake/BuildType.cmake b/lasp/cmake/BuildType.cmake new file mode 100644 index 0000000..caeee6d --- /dev/null +++ b/lasp/cmake/BuildType.cmake @@ -0,0 +1,13 @@ +# Set a default build type if none was specified +set(default_build_type "Release") +if(EXISTS "${CMAKE_SOURCE_DIR}/.git") + set(default_build_type "Debug") +endif() + +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Setting build type to '${default_build_type}' as none was specified.") + set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE + STRING "Choose the type of build." FORCE) + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release") +endif() diff --git a/lasp/device/CMakeLists.txt b/lasp/device/CMakeLists.txt index cec4915..a40bdd7 100644 --- a/lasp/device/CMakeLists.txt +++ b/lasp/device/CMakeLists.txt @@ -1,12 +1,13 @@ set(cpp_daq_files lasp_cppdaq.cpp) -set(cpp_daq_linklibs pthread) +set(cpp_daq_linklibs ${LASP_THREADING_LIBRARIES}) +include_directories(../c) -if(LASP_RTAUDIO) +if(LASP_HAS_RTAUDIO) include_directories(/usr/include/rtaudio) list(APPEND cpp_daq_files lasp_cpprtaudio.cpp) list(PREPEND cpp_daq_linklibs rtaudio) endif() -if(LASP_ULDAQ) +if(LASP_HAS_ULDAQ) list(APPEND cpp_daq_files lasp_cppuldaq.cpp) list(PREPEND cpp_daq_linklibs uldaq) endif() diff --git a/lasp/device/lasp_common_decls.pxd b/lasp/device/lasp_common_decls.pxd index 8152470..5fec933 100644 --- a/lasp/device/lasp_common_decls.pxd +++ b/lasp/device/lasp_common_decls.pxd @@ -37,7 +37,7 @@ cdef extern from "lasp_pyarray.h": bool transfer_ownership, bool F_contiguous) -ctypedef unsigned us +ctypedef size_t us ctypedef vector[bool] boolvec ctypedef vector[double] dvec ctypedef vector[us] usvec diff --git a/lasp/device/lasp_cppdaq.h b/lasp/device/lasp_cppdaq.h index c238c12..c342fc0 100644 --- a/lasp/device/lasp_cppdaq.h +++ b/lasp/device/lasp_cppdaq.h @@ -1,11 +1,13 @@ #ifndef LASP_CPPDAQ_H #define LASP_CPPDAQ_H +#include "lasp_config.h" +#include "lasp_types.h" -#ifdef HAS_RTAUDIO_API +#ifdef LASP_HAS_RTAUDIO #include #endif -#ifdef HAS_ULDAQ_API +#ifdef LASP_HAS_ULDAQ #include #endif @@ -25,8 +27,6 @@ using std::string; using std::vector; using std::to_string; - -typedef unsigned int us; typedef vector boolvec; typedef vector dvec; typedef vector usvec; @@ -76,10 +76,10 @@ class DaqApi { static vector getAvailableApis(); }; -#ifdef HAS_ULDAQ_API +#ifdef LASP_HAS_ULDAQ const DaqApi uldaqapi("UlDaq", 0); #endif -#ifdef HAS_RTAUDIO_API +#ifdef LASP_HAS_RTAUDIO const DaqApi rtaudioAlsaApi("RtAudio Linux ALSA", 1, RtAudio::Api::LINUX_ALSA); const DaqApi rtaudioPulseaudioApi("RtAudio Linux Pulseaudio", 2, RtAudio::Api::LINUX_PULSE); diff --git a/lasp/device/lasp_cpprtaudio.cpp b/lasp/device/lasp_cpprtaudio.cpp index 8a77d01..a12ca76 100644 --- a/lasp/device/lasp_cpprtaudio.cpp +++ b/lasp/device/lasp_cpprtaudio.cpp @@ -4,6 +4,7 @@ #include #include #include + #if MS_WIN64 typedef uint8_t u_int8_t; #endif @@ -181,7 +182,7 @@ class AudioDaq: public Daq { instreamparams, format, (us) samplerate(), - &nFramesPerBlock, + (unsigned*) &nFramesPerBlock, &mycallback, (void*) this, &streamoptions, diff --git a/lasp/device/lasp_cppuldaq.cpp b/lasp/device/lasp_cppuldaq.cpp index 70e230f..064e324 100644 --- a/lasp/device/lasp_cppuldaq.cpp +++ b/lasp/device/lasp_cppuldaq.cpp @@ -70,7 +70,7 @@ public: UlError err; us numdevs = MAX_DEV_COUNT_PER_API; - err = ulGetDaqDeviceInventory(interfaceType, devdescriptors, &numdevs); + err = ulGetDaqDeviceInventory(interfaceType, devdescriptors, (unsigned*) &numdevs); if (err != ERR_NO_ERROR) { throw runtime_error("Device inventarization failed"); } @@ -531,7 +531,7 @@ void fillUlDaqDeviceInfo(vector &devinfolist) { DaqDeviceDescriptor descriptor; DaqDeviceInterface interfaceType = ANY_IFC; - err = ulGetDaqDeviceInventory(interfaceType, devdescriptors, &numdevs); + err = ulGetDaqDeviceInventory(interfaceType, devdescriptors,static_cast(&numdevs)); if (err != ERR_NO_ERROR) throw std::runtime_error("UlDaq device inventarization failed"); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f077ccc..1159d75 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,10 +6,10 @@ add_executable(test_workers test_workers.c) add_executable(test_fft test_fft.c) add_executable(test_math test_math.c) -target_link_libraries(test_bf lasp_lib) -target_link_libraries(test_fft lasp_lib) -target_link_libraries(test_workers lasp_lib) -target_link_libraries(test_math lasp_lib) +target_link_libraries(test_bf lasp_lib ${LASP_THREADING_LIBRARIES}) +target_link_libraries(test_fft lasp_lib ${LASP_THREADING_LIBRARIES}) +target_link_libraries(test_workers lasp_lib ${LASP_THREADING_LIBRARIES}) +target_link_libraries(test_math lasp_lib ${LASP_THREADING_LIBRARIES}) if(LASP_ULDAQ) add_executable(test_uldaq test_uldaq.cpp)