comparison vamp/frames.py @ 95:3e5791890b65

refactor, add process_frames
author Chris Cannam
date Mon, 02 Feb 2015 17:15:15 +0000
parents d91a2285fbb2
children 2370b942cd32
comparison
equal deleted inserted replaced
94:c3318a95625b 95:3e5791890b65
1 '''A high-level interface to the vampyhost extension module, for quickly and easily running Vamp audio analysis plugins on audio files and buffers.''' 1 '''A high-level interface to the vampyhost extension module, for quickly and easily running Vamp audio analysis plugins on audio files and buffers.'''
2 2
3 import numpy 3 import numpy
4 4
5 def frames_from_array(arr, step_size, frameSize): 5 def frames_from_array(arr, step_size, frame_size):
6 """Generate a list of frames of size frameSize, extracted from the input array arr at step_size intervals""" 6 """Generate a list of frames of size frame_size, extracted from the input array arr at step_size intervals"""
7 # presumably such a function exists in many places, but I need practice 7 # presumably such a function exists in many places, but I need practice
8 assert(step_size > 0) 8 assert(step_size > 0)
9 if arr.ndim == 1: # turn 1d into 2d array with 1 channel 9 if arr.ndim == 1: # turn 1d into 2d array with 1 channel
10 arr = numpy.reshape(arr, (1, arr.shape[0])) 10 arr = numpy.reshape(arr, (1, arr.shape[0]))
11 assert(arr.ndim == 2) 11 assert(arr.ndim == 2)
12 n = arr.shape[1] 12 n = arr.shape[1]
13 i = 0 13 i = 0
14 while (i < n): 14 while (i < n):
15 frame = arr[:, i : i + frameSize] 15 frame = arr[:, i : i + frame_size]
16 w = frame.shape[1] 16 w = frame.shape[1]
17 if (w < frameSize): 17 if (w < frame_size):
18 pad = numpy.zeros((frame.shape[0], frameSize - w)) 18 pad = numpy.zeros((frame.shape[0], frame_size - w))
19 frame = numpy.concatenate((frame, pad), 1) 19 frame = numpy.concatenate((frame, pad), 1)
20 yield frame 20 yield frame
21 i = i + step_size 21 i = i + step_size
22 22