Skip to content

Commit

Permalink
re-integrated read and readinto
Browse files Browse the repository at this point in the history
  • Loading branch information
bastibe committed Apr 30, 2014
1 parent db2cb0b commit a700fcf
Showing 1 changed file with 4 additions and 25 deletions.
29 changes: 4 additions & 25 deletions pysoundfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,38 +612,17 @@ def read(self, frames=-1, dtype='float64', always_2d=True,
"""

self._check_if_closed()
if self.mode == 'w':
raise RuntimeError("Cannot read from file opened in write mode")

if out is None:
if frames < 0:
frames = self.frames - self.seek(0, SEEK_CUR, 'r')
out = _np.empty((frames, self.channels), dtype)
if not always_2d and out.shape[1] == 1:
out = out.flatten()

try:
out = self._readinto(out, fill_value)
except Exception as e:
raise e

return out

def _readinto(self, out, fill_value=None):
"""Read a number of frames from the file into an array.
Reads the given number of frames in the given data format from
the current read position. This also advances the read
position by the same number of frames.
The data is written into the given NumPy array. If there is
not enough data left in the file to fill the array, the rest
of the frames are ignored and a smaller view to the array is
returned. Use fill_value to fill the rest of the array and
return the full-length array.
"""
self._check_if_closed()
if self.mode == 'w':
raise RuntimeError("Cannot read from file opened in write mode")

try:
ffi_type = _ffi_types[out.dtype]
except KeyError:
Expand Down

0 comments on commit a700fcf

Please sign in to comment.