diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 59fb1ad2..6892a435 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -17,6 +17,7 @@ Bugfix - Fixes a bug when plotting an anechoic room - Fixes a buggy assert from ``rir_build.cpp`` - Makes the build system consistent for all source files in ``pyroomacoustics/libroom_src`` +- Fixes a call to a deprecated function of scipy.integrate in ``pyroomacoustics/denoise/iterative_wiener`` (issue #362) `0.7.6`_ - 2024-08-05 --------------------- diff --git a/pyroomacoustics/denoise/iterative_wiener.py b/pyroomacoustics/denoise/iterative_wiener.py index 318ab275..41a379b4 100644 --- a/pyroomacoustics/denoise/iterative_wiener.py +++ b/pyroomacoustics/denoise/iterative_wiener.py @@ -337,7 +337,14 @@ def _lpc_all_pole(omega): d_omega = 2 * np.pi / 1000 omega_vals = np.arange(-np.pi, np.pi, d_omega) vec_integrand = np.vectorize(_lpc_all_pole) - integral = integrate.trapz(vec_integrand(omega_vals), omega_vals) + + try: + integral = integrate.trapezoid(vec_integrand(omega_vals), omega_vals) + except AttributeError: + # older versions of scipy do not have the function 'trapezoid' + # fall back to the legacy function name + integral = integrate.trapz(vec_integrand(omega_vals), omega_vals) + return rhs * 2 * np.pi / N / integral diff --git a/pyroomacoustics/denoise/tests/test_iterative_wiener.py b/pyroomacoustics/denoise/tests/test_iterative_wiener.py new file mode 100644 index 00000000..60f46697 --- /dev/null +++ b/pyroomacoustics/denoise/tests/test_iterative_wiener.py @@ -0,0 +1,38 @@ +import numpy as np + +import pyroomacoustics as pra + + +def test_iterative_wiener(): + """ + A simple functional test that the call does not produce any errors. + """ + # parameters + num_blocks = 20 + nfft = 512 + hop = nfft // 2 + + # create a dummy signal + blocks = np.random.randn(num_blocks, hop) + + # initialize STFT and IterativeWiener objects + stft = pra.transform.STFT(nfft, hop=hop, analysis_window=pra.hann(nfft)) + scnr = pra.denoise.IterativeWiener( + frame_len=nfft, lpc_order=20, iterations=2, alpha=0.8, thresh=0.01 + ) + + # apply block-by-block + processed_blocks = [] + for n in range(num_blocks): + + # go to frequency domain, 50% overlap + stft.analysis(blocks[n]) + + # compute wiener output + X = scnr.compute_filtered_output( + current_frame=stft.fft_in_buffer, frame_dft=stft.X + ) + + # back to time domain + mono_denoised = stft.synthesis(X) + processed_blocks.append(mono_denoised)