view framer.py @ 12:9973b7cd0d31 tip

Implement rest of tempo estimator
author Chris Cannam
date Mon, 08 Oct 2012 15:46:54 +0100
parents 7fc62809da94
children
line wrap: on
line source

import numpy as np

def get_frame_count(nsamples, hop):
    """Given the number of samples, return the number of non-overlapping frames of length hop we can extract from them."""
    return int(np.ceil(nsamples / float(hop)))

def get_frame(samples, hop, n):
    """Given samples and hop, return the n'th non-overlapping frame of length hop."""
    frame = samples[n * hop : (n+1) * hop]
    if len(frame) < hop:
        frame = np.append(frame, np.zeros(hop - len(frame)))
    return frame