-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
【Hackathon 7th No.22】NO.22 在 paddle.audio.functional.get_window 中支持 bartlett 、 kaiser 和 nuttall 窗函数 -part #68268
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,8 @@ | |
'hamming', | ||
'hann', | ||
'kaiser', | ||
'bartlett', | ||
'nuttall', | ||
'gaussian', | ||
'exponential', | ||
'triang', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,6 +259,7 @@ def test_gaussian_window_and_exception(self, n_fft: int): | |
np.testing.assert_array_almost_equal( | ||
window_scipy_exp, window_paddle_exp.numpy(), decimal=5 | ||
) | ||
|
||
try: | ||
window_paddle = paddle.audio.functional.get_window("hann", -1) | ||
except ValueError: | ||
|
@@ -292,7 +293,14 @@ def dct(n_filters, n_input): | |
np.testing.assert_array_almost_equal(librosa_dct, paddle_dct, decimal=5) | ||
|
||
@parameterize( | ||
[128, 256, 512], ["hamming", "hann", "triang", "bohman"], [True, False] | ||
[128, 256, 512], | ||
[ | ||
"hamming", | ||
"hann", | ||
"triang", | ||
"bohman", | ||
], | ||
[True, False], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
我看这里的修改和原来的一样呀。 目前单侧没有过。There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已经可以了,请review @jeff41404 |
||
) | ||
def test_stft_and_spect( | ||
self, n_fft: int, window_str: str, center_flag: bool | ||
|
@@ -347,7 +355,14 @@ def test_stft_and_spect( | |
) | ||
|
||
@parameterize( | ||
[128, 256, 512], [64, 82], ["hamming", "hann", "triang", "bohman"] | ||
[128, 256, 512], | ||
[64, 82], | ||
[ | ||
"hamming", | ||
"hann", | ||
"triang", | ||
"bohman", | ||
], | ||
) | ||
def test_istft(self, n_fft: int, hop_length: int, window_str: str): | ||
if len(self.waveform.shape) == 2: # (C, T) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import unittest | ||
|
||
from scipy import signal | ||
|
||
import paddle | ||
import paddle.audio | ||
from paddle.base import core | ||
|
||
|
||
class TestAudioFuncitons(unittest.TestCase): | ||
def test_bartlett_nuttall_kaiser_window(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's better to add other 11 unit tests of window function besides these three? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 请稍等,我现在就加上去 |
||
paddle.disable_static( | ||
paddle.CUDAPlace(0) | ||
if core.is_compiled_with_cuda() | ||
else paddle.CPUPlace() | ||
) | ||
n_fft = 1 | ||
|
||
window_scipy_bartlett = signal.windows.bartlett(n_fft) | ||
window_paddle_bartlett = paddle.audio.functional.get_window( | ||
'bartlett', n_fft | ||
) | ||
window_scipy_bartlett = paddle.to_tensor( | ||
window_scipy_bartlett, dtype=window_paddle_bartlett.dtype | ||
) | ||
paddle.allclose( | ||
window_scipy_bartlett, | ||
window_paddle_bartlett, | ||
atol=0.0001, | ||
rtol=0.0001, | ||
) | ||
|
||
window_scipy_nuttall = signal.windows.nuttall(n_fft) | ||
window_paddle_nuttall = paddle.audio.functional.get_window( | ||
'nuttall', n_fft | ||
) | ||
window_scipy_nuttall = paddle.to_tensor( | ||
window_scipy_nuttall, dtype=window_paddle_nuttall.dtype | ||
) | ||
paddle.allclose( | ||
window_scipy_nuttall, | ||
window_paddle_nuttall, | ||
atol=0.0001, | ||
rtol=0.0001, | ||
) | ||
|
||
window_scipy_kaiser = signal.windows.kaiser(n_fft, beta=14.0) | ||
window_paddle_kaiser = paddle.audio.functional.get_window( | ||
('kaiser', 14.0), n_fft | ||
) | ||
window_scipy_kaiser = paddle.to_tensor( | ||
window_scipy_kaiser, dtype=window_paddle_kaiser.dtype | ||
) | ||
paddle.allclose( | ||
window_scipy_kaiser, window_paddle_kaiser, atol=0.0001, rtol=0.0001 | ||
) | ||
|
||
n_fft = 512 | ||
|
||
window_scipy_bartlett = signal.windows.bartlett(n_fft) | ||
window_paddle_bartlett = paddle.audio.functional.get_window( | ||
'bartlett', n_fft | ||
) | ||
window_scipy_bartlett = paddle.to_tensor( | ||
window_scipy_bartlett, dtype=window_paddle_bartlett.dtype | ||
) | ||
paddle.allclose( | ||
window_scipy_bartlett, | ||
window_paddle_bartlett, | ||
atol=0.0001, | ||
rtol=0.0001, | ||
) | ||
|
||
window_scipy_nuttall = signal.windows.nuttall(n_fft) | ||
window_paddle_nuttall = paddle.audio.functional.get_window( | ||
'nuttall', n_fft | ||
) | ||
window_scipy_nuttall = paddle.to_tensor( | ||
window_scipy_nuttall, dtype=window_paddle_nuttall.dtype | ||
) | ||
paddle.allclose( | ||
window_scipy_nuttall, | ||
window_paddle_nuttall, | ||
atol=0.0001, | ||
rtol=0.0001, | ||
) | ||
|
||
window_scipy_kaiser = signal.windows.kaiser(n_fft, beta=14.0) | ||
window_paddle_kaiser = paddle.audio.functional.get_window( | ||
('kaiser', 14.0), n_fft | ||
) | ||
window_scipy_kaiser = paddle.to_tensor( | ||
window_scipy_kaiser, dtype=window_paddle_kaiser.dtype | ||
) | ||
paddle.allclose( | ||
window_scipy_kaiser, window_paddle_kaiser, atol=0.0001, rtol=0.0001 | ||
) | ||
paddle.enable_static() | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because of adding types of window functions, we should synchronously expand the introduction documents of
window
member inSpectrogram
,MelSpectrogram
,LogMelSpectrogram
, andMFCC
classes below in this file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的好的