@@ -211,10 +211,10 @@ def read(file, frames=-1, start=0, stop=None, dtype='float64', always_2d=False,
211
211
array anyway.
212
212
213
213
If `out` was specified, it is returned. If `out` has more
214
- frames than available in the file (or if `frames ` is smaller
215
- than the length of `out`) and no `fill_value` is given , then
216
- only a part of `out` is overwritten and a view containing all
217
- valid frames is returned.
214
+ frames than available in the file and no `fill_value ` is given,
215
+ or if `frames` is smaller than the length of `out`, then only a
216
+ part of `out` is overwritten and a view containing all valid
217
+ frames is returned.
218
218
samplerate : int
219
219
The sample rate of the audio file.
220
220
@@ -806,12 +806,11 @@ def read(self, frames=-1, dtype='float64', always_2d=False,
806
806
one-dimensional array is returned. Use ``always_2d=True``
807
807
to return a two-dimensional array anyway.
808
808
809
- If `out` was specified, it is returned. If `out` has more
810
- frames than available in the file (or if `frames` is
811
- smaller than the length of `out`) and no `fill_value` is
812
- given, then only a part of `out` is overwritten and a view
813
- containing all valid frames is returned. numpy.ndarray or
814
- type(out)
809
+ If `out` was specified, it is returned. If `out` has more
810
+ frames than available in the file and no `fill_value` is
811
+ given, or if `frames` is smaller than the length of `out`,
812
+ then only a part of `out` is overwritten and a view
813
+ containing all valid frames is returned.
815
814
816
815
Other Parameters
817
816
----------------
@@ -850,18 +849,25 @@ def read(self, frames=-1, dtype='float64', always_2d=False,
850
849
buffer_read, .write
851
850
852
851
"""
852
+ explicit_frames = frames >= 0
853
+ if out is not None and (frames < 0 or frames > len (out )):
854
+ frames = len (out )
855
+ max_frames = self ._check_frames (frames , fill_value )
853
856
if out is None :
854
- frames = self ._check_frames (frames , fill_value )
855
- out = self ._create_empty_array (frames , always_2d , dtype )
856
- else :
857
- if frames < 0 or frames > len (out ):
858
- frames = len (out )
859
- frames = self ._array_io ('read' , out , frames )
860
- if len (out ) > frames :
857
+ out = self ._create_empty_array (max_frames , always_2d , dtype )
858
+ read_frames = self ._array_io ('read' , out , max_frames )
859
+ if read_frames < max_frames :
861
860
if fill_value is None :
862
- out = out [:frames ]
861
+ # NB: This can only happen in non-seekable files
862
+ assert not self .seekable ()
863
+ out = out [:read_frames ]
864
+ else :
865
+ out [read_frames :max_frames ] = fill_value
866
+ if max_frames < len (out ):
867
+ if explicit_frames or fill_value is None :
868
+ out = out [:max_frames ]
863
869
else :
864
- out [frames :] = fill_value
870
+ out [max_frames :] = fill_value
865
871
return out
866
872
867
873
def buffer_read (self , frames = - 1 , dtype = None ):
0 commit comments