Skip to content

Commit ac983e5

Browse files
committed
Added two-dimensional indexing
1 parent 42dc599 commit ac983e5

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

pysoundfile.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,23 @@ def _get_slice_bounds(self, frame):
429429
return start, stop
430430

431431
def __getitem__(self, frame):
432-
# access the file as if it where a one-dimensional Numpy
433-
# array. Data must be in the form (frames x channels).
434-
# Both open slice bounds and negative values are allowed.
432+
# access the file as if it where a Numpy array. The data is
433+
# returned as numpy array.
434+
second_frame = None
435+
if isinstance(frame, tuple):
436+
if len(frame) > 2:
437+
raise AttributeError(
438+
"SoundFile can only be accessed in one or two dimensions")
439+
frame, second_frame = frame
435440
start, stop = self._get_slice_bounds(frame)
436441
curr = self.seek(0)
437442
self.seek_absolute(start)
438443
data = self.read(stop - start)
439444
self.seek_absolute(curr)
440-
return data
445+
if second_frame:
446+
return data[(slice(None), second_frame)]
447+
else:
448+
return data
441449

442450
def __setitem__(self, frame, data):
443451
# access the file as if it where a one-dimensional Numpy

0 commit comments

Comments
 (0)