|
9 | 9 | Python-SoXR is a Python wrapper of libsoxr. |
10 | 10 | """ |
11 | 11 |
|
| 12 | +from concurrent.futures import ThreadPoolExecutor |
| 13 | +from functools import partial |
| 14 | + |
12 | 15 | import numpy as np |
13 | 16 | import pytest |
14 | 17 | import soxr |
@@ -63,7 +66,7 @@ def test_length_match(in_rate, out_rate, length): |
63 | 66 | assert np.allclose(y_oneshot, y_split) |
64 | 67 |
|
65 | 68 |
|
66 | | -@pytest.mark.parametrize('channels', [1, 2, 3, 5, 7, 97, 197]) |
| 69 | +@pytest.mark.parametrize('channels', [1, 2, 3, 5, 7, 24, 49]) |
67 | 70 | def test_channel_match(channels): |
68 | 71 | x = np.random.randn(30011, channels).astype(np.float32) |
69 | 72 |
|
@@ -129,7 +132,9 @@ def test_stream_length(in_rate, out_rate, chunk_size, length): |
129 | 132 | def make_tone(freq, sr, duration): |
130 | 133 | length = int(sr * duration) |
131 | 134 | sig = np.sin(2 * np.pi * freq / sr * np.arange(length)) |
132 | | - return sig * np.hanning(length) |
| 135 | + sig = sig * np.hanning(length) |
| 136 | + |
| 137 | + return np.stack([sig, np.zeros_like(sig)], axis=-1) |
133 | 138 |
|
134 | 139 |
|
135 | 140 | @pytest.mark.parametrize('in_rate,out_rate', [(44100, 22050), (22050, 32000)]) |
@@ -162,3 +167,17 @@ def test_int_sine(in_rate, out_rate, dtype): |
162 | 167 |
|
163 | 168 | assert np.allclose(y, y_pred, atol=2) |
164 | 169 | assert np.allclose(y, y_split, atol=2) |
| 170 | + |
| 171 | + |
| 172 | +@pytest.mark.parametrize('num_task', [2, 3, 4, 5, 6, 7, 8, 9, 12, 17, 32]) |
| 173 | +def test_multithread(num_task): |
| 174 | + x = np.random.randn(25999, 2).astype(np.float32) |
| 175 | + |
| 176 | + with ThreadPoolExecutor() as p: |
| 177 | + results = p.map( |
| 178 | + partial(soxr.resample, in_rate=44100, out_rate=32000), |
| 179 | + [x] * num_task |
| 180 | + ) |
| 181 | + results = list(results) |
| 182 | + |
| 183 | + assert np.allclose(results[-2], results[-1]) |
0 commit comments