Skip to content

Commit

Permalink
Audaspace: add support for PulseAudio on Linux
Browse files Browse the repository at this point in the history
This adds PulseAudio as audio backend on Linux.
PulseAudio is the main audio engine used on most,
if not all, Linux distributions today.

Ref T86590
  • Loading branch information
neXyon committed Mar 16, 2021
1 parent 7b8fc30 commit d33339e
Show file tree
Hide file tree
Showing 23 changed files with 728 additions and 2 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ endif()
if(UNIX AND NOT APPLE)
option(WITH_SDL_DYNLOAD "Enable runtime dynamic SDL libraries loading" OFF)
endif()
if(UNIX AND NOT APPLE)
option(WITH_PULSEAUDIO "Enable PulseAudio for audio support on Linux" ON)
option(WITH_PULSEAUDIO_DYNLOAD "Enable runtime dynamic PulseAudio libraries loading" OFF)
else()
set(WITH_PULSEAUDIO OFF)
endif()

# Compression
option(WITH_LZO "Enable fast LZO compression (used for pointcache)" ON)
Expand Down Expand Up @@ -675,6 +681,7 @@ endif()

set_and_warn_dependency(WITH_AUDASPACE WITH_OPENAL OFF)
set_and_warn_dependency(WITH_AUDASPACE WITH_JACK OFF)
set_and_warn_dependency(WITH_AUDASPACE WITH_PULSEAUDIO OFF)

if(NOT WITH_SDL AND WITH_GHOST_SDL)
message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL")
Expand Down Expand Up @@ -1937,6 +1944,8 @@ if(FIRST_RUN)
info_cfg_option(WITH_OPENAL)
info_cfg_option(WITH_SDL)
info_cfg_option(WITH_SDL_DYNLOAD)
info_cfg_option(WITH_PULSEAUDIO)
info_cfg_option(WITH_PULSEAUDIO_DYNLOAD)

info_cfg_text("Compression:")
info_cfg_option(WITH_LZMA)
Expand Down
33 changes: 32 additions & 1 deletion build_files/build_environment/install_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ARGS=$( \
getopt \
-o s:i:t:h \
--long source:,install:,tmp:,info:,threads:,help,show-deps,no-sudo,no-build,no-confirm,\
with-all,with-opencollada,with-jack,with-embree,with-oidn,with-nanovdb,\
with-all,with-opencollada,with-jack,with-pulseaudio,with-embree,with-oidn,with-nanovdb,\
ver-ocio:,ver-oiio:,ver-llvm:,ver-osl:,ver-osd:,ver-openvdb:,ver-xr-openxr:,\
force-all,force-python,force-boost,force-tbb,\
force-ocio,force-openexr,force-oiio,force-llvm,force-osl,force-osd,force-openvdb,\
Expand Down Expand Up @@ -157,6 +157,9 @@ ARGUMENTS_INFO="\"COMMAND LINE ARGUMENTS:
--with-jack
Install the jack libraries.
--with-pulseaudio
Install the pulseaudio libraries.
--ver-ocio=<ver>
Force version of OCIO library.
Expand Down Expand Up @@ -721,6 +724,9 @@ while true; do
--with-jack)
WITH_JACK=true; shift; continue;
;;
--with-pulseaudio)
WITH_PULSEAUDIO=true; shift; continue;
;;
--ver-ocio)
OCIO_VERSION="$2"
OCIO_VERSION_MIN=$OCIO_VERSION
Expand Down Expand Up @@ -985,6 +991,7 @@ fi
if [ "$WITH_ALL" = true ]; then
WITH_JACK=true
WITH_NANOVDB=true
WITH_PULSEAUDIO=true
fi

if [ "$WITH_NANOVDB" = true ]; then
Expand Down Expand Up @@ -3877,6 +3884,10 @@ install_DEB() {
fi
fi

if [ "$WITH_PULSEAUDIO" = true ]; then
_packages="$_packages libpulse-dev"
fi

PRINT ""
install_packages_DEB $_packages

Expand Down Expand Up @@ -4499,6 +4510,10 @@ install_RPM() {
_packages="$_packages jack-audio-connection-kit-devel"
fi

if [ "$WITH_PULSEAUDIO" = true ]; then
_packages="$_packages pulseaudio-libs-devel"
fi

PRINT ""
install_packages_RPM $_packages

Expand Down Expand Up @@ -4542,6 +4557,10 @@ install_RPM() {
X264_USE=true
fi

if [ "$WITH_PULSEAUDIO" = true ]; then
_packages="$_packages libpulse-devel"
fi

if [ "$WITH_ALL" = true ]; then
PRINT ""
XVID_DEV="libxvidcore-devel"
Expand Down Expand Up @@ -5073,6 +5092,10 @@ install_ARCH() {
_packages="$_packages jack2"
fi

if [ "$WITH_PULSEAUDIO" = true ]; then
_packages="$_packages libpulse"
fi

PRINT ""
install_packages_ARCH $_packages

Expand Down Expand Up @@ -5888,6 +5911,14 @@ print_info() {
_buildargs="$_buildargs $_1 $_2"
fi

if [ "$WITH_PULSEAUDIO" = true ]; then
_1="-D WITH_PULSEAUDIO=ON"
_2="-D WITH_PULSEAUDIO_DYNLOAD=ON"
PRINT " $_1"
PRINT " $_2"
_buildargs="$_buildargs $_1 $_2"
fi

if [ "$ALEMBIC_SKIP" = false ]; then
_1="-D WITH_ALEMBIC=ON"
PRINT " $_1"
Expand Down
1 change: 1 addition & 0 deletions build_files/buildbot/config/blender_linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(WITH_DOC_MANPAGE OFF CACHE BOOL "" FORCE)
# Options which are specific to Linux release builds only

set(WITH_JACK_DYNLOAD ON CACHE BOOL "" FORCE)
set(WITH_PULSEAUDIO_DYNLOAD ON CACHE BOOL "" FORCE)
set(WITH_SDL_DYNLOAD ON CACHE BOOL "" FORCE)

# ######## Release environment specific settings ########
Expand Down
60 changes: 60 additions & 0 deletions build_files/cmake/Modules/FindPulse.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# - Find PulseAudio library
# Find the native PulseAudio includes and library
# This module defines
# LIBPULSE_INCLUDE_DIRS, where to find pulse/pulseaudio.h, Set when
# LIBPULSE_INCLUDE_DIR is found.
# LIBPULSE_LIBRARIES, libraries to link against to use PulseAudio.
# LIBPULSE_ROOT_DIR, The base directory to search for PulseAudio.
# This can also be an environment variable.
# PULSE_FOUND, If false, do not try to use PulseAudio.
#
# also defined, but not for general use are
# LIBPULSE_LIBRARY, where to find the PulseAudio library.

#=============================================================================
# Copyright 2021 Blender Foundation.
#
# Distributed under the OSI-approved BSD 3-Clause License,
# see accompanying file BSD-3-Clause-license.txt for details.
#=============================================================================

# If LIBPULSE_ROOT_DIR was defined in the environment, use it.
IF(NOT LIBPULSE_ROOT_DIR AND NOT $ENV{LIBPULSE_ROOT_DIR} STREQUAL "")
SET(LIBPULSE_ROOT_DIR $ENV{LIBPULSE_ROOT_DIR})
ENDIF()

SET(_pulse_SEARCH_DIRS
${LIBPULSE_ROOT_DIR}
)

FIND_PATH(LIBPULSE_INCLUDE_DIR pulse/pulseaudio.h
HINTS
${_pulse_SEARCH_DIRS}
PATH_SUFFIXES
include
)

FIND_LIBRARY(LIBPULSE_LIBRARY
NAMES
pulse
HINTS
${_pulse_SEARCH_DIRS}
PATH_SUFFIXES
lib64 lib
)

# handle the QUIETLY and REQUIRED arguments and set PULSE_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Pulse DEFAULT_MSG
LIBPULSE_LIBRARY LIBPULSE_INCLUDE_DIR)

IF(PULSE_FOUND)
SET(LIBPULSE_LIBRARIES ${LIBPULSE_LIBRARY})
SET(LIBPULSE_INCLUDE_DIRS ${LIBPULSE_INCLUDE_DIR})
ENDIF()

MARK_AS_ADVANCED(
LIBPULSE_INCLUDE_DIR
LIBPULSE_LIBRARY
)
1 change: 1 addition & 0 deletions build_files/cmake/config/blender_full.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ endif()
if(UNIX AND NOT APPLE)
set(WITH_DOC_MANPAGE ON CACHE BOOL "" FORCE)
set(WITH_GHOST_XDND ON CACHE BOOL "" FORCE)
set(WITH_PULSEAUDIO ON CACHE BOOL "" FORCE)
set(WITH_X11_XINPUT ON CACHE BOOL "" FORCE)
set(WITH_X11_XF86VMODE ON CACHE BOOL "" FORCE)
endif()
Expand Down
1 change: 1 addition & 0 deletions build_files/cmake/config/blender_headless.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set(WITH_HEADLESS ON CACHE BOOL "" FORCE)
# so the python module doesn't hold the audio device and loads quickly.
set(WITH_AUDASPACE OFF CACHE BOOL "" FORCE)
set(WITH_JACK OFF CACHE BOOL "" FORCE)
set(WITH_PULSEAUDIO OFF CACHE BOOL "" FORCE)
set(WITH_SDL OFF CACHE BOOL "" FORCE)
set(WITH_OPENAL OFF CACHE BOOL "" FORCE)
set(WITH_CODEC_FFMPEG OFF CACHE BOOL "" FORCE)
Expand Down
1 change: 1 addition & 0 deletions build_files/cmake/config/blender_lite.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ set(WITH_OPENSUBDIV OFF CACHE BOOL "" FORCE)
set(WITH_OPENVDB OFF CACHE BOOL "" FORCE)
set(WITH_POTRACE OFF CACHE BOOL "" FORCE)
set(WITH_PUGIXML OFF CACHE BOOL "" FORCE)
set(WITH_PULSEAUDIO OFF CACHE BOOL "" FORCE)
set(WITH_NANOVDB OFF CACHE BOOL "" FORCE)
set(WITH_QUADRIFLOW OFF CACHE BOOL "" FORCE)
set(WITH_SDL OFF CACHE BOOL "" FORCE)
Expand Down
1 change: 1 addition & 0 deletions build_files/cmake/config/blender_release.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ endif()
if(UNIX AND NOT APPLE)
set(WITH_DOC_MANPAGE ON CACHE BOOL "" FORCE)
set(WITH_GHOST_XDND ON CACHE BOOL "" FORCE)
set(WITH_PULSEAUDIO ON CACHE BOOL "" FORCE)
set(WITH_X11_XINPUT ON CACHE BOOL "" FORCE)
set(WITH_X11_XF86VMODE ON CACHE BOOL "" FORCE)
endif()
Expand Down
1 change: 1 addition & 0 deletions build_files/cmake/config/bpy_module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(WITH_PYTHON_INSTALL OFF CACHE BOOL "" FORCE)
# so the python module doesn't hold the audio device and loads quickly.
set(WITH_AUDASPACE OFF CACHE BOOL "" FORCE)
set(WITH_JACK OFF CACHE BOOL "" FORCE)
set(WITH_PULSEAUDIO OFF CACHE BOOL "" FORCE)
set(WITH_SDL OFF CACHE BOOL "" FORCE)
set(WITH_OPENAL OFF CACHE BOOL "" FORCE)
set(WITH_CODEC_FFMPEG OFF CACHE BOOL "" FORCE)
Expand Down
3 changes: 3 additions & 0 deletions build_files/cmake/macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,9 @@ function(SETUP_LIBDIRS)
if(WITH_JACK AND NOT WITH_JACK_DYNLOAD)
link_directories(${JACK_LIBPATH})
endif()
if(WITH_PULSEAUDIO AND NOT WITH_PULSEAUDIO_DYNLOAD)
link_directories(${LIBPULSE_LIBPATH})
endif()
if(WITH_CODEC_SNDFILE)
link_directories(${LIBSNDFILE_LIBPATH})
endif()
Expand Down
8 changes: 8 additions & 0 deletions build_files/cmake/platform/platform_unix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,14 @@ if(WITH_JACK)
endif()
endif()

# Pulse is intended to use the system library.
if(WITH_PULSEAUDIO)
find_package_wrapper(Pulse)
if(NOT PULSE_FOUND)
set(WITH_PULSEAUDIO OFF)
endif()
endif()

# Audio IO
if(WITH_SYSTEM_AUDASPACE)
find_package_wrapper(Audaspace)
Expand Down
3 changes: 3 additions & 0 deletions doc/doxygen/doxygen.intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
/** \defgroup audopenal Audaspace OpenAL
* \ingroup audaspace
*/
/** \defgroup audpulseaudio Audaspace PulseAudio
* \ingroup audaspace
*/
/** \defgroup audpython Audaspace Python
* \ingroup audaspace
*/
Expand Down
55 changes: 55 additions & 0 deletions extern/audaspace/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ if(AUDASPACE_STANDALONE)
option(WITH_SDL "Build With SDL" TRUE)
option(WITH_STRICT_DEPENDENCIES "Error and abort instead of warning if a library is not found." FALSE)

if(NOT WIN32 AND NOT APPLE)
option(WITH_PULSEAUDIO "Build With PulseAudio" TRUE)
endif()

if(WITH_STRICT_DEPENDENCIES)
set(PACKAGE_OPTION REQUIRED)
endif()
Expand All @@ -306,10 +310,12 @@ if(AUDASPACE_STANDALONE)
cmake_dependent_option(PLUGIN_JACK "Build JACK Plugin" TRUE "WITH_JACK;SHARED_LIBRARY" FALSE)
cmake_dependent_option(PLUGIN_LIBSNDFILE "Build LibSndFile Plugin" TRUE "WITH_LIBSNDFILE;SHARED_LIBRARY" FALSE)
cmake_dependent_option(PLUGIN_OPENAL "Build OpenAL Plugin" TRUE "WITH_OPENAL;SHARED_LIBRARY" FALSE)
cmake_dependent_option(PLUGIN_PULSEAUDIO "Build PulseAudio Plugin" TRUE "WITH_PULSEAUDIO;SHARED_LIBRARY" FALSE)
cmake_dependent_option(PLUGIN_SDL "Build SDL Plugin" TRUE "WITH_SDL;SHARED_LIBRARY" FALSE)
cmake_dependent_option(WITH_PYTHON_MODULE "Build Python Module" TRUE "WITH_PYTHON" FALSE)
cmake_dependent_option(USE_SDL2 "Use SDL2 instead of 1 if available" TRUE "WITH_SDL" FALSE)
cmake_dependent_option(DYNLOAD_JACK "Dynamically load JACK" FALSE "WITH_JACK" FALSE)
cmake_dependent_option(DYNLOAD_PULSEAUDIO "Dynamically load PulseAudio" FALSE "WITH_PULSEAUDIO" FALSE)
cmake_dependent_option(WITH_BINDING_DOCS "Build C/Python HTML Documentation with Sphinx" TRUE "WITH_PYTHON_MODULE" FALSE)
endif()

Expand Down Expand Up @@ -598,6 +604,42 @@ if(WITH_OPENAL)
endif()
endif()

# PulseAudio
if(WITH_PULSEAUDIO)
if(AUDASPACE_STANDALONE)
find_package(LibPulse ${PACKAGE_OPTION})
endif()

if(LIBPULSE_FOUND)
set(PULSEAUDIO_SRC
plugins/pulseaudio/PulseAudioDevice.cpp
plugins/pulseaudio/PulseAudioLibrary.cpp
)
set(PULSEAUDIO_HDR
plugins/pulseaudio/PulseAudioDevice.h
plugins/pulseaudio/PulseAudioLibrary.h
plugins/pulseaudio/PulseAudioSymbols.h
)

if(DYNLOAD_PULSEAUDIO)
add_definitions(-DDYNLOAD_PULSEAUDIO)
endif()

if(NOT PLUGIN_PULSEAUDIO)
list(APPEND INCLUDE ${LIBPULSE_INCLUDE_DIR})
if(NOT DYNLOAD_PULSEAUDIO)
list(APPEND LIBRARIES ${LIBPULSE_LIBRARY})
endif()
list(APPEND SRC ${PULSEAUDIO_SRC})
list(APPEND HDR ${PULSEAUDIO_HDR})
list(APPEND STATIC_PLUGINS PulseAudioDevice)
endif()
else()
set(WITH_PULSEAUDIO FALSE CACHE BOOL "Build With PulseAudio" FORCE)
message(WARNING "PulseAudio not found, plugin will not be built.")
endif()
endif()

# Python
if(WITH_PYTHON)
if(AUDASPACE_STANDALONE)
Expand Down Expand Up @@ -797,6 +839,19 @@ if(WITH_OPENAL AND PLUGIN_OPENAL)
install(TARGETS audopenal DESTINATION ${DEFAULT_PLUGIN_PATH})
endif()

if(WITH_PULSEAUDIO AND PLUGIN_PULSEAUDIO)
add_definitions(-DPULSEAUDIO_PLUGIN)
include_directories(${INCLUDE} ${LIBPULSE_INCLUDE_DIR})
add_library(audpulseaudio SHARED ${PULSEAUDIO_SRC} ${PULSEAUDIO_HDR} ${HDR})
set_target_properties(audpulseaudio PROPERTIES SOVERSION ${AUDASPACE_VERSION})
if(DYNLOAD_PULSEAUDIO)
target_link_libraries(audpulseaudio audaspace)
else()
target_link_libraries(audpulseaudio audaspace ${LIBPULSE_LIBRARY})
endif()
install(TARGETS audpulseaudio DESTINATION ${DEFAULT_PLUGIN_PATH})
endif()

if(WITH_SDL AND PLUGIN_SDL)
add_definitions(-DSDL_PLUGIN)
include_directories(${INCLUDE} ${SDL_INCLUDE_DIR})
Expand Down
3 changes: 3 additions & 0 deletions extern/audaspace/blender_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ set(PLUGIN_FFMPEG FALSE) # "Build FFMPEG Plugin"
set(PLUGIN_JACK FALSE) # "Build JACK Plugin"
set(PLUGIN_LIBSNDFILE FALSE) # "Build LibSndFile Plugin"
set(PLUGIN_OPENAL FALSE) # "Build OpenAL Plugin"
set(PLUGIN_PULSEAUDIO FALSE) # "Build PulseAudio Plugin"
set(PLUGIN_SDL FALSE) # "Build SDL Plugin"
set(WITH_PYTHON_MODULE FALSE) # "Build Python Module"
set(DYNLOAD_JACK ${WITH_JACK_DYNLOAD}) # "Dynamically load JACK"
set(DYNLOAD_PULSEAUDIO ${WITH_PULSEAUDIO_DYNLOAD}) # "Dynamically load PulseAudio"
set(WITH_BINDING_DOCS FALSE) # "Build C/Python HTML Documentation with Sphinx"
set(DEFAULT_PLUGIN_PATH "plugins") # "Default plugin installation and loading path."
set(FFMPEG_FOUND ${WITH_CODEC_FFMPEG})
set(JACK_FOUND ${WITH_JACK})
set(LIBSNDFILE_FOUND ${WITH_CODEC_SNDFILE})
set(OPENAL_FOUND ${WITH_OPENAL})
set(LIBPULSE_FOUND ${WITH_PULSEAUDIO})
set(PYTHONLIBS_FOUND TRUE)
set(NUMPY_FOUND ${WITH_PYTHON_NUMPY})
set(NUMPY_INCLUDE_DIRS ${PYTHON_NUMPY_INCLUDE_DIRS})
Expand Down
Loading

0 comments on commit d33339e

Please sign in to comment.