Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion soundfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ def blocks(self, blocksize=None, overlap=0, frames=-1, dtype='float64',
if out is None:
if blocksize is None:
raise TypeError("One of {blocksize, out} must be specified")
out_size = min(blocksize, frames)
out_size = blocksize if fill_value is not None else min(blocksize, frames)
out = self._create_empty_array(out_size, always_2d, dtype)
copy_out = True
else:
Expand Down
23 changes: 23 additions & 0 deletions tests/test_soundfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,17 +403,40 @@ def test_blocks_inplace_modification(file_stereo_r):


def test_blocks_mono():
blocks = list(sf.blocks(filename_mono, blocksize=3, dtype='int16'))
assert_equal_list_of_arrays(blocks, [[0, 1, 2], [-2, -1]])


def test_blocks_with_fill_value_mono():
blocks = list(sf.blocks(filename_mono, blocksize=3, dtype='int16',
fill_value=0))
assert_equal_list_of_arrays(blocks, [[0, 1, 2], [-2, -1, 0]])


def test_blocks_with_overlap_and_fill_value_mono():
blocks = list(sf.blocks(filename_mono, blocksize=4, dtype='int16',
overlap=2, fill_value=0))
assert_equal_list_of_arrays(blocks, [[0, 1, 2, -2], [2, -2, -1, 0]])


def test_block_longer_than_file_with_overlap_mono():
blocks = list(sf.blocks(filename_mono, blocksize=20, dtype='int16',
overlap=2))
assert_equal_list_of_arrays(blocks, [[0, 1, 2, -2, -1]])


def test_block_longer_than_file_with_fill_value_mono():
blocks = list(sf.blocks(filename_mono, blocksize=10, dtype='int16',
fill_value=0))
assert_equal_list_of_arrays(blocks, [[0, 1, 2, -2, -1, 0, 0, 0, 0, 0]])


def test_block_longer_than_file_with_overlap_and_fill_value_mono():
blocks = list(sf.blocks(filename_mono, blocksize=10, dtype='int16',
overlap=2, fill_value=0))
assert_equal_list_of_arrays(blocks, [[0, 1, 2, -2, -1, 0, 0, 0, 0, 0]])


def test_blocks_rplus(sf_stereo_rplus):
blocks = list(sf_stereo_rplus.blocks(blocksize=2))
assert_equal_list_of_arrays(blocks, [data_stereo[0:2], data_stereo[2:4]])
Expand Down
Loading