Skip to content

Commit

Permalink
Merge pull request #3263 from remjey/rnnoise-plugin
Browse files Browse the repository at this point in the history
obs-filters: Add RNNoise to noise suppression filter
  • Loading branch information
jp9000 committed Aug 18, 2020
2 parents 51462e4 + 7e39109 commit 076baa3
Show file tree
Hide file tree
Showing 6 changed files with 424 additions and 48 deletions.
68 changes: 68 additions & 0 deletions cmake/Modules/FindLibrnnoise.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Once done these will be defined:
#
# LIBRNNOISE_FOUND
# LIBRNNOISE_INCLUDE_DIRS
# LIBRNNOISE_LIBRARIES
#
# For use in OBS:
#
# RNNOISE_INCLUDE_DIR

find_package(PkgConfig QUIET)
if (PKG_CONFIG_FOUND)
pkg_check_modules(_RNNOISE QUIET rnnoise)
endif()

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_lib_suffix 64)
else()
set(_lib_suffix 32)
endif()

find_path(RNNOISE_INCLUDE_DIR
NAMES rnnoise.h
HINTS
ENV rnnoisePath${_lib_suffix}
ENV rnnoisePath
ENV DepsPath${_lib_suffix}
ENV DepsPath
${rnnoisePath${_lib_suffix}}
${rnnoisePath}
${DepsPath${_lib_suffix}}
${DepsPath}
${_RNNOISE_INCLUDE_DIRS}
PATHS
/usr/include /usr/local/include /opt/local/include /sw/include
PATH_SUFFIXES
include)

find_library(RNNOISE_LIB
NAMES ${_RNNOISE_LIBRARIES} rnnoise
HINTS
ENV rnnoisePath${_lib_suffix}
ENV rnnoisePath
ENV DepsPath${_lib_suffix}
ENV DepsPath
${rnnoisePath${_lib_suffix}}
${rnnoisePath}
${DepsPath${_lib_suffix}}
${DepsPath}
${_RNNOISE_LIBRARY_DIRS}
PATHS
/usr/lib /usr/local/lib /opt/local/lib /sw/lib
PATH_SUFFIXES
lib${_lib_suffix} lib
libs${_lib_suffix} libs
bin${_lib_suffix} bin
../lib${_lib_suffix} ../lib
../libs${_lib_suffix} ../libs
../bin${_lib_suffix} ../bin)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Librnnoise DEFAULT_MSG RNNOISE_LIB RNNOISE_INCLUDE_DIR)
mark_as_advanced(RNNOISE_INCLUDE_DIR RNNOISE_LIB)

if(LIBRNNOISE_FOUND)
set(LIBRNNOISE_INCLUDE_DIRS ${RNNOISE_INCLUDE_DIR})
set(LIBRNNOISE_LIBRARIES ${RNNOISE_LIB})
endif()
54 changes: 40 additions & 14 deletions plugins/obs-filters/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,48 @@
project(obs-filters)

option(DISABLE_SPEEXDSP "Disable building of the SpeexDSP-based Noise Suppression filter" OFF)
option(DISABLE_RNNOISE "Disable building of the RNNoise-based Noise Suppression filter" OFF)

if(DISABLE_SPEEXDSP)
message(STATUS "SpeexDSP support disabled")
set(LIBSPEEXDSP_FOUND FALSE)
if(DISABLE_SPEEXDSP AND DISABLE_RNNOISE)
message(STATUS "SpeexDSP and RNNoise support disabled")
set(NOISEREDUCTION_ENABLED FALSE)
else()
find_package(Libspeexdsp QUIET)

if(NOT LIBSPEEXDSP_FOUND)
message(STATUS "SpeexDSP support not found")
if(DISABLE_SPEEXDSP)
message(STATUS "SpeexDSP support disabled")
set(LIBSPEEXDSP_FOUND FALSE)
else()
message(STATUS "SpeexDSP supported")
set(obs-filters_LIBSPEEXDSP_SOURCES
find_package(Libspeexdsp QUIET)
if(NOT LIBSPEEXDSP_FOUND)
message(STATUS "SpeexDSP support not found")
set(LIBSPEEXDSP_FOUND FALSE)
else()
message(STATUS "SpeexDSP supported")
add_definitions(-DLIBSPEEXDSP_ENABLED)
endif()
endif()

if(DISABLE_RNNOISE)
message(STATUS "RNNoise support disabled")
set(LIBRNNOISE_FOUND FALSE)
else()
find_package(Librnnoise QUIET)
if(NOT LIBRNNOISE_FOUND)
message(STATUS "RNNoise support not found")
set(LIBRNNOISE_FOUND FALSE)
else()
message(STATUS "RNNoise supported")
add_definitions(-DLIBRNNOISE_ENABLED)
endif()

endif()

if(LIBSPEEXDSP_FOUND OR LIBRNNOISE_FOUND)
message(STATUS "Noise Reduction effect enabled")
set(obs-filters_NOISEREDUCTION_SOURCES
noise-suppress-filter.c)
set(obs-filters_LIBSPEEXDSP_LIBRARIES
${LIBSPEEXDSP_LIBRARIES})
set(obs-filters_NOISEREDUCTION_LIBRARIES
${LIBSPEEXDSP_LIBRARIES} ${LIBRNNOISE_LIBRARIES})
set(NOISEREDUCTION_ENABLED TRUE)
endif()
endif()

Expand All @@ -25,7 +51,7 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/obs-filters-config.h.in"

set(obs-filters_config_HEADERS
"${CMAKE_BINARY_DIR}/plugins/obs-filters/config/obs-filters-config.h")
include_directories(${LIBSPEEXDSP_INCLUDE_DIRS}
include_directories(${LIBSPEEXDSP_INCLUDE_DIRS} ${LIBRNNOISE_INCLUDE_DIRS}
"${CMAKE_BINARY_DIR}/plugins/obs-filters/config")

if(MSVC)
Expand Down Expand Up @@ -64,11 +90,11 @@ endif()
add_library(obs-filters MODULE
${obs-filters_SOURCES}
${obs-filters_config_HEADERS}
${obs-filters_LIBSPEEXDSP_SOURCES})
${obs-filters_NOISEREDUCTION_SOURCES})
target_link_libraries(obs-filters
libobs
${obs-filters_PLATFORM_DEPS}
${obs-filters_LIBSPEEXDSP_LIBRARIES})
${obs-filters_NOISEREDUCTION_LIBRARIES})
set_target_properties(obs-filters PROPERTIES FOLDER "plugins")

install_obs_plugin_with_data(obs-filters data)
3 changes: 3 additions & 0 deletions plugins/obs-filters/data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ ScaleFiltering.Bicubic="Bicubic"
ScaleFiltering.Lanczos="Lanczos"
ScaleFiltering.Area="Area"
NoiseSuppress.SuppressLevel="Suppression Level"
NoiseSuppress.Method="Method"
NoiseSuppress.Method.Speex="Speex (lower CPU usage)"
NoiseSuppress.Method.RNNoise="RNNoise (higher quality)"
Saturation="Saturation"
HueShift="Hue Shift"
Amount="Amount"
Expand Down
Loading

0 comments on commit 076baa3

Please sign in to comment.