-
-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import unittest | ||
|
||
import numpy as np | ||
from numpy.testing import assert_almost_equal | ||
|
||
from audiomentations.augmentations.transforms import Gain | ||
from audiomentations.core.composition import Compose | ||
|
||
|
||
class TestGain(unittest.TestCase): | ||
def test_gain(self): | ||
samples = np.array([1.0, 0.5, -0.25, -0.125, 0.0], dtype=np.float32) | ||
sample_rate = 16000 | ||
|
||
augment = Compose([Gain(min_gain_in_db=-6, max_gain_in_db=-6, p=1.0)]) | ||
processed_samples = augment(samples=samples, sample_rate=sample_rate) | ||
assert_almost_equal( | ||
processed_samples, | ||
np.array( | ||
[0.5011872, 0.2505936, -0.1252968, -0.0626484, 0.0], dtype=np.float32 | ||
), | ||
) | ||
self.assertEqual(processed_samples.dtype, np.float32) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
import unittest | ||
|
||
from audiomentations import calculate_desired_noise_rms | ||
from audiomentations.core.utils import ( | ||
calculate_desired_noise_rms, | ||
convert_decibels_to_amplitude_ratio, | ||
) | ||
|
||
|
||
class TestUtils(unittest.TestCase): | ||
def test_calculate_desired_noise_rms(self): | ||
noise_rms = calculate_desired_noise_rms(clean_rms=0.5, snr=6) | ||
self.assertAlmostEqual(noise_rms, 0.2505936168136362) | ||
|
||
def test_convert_decibels_to_amplitude_ratio(self): | ||
amplitude_ratio = convert_decibels_to_amplitude_ratio(decibels=-6) | ||
self.assertAlmostEqual(amplitude_ratio, 0.5011872336272722) | ||
|
||
amplitude_ratio = convert_decibels_to_amplitude_ratio(decibels=6) | ||
self.assertAlmostEqual(amplitude_ratio, 1.9952623149688795) |