annotate vamp/frames.py @ 84:d91a2285fbb2

naming: local variables snake_case
author Chris Cannam
date Wed, 21 Jan 2015 13:04:01 +0000
parents a11b57e9fb0b
children 3e5791890b65
rev   line source
Chris@56 1 '''A high-level interface to the vampyhost extension module, for quickly and easily running Vamp audio analysis plugins on audio files and buffers.'''
Chris@56 2
Chris@56 3 import numpy
Chris@56 4
Chris@84 5 def frames_from_array(arr, step_size, frameSize):
Chris@84 6 """Generate a list of frames of size frameSize, extracted from the input array arr at step_size intervals"""
Chris@56 7 # presumably such a function exists in many places, but I need practice
Chris@84 8 assert(step_size > 0)
Chris@56 9 if arr.ndim == 1: # turn 1d into 2d array with 1 channel
Chris@56 10 arr = numpy.reshape(arr, (1, arr.shape[0]))
Chris@56 11 assert(arr.ndim == 2)
Chris@56 12 n = arr.shape[1]
Chris@56 13 i = 0
Chris@56 14 while (i < n):
Chris@56 15 frame = arr[:, i : i + frameSize]
Chris@56 16 w = frame.shape[1]
Chris@56 17 if (w < frameSize):
Chris@56 18 pad = numpy.zeros((frame.shape[0], frameSize - w))
Chris@56 19 frame = numpy.concatenate((frame, pad), 1)
Chris@56 20 yield frame
Chris@84 21 i = i + step_size
Chris@56 22