Skip to content

Commit

Permalink
obs-filters: Factor out NVIDIA Audio effects
Browse files Browse the repository at this point in the history
Currently, the three NVIDIA Audio Effects (noise suppression, room echo
removal, noise suppression + room echo removal combined) are part of
the noise suppression filter.
Historically, it's because a lot of code was shared between speex,
rnnoise & NVIDIA noise suppression.
But the NVIDIA code has become bulkier & cumbersome due to:
- addition of other effects;
- addition of a deferred loading thread.
The factorisation makes the code very difficult to maintain for
(un)readability reasons.
This will make it easier to add other audio effects, should we wish to.
Developers life will be easier too when debugging.
The code has been reorganized and comments added.
I also added a mutex in the process_fx function to avoid a crash when
swapping effects.
A deprecation warning has been added to the noise suppression filter to
direct users to the new filter.

Signed-off-by: pkv <[email protected]>
  • Loading branch information
pkviet committed Aug 17, 2023
1 parent 32c0792 commit 84e4a18
Show file tree
Hide file tree
Showing 7 changed files with 986 additions and 35 deletions.
5 changes: 4 additions & 1 deletion plugins/obs-filters/cmake/legacy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ if(LIBNVVFX_FOUND)
target_sources(obs-filters PRIVATE nvidia-greenscreen-filter.c)
obs_status(STATUS "NVIDIA Video FX support enabled; requires redist to be installed by end-user")
endif()

if(LIBNVAFX_FOUND)
target_sources(obs-filters PRIVATE nvidia-audiofx-filter.c)
obs_status(STATUS "NVIDIA Audio FX support enabled; requires redist to be installed by end-user")
endif()
target_include_directories(obs-filters PRIVATE $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/config>)

target_link_libraries(obs-filters PRIVATE OBS::libobs)
Expand Down
1 change: 1 addition & 0 deletions plugins/obs-filters/cmake/nvidia.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ endif()

if(ENABLE_NVAFX)
target_enable_feature(obs-filters "NVIDIA Audio FX support" LIBNVAFX_ENABLED HAS_NOISEREDUCTION)
target_sources(obs-filters PRIVATE nvidia-audiofx-filter.c)
else()
target_disable_feature(obs-filters "NVIDIA Audio FX support")
endif()
Expand Down
2 changes: 2 additions & 0 deletions plugins/obs-filters/data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ NoiseSuppress.Method.Nvafx.Denoiser="NVIDIA Noise Removal"
NoiseSuppress.Method.Nvafx.Dereverb="NVIDIA Room Echo Removal"
NoiseSuppress.Method.Nvafx.DenoiserPlusDereverb="NVIDIA Noise Removal + Room Echo Removal"
NoiseSuppress.Method.Nvafx.Deprecation="WARNING: Please upgrade both NVIDIA Video & Audio SDK. Your current version of Audio SDK is outdated."
NoiseSuppress.Method.Nvafx.Deprecation2="WARNING: NVIDIA Audio Effects are planned for removal from the 'noise suppression' filter. If you use them, please migrate to the new dedicated filter 'NVIDIA Audio Effects'."
Saturation="Saturation"
HueShift="Hue Shift"
Amount="Amount"
Expand Down Expand Up @@ -133,3 +134,4 @@ Upward.Compressor="Upward Compressor"
3BandEq.low="Low"
3BandEq.mid="Mid"
3BandEq.high="High"
NvidiaAudioFX="NVIDIA Audio Effects"
43 changes: 43 additions & 0 deletions plugins/obs-filters/noise-suppress-filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ bool nvafx_loaded = false;
MT_("NoiseSuppress.Method.Nvafx.DenoiserPlusDereverb")
#define TEXT_METHOD_NVAFX_DEPRECATION \
MT_("NoiseSuppress.Method.Nvafx.Deprecation")
#define TEXT_METHOD_NVAFX_DEPRECATION2 \
MT_("NoiseSuppress.Method.Nvafx.Deprecation2")

#define MAX_PREPROC_CHANNELS 8

Expand Down Expand Up @@ -622,6 +624,41 @@ static void noise_suppress_update(void *data, obs_data_t *s)
#pragma warning(push)
#pragma warning(disable : 4706)
#endif
void release_lib(void)
{
#ifdef LIBNVAFX_ENABLED
NvAFX_GetEffectList = NULL;
NvAFX_CreateEffect = NULL;
NvAFX_CreateChainedEffect = NULL;
NvAFX_DestroyEffect = NULL;
NvAFX_SetU32 = NULL;
NvAFX_SetU32List = NULL;
NvAFX_SetString = NULL;
NvAFX_SetStringList = NULL;
NvAFX_SetFloat = NULL;
NvAFX_SetFloatList = NULL;
NvAFX_GetU32 = NULL;
NvAFX_GetString = NULL;
NvAFX_GetStringList = NULL;
NvAFX_GetFloat = NULL;
NvAFX_GetFloatList = NULL;
NvAFX_Load = NULL;
NvAFX_GetSupportedDevices = NULL;
NvAFX_Run = NULL;
NvAFX_Reset = NULL;
if (nv_audiofx) {
FreeLibrary(nv_audiofx);
nv_audiofx = NULL;
}
cuCtxGetCurrent = NULL;
cuCtxPopCurrent = NULL;
cuInit = NULL;
if (nv_cuda) {
FreeLibrary(nv_cuda);
nv_cuda = NULL;
}
#endif
}
bool load_nvafx(void)
{
#ifdef LIBNVAFX_ENABLED
Expand Down Expand Up @@ -1234,6 +1271,12 @@ static obs_properties_t *noise_suppress_properties(void *data)
obs_property_set_long_description(
warning, TEXT_METHOD_NVAFX_DEPRECATION);
}
obs_property_t *warning2 = obs_properties_add_text(ppts, "deprecation2",
NULL, OBS_TEXT_INFO);
obs_property_text_set_info_type(warning2, OBS_TEXT_INFO_WARNING);
obs_property_set_long_description(warning2,
TEXT_METHOD_NVAFX_DEPRECATION2);

#if defined(LIBRNNOISE_ENABLED) && defined(LIBSPEEXDSP_ENABLED)
if (!nvafx_loaded) {
obs_property_list_item_disable(method, 2, true);
Expand Down
36 changes: 2 additions & 34 deletions plugins/obs-filters/nvafx-load.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once
#include <Windows.h>
#include <stdio.h>
#include <stdbool.h>
Expand Down Expand Up @@ -252,40 +253,6 @@ static cuCtxGetCurrent_t cuCtxGetCurrent = NULL;
static cuCtxPopCurrent_t cuCtxPopCurrent = NULL;
static cuInit_t cuInit = NULL;

void release_lib(void)
{
NvAFX_GetEffectList = NULL;
NvAFX_CreateEffect = NULL;
NvAFX_CreateChainedEffect = NULL;
NvAFX_DestroyEffect = NULL;
NvAFX_SetU32 = NULL;
NvAFX_SetU32List = NULL;
NvAFX_SetString = NULL;
NvAFX_SetStringList = NULL;
NvAFX_SetFloat = NULL;
NvAFX_SetFloatList = NULL;
NvAFX_GetU32 = NULL;
NvAFX_GetString = NULL;
NvAFX_GetStringList = NULL;
NvAFX_GetFloat = NULL;
NvAFX_GetFloatList = NULL;
NvAFX_Load = NULL;
NvAFX_GetSupportedDevices = NULL;
NvAFX_Run = NULL;
NvAFX_Reset = NULL;
if (nv_audiofx) {
FreeLibrary(nv_audiofx);
nv_audiofx = NULL;
}
cuCtxGetCurrent = NULL;
cuCtxPopCurrent = NULL;
cuInit = NULL;
if (nv_cuda) {
FreeLibrary(nv_cuda);
nv_cuda = NULL;
}
}

static bool nvafx_get_sdk_path(char *buffer, const size_t len)
{
DWORD ret =
Expand Down Expand Up @@ -334,4 +301,5 @@ static unsigned int get_lib_version(void)
SetDllDirectoryA(NULL);
return version;
}

#endif
Loading

0 comments on commit 84e4a18

Please sign in to comment.