Chris@117
|
1 #!/usr/bin/env python
|
Chris@117
|
2
|
Chris@117
|
3 # Python Vamp Host
|
Chris@117
|
4 # Copyright (c) 2008-2015 Queen Mary, University of London
|
Chris@117
|
5 #
|
Chris@117
|
6 # Permission is hereby granted, free of charge, to any person
|
Chris@117
|
7 # obtaining a copy of this software and associated documentation
|
Chris@117
|
8 # files (the "Software"), to deal in the Software without
|
Chris@117
|
9 # restriction, including without limitation the rights to use, copy,
|
Chris@117
|
10 # modify, merge, publish, distribute, sublicense, and/or sell copies
|
Chris@117
|
11 # of the Software, and to permit persons to whom the Software is
|
Chris@117
|
12 # furnished to do so, subject to the following conditions:
|
Chris@117
|
13 #
|
Chris@117
|
14 # The above copyright notice and this permission notice shall be
|
Chris@117
|
15 # included in all copies or substantial portions of the Software.
|
Chris@117
|
16 #
|
Chris@117
|
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
Chris@117
|
18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
Chris@117
|
19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
Chris@117
|
20 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
Chris@117
|
21 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
Chris@117
|
22 # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
Chris@117
|
23 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
Chris@117
|
24 #
|
Chris@117
|
25 # Except as contained in this notice, the names of the Centre for
|
Chris@117
|
26 # Digital Music and Queen Mary, University of London shall not be
|
Chris@117
|
27 # used in advertising or otherwise to promote the sale, use or other
|
Chris@117
|
28 # dealings in this Software without prior written authorization.
|
Chris@117
|
29
|
Chris@56
|
30 '''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
|
31
|
Chris@56
|
32 import numpy
|
Chris@56
|
33
|
Chris@95
|
34 def frames_from_array(arr, step_size, frame_size):
|
Chris@95
|
35 """Generate a list of frames of size frame_size, extracted from the input array arr at step_size intervals"""
|
Chris@56
|
36 # presumably such a function exists in many places, but I need practice
|
Chris@84
|
37 assert(step_size > 0)
|
Chris@56
|
38 if arr.ndim == 1: # turn 1d into 2d array with 1 channel
|
Chris@56
|
39 arr = numpy.reshape(arr, (1, arr.shape[0]))
|
Chris@56
|
40 assert(arr.ndim == 2)
|
Chris@56
|
41 n = arr.shape[1]
|
Chris@56
|
42 i = 0
|
Chris@56
|
43 while (i < n):
|
Chris@95
|
44 frame = arr[:, i : i + frame_size]
|
Chris@56
|
45 w = frame.shape[1]
|
Chris@95
|
46 if (w < frame_size):
|
Chris@95
|
47 pad = numpy.zeros((frame.shape[0], frame_size - w))
|
Chris@56
|
48 frame = numpy.concatenate((frame, pad), 1)
|
Chris@56
|
49 yield frame
|
Chris@84
|
50 i = i + step_size
|
Chris@56
|
51
|