Skip to content

Commit f2f434a

Browse files
mgeierbastibe
authored andcommitted
Change argument order
The arguments which are forwarded to the SoundFile constructor, are moved to the back (because they are very seldomly used). See also #78.
1 parent e8a8de1 commit f2f434a

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

pysoundfile.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@
277277
_snd = _ffi.dlopen('sndfile')
278278

279279

280-
def read(file, samplerate=None, channels=None, subtype=None, endian=None,
281-
format=None, closefd=True, start=0, stop=None, frames=-1,
282-
dtype='float64', always_2d=True, fill_value=None, out=None):
280+
def read(file, frames=-1, start=0, stop=None, dtype='float64', always_2d=True,
281+
fill_value=None, out=None, samplerate=None, channels=None,
282+
format=None, subtype=None, endian=None, closefd=True):
283283
"""Read a sound file and return its contents as NumPy array.
284284
285285
The number of frames to read can be specified with ``frames``, the
@@ -309,16 +309,16 @@ def read(file, samplerate=None, channels=None, subtype=None, endian=None,
309309
----------
310310
file : A filename or a ``file`` object or file descriptor
311311
The file to open.
312+
frames : int, optional
313+
The number of frames to read. If ``-1``, the whole rest of the
314+
file is read. Only two of ``start``, ``stop``, and ``frames``
315+
can be given.
312316
start : int, optional
313317
Where to start reading. Only two of ``start``, ``stop``, and
314318
``frames`` can be given.
315319
stop : int, optional
316320
Where to stop reading. Only two of ``start``, ``stop``, and
317321
``frames`` can be given. Ignored if ``None``.
318-
frames : int, optional
319-
The number of frames to read. If ``-1``, the whole rest of the
320-
file is read. Only two of ``start``, ``stop``, and ``frames``
321-
can be given.
322322
dtype : {'float64', 'float32', 'int32', 'int16'}, optional
323323
The data type to read. Floating point data is typically in
324324
the range -1..1, and integer data is always in the range
@@ -362,7 +362,7 @@ def read(file, samplerate=None, channels=None, subtype=None, endian=None,
362362

363363
with SoundFile(file, 'r', samplerate, channels,
364364
subtype, endian, format, closefd) as f:
365-
start, frames = _get_read_range(start, stop, frames, f.frames)
365+
start, frames = _get_read_range(frames, start, stop, f.frames)
366366
f.seek(start, SEEK_SET)
367367
data = f.read(frames, dtype, always_2d, fill_value, out)
368368
return data, f.samplerate
@@ -410,10 +410,10 @@ def write(data, file, samplerate,
410410
f.write(data)
411411

412412

413-
def blocks(file, samplerate=None, channels=None,
414-
subtype=None, endian=None, format=None, closefd=True,
415-
blocksize=None, overlap=0, start=0, stop=None, frames=-1,
416-
dtype='float64', always_2d=True, fill_value=None, out=None):
413+
def blocks(file, blocksize=None, overlap=0, frames=-1, start=0, stop=None,
414+
dtype='float64', always_2d=True, fill_value=None, out=None,
415+
samplerate=None, channels=None,
416+
format=None, subtype=None, endian=None, closefd=True):
417417
"""Return a generator for block-wise processing.
418418
419419
All keyword arguments of :meth:`SoundFile.blocks` are
@@ -437,7 +437,7 @@ def blocks(file, samplerate=None, channels=None,
437437
must be given.
438438
overlap : int, optional
439439
The number of frames to rewind between each block.
440-
start, stop, frames
440+
frames, start, stop
441441
See :func:`read`.
442442
dtype : {'float64', 'float32', 'int32', 'int16'}, optional
443443
See :func:`read`.
@@ -452,10 +452,10 @@ def blocks(file, samplerate=None, channels=None,
452452
453453
Other Parameters
454454
----------------
455-
samplerate, channels, format, subtype, endian, closefd
456-
See :class:`SoundFile`.
457455
always_2d, fill_value, out
458456
See :func:`read`.
457+
samplerate, channels, format, subtype, endian, closefd
458+
See :class:`SoundFile`.
459459
460460
Examples
461461
--------
@@ -470,7 +470,7 @@ def blocks(file, samplerate=None, channels=None,
470470

471471
with SoundFile(file, 'r', samplerate, channels,
472472
subtype, endian, format, closefd) as f:
473-
start, frames = _get_read_range(start, stop, frames, f.frames)
473+
start, frames = _get_read_range(frames, start, stop, f.frames)
474474
f.seek(start, SEEK_SET)
475475
for block in f.blocks(blocksize, overlap, frames,
476476
dtype, always_2d, fill_value, out):
@@ -1211,7 +1211,7 @@ def _read_or_write(self, funcname, array, frames):
12111211
return frames
12121212

12131213

1214-
def _get_read_range(start, stop, frames, total_frames):
1214+
def _get_read_range(frames, start, stop, total_frames):
12151215
# Calculate start frame and length
12161216
start, stop, _ = slice(start, stop).indices(total_frames)
12171217
if stop < start:

tests/test_argspec.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ def test_if_blocks_function_and_method_have_same_defaults():
7171

7272

7373
def test_order_of_blocks_arguments():
74+
# Only the first few are checked
7475
meth_args = blocks_method.args[1:] # remove 'self'
75-
meth_args[2:2] = ['start', 'stop']
76-
init_args = init.args[1:] # remove 'self'
77-
init_args.remove('mode')
78-
assert blocks_function.args == init_args + meth_args
76+
meth_args[3:3] = ['start', 'stop']
77+
assert blocks_function.args[:10] == ['file'] + meth_args

0 commit comments

Comments
 (0)