Skip to content

πŸŽ› πŸ”Š A Python library for audio.

Speed up test suite.

Peter Sobot6ba51805a2c7
diff --git a/.github/workflows/all.yml b/.github/workflows/all.yml
index b238426..a6e3269 100644
--- a/.github/workflows/all.yml
+++ b/.github/workflows/all.yml
@@ -59,7 +59,7 @@ jobs:
MINIMUM_COVERAGE_PERCENTAGE: 80
strategy:
matrix:
- python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
+ python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12.0-alpha.3']
# TODO: Switch back to macos-latest once https://github.com/actions/python-versions/pull/114 is fixed
os: ['ubuntu-20.04', windows-latest, macos-12]
name: Test with Python ${{ matrix.python-version }} on ${{ matrix.os }}
@@ -260,7 +260,7 @@ jobs:
with:
python-version: "3.10"
- name: Install cibuildwheel
- run: python -m pip install cibuildwheel>=2.9.0
+ run: python -m pip install 'cibuildwheel>=2.11.0'
- name: Set up QEMU for aarch64 on Linux
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v1
diff --git a/tests/test_pitch_shift.py b/tests/test_pitch_shift.py
index 293f972..7b3f9f6 100644
--- a/tests/test_pitch_shift.py
+++ b/tests/test_pitch_shift.py
@@ -21,10 +21,10 @@ from pedalboard import Pedalboard, PitchShift
@pytest.mark.parametrize("semitones", [-12, 0, 12])
[email protected]("fundamental_hz", [440, 880])
[email protected]("fundamental_hz", [440])
@pytest.mark.parametrize("sample_rate", [22050, 44100, 48000])
def test_pitch_shift(semitones, fundamental_hz, sample_rate):
- num_seconds = 10.0
+ num_seconds = 1.0
samples = np.arange(num_seconds * sample_rate)
sine_wave = np.sin(2 * np.pi * fundamental_hz * samples / sample_rate)
plugin = PitchShift(semitones)
@@ -39,24 +39,22 @@ def test_pitch_shift_extremes_throws_errors(semitones):
PitchShift(semitones)
[email protected]("semitones", [-72, -36, -12, 12, 36, 72])
[email protected]("sample_rate", [22050, 44100, 48000])
[email protected]("buffer_size", [32, 512, 8192])
-def test_pitch_shift_extremes(semitones, sample_rate, buffer_size):
- noise = np.random.rand(int(5.0 * sample_rate))
- plugin = PitchShift(semitones)
- output = plugin.process(noise, sample_rate, buffer_size=buffer_size)
[email protected]("semitones", [-72, 72])
[email protected]("sample_rate", [48000])
[email protected]("duration", [0.25])
+def test_pitch_shift_extremes(semitones, sample_rate, duration):
+ noise = np.random.rand(int(duration * sample_rate))
+ output = PitchShift(semitones).process(noise, sample_rate)
assert np.all(np.isfinite(output))
[email protected]("semitones", [0])
@pytest.mark.parametrize("fundamental_hz", [440.0, 880.0])
@pytest.mark.parametrize("sample_rate", [22050, 44100, 48000])
@pytest.mark.parametrize("buffer_size", [32, 512, 513, 1024, 1029, 2048, 8192])
-def test_pitch_shift_latency_compensation(semitones, fundamental_hz, sample_rate, buffer_size):
- num_seconds = 5.0
+def test_pitch_shift_latency_compensation(fundamental_hz, sample_rate, buffer_size):
+ num_seconds = 2.0
samples = np.arange(num_seconds * sample_rate)
sine_wave = np.sin(2 * np.pi * fundamental_hz * samples / sample_rate)
- plugin = Pedalboard([PitchShift(semitones), PitchShift(-semitones)])
+ plugin = Pedalboard([PitchShift(0)])
output = plugin.process(sine_wave, sample_rate, buffer_size=buffer_size)
np.testing.assert_allclose(sine_wave, output, atol=1e-6)
diff --git a/tests/test_resample.py b/tests/test_resample.py
index f9d0036..e8177cd 100644
--- a/tests/test_resample.py
+++ b/tests/test_resample.py
@@ -50,7 +50,12 @@ def test_resample(
quality: Resample.Quality,
plugin_class,
):
- sine_wave = generate_sine_at(sample_rate, fundamental_hz, num_channels=num_channels)
+ sine_wave = generate_sine_at(
+ sample_rate,
+ fundamental_hz,
+ num_seconds=duration,
+ num_channels=num_channels,
+ )
plugin = plugin_class(target_sample_rate, quality=quality)
output = plugin.process(sine_wave, sample_rate, buffer_size=buffer_size)
np.testing.assert_allclose(sine_wave, output, atol=TOLERANCE_PER_QUALITY[quality])
@@ -72,7 +77,12 @@ def test_resample_invariant_to_buffer_size(
quality: Resample.Quality,
plugin_class,
):
- sine_wave = generate_sine_at(sample_rate, fundamental_hz, num_channels=num_channels)
+ sine_wave = generate_sine_at(
+ sample_rate,
+ fundamental_hz,
+ num_seconds=duration,
+ num_channels=num_channels,
+ )
plugin = plugin_class(target_sample_rate, quality=quality)
buffer_sizes = [1, 7000, 8192, 1_000_000]
@@ -113,9 +123,9 @@ def test_identical_noise_with_zero_order_hold(
@pytest.mark.parametrize("fundamental_hz", [10])
@pytest.mark.parametrize("sample_rate", [100, 384_123.45])
@pytest.mark.parametrize("target_sample_rate", [100, 384_123.45])
[email protected]("buffer_size", [1, 1_000_000])
[email protected]("buffer_size", [1_000_000])
@pytest.mark.parametrize("duration", DURATIONS)
[email protected]("num_channels", [1, 2])
[email protected]("num_channels", [1])
@pytest.mark.parametrize("quality", TOLERANCE_PER_QUALITY.keys())
@pytest.mark.parametrize("plugin_class", [Resample, ResampleWithLatency])
def test_extreme_resampling(
@@ -128,7 +138,12 @@ def test_extreme_resampling(
quality: Resample.Quality,
plugin_class,
):
- sine_wave = generate_sine_at(sample_rate, fundamental_hz, num_channels=num_channels)
+ sine_wave = generate_sine_at(
+ sample_rate,
+ fundamental_hz,
+ num_seconds=duration,
+ num_channels=num_channels,
+ )
plugin = plugin_class(target_sample_rate, quality=quality)
output = plugin.process(sine_wave, sample_rate, buffer_size=buffer_size)
np.testing.assert_allclose(sine_wave, output, atol=TOLERANCE_PER_QUALITY[quality])
diff --git a/tests/test_resampled_io.py b/tests/test_resampled_io.py
index a4879d0..6e905a2 100644
--- a/tests/test_resampled_io.py
+++ b/tests/test_resampled_io.py
@@ -134,12 +134,13 @@ def test_seek_resampled(sample_rate: float, target_sample_rate: float, quality):
@pytest.mark.parametrize("sample_rate", [8000, 11025, 22050, 44100, 48000])
@pytest.mark.parametrize("target_sample_rate", [8000, 11025, 12345.67, 22050, 44100, 48000])
[email protected]("chunk_size", [1, 4, 5, 10, 100])
[email protected]("chunk_size", [1000])
[email protected]("duration", [1.0])
@pytest.mark.parametrize("quality", QUALITIES)
def test_read_resampled_in_chunks(
- sample_rate: float, target_sample_rate: float, chunk_size: int, quality
+ sample_rate: float, target_sample_rate: float, chunk_size: int, duration: float, quality
):
- signal = np.linspace(1, sample_rate, sample_rate).astype(np.float32)
+ signal = np.linspace(1, sample_rate, int(sample_rate * duration)).astype(np.float32)
expected_signal = expected_output(signal, sample_rate, target_sample_rate, 1, quality)
read_buffer = BytesIO()
@@ -166,6 +167,19 @@ def test_read_resampled_in_chunks(
assert samples_received == f.tell()
[email protected]("sample_rate", [8000, 48000])
[email protected]("target_sample_rate", [8000, 12345.67, 22050, 44100, 48000])
[email protected]("chunk_size", [1, 4, 5])
[email protected]("duration", [0.1])
[email protected]("quality", QUALITIES)
+def test_read_resampled_with_tiny_chunks(
+ sample_rate: float, target_sample_rate: float, chunk_size: int, duration, quality
+):
+ if sample_rate == target_sample_rate:
+ return
+ test_read_resampled_in_chunks(sample_rate, target_sample_rate, chunk_size, duration, quality)
+
+
@pytest.mark.parametrize("sample_rate", [8000, 11025, 22050, 44100, 48000])
@pytest.mark.parametrize("target_sample_rate", [8000, 11025, 12345.67, 22050, 44100, 48000])
@pytest.mark.parametrize("quality", QUALITIES)