annotate 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 |
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@95
|
5 def frames_from_array(arr, step_size, frame_size):
|
Chris@95
|
6 """Generate a list of frames of size frame_size, 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@95
|
15 frame = arr[:, i : i + frame_size]
|
Chris@56
|
16 w = frame.shape[1]
|
Chris@95
|
17 if (w < frame_size):
|
Chris@95
|
18 pad = numpy.zeros((frame.shape[0], frame_size - 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
|