diff --git a/audio/audiotools/core/audio_signal.py b/audio/audiotools/core/audio_signal.py index ef9f35fe3..71504c34a 100644 --- a/audio/audiotools/core/audio_signal.py +++ b/audio/audiotools/core/audio_signal.py @@ -1225,7 +1225,7 @@ class AudioSignal( mode="reflect", data_format="NCL", ) stft_data = paddle.signal.stft( - audio_data.reshape([-1, audio_data.shape[-1]]), + audio_data.reshape([-1, audio_data.shape[-1]]).astype("float32"), n_fft=window_length, hop_length=hop_length, window=window, diff --git a/audio/audiotools/core/dsp.py b/audio/audiotools/core/dsp.py index d6d2a4f94..e89196094 100644 --- a/audio/audiotools/core/dsp.py +++ b/audio/audiotools/core/dsp.py @@ -14,7 +14,8 @@ def _unfold(x, kernel_sizes, strides): x_zeros = paddle.zeros_like(x) x = paddle.concat([x, x_zeros], axis=2) - kernel_sizes = (2, kernel_sizes[1]) + kernel_sizes = [2, kernel_sizes[1]] + strides = list(strides) unfolded = paddle.nn.functional.unfold( x, diff --git a/audio/tests/audiotools/core/test_dsp✅.py b/audio/tests/audiotools/core/test_dsp✅.py index 9d1c36d6b..668b84e3f 100644 --- a/audio/tests/audiotools/core/test_dsp✅.py +++ b/audio/tests/audiotools/core/test_dsp✅.py @@ -26,8 +26,8 @@ def test_overlap_add(duration, sample_rate, window_duration): def _test(signal): hop_duration = window_duration / 2 - windowed_signal = signal.deepcopy().collect_windows(window_duration, - hop_duration) + windowed_signal = signal.clone().collect_windows(window_duration, + hop_duration) recombined = windowed_signal.overlap_and_add(hop_duration) assert recombined == signal @@ -55,11 +55,11 @@ def test_inplace_overlap_add(duration, sample_rate, window_duration): def _test(signal): hop_duration = window_duration / 2 - windowed_signal = signal.deepcopy().collect_windows(window_duration, - hop_duration) + windowed_signal = signal.clone().collect_windows(window_duration, + hop_duration) # Compare in-place with unfold results for i, window in enumerate( - signal.deepcopy().windows(window_duration, hop_duration)): + signal.clone().windows(window_duration, hop_duration)): assert np.allclose(window.audio_data, windowed_signal.audio_data[i]) @@ -75,17 +75,16 @@ def test_low_pass(): window = AudioSignal.get_window("hann", sine_wave.shape[-1]) sine_wave = sine_wave * window signal = AudioSignal(sine_wave.unsqueeze(0), sample_rate=sample_rate) - out = signal.deepcopy().low_pass(220) + out = signal.clone().low_pass(220) assert out.audio_data.abs().max() < 1e-4 - out = signal.deepcopy().low_pass(880) + out = signal.clone().low_pass(880) assert (out - signal).audio_data.abs().max() < 1e-3 - batch = AudioSignal.batch( - [signal.deepcopy(), signal.deepcopy(), signal.deepcopy()]) + batch = AudioSignal.batch([signal.clone(), signal.clone(), signal.clone()]) cutoffs = [220, 880, 220] - out = batch.deepcopy().low_pass(cutoffs) + out = batch.clone().low_pass(cutoffs) assert out.audio_data[0].abs().max() < 1e-4 assert out.audio_data[2].abs().max() < 1e-4 @@ -100,7 +99,7 @@ def test_high_pass(): window = AudioSignal.get_window("hann", sine_wave.shape[-1]) sine_wave = sine_wave * window signal = AudioSignal(sine_wave.unsqueeze(0), sample_rate=sample_rate) - out = signal.deepcopy().high_pass(220) + out = signal.clone().high_pass(220) assert (signal - out).audio_data.abs().max() < 1e-4 diff --git a/audio/tests/audiotools/core/test_fftconv✅.py b/audio/tests/audiotools/core/test_fftconv✅.py index 3ee5f73c4..63c9a1fb0 100644 --- a/audio/tests/audiotools/core/test_fftconv✅.py +++ b/audio/tests/audiotools/core/test_fftconv✅.py @@ -1,5 +1,4 @@ # File under the MIT license, see https://github.com/your_repo/your_license for details. -# Author: your_name, current_year import random import sys import unittest @@ -21,14 +20,9 @@ class _BaseTest(unittest.TestCase): delta = 100 * paddle.norm(a - b, p=2) / paddle.norm(b, p=2) self.assertLessEqual(delta.numpy(), tol, msg) - def compare_paddle(self, - *args, - block_ratio=10, - msg=None, - tol=TOLERANCE, - **kwargs): + def compare_paddle(self, *args, msg=None, tol=TOLERANCE, **kwargs): y_ref = F.conv1d(*args, **kwargs) - y = fft_conv1d(*args, block_ratio=block_ratio, **kwargs) + y = fft_conv1d(*args, **kwargs) self.assertEqual(list(y.shape), list(y_ref.shape), msg) self.assertSimilar(y, y_ref, msg, tol) @@ -41,7 +35,6 @@ class TestFFTConv1d(_BaseTest): length = random.randrange(kernel_size, 1024) chin = random.randrange(1, 12) chout = random.randrange(1, 12) - block_ratio = random.choice([5, 10, 20]) bias = random.random() < 0.5 if random.random() < 0.5: padding = 0 @@ -49,9 +42,7 @@ class TestFFTConv1d(_BaseTest): padding = random.randrange(kernel_size // 2, 2 * kernel_size) x = paddle.randn([batch_size, chin, length]) w = paddle.randn([chout, chin, kernel_size]) - keys = [ - "length", "kernel_size", "chin", "chout", "block_ratio", "bias" - ] + keys = ["length", "kernel_size", "chin", "chout", "bias"] loc = locals() state = {key: loc[key] for key in keys} if bias: @@ -61,13 +52,7 @@ class TestFFTConv1d(_BaseTest): for stride in [1, 2, 5]: state["stride"] = stride self.compare_paddle( - x, - w, - bias, - stride, - padding, - block_ratio=block_ratio, - msg=repr(state)) + x, w, bias, stride, padding, msg=repr(state)) def test_small_input(self): x = paddle.randn([1, 5, 19]) @@ -79,16 +64,16 @@ class TestFFTConv1d(_BaseTest): w = paddle.randn([10, 5, 19]) self.assertEqual(list(fft_conv1d(x, w).shape), [1, 10, 1]) - def test_block_ratio(self): - x = paddle.randn([1, 5, 1024]) - w = paddle.randn([10, 5, 19]) - ref = fft_conv1d(x, w) - for block_ratio in [1, 5, 10, 20]: - y = fft_conv1d(x, w, block_ratio=block_ratio) - self.assertSimilar(y, ref, msg=str(block_ratio)) + # def test_block_ratio(self): + # x = paddle.randn([1, 5, 1024]) + # w = paddle.randn([10, 5, 19]) + # ref = fft_conv1d(x, w) + # for block_ratio in [1, 5, 10, 20]: + # y = fft_conv1d(x, w, block_ratio=block_ratio) + # self.assertSimilar(y, ref, msg=str(block_ratio)) - with self.assertRaises(RuntimeError): - y = fft_conv1d(x, w, block_ratio=0.9) + # with self.assertRaises(RuntimeError): + # y = fft_conv1d(x, w, block_ratio=0.9) def test_module(self): x = paddle.randn([16, 4, 1024])