1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 from timeside.core import implements, interfacedoc
23 from timeside.analyzer.core import Analyzer
24 from timeside.api import IAnalyzer
25
26 import subprocess
27 import numpy as np
31 implements(IAnalyzer)
32
40
41 @interfacedoc
42 - def setup(self, channels=None, samplerate=None,
43 blocksize=None, totalframes=None):
46
47 @staticmethod
48 @interfacedoc
50 return "vamp_simple_host"
51
52 @staticmethod
53 @interfacedoc
55 return "Vamp Plugins host"
56
57 @staticmethod
58 @interfacedoc
61
62 - def process(self, frames, eod=False):
63 pass
64 return frames, eod
65
66 - def post_process(self):
67
68
69 wavfile = self.mediainfo()['uri'].split('file://')[-1]
70
71 for plugin_line in self.plugin_list:
72
73 plugin = ':'.join(plugin_line)
74 (time, duration, value) = self.vamp_plugin(plugin, wavfile)
75 if value is None:
76 return
77
78 if duration is not None:
79 plugin_res = self.new_result(data_mode='value', time_mode='segment')
80 plugin_res.data_object.duration = duration
81 else:
82 plugin_res = self.new_result(data_mode='value', time_mode='event')
83
84 plugin_res.data_object.time = time
85 plugin_res.data_object.value = value
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109 plugin_res.id_metadata.id += '.' + '.'.join(plugin_line[1:])
110 plugin_res.id_metadata.name += ' ' + \
111 ' '.join(plugin_line[1:])
112
113 self.process_pipe.results.add(plugin_res)
114
115 @staticmethod
117
118 args = [plugin, wavfile]
119
120 stdout = VampSimpleHost.SimpleHostProcess(args)
121
122 stderr = stdout[0:8]
123 res = stdout[8:]
124
125 if len(res) == 0:
126 return ([], [], [])
127
128
129 blocksize_info = stderr[4]
130
131 import re
132
133 m = re.match(
134 'Using block size = (\d+), step size = (\d+)', blocksize_info)
135
136 blocksize = int(m.groups()[0])
137 stepsize = int(m.groups()[1])
138
139
140 value = np.asfarray([line.split(': ')[1].split(' ') for line in res if (len(line.split(': ')) > 1)])
141 time = np.asfarray([r.split(':')[0].split(',')[0] for r in res])
142
143 time_len = len(res[0].split(':')[0].split(','))
144 if time_len == 1:
145
146 duration = None
147 elif time_len == 2:
148
149 duration = np.asfarray([r.split(':')[0].split(',')[1] for r in res])
150
151 return (time, duration, value)
152
153 @staticmethod
159
160 @staticmethod
162 """Call vamp-simple-host"""
163
164 vamp_host = 'vamp-simple-host'
165 command = [vamp_host]
166 command.extend(argslist)
167
168 stdout = subprocess.check_output(
169 command, stderr=subprocess.STDOUT).splitlines()
170
171 return stdout
172