Skip to content

Commit

Permalink
Merge pull request #68 from bmcfee/frame-error-67
Browse files Browse the repository at this point in the history
fixes #67, pads by one frame past last event
  • Loading branch information
bmcfee committed May 3, 2017
2 parents 036fb28 + c858daa commit 033c2f1
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions pumpp/task/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,19 @@ def encode_events(self, duration, events, values, dtype=np.bool):
n_total = int(time_to_frames(duration, sr=self.sr,
hop_length=self.hop_length))

target = np.empty((n_total, values.shape[1]), dtype=dtype)
n_alloc = n_total
if np.any(frames):
n_alloc = max(n_total, 1 + int(frames.max()))

target = np.empty((n_alloc, values.shape[1]),
dtype=dtype)

target.fill(fill_value(dtype))
values = values.astype(dtype)
for column, event in zip(values, frames):
target[event] += column

return target
return target[:n_total]

def encode_intervals(self, duration, intervals, values, dtype=np.bool,
multi=True, fill=None):
Expand Down Expand Up @@ -205,7 +210,13 @@ def encode_intervals(self, duration, intervals, values, dtype=np.bool,

values = values.astype(dtype)

target = np.empty((n_total, values.shape[1]), dtype=dtype)
n_alloc = n_total
if np.any(frames):
n_alloc = max(n_total, 1 + int(frames.max()))

target = np.empty((n_alloc, values.shape[1]),

dtype=dtype)

target.fill(fill)

Expand All @@ -215,7 +226,7 @@ def encode_intervals(self, duration, intervals, values, dtype=np.bool,
else:
target[interval[0]:interval[1]] = column

return target
return target[:n_total]

def decode_events(self, encoded):
'''Decode labeled events into (time, value) pairs
Expand Down

0 comments on commit 033c2f1

Please sign in to comment.