Skip to content

Commit

Permalink
Fix out of bounds error
Browse files Browse the repository at this point in the history
`iter_chunks` now uses `np.linspace` to generate indices. In addition
to fixing the out of bounds error, this also ensures each chunk
generates an approximately equal number of indices.
  • Loading branch information
shawwn committed May 25, 2017
1 parent f63a985 commit 2f569d0
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions moviepy/audio/AudioClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@ def iter_chunks(self, chunksize=None, chunk_duration=None, fps=None,

totalsize = int(fps*self.duration)

if (totalsize % chunksize == 0):
nchunks = totalsize // chunksize
else:
nchunks = totalsize // chunksize + 1
nchunks = totalsize // chunksize + 1

pospos = list(range(0, totalsize, chunksize))+[totalsize]
pospos = np.linspace(0, totalsize, nchunks + 1, endpoint=True, dtype=int)

def generator():
for i in range(nchunks):
size = pospos[i+1] - pospos[i]
assert(size <= chunksize)
tt = (1.0/fps)*np.arange(pospos[i],pospos[i+1])
yield self.to_soundarray(tt, nbytes= nbytes, quantize=quantize, fps=fps,
buffersize=chunksize)
Expand Down

0 comments on commit 2f569d0

Please sign in to comment.