Skip to content

Commit 7868503

Browse files
author
Benjamin Moody
committed
Add a test case for reading a long-duration FLAC file.
To ensure that samples are loaded correctly if the file contains more than 2**24 total samples (which tickles a bug in libsndfile), test reading a file containing three constant signals.
1 parent e627523 commit 7868503

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

sample-data/flac_3_constant.dat

20 KB
Binary file not shown.

sample-data/flac_3_constant.hea

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
flac_3_constant 3 250 5600000
2+
flac_3_constant.dat 508 200 8 0 25 15104 0 col 0
3+
flac_3_constant.dat 508 200 8 0 50 30208 0 col 1
4+
flac_3_constant.dat 508 200 8 0 75 -20224 0 col 2

tests/test_record.py

+22
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,28 @@ def test_read_flac(self):
249249
f"Mismatch in {name}",
250250
)
251251

252+
def test_read_flac_longduration(self):
253+
"""
254+
Three signals multiplexed in a FLAC file, over 2**24 samples.
255+
256+
Input file created with:
257+
yes 25 50 75 | head -5600000 |
258+
wrsamp -O 508 -o flac_3_constant 0 1 2
259+
260+
Note that the total number of samples (across the three
261+
channels) exceeds 2**24. There is a bug in libsndfile that
262+
causes it to break if we try to read more than 2**24 total
263+
samples at a time, when the number of channels is not a power
264+
of two.
265+
"""
266+
record = wfdb.rdrecord("sample-data/flac_3_constant")
267+
sig_target = np.repeat(
268+
np.array([[0.125, 0.25, 0.375]], dtype="float64"),
269+
5600000,
270+
axis=0,
271+
)
272+
np.testing.assert_array_equal(record.p_signal, sig_target)
273+
252274
# ------------------ 2. Special format records ------------------ #
253275

254276
def test_2a(self):

0 commit comments

Comments
 (0)