diff --git a/cmake/portaudio.cmake b/cmake/portaudio.cmake index 342fb1f..ae6dca5 100644 --- a/cmake/portaudio.cmake +++ b/cmake/portaudio.cmake @@ -2,6 +2,7 @@ if(LASP_HAS_PORTAUDIO) message("Building with Portaudio backend") if(WIN32) + set(PA_USE_ALSA FALSE CACHE BOOL "Build PortAudio with ALSA backend") else() # Unix set(PA_USE_ALSA TRUE CACHE BOOL "Build PortAudio with ALSA backend") @@ -9,7 +10,15 @@ if(LASP_HAS_PORTAUDIO) set(PA_USE_PULSEAUDIO FALSE CACHE BOOL "Build PortAudio with PulseAudio backend") set(PA_BUILD_SHARED_LIBS FALSE CACHE BOOL "Build static library") endif() + add_subdirectory(third_party/portaudio) include_directories(third_party/portaudio/include) link_directories(third_party/portaudio) + + if(PA_USE_ALSA) + add_definitions(-DLASP_HAS_PA_ALSA=1) + else() + add_definitions(-DLASP_HAS_PA_ALSA=0) + endif() + endif() diff --git a/cpp_src/device/lasp_streammgr.cpp b/cpp_src/device/lasp_streammgr.cpp index b72f575..526e0c8 100644 --- a/cpp_src/device/lasp_streammgr.cpp +++ b/cpp_src/device/lasp_streammgr.cpp @@ -75,7 +75,7 @@ StreamMgr::StreamMgr() { DEBUGTRACE_ENTER; // Trigger a scan for the available devices, in the background. - rescanDAQDevices(false); + rescanDAQDevices(true); } #if LASP_DEBUG == 1 void StreamMgr::checkRightThread() const { @@ -107,13 +107,44 @@ void StreamMgr::rescanDAQDevices(bool background, _pool.push_task(&StreamMgr::rescanDAQDevices_impl, this, callback); } } +#if LASP_HAS_PORTAUDIO && LASP_HAS_PA_ALSA +#include +void empty_handler(const char *file, int line, const char *function, int err, + const char *fmt, ...) {} + +// Temporarily set the ALSA eror handler to something that does nothing, to +// prevent ALSA from spitting out all kinds of misconfiguration errors. +class MuteErrHandler { + private: + snd_lib_error_handler_t _default_handler; + + public: + explicit MuteErrHandler() { + _default_handler = snd_lib_error; + snd_lib_error_set_handler(empty_handler); + } + + ~MuteErrHandler() { snd_lib_error_set_handler(_default_handler); } +}; +#else +// Does nothin in case of no ALSA +class MuteErrHandler {}; +#endif + void StreamMgr::rescanDAQDevices_impl(std::function callback) { DEBUGTRACE_ENTER; + assert(!_inputStream && !_outputStream); Lck lck(_mtx); - _devices = DeviceInfo::getDeviceInfo(); + // Alsa spits out annoying messages that are not useful + { + MuteErrHandler guard; + + _devices = DeviceInfo::getDeviceInfo(); + } if (callback) { callback(); } + _scanningDevices = false; } void StreamMgr::inCallback(const DaqData &data) { diff --git a/cpp_src/device/portaudio/lasp_portaudiodaq.cpp b/cpp_src/device/portaudio/lasp_portaudiodaq.cpp index a724b91..05e7cc7 100644 --- a/cpp_src/device/portaudio/lasp_portaudiodaq.cpp +++ b/cpp_src/device/portaudio/lasp_portaudiodaq.cpp @@ -93,6 +93,7 @@ void fillPortAudioDeviceInfo(DeviceInfoList &devinfolist) { d.api = portaudioALSAApi; break; case paASIO: + hasDuplexMode = true; d.api = portaudioASIOApi; break; case paDirectSound: