From e42372b63d25c0633df2a7bab62c711f7b88a6f4 Mon Sep 17 00:00:00 2001 From: Gautzilla Date: Thu, 26 Mar 2026 17:31:42 +0100 Subject: [PATCH 1/2] add test for resampling from different sample rates --- tests/test_audio.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_audio.py b/tests/test_audio.py index 1cc6d667..fd8e3780 100644 --- a/tests/test_audio.py +++ b/tests/test_audio.py @@ -2120,3 +2120,25 @@ def test_audio_data_equality( # AudioDataset equality should account for sample rate assert ads1 != ads2 + + +def test_resampling_from_different_origin_frequencies(tmp_path: Path) -> None: + sf.write( + tmp_path / "a1.wav", + data=[0.5] * 48_000, + samplerate=48_000, + ) + sf.write( + tmp_path / "a2.wav", + data=[0.5] * 48_000, + samplerate=24_000, + ) + af1 = AudioFile(tmp_path / "a1.wav", begin=Timestamp("2024-01-01 12:00:00")) + af2 = AudioFile(tmp_path / "a2.wav", begin=Timestamp("2024-01-01 12:00:01")) + + ad = AudioData.from_files( + [af1, af2], + sample_rate=12_000, + ) + + ad.get_value() From 68515e843814694812f808014804fd405498a2a8 Mon Sep 17 00:00:00 2001 From: Gautzilla Date: Thu, 26 Mar 2026 17:48:09 +0100 Subject: [PATCH 2/2] fix empty flush sample count --- src/osekit/core/audio_data.py | 3 ++- tests/test_audio.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/osekit/core/audio_data.py b/src/osekit/core/audio_data.py index 38d5ed69..d592ae28 100644 --- a/src/osekit/core/audio_data.py +++ b/src/osekit/core/audio_data.py @@ -272,7 +272,8 @@ def stream(self, chunk_size: int = 8192) -> Generator[np.ndarray, None, None]: remaining_samples=total_samples - produced_samples, ) yield flush - produced_samples += len(flush[0]) + if flush.size > 0: + produced_samples += len(flush[0]) input_sr = item.sample_rate quality = resample_quality_settings[ "downsample" if input_sr > self.sample_rate else "upsample" diff --git a/tests/test_audio.py b/tests/test_audio.py index fd8e3780..3f9c6122 100644 --- a/tests/test_audio.py +++ b/tests/test_audio.py @@ -2141,4 +2141,5 @@ def test_resampling_from_different_origin_frequencies(tmp_path: Path) -> None: sample_rate=12_000, ) - ad.get_value() + vs = ad.get_value() + assert vs.size == int(ad.duration.total_seconds()) * ad.sample_rate