Skip to content

Commit

Permalink
fixed case when accessing time out of the estimated valid range
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Gygli committed Mar 13, 2017
1 parent da10425 commit 68df86c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions moviepy/audio/io/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,13 @@ def get_frame(self, tt):

# elements of t that are actually in the range of the
# audio file.

in_time = (tt>=0) & (tt < self.duration)

# Check that the requested time is in the valid range
if not in_time.any():
raise IOError("Error in file %s, "%(self.filename)+
"Accessing time t=%.02f-%.02f seconds, "%(tt[0], tt[-1])+
"with clip duration=%d seconds, "%self.duration)

# The np.round in the next line is super-important.
# Removing it results in artifacts in the noise.
Expand All @@ -187,7 +192,7 @@ def get_frame(self, tt):
warnings.warn("Error in file %s, "%(self.filename)+
"At time t=%.02f-%.02f seconds, "%(tt[0], tt[-1])+
"indices wanted: %d-%d, "%(indices.min(), indices.max())+
"but len(buffer)=%d"%(len(self.buffer))+ str(error),
"but len(buffer)=%d\n"%(len(self.buffer))+ str(error),
UserWarning)

# repeat the last frame instead
Expand Down

0 comments on commit 68df86c

Please sign in to comment.