aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZakaria Zbitou <zbitou.zakaria@gmail.com>2026-08-23 18:56:21 +0200
committerZakaria Zbitou <zbitou.zakaria@gmail.com>2026-08-23 18:56:21 +0200
commitab97f7cf5d16bc2f58c069ee48621124bc024644 (patch)
tree185561dea344641d1baf3ea38b3dac03ef0445d7
parent99b31871fba0e86bad72137ac7601f5085d8e4a7 (diff)
downloadapollo-gfx803-ab97f7cf5d16bc2f58c069ee48621124bc024644.tar.gz
Add a failing test for chunk padding wider than the hop
This commit is expected to fail, so the bug can be confirmed before any fix lands. Check out this commit and run: python -m unittest discover -s tests The suite reports one failure: with 0.5 s chunks, a 0.1 s overlap and 0.5 s of padding, an identity model differs from its own input on 27.8% of samples. The fix follows in the next commit.
-rw-r--r--tests/test_inference.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/test_inference.py b/tests/test_inference.py
index 147be58..c6360b5 100644
--- a/tests/test_inference.py
+++ b/tests/test_inference.py
@@ -296,6 +296,51 @@ class InferenceTests(unittest.TestCase):
output, _ = sf.read(output_path, dtype="float32", always_2d=True)
self.assertFalse(np.isfinite(output).all())
+ def test_chunk_padding_wider_than_the_hop_reproduces_the_input(self):
+ """Regression: chunk padding wider than the hop silenced whole chunks.
+
+ `padded_start` was `start - chunk_pad_samples` for every chunk after
+ the first, which goes negative once the padding exceeds the hop. A
+ negative slice start is read from the end of the audio, so the slice
+ came back empty and `F.pad` filled the whole chunk with zeros, which
+ the crossfades then blended into the output.
+
+ Reproducing it needs padding wider than the hop and a chunk after the
+ first, so the file has to hold at least two chunks: 0.5 s chunks with
+ a 0.1 s overlap leave a 0.4 s hop, and 0.5 s of padding exceeds it.
+ The second chunk starts at 0.4 s, giving `padded_start = -0.1 s`.
+ """
+ with tempfile.TemporaryDirectory() as directory:
+ root = Path(directory)
+ input_path = root / "input.wav"
+ output_path = root / "output.wav"
+ checkpoint_path = root / "checkpoint.bin"
+ checkpoint_path.touch()
+
+ sample_count = int(inference.SAMPLE_RATE * 1.8)
+ samples = np.linspace(-0.5, 0.5, sample_count, dtype=np.float32)
+ stereo = np.stack((samples, -samples), axis=1)
+ sf.write(input_path, stereo, inference.SAMPLE_RATE, subtype="FLOAT")
+
+ model = IdentityModel()
+ with mock.patch.object(
+ inference.look2hear.models.BaseModel,
+ "from_pretrain",
+ return_value=model,
+ ):
+ inference.run_inference(
+ input_path,
+ output_path,
+ checkpoint_path,
+ requested_device="cpu",
+ chunk_seconds=0.5,
+ overlap_seconds=0.1,
+ chunk_pad_seconds=0.5,
+ )
+
+ output, _ = sf.read(output_path, dtype="float32", always_2d=True)
+ np.testing.assert_allclose(output, stereo, rtol=0, atol=1e-6)
+
def test_short_input_uses_original_full_file_path(self):
audio = torch.zeros(1, 2, inference.SAMPLE_RATE // 4)
model = IdentityModel()