Skip to content

Commit d20f5c5

Browse files
committed
Added tests for gain
1 parent 95ce067 commit d20f5c5

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

test/assets/sinewave_soxgain5.wav

250 KB
Binary file not shown.

test/test_functional.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pytest
88
import unittest
99
import common_utils
10+
import os
1011

1112
from torchaudio.common_utils import IMPORT_LIBROSA
1213

@@ -247,6 +248,19 @@ def test_create_fb(self):
247248
self._test_create_fb(n_mels=56, fmin=1900.0, fmax=900.0)
248249
self._test_create_fb(n_mels=10, fmin=1900.0, fmax=900.0)
249250

251+
def test_gain(self):
252+
test_dirpath, test_dir = common_utils.create_temp_assets_dir()
253+
test_filepath = os.path.join(test_dirpath, "assets", "sinewave.wav")
254+
255+
waveform, sample_rate = torchaudio.load(test_filepath)
256+
waveform_gain = F.gain(waveform, 5)
257+
self.assertTrue(waveform_gain.abs().max().item(), 1.)
258+
259+
test_filepath_sox_gain = os.path.join(test_dirpath, "assets", "sinewave_soxgain5.wav")
260+
sox_gain_waveform, sox_sr = torchaudio.load(test_filepath_sox_gain)
261+
262+
self.assertTrue(torch.allclose(waveform_gain, sox_gain_waveform))
263+
250264

251265
def _num_stft_bins(signal_len, fft_len, hop_length, pad):
252266
return (signal_len + 2 * pad - fft_len + hop_length) // hop_length
@@ -346,5 +360,6 @@ def test_mask_along_axis_iid(specgrams, mask_param, mask_value, axis):
346360
assert (num_masked_columns < mask_param).sum() == num_masked_columns.numel()
347361

348362

363+
349364
if __name__ == '__main__':
350365
unittest.main()

0 commit comments

Comments
 (0)