annotate vamp/frames.py @ 81:0a2f2e7803ea
naming: PyPluginObject members snake_case
| author |
Chris Cannam |
| date |
Wed, 21 Jan 2015 12:32:32 +0000 |
| parents |
ad08a0fe6673 |
| children |
a11b57e9fb0b |
| 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@56
|
5 def framesFromArray(arr, stepSize, frameSize):
|
|
Chris@56
|
6 """Generate a list of frames of size frameSize, extracted from the input array arr at stepSize intervals"""
|
|
Chris@56
|
7 # presumably such a function exists in many places, but I need practice
|
|
Chris@56
|
8 assert(stepSize > 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@56
|
21 i = i + stepSize
|
|
Chris@56
|
22
|