diff --git a/plugins/obs-filters/data/locale/en-US.ini b/plugins/obs-filters/data/locale/en-US.ini index a5bdbfc7094918..9e39b02d1c9ef9 100644 --- a/plugins/obs-filters/data/locale/en-US.ini +++ b/plugins/obs-filters/data/locale/en-US.ini @@ -88,7 +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'." +NoiseSuppress.Method.Nvafx.Deprecation2="WARNING: NVIDIA Audio Effects have been removed 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" diff --git a/plugins/obs-filters/noise-suppress-filter.c b/plugins/obs-filters/noise-suppress-filter.c index e2b993877437be..6e11d617096ee1 100644 --- a/plugins/obs-filters/noise-suppress-filter.c +++ b/plugins/obs-filters/noise-suppress-filter.c @@ -41,7 +41,6 @@ bool nvafx_loaded = false; /* -------------------------------------------------------- */ #define S_SUPPRESS_LEVEL "suppress_level" -#define S_NVAFX_INTENSITY "intensity" #define S_METHOD "method" #define S_METHOD_SPEEX "speex" #define S_METHOD_RNN "rnnoise" @@ -51,7 +50,6 @@ bool nvafx_loaded = false; #define MT_ obs_module_text #define TEXT_SUPPRESS_LEVEL MT_("NoiseSuppress.SuppressLevel") -#define TEXT_NVAFX_INTENSITY MT_("NoiseSuppress.Intensity") #define TEXT_METHOD MT_("NoiseSuppress.Method") #define TEXT_METHOD_SPEEX MT_("NoiseSuppress.Method.Speex") #define TEXT_METHOD_RNN MT_("NoiseSuppress.Method.RNNoise") @@ -59,8 +57,6 @@ bool nvafx_loaded = false; #define TEXT_METHOD_NVAFX_DEREVERB MT_("NoiseSuppress.Method.Nvafx.Dereverb") #define TEXT_METHOD_NVAFX_DEREVERB_DENOISER \ 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") @@ -95,8 +91,6 @@ struct noise_suppress_data { struct circlebuf output_buffers[MAX_PREPROC_CHANNELS]; bool use_rnnoise; - bool use_nvafx; - bool nvafx_enabled; bool has_mono_src; volatile bool reinit_done; #ifdef LIBSPEEXDSP_ENABLED @@ -113,27 +107,6 @@ struct noise_suppress_data { audio_resampler_t *rnn_resampler_back; #endif -#ifdef LIBNVAFX_ENABLED - /* NVAFX handle, one per audio channel */ - NvAFX_Handle handle[MAX_PREPROC_CHANNELS]; - - uint32_t sample_rate; - float intensity_ratio; - unsigned int num_samples_per_frame, num_channels; - char *model; - bool nvafx_initialized; - const char *fx; - char *sdk_path; - - /* Resampler */ - audio_resampler_t *nvafx_resampler; - audio_resampler_t *nvafx_resampler_back; - - /* Initialization */ - bool nvafx_loading; - pthread_t nvafx_thread; - pthread_mutex_t nvafx_mutex; -#endif /* PCM buffers */ float *copy_buffers[MAX_PREPROC_CHANNELS]; #ifdef LIBSPEEXDSP_ENABLED @@ -142,21 +115,12 @@ struct noise_suppress_data { #ifdef LIBRNNOISE_ENABLED float *rnn_segment_buffers[MAX_PREPROC_CHANNELS]; #endif -#ifdef LIBNVAFX_ENABLED - float *nvafx_segment_buffers[MAX_PREPROC_CHANNELS]; -#endif /* output data */ struct obs_audio_data output_audio; DARRAY(float) output_data; }; -#ifdef LIBNVAFX_ENABLED -/* global mutex for nvafx load functions since they aren't thread-safe */ -bool nvafx_initializer_mutex_initialized; -pthread_mutex_t nvafx_initializer_mutex; -#endif - /* -------------------------------------------------------- */ #define SUP_MIN -60 @@ -179,25 +143,12 @@ static void noise_suppress_destroy(void *data) { struct noise_suppress_data *ng = data; -#ifdef LIBNVAFX_ENABLED - if (ng->nvafx_enabled) - pthread_mutex_lock(&ng->nvafx_mutex); -#endif - for (size_t i = 0; i < ng->channels; i++) { #ifdef LIBSPEEXDSP_ENABLED speex_preprocess_state_destroy(ng->spx_states[i]); #endif #ifdef LIBRNNOISE_ENABLED rnnoise_destroy(ng->rnn_states[i]); -#endif -#ifdef LIBNVAFX_ENABLED - if (ng->handle[0]) { - if (NvAFX_DestroyEffect(ng->handle[i]) != - NVAFX_STATUS_SUCCESS) { - do_log(LOG_ERROR, "NvAFX_Release() failed"); - } - } #endif circlebuf_free(&ng->input_buffers[i]); circlebuf_free(&ng->output_buffers[i]); @@ -214,183 +165,12 @@ static void noise_suppress_destroy(void *data) audio_resampler_destroy(ng->rnn_resampler_back); } #endif -#ifdef LIBNVAFX_ENABLED - bfree(ng->nvafx_segment_buffers[0]); - - if (ng->nvafx_resampler) { - audio_resampler_destroy(ng->nvafx_resampler); - audio_resampler_destroy(ng->nvafx_resampler_back); - } - bfree(ng->model); - bfree(ng->sdk_path); - bfree((void *)ng->fx); - if (ng->nvafx_enabled) { - if (ng->use_nvafx) - pthread_join(ng->nvafx_thread, NULL); - pthread_mutex_unlock(&ng->nvafx_mutex); - pthread_mutex_destroy(&ng->nvafx_mutex); - } -#endif - bfree(ng->copy_buffers[0]); circlebuf_free(&ng->info_buffer); da_free(ng->output_data); bfree(ng); } -static bool nvafx_initialize_internal(void *data) -{ -#ifdef LIBNVAFX_ENABLED - struct noise_suppress_data *ng = data; - NvAFX_Status err; - - if (!ng->handle[0]) { - ng->sample_rate = NVAFX_SAMPLE_RATE; - for (size_t i = 0; i < ng->channels; i++) { - // Create FX - CUcontext old = {0}; - CUcontext curr = {0}; - if (cuCtxGetCurrent(&old) != CUDA_SUCCESS) { - goto failure; - } - // if initialization was with rnnoise or speex - if (strcmp(ng->fx, S_METHOD_NVAFX_DENOISER) != 0 && - strcmp(ng->fx, S_METHOD_NVAFX_DEREVERB) != 0 && - strcmp(ng->fx, S_METHOD_NVAFX_DEREVERB_DENOISER) != - 0) { - ng->fx = bstrdup(S_METHOD_NVAFX_DENOISER); - } - err = NvAFX_CreateEffect(ng->fx, &ng->handle[i]); - if (err != NVAFX_STATUS_SUCCESS) { - do_log(LOG_ERROR, - "%s FX creation failed, error %i", - ng->fx, err); - goto failure; - } - if (cuCtxGetCurrent(&curr) != CUDA_SUCCESS) { - goto failure; - } - if (curr != old) { - cuCtxPopCurrent(NULL); - } - // Set sample rate of FX - err = NvAFX_SetU32(ng->handle[i], - NVAFX_PARAM_INPUT_SAMPLE_RATE, - ng->sample_rate); - if (err != NVAFX_STATUS_SUCCESS) { - do_log(LOG_ERROR, - "NvAFX_SetU32(Sample Rate: %u) failed, error %i", - ng->sample_rate, err); - goto failure; - } - - // Set intensity of FX - err = NvAFX_SetFloat(ng->handle[i], - NVAFX_PARAM_INTENSITY_RATIO, - ng->intensity_ratio); - if (err != NVAFX_STATUS_SUCCESS) { - do_log(LOG_ERROR, - "NvAFX_SetFloat(Intensity Ratio: %f) failed, error %i", - ng->intensity_ratio, err); - goto failure; - } - - // Set AI models path - err = NvAFX_SetString(ng->handle[i], - NVAFX_PARAM_MODEL_PATH, - ng->model); - if (err != NVAFX_STATUS_SUCCESS) { - do_log(LOG_ERROR, - "NvAFX_SetString() failed, error %i", - err); - goto failure; - } - - // Load FX - err = NvAFX_Load(ng->handle[i]); - if (err != NVAFX_STATUS_SUCCESS) { - do_log(LOG_ERROR, - "NvAFX_Load() failed with error %i", - err); - goto failure; - } - os_atomic_set_bool(&ng->reinit_done, true); - } - } - return true; - -failure: - ng->use_nvafx = false; - return false; - -#else - UNUSED_PARAMETER(data); - return false; -#endif -} - -static void *nvafx_initialize(void *data) -{ -#ifdef LIBNVAFX_ENABLED - struct noise_suppress_data *ng = data; - NvAFX_Status err; - - if (!ng->use_nvafx || !nvafx_loaded) { - return NULL; - } - pthread_mutex_lock(&ng->nvafx_mutex); - pthread_mutex_lock(&nvafx_initializer_mutex); - if (!nvafx_initialize_internal(data)) { - goto failure; - } - if (ng->use_nvafx) { - err = NvAFX_GetU32(ng->handle[0], - NVAFX_PARAM_NUM_INPUT_CHANNELS, - &ng->num_channels); - if (err != NVAFX_STATUS_SUCCESS) { - do_log(LOG_ERROR, - "NvAFX_GetU32() failed to get the number of channels, error %i", - err); - goto failure; - } - if (ng->num_channels != 1) { - do_log(LOG_ERROR, - "The number of channels is not 1 in the sdk any more ==> update code"); - goto failure; - } - NvAFX_Status err = NvAFX_GetU32( - ng->handle[0], NVAFX_PARAM_NUM_INPUT_SAMPLES_PER_FRAME, - &ng->num_samples_per_frame); - if (err != NVAFX_STATUS_SUCCESS) { - do_log(LOG_ERROR, - "NvAFX_GetU32() failed to get the number of samples per frame, error %i", - err); - goto failure; - } - if (ng->num_samples_per_frame != NVAFX_FRAME_SIZE) { - do_log(LOG_ERROR, - "The number of samples per frame has changed from 480 (= 10 ms) ==> update code"); - goto failure; - } - } - ng->nvafx_initialized = true; - ng->nvafx_loading = false; - pthread_mutex_unlock(&nvafx_initializer_mutex); - pthread_mutex_unlock(&ng->nvafx_mutex); - return NULL; - -failure: - ng->use_nvafx = false; - pthread_mutex_unlock(&nvafx_initializer_mutex); - pthread_mutex_unlock(&ng->nvafx_mutex); - return NULL; - -#else - UNUSED_PARAMETER(data); - return NULL; -#endif -} - static inline void alloc_channel(struct noise_suppress_data *ng, uint32_t sample_rate, size_t channel, size_t frames) @@ -431,25 +211,7 @@ static inline enum speaker_layout convert_speaker_layout(uint8_t channels) return SPEAKERS_UNKNOWN; } } -#ifdef LIBNVAFX_ENABLED -static void set_model(void *data, const char *method) -{ - struct noise_suppress_data *ng = data; - const char *file; - if (strcmp(NVAFX_EFFECT_DEREVERB, method) == 0) - file = NVAFX_EFFECT_DEREVERB_MODEL; - else if (strcmp(NVAFX_EFFECT_DEREVERB_DENOISER, method) == 0) - file = NVAFX_EFFECT_DEREVERB_DENOISER_MODEL; - else - file = NVAFX_EFFECT_DENOISER_MODEL; - size_t size = strlen(ng->sdk_path) + strlen(file) + 1; - char *buffer = (char *)bmalloc(size); - - strcpy(buffer, ng->sdk_path); - strcat(buffer, file); - ng->model = buffer; -} -#endif + static void noise_suppress_update(void *data, obs_data_t *s) { struct noise_suppress_data *ng = data; @@ -463,79 +225,15 @@ static void noise_suppress_update(void *data, obs_data_t *s) ng->latency = 1000000000LL / (1000 / BUFFER_SIZE_MSEC); ng->use_rnnoise = strcmp(method, S_METHOD_RNN) == 0; - bool nvafx_requested = - strcmp(method, S_METHOD_NVAFX_DENOISER) == 0 || - strcmp(method, S_METHOD_NVAFX_DEREVERB) == 0 || - strcmp(method, S_METHOD_NVAFX_DEREVERB_DENOISER) == 0; -#ifdef LIBNVAFX_ENABLED - if (nvafx_requested && ng->nvafx_enabled) - set_model(ng, method); - float intensity = (float)obs_data_get_double(s, S_NVAFX_INTENSITY); - if (ng->use_nvafx && ng->nvafx_initialized) { - if (intensity != ng->intensity_ratio && - (strcmp(ng->fx, method) == 0)) { - NvAFX_Status err; - ng->intensity_ratio = intensity; - pthread_mutex_lock(&ng->nvafx_mutex); - for (size_t i = 0; i < ng->channels; i++) { - err = NvAFX_SetFloat( - ng->handle[i], - NVAFX_PARAM_INTENSITY_RATIO, - ng->intensity_ratio); - if (err != NVAFX_STATUS_SUCCESS) { - do_log(LOG_ERROR, - "NvAFX_SetFloat(Intensity Ratio: %f) failed, error %i", - ng->intensity_ratio, err); - ng->use_nvafx = false; - } - } - pthread_mutex_unlock(&ng->nvafx_mutex); - } - if ((strcmp(ng->fx, method) != 0)) { - pthread_mutex_lock(&ng->nvafx_mutex); - bfree((void *)ng->fx); - ng->fx = bstrdup(method); - ng->intensity_ratio = intensity; - set_model(ng, method); - os_atomic_set_bool(&ng->reinit_done, false); - for (int i = 0; i < (int)ng->channels; i++) { - /* Destroy previous FX */ - if (NvAFX_DestroyEffect(ng->handle[i]) != - NVAFX_STATUS_SUCCESS) { - do_log(LOG_ERROR, - "FX failed to be destroyed."); - ng->use_nvafx = false; - } else - ng->handle[i] = NULL; - } - if (ng->use_nvafx) { - nvafx_initialize_internal(data); - } - pthread_mutex_unlock(&ng->nvafx_mutex); - } - } else { - ng->fx = bstrdup(method); - } - -#endif - ng->use_nvafx = ng->nvafx_enabled && nvafx_requested; - /* Process 10 millisecond segments to keep latency low. */ /* Also RNNoise only supports buffers of this exact size. */ /* At 48kHz, NVAFX processes 480 samples which corresponds to 10 ms.*/ ng->frames = frames; ng->channels = channels; -#ifdef LIBNVAFX_ENABLED - -#endif /* Ignore if already allocated */ #if defined(LIBSPEEXDSP_ENABLED) - if (!ng->use_rnnoise && !ng->use_nvafx && ng->spx_states[0]) - return; -#endif -#ifdef LIBNVAFX_ENABLED - if (ng->use_nvafx && (ng->nvafx_initialized || ng->nvafx_loading)) + if (!ng->use_rnnoise && ng->spx_states[0]) return; #endif #ifdef LIBRNNOISE_ENABLED @@ -551,10 +249,6 @@ static void noise_suppress_update(void *data, obs_data_t *s) #ifdef LIBRNNOISE_ENABLED ng->rnn_segment_buffers[0] = bmalloc(RNNOISE_FRAME_SIZE * channels * sizeof(float)); -#endif -#ifdef LIBNVAFX_ENABLED - ng->nvafx_segment_buffers[0] = - bmalloc(NVAFX_FRAME_SIZE * channels * sizeof(float)); #endif for (size_t c = 1; c < channels; ++c) { ng->copy_buffers[c] = ng->copy_buffers[c - 1] + frames; @@ -565,20 +259,8 @@ static void noise_suppress_update(void *data, obs_data_t *s) #ifdef LIBRNNOISE_ENABLED ng->rnn_segment_buffers[c] = ng->rnn_segment_buffers[c - 1] + RNNOISE_FRAME_SIZE; -#endif -#ifdef LIBNVAFX_ENABLED - ng->nvafx_segment_buffers[c] = - ng->nvafx_segment_buffers[c - 1] + NVAFX_FRAME_SIZE; #endif } - -#ifdef LIBNVAFX_ENABLED - if (!ng->nvafx_initialized && ng->use_nvafx && !ng->nvafx_loading) { - ng->intensity_ratio = intensity; - ng->nvafx_loading = true; - pthread_create(&ng->nvafx_thread, NULL, nvafx_initialize, ng); - } -#endif for (size_t i = 0; i < channels; i++) alloc_channel(ng, sample_rate, i, frames); @@ -600,231 +282,14 @@ static void noise_suppress_update(void *data, obs_data_t *s) ng->rnn_resampler_back = audio_resampler_create(&src, &dst); } #endif -#ifdef LIBNVAFX_ENABLED - if (sample_rate == NVAFX_SAMPLE_RATE) { - ng->nvafx_resampler = NULL; - ng->nvafx_resampler_back = NULL; - } else { - struct resample_info src, dst; - src.samples_per_sec = sample_rate; - src.format = AUDIO_FORMAT_FLOAT_PLANAR; - src.speakers = convert_speaker_layout((uint8_t)channels); - - dst.samples_per_sec = NVAFX_SAMPLE_RATE; - dst.format = AUDIO_FORMAT_FLOAT_PLANAR; - dst.speakers = convert_speaker_layout((uint8_t)channels); - - ng->nvafx_resampler = audio_resampler_create(&dst, &src); - ng->nvafx_resampler_back = audio_resampler_create(&src, &dst); - } -#endif } -#ifdef _MSC_VER -#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 - unsigned int version = get_lib_version(); - uint8_t major = (version >> 24) & 0xff; - uint8_t minor = (version >> 16) & 0x00ff; - uint8_t build = (version >> 8) & 0x0000ff; - uint8_t revision = (version >> 0) & 0x000000ff; - if (version) { - blog(LOG_INFO, - "[noise suppress]: NVIDIA AUDIO FX version: %i.%i.%i.%i", - major, minor, build, revision); - if (version < MIN_AFX_SDK_VERSION) { - blog(LOG_INFO, - "[noise suppress]: NVIDIA AUDIO Effects SDK is outdated. Please update both audio & video SDK."); - } - } - if (!load_lib()) { - blog(LOG_INFO, - "[noise suppress]: NVIDIA denoiser disabled, redistributable not found or could not be loaded."); - return false; - } - - nvafx_initializer_mutex_initialized = - pthread_mutex_init(&nvafx_initializer_mutex, NULL) == 0; - -#define LOAD_SYM_FROM_LIB(sym, lib, dll) \ - if (!(sym = (sym##_t)GetProcAddress(lib, #sym))) { \ - DWORD err = GetLastError(); \ - printf("[noise suppress]: Couldn't load " #sym " from " dll \ - ": %lu (0x%lx)", \ - err, err); \ - goto unload_everything; \ - } - -#define LOAD_SYM(sym) LOAD_SYM_FROM_LIB(sym, nv_audiofx, "NVAudioEffects.dll") - LOAD_SYM(NvAFX_GetEffectList); - LOAD_SYM(NvAFX_CreateEffect); - LOAD_SYM(NvAFX_CreateChainedEffect); - LOAD_SYM(NvAFX_DestroyEffect); - LOAD_SYM(NvAFX_SetU32); - LOAD_SYM(NvAFX_SetU32List); - LOAD_SYM(NvAFX_SetString); - LOAD_SYM(NvAFX_SetStringList); - LOAD_SYM(NvAFX_SetFloat); - LOAD_SYM(NvAFX_SetFloatList); - LOAD_SYM(NvAFX_GetU32); - LOAD_SYM(NvAFX_GetString); - LOAD_SYM(NvAFX_GetStringList); - LOAD_SYM(NvAFX_GetFloat); - LOAD_SYM(NvAFX_GetFloatList); - LOAD_SYM(NvAFX_Load); - LOAD_SYM(NvAFX_GetSupportedDevices); - LOAD_SYM(NvAFX_Run); - LOAD_SYM(NvAFX_Reset); -#undef LOAD_SYM -#define LOAD_SYM(sym) LOAD_SYM_FROM_LIB(sym, nv_cuda, "nvcuda.dll") - LOAD_SYM(cuCtxGetCurrent); - LOAD_SYM(cuCtxPopCurrent); - LOAD_SYM(cuInit); -#undef LOAD_SYM - - NvAFX_Status err; - CUresult cudaerr; - - NvAFX_Handle h = NULL; - - cudaerr = cuInit(0); - if (cudaerr != CUDA_SUCCESS) { - goto cuda_errors; - } - CUcontext old = {0}; - CUcontext curr = {0}; - cudaerr = cuCtxGetCurrent(&old); - if (cudaerr != CUDA_SUCCESS) { - goto cuda_errors; - } - - err = NvAFX_CreateEffect(NVAFX_EFFECT_DENOISER, &h); - cudaerr = cuCtxGetCurrent(&curr); - if (cudaerr != CUDA_SUCCESS) { - goto cuda_errors; - } - - if (curr != old) { - cudaerr = cuCtxPopCurrent(NULL); - if (cudaerr != CUDA_SUCCESS) - goto cuda_errors; - } - - if (err != NVAFX_STATUS_SUCCESS) { - if (err == NVAFX_STATUS_GPU_UNSUPPORTED) { - blog(LOG_INFO, - "[noise suppress]: NVIDIA AUDIO FX disabled: unsupported GPU"); - } else { - blog(LOG_ERROR, - "[noise suppress]: NVIDIA AUDIO FX disabled, error %i", - err); - } - goto unload_everything; - } - - err = NvAFX_DestroyEffect(h); - if (err != NVAFX_STATUS_SUCCESS) { - blog(LOG_ERROR, - "[noise suppress]: NVIDIA AUDIO FX disabled, error %i", - err); - goto unload_everything; - } - - nvafx_loaded = true; - blog(LOG_INFO, "[noise suppress]: NVIDIA AUDIO FX enabled"); - return true; - -cuda_errors: - blog(LOG_ERROR, - "[noise suppress]: NVIDIA AUDIO FX disabled, CUDA error %i", - cudaerr); -unload_everything: - release_lib(); -#endif - return false; -} -#ifdef _MSC_VER -#pragma warning(pop) -#endif - -#ifdef LIBNVAFX_ENABLED -void unload_nvafx(void) -{ - release_lib(); - - if (nvafx_initializer_mutex_initialized) { - pthread_mutex_destroy(&nvafx_initializer_mutex); - nvafx_initializer_mutex_initialized = false; - } -} -#endif - static void *noise_suppress_create(obs_data_t *settings, obs_source_t *filter) { struct noise_suppress_data *ng = bzalloc(sizeof(struct noise_suppress_data)); ng->context = filter; - -#ifdef LIBNVAFX_ENABLED - char sdk_path[MAX_PATH]; - - if (!nvafx_get_sdk_path(sdk_path, sizeof(sdk_path))) { - ng->nvafx_enabled = false; - do_log(LOG_ERROR, "NVAFX redist is not installed."); - } else { - size_t size = sizeof(sdk_path) + 1; - ng->sdk_path = bmalloc(size); - strcpy(ng->sdk_path, sdk_path); - ng->nvafx_enabled = true; - ng->nvafx_initialized = false; - ng->nvafx_loading = false; - ng->fx = NULL; - - pthread_mutex_init(&ng->nvafx_mutex, NULL); - - info("NVAFX SDK redist path was found here %s", sdk_path); - } -#endif noise_suppress_update(ng, settings); return ng; } @@ -943,113 +408,6 @@ static inline void process_rnnoise(struct noise_suppress_data *ng) #endif } -static inline void process_nvafx(struct noise_suppress_data *ng) -{ -#ifdef LIBNVAFX_ENABLED - if (nvafx_loaded && ng->use_nvafx && ng->nvafx_initialized) { - /* Resample if necessary */ - if (ng->nvafx_resampler) { - float *output[MAX_PREPROC_CHANNELS]; - uint32_t out_frames; - uint64_t ts_offset; - audio_resampler_resample( - ng->nvafx_resampler, (uint8_t **)output, - &out_frames, &ts_offset, - (const uint8_t **)ng->copy_buffers, - (uint32_t)ng->frames); - - for (size_t i = 0; i < ng->channels; i++) { - for (ssize_t j = 0, k = (ssize_t)out_frames - - NVAFX_FRAME_SIZE; - j < NVAFX_FRAME_SIZE; ++j, ++k) { - if (k >= 0) { - ng->nvafx_segment_buffers[i][j] = - output[i][k]; - } else { - ng->nvafx_segment_buffers[i][j] = - 0; - } - } - } - } else { - for (size_t i = 0; i < ng->channels; i++) { - for (size_t j = 0; j < NVAFX_FRAME_SIZE; ++j) { - ng->nvafx_segment_buffers[i][j] = - ng->copy_buffers[i][j]; - } - } - } - - /* Execute */ - size_t runs = ng->has_mono_src ? 1 : ng->channels; - if (ng->reinit_done) { - pthread_mutex_lock(&ng->nvafx_mutex); - for (size_t i = 0; i < runs; i++) { - NvAFX_Status err = - NvAFX_Run(ng->handle[i], - &ng->nvafx_segment_buffers[i], - &ng->nvafx_segment_buffers[i], - ng->num_samples_per_frame, - ng->num_channels); - if (err != NVAFX_STATUS_SUCCESS) { - if (err == NVAFX_STATUS_FAILED) { - do_log(LOG_DEBUG, - "NvAFX_Run() failed, error NVAFX_STATUS_FAILED.\n" - "This can occur when changing the FX and is not consequential."); - os_atomic_set_bool( - &ng->reinit_done, - false); // stop all processing; this will be reset at new init - } else { - do_log(LOG_ERROR, - "NvAFX_Run() failed, error %i.\n", - err); - } - } - } - pthread_mutex_unlock(&ng->nvafx_mutex); - } - if (ng->has_mono_src) { - memcpy(ng->nvafx_segment_buffers[1], - ng->nvafx_segment_buffers[0], - NVAFX_FRAME_SIZE * sizeof(float)); - } - /* Revert signal level adjustment, resample back if necessary */ - if (ng->nvafx_resampler) { - float *output[MAX_PREPROC_CHANNELS]; - uint32_t out_frames; - uint64_t ts_offset; - audio_resampler_resample( - ng->nvafx_resampler_back, (uint8_t **)output, - &out_frames, &ts_offset, - (const uint8_t **)ng->nvafx_segment_buffers, - NVAFX_FRAME_SIZE); - - for (size_t i = 0; i < ng->channels; i++) { - for (ssize_t j = 0, k = (ssize_t)out_frames - - ng->frames; - j < (ssize_t)ng->frames; ++j, ++k) { - if (k >= 0) { - ng->copy_buffers[i][j] = - output[i][k]; - } else { - ng->copy_buffers[i][j] = 0; - } - } - } - } else { - for (size_t i = 0; i < ng->channels; i++) { - for (size_t j = 0; j < NVAFX_FRAME_SIZE; ++j) { - ng->copy_buffers[i][j] = - ng->nvafx_segment_buffers[i][j]; - } - } - } - } -#else - UNUSED_PARAMETER(ng); -#endif -} - static inline void process(struct noise_suppress_data *ng) { /* Pop from input circlebuf */ @@ -1059,10 +417,6 @@ static inline void process(struct noise_suppress_data *ng) if (ng->use_rnnoise) { process_rnnoise(ng); - } else if (ng->use_nvafx) { - if (nvafx_loaded) { - process_nvafx(ng); - } } else { process_speexdsp(ng); } @@ -1179,17 +533,10 @@ static bool noise_suppress_method_modified(obs_properties_t *props, { obs_property_t *p_suppress_level = obs_properties_get(props, S_SUPPRESS_LEVEL); - obs_property_t *p_navfx_intensity = - obs_properties_get(props, S_NVAFX_INTENSITY); const char *method = obs_data_get_string(settings, S_METHOD); bool enable_level = strcmp(method, S_METHOD_SPEEX) == 0; - bool enable_intensity = - strcmp(method, S_METHOD_NVAFX_DENOISER) == 0 || - strcmp(method, S_METHOD_NVAFX_DEREVERB) == 0 || - strcmp(method, S_METHOD_NVAFX_DEREVERB_DENOISER) == 0; obs_property_set_visible(p_suppress_level, enable_level); - obs_property_set_visible(p_navfx_intensity, enable_intensity); UNUSED_PARAMETER(property); return true; @@ -1203,9 +550,6 @@ static void noise_suppress_defaults_v1(obs_data_t *s) #else obs_data_set_default_string(s, S_METHOD, S_METHOD_SPEEX); #endif -#if defined(LIBNVAFX_ENABLED) - obs_data_set_default_double(s, S_NVAFX_INTENSITY, 1.0); -#endif } static void noise_suppress_defaults_v2(obs_data_t *s) @@ -1216,9 +560,6 @@ static void noise_suppress_defaults_v2(obs_data_t *s) #else obs_data_set_default_string(s, S_METHOD, S_METHOD_SPEEX); #endif -#if defined(LIBNVAFX_ENABLED) - obs_data_set_default_double(s, S_NVAFX_INTENSITY, 1.0); -#endif } static obs_properties_t *noise_suppress_properties(void *data) @@ -1237,16 +578,16 @@ static obs_properties_t *noise_suppress_properties(void *data) obs_property_list_add_string(method, TEXT_METHOD_SPEEX, S_METHOD_SPEEX); obs_property_list_add_string(method, TEXT_METHOD_RNN, S_METHOD_RNN); #ifdef LIBNVAFX_ENABLED - if (ng->nvafx_enabled) { - obs_property_list_add_string(method, TEXT_METHOD_NVAFX_DENOISER, - S_METHOD_NVAFX_DENOISER); - obs_property_list_add_string(method, TEXT_METHOD_NVAFX_DEREVERB, - S_METHOD_NVAFX_DEREVERB); - obs_property_list_add_string( - method, TEXT_METHOD_NVAFX_DEREVERB_DENOISER, - S_METHOD_NVAFX_DEREVERB_DENOISER); - } - + obs_property_list_add_string(method, TEXT_METHOD_NVAFX_DENOISER, + S_METHOD_NVAFX_DENOISER); + obs_property_list_add_string(method, TEXT_METHOD_NVAFX_DEREVERB, + S_METHOD_NVAFX_DEREVERB); + obs_property_list_add_string(method, + TEXT_METHOD_NVAFX_DEREVERB_DENOISER, + S_METHOD_NVAFX_DEREVERB_DENOISER); + obs_property_list_item_disable(method, 2, false); + obs_property_list_item_disable(method, 3, false); + obs_property_list_item_disable(method, 4, false); #endif obs_property_set_modified_callback(method, noise_suppress_method_modified); @@ -1260,19 +601,6 @@ static obs_properties_t *noise_suppress_properties(void *data) #endif #ifdef LIBNVAFX_ENABLED - if (ng->nvafx_enabled) { - obs_properties_add_float_slider(ppts, S_NVAFX_INTENSITY, - TEXT_NVAFX_INTENSITY, 0.0f, - 1.0f, 0.01f); - } - unsigned int version = get_lib_version(); - if (version && version < MIN_AFX_SDK_VERSION) { - obs_property_t *warning = obs_properties_add_text( - ppts, "deprecation", NULL, OBS_TEXT_INFO); - obs_property_text_set_info_type(warning, OBS_TEXT_INFO_WARNING); - 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); diff --git a/plugins/obs-filters/obs-filters.c b/plugins/obs-filters/obs-filters.c index 09f7c72bbb4e3c..b3644ae84833d1 100644 --- a/plugins/obs-filters/obs-filters.c +++ b/plugins/obs-filters/obs-filters.c @@ -30,8 +30,6 @@ extern struct obs_source_info async_delay_filter; extern struct obs_source_info noise_suppress_filter; extern struct obs_source_info noise_suppress_filter_v2; extern struct obs_source_info nvidia_audiofx_filter; -extern bool load_nvafx(void); -extern void unload_nvafx(void); #endif extern bool load_nvidia_afx(void); extern void unload_nvidia_afx(void); @@ -73,7 +71,6 @@ bool obs_module_load(void) #if defined(HAS_NOISEREDUCTION) #ifdef LIBNVAFX_ENABLED /* load nvidia audio fx dll */ - load_nvafx(); if (load_nvidia_afx()) obs_register_source(&nvidia_audiofx_filter); #endif @@ -98,7 +95,6 @@ bool obs_module_load(void) void obs_module_unload(void) { #ifdef LIBNVAFX_ENABLED - unload_nvafx(); unload_nvidia_afx(); #endif #ifdef LIBNVVFX_ENABLED