matthiasm@0
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@9
|
2
|
matthiasm@0
|
3 /*
|
Chris@9
|
4 pYIN - A fundamental frequency estimator for monophonic audio
|
Chris@9
|
5 Centre for Digital Music, Queen Mary, University of London.
|
Chris@9
|
6
|
Chris@9
|
7 This program is free software; you can redistribute it and/or
|
Chris@9
|
8 modify it under the terms of the GNU General Public License as
|
Chris@9
|
9 published by the Free Software Foundation; either version 2 of the
|
Chris@9
|
10 License, or (at your option) any later version. See the file
|
Chris@9
|
11 COPYING included with this distribution for more information.
|
matthiasm@0
|
12 */
|
matthiasm@0
|
13
|
matthiasm@36
|
14 #include "PYinVamp.h"
|
matthiasm@0
|
15 #include "MonoNote.h"
|
matthiasm@0
|
16 #include "MonoPitch.h"
|
matthiasm@0
|
17
|
matthiasm@0
|
18 #include "vamp-sdk/FFT.h"
|
matthiasm@0
|
19
|
matthiasm@0
|
20 #include <vector>
|
matthiasm@0
|
21 #include <algorithm>
|
matthiasm@0
|
22
|
matthiasm@0
|
23 #include <cstdio>
|
matthiasm@0
|
24 #include <cmath>
|
matthiasm@0
|
25 #include <complex>
|
matthiasm@0
|
26
|
matthiasm@0
|
27 using std::string;
|
matthiasm@0
|
28 using std::vector;
|
matthiasm@0
|
29 using Vamp::RealTime;
|
matthiasm@0
|
30
|
matthiasm@0
|
31
|
matthiasm@36
|
32 PYinVamp::PYinVamp(float inputSampleRate) :
|
matthiasm@0
|
33 Plugin(inputSampleRate),
|
matthiasm@0
|
34 m_channels(0),
|
matthiasm@0
|
35 m_stepSize(256),
|
matthiasm@0
|
36 m_blockSize(2048),
|
matthiasm@0
|
37 m_fmin(40),
|
matthiasm@58
|
38 m_fmax(1600),
|
matthiasm@0
|
39 m_yin(2048, inputSampleRate, 0.0),
|
matthiasm@0
|
40 m_oF0Candidates(0),
|
matthiasm@0
|
41 m_oF0Probs(0),
|
matthiasm@0
|
42 m_oVoicedProb(0),
|
matthiasm@0
|
43 m_oCandidateSalience(0),
|
matthiasm@0
|
44 m_oSmoothedPitchTrack(0),
|
matthiasm@0
|
45 m_oNotes(0),
|
matthiasm@0
|
46 m_threshDistr(2.0f),
|
matthiasm@6
|
47 m_outputUnvoiced(0.0f),
|
matthiasm@0
|
48 m_pitchProb(0),
|
matthiasm@0
|
49 m_timestamp(0)
|
matthiasm@0
|
50 {
|
matthiasm@0
|
51 }
|
matthiasm@0
|
52
|
matthiasm@36
|
53 PYinVamp::~PYinVamp()
|
matthiasm@0
|
54 {
|
matthiasm@0
|
55 }
|
matthiasm@0
|
56
|
matthiasm@0
|
57 string
|
matthiasm@36
|
58 PYinVamp::getIdentifier() const
|
matthiasm@0
|
59 {
|
matthiasm@1
|
60 return "pyin";
|
matthiasm@0
|
61 }
|
matthiasm@0
|
62
|
matthiasm@0
|
63 string
|
matthiasm@36
|
64 PYinVamp::getName() const
|
matthiasm@0
|
65 {
|
matthiasm@1
|
66 return "pYin";
|
matthiasm@0
|
67 }
|
matthiasm@0
|
68
|
matthiasm@0
|
69 string
|
matthiasm@36
|
70 PYinVamp::getDescription() const
|
matthiasm@0
|
71 {
|
matthiasm@0
|
72 return "Monophonic pitch and note tracking based on a probabilistic Yin extension.";
|
matthiasm@0
|
73 }
|
matthiasm@0
|
74
|
matthiasm@0
|
75 string
|
matthiasm@36
|
76 PYinVamp::getMaker() const
|
matthiasm@0
|
77 {
|
matthiasm@0
|
78 return "Matthias Mauch";
|
matthiasm@0
|
79 }
|
matthiasm@0
|
80
|
matthiasm@0
|
81 int
|
matthiasm@36
|
82 PYinVamp::getPluginVersion() const
|
matthiasm@0
|
83 {
|
matthiasm@0
|
84 // Increment this each time you release a version that behaves
|
matthiasm@0
|
85 // differently from the previous one
|
matthiasm@0
|
86 return 1;
|
matthiasm@0
|
87 }
|
matthiasm@0
|
88
|
matthiasm@0
|
89 string
|
matthiasm@36
|
90 PYinVamp::getCopyright() const
|
matthiasm@0
|
91 {
|
matthiasm@0
|
92 return "GPL";
|
matthiasm@0
|
93 }
|
matthiasm@0
|
94
|
matthiasm@36
|
95 PYinVamp::InputDomain
|
matthiasm@36
|
96 PYinVamp::getInputDomain() const
|
matthiasm@0
|
97 {
|
matthiasm@0
|
98 return TimeDomain;
|
matthiasm@0
|
99 }
|
matthiasm@0
|
100
|
matthiasm@0
|
101 size_t
|
matthiasm@36
|
102 PYinVamp::getPreferredBlockSize() const
|
matthiasm@0
|
103 {
|
matthiasm@0
|
104 return 2048;
|
matthiasm@0
|
105 }
|
matthiasm@0
|
106
|
matthiasm@0
|
107 size_t
|
matthiasm@36
|
108 PYinVamp::getPreferredStepSize() const
|
matthiasm@0
|
109 {
|
matthiasm@0
|
110 return 256;
|
matthiasm@0
|
111 }
|
matthiasm@0
|
112
|
matthiasm@0
|
113 size_t
|
matthiasm@36
|
114 PYinVamp::getMinChannelCount() const
|
matthiasm@0
|
115 {
|
matthiasm@0
|
116 return 1;
|
matthiasm@0
|
117 }
|
matthiasm@0
|
118
|
matthiasm@0
|
119 size_t
|
matthiasm@36
|
120 PYinVamp::getMaxChannelCount() const
|
matthiasm@0
|
121 {
|
matthiasm@0
|
122 return 1;
|
matthiasm@0
|
123 }
|
matthiasm@0
|
124
|
matthiasm@36
|
125 PYinVamp::ParameterList
|
matthiasm@36
|
126 PYinVamp::getParameterDescriptors() const
|
matthiasm@0
|
127 {
|
matthiasm@0
|
128 ParameterList list;
|
matthiasm@0
|
129
|
matthiasm@0
|
130 ParameterDescriptor d;
|
matthiasm@0
|
131
|
matthiasm@0
|
132 d.identifier = "threshdistr";
|
matthiasm@0
|
133 d.name = "Yin threshold distribution";
|
matthiasm@0
|
134 d.description = ".";
|
matthiasm@0
|
135 d.unit = "";
|
matthiasm@0
|
136 d.minValue = 0.0f;
|
matthiasm@0
|
137 d.maxValue = 7.0f;
|
matthiasm@0
|
138 d.defaultValue = 2.0f;
|
matthiasm@0
|
139 d.isQuantized = true;
|
matthiasm@0
|
140 d.quantizeStep = 1.0f;
|
matthiasm@0
|
141 d.valueNames.push_back("Uniform");
|
matthiasm@0
|
142 d.valueNames.push_back("Beta (mean 0.10)");
|
matthiasm@0
|
143 d.valueNames.push_back("Beta (mean 0.15)");
|
matthiasm@0
|
144 d.valueNames.push_back("Beta (mean 0.20)");
|
matthiasm@0
|
145 d.valueNames.push_back("Beta (mean 0.30)");
|
matthiasm@0
|
146 d.valueNames.push_back("Single Value 0.10");
|
matthiasm@0
|
147 d.valueNames.push_back("Single Value 0.15");
|
matthiasm@0
|
148 d.valueNames.push_back("Single Value 0.20");
|
matthiasm@0
|
149 list.push_back(d);
|
matthiasm@0
|
150
|
matthiasm@0
|
151 d.identifier = "outputunvoiced";
|
matthiasm@0
|
152 d.valueNames.clear();
|
matthiasm@0
|
153 d.name = "Output estimates classified as unvoiced?";
|
matthiasm@0
|
154 d.description = ".";
|
matthiasm@0
|
155 d.unit = "";
|
matthiasm@0
|
156 d.minValue = 0.0f;
|
matthiasm@0
|
157 d.maxValue = 2.0f;
|
matthiasm@6
|
158 d.defaultValue = 0.0f;
|
matthiasm@0
|
159 d.isQuantized = true;
|
matthiasm@0
|
160 d.quantizeStep = 1.0f;
|
matthiasm@0
|
161 d.valueNames.push_back("No");
|
matthiasm@0
|
162 d.valueNames.push_back("Yes");
|
matthiasm@0
|
163 d.valueNames.push_back("Yes, as negative frequencies");
|
matthiasm@0
|
164 list.push_back(d);
|
matthiasm@0
|
165
|
matthiasm@0
|
166 return list;
|
matthiasm@0
|
167 }
|
matthiasm@0
|
168
|
matthiasm@0
|
169 float
|
matthiasm@36
|
170 PYinVamp::getParameter(string identifier) const
|
matthiasm@0
|
171 {
|
matthiasm@0
|
172 if (identifier == "threshdistr") {
|
matthiasm@0
|
173 return m_threshDistr;
|
matthiasm@0
|
174 }
|
matthiasm@0
|
175 if (identifier == "outputunvoiced") {
|
matthiasm@0
|
176 return m_outputUnvoiced;
|
matthiasm@0
|
177 }
|
matthiasm@0
|
178 return 0.f;
|
matthiasm@0
|
179 }
|
matthiasm@0
|
180
|
matthiasm@0
|
181 void
|
matthiasm@36
|
182 PYinVamp::setParameter(string identifier, float value)
|
matthiasm@0
|
183 {
|
matthiasm@0
|
184 if (identifier == "threshdistr")
|
matthiasm@0
|
185 {
|
matthiasm@0
|
186 m_threshDistr = value;
|
matthiasm@0
|
187 }
|
matthiasm@0
|
188 if (identifier == "outputunvoiced")
|
matthiasm@0
|
189 {
|
matthiasm@0
|
190 m_outputUnvoiced = value;
|
matthiasm@0
|
191 }
|
matthiasm@0
|
192
|
matthiasm@0
|
193 }
|
matthiasm@0
|
194
|
matthiasm@36
|
195 PYinVamp::ProgramList
|
matthiasm@36
|
196 PYinVamp::getPrograms() const
|
matthiasm@0
|
197 {
|
matthiasm@0
|
198 ProgramList list;
|
matthiasm@0
|
199 return list;
|
matthiasm@0
|
200 }
|
matthiasm@0
|
201
|
matthiasm@0
|
202 string
|
matthiasm@36
|
203 PYinVamp::getCurrentProgram() const
|
matthiasm@0
|
204 {
|
matthiasm@0
|
205 return ""; // no programs
|
matthiasm@0
|
206 }
|
matthiasm@0
|
207
|
matthiasm@0
|
208 void
|
matthiasm@36
|
209 PYinVamp::selectProgram(string name)
|
matthiasm@0
|
210 {
|
matthiasm@0
|
211 }
|
matthiasm@0
|
212
|
matthiasm@36
|
213 PYinVamp::OutputList
|
matthiasm@36
|
214 PYinVamp::getOutputDescriptors() const
|
matthiasm@0
|
215 {
|
matthiasm@0
|
216 OutputList outputs;
|
matthiasm@0
|
217
|
matthiasm@0
|
218 OutputDescriptor d;
|
matthiasm@0
|
219
|
matthiasm@0
|
220 int outputNumber = 0;
|
matthiasm@0
|
221
|
matthiasm@0
|
222 d.identifier = "f0candidates";
|
matthiasm@0
|
223 d.name = "F0 Candidates";
|
matthiasm@0
|
224 d.description = "Estimated fundamental frequency candidates.";
|
matthiasm@0
|
225 d.unit = "Hz";
|
matthiasm@0
|
226 d.hasFixedBinCount = false;
|
matthiasm@0
|
227 // d.binCount = 1;
|
matthiasm@0
|
228 d.hasKnownExtents = true;
|
matthiasm@0
|
229 d.minValue = m_fmin;
|
matthiasm@0
|
230 d.maxValue = 500;
|
matthiasm@0
|
231 d.isQuantized = false;
|
matthiasm@0
|
232 d.sampleType = OutputDescriptor::FixedSampleRate;
|
matthiasm@0
|
233 d.sampleRate = (m_inputSampleRate / m_stepSize);
|
matthiasm@0
|
234 d.hasDuration = false;
|
matthiasm@0
|
235 outputs.push_back(d);
|
matthiasm@0
|
236 m_oF0Candidates = outputNumber++;
|
matthiasm@0
|
237
|
matthiasm@0
|
238 d.identifier = "f0probs";
|
matthiasm@0
|
239 d.name = "Candidate Probabilities";
|
matthiasm@0
|
240 d.description = "Probabilities of estimated fundamental frequency candidates.";
|
matthiasm@0
|
241 d.unit = "";
|
matthiasm@0
|
242 d.hasFixedBinCount = false;
|
matthiasm@0
|
243 // d.binCount = 1;
|
matthiasm@0
|
244 d.hasKnownExtents = true;
|
matthiasm@0
|
245 d.minValue = 0;
|
matthiasm@0
|
246 d.maxValue = 1;
|
matthiasm@0
|
247 d.isQuantized = false;
|
matthiasm@0
|
248 d.sampleType = OutputDescriptor::FixedSampleRate;
|
matthiasm@0
|
249 d.sampleRate = (m_inputSampleRate / m_stepSize);
|
matthiasm@0
|
250 d.hasDuration = false;
|
matthiasm@0
|
251 outputs.push_back(d);
|
matthiasm@0
|
252 m_oF0Probs = outputNumber++;
|
matthiasm@0
|
253
|
matthiasm@0
|
254 d.identifier = "voicedprob";
|
matthiasm@0
|
255 d.name = "Voiced Probability";
|
matthiasm@0
|
256 d.description = "Probability that the signal is voiced according to Probabilistic Yin.";
|
matthiasm@0
|
257 d.unit = "";
|
matthiasm@0
|
258 d.hasFixedBinCount = true;
|
matthiasm@0
|
259 d.binCount = 1;
|
matthiasm@0
|
260 d.hasKnownExtents = true;
|
matthiasm@0
|
261 d.minValue = 0;
|
matthiasm@0
|
262 d.maxValue = 1;
|
matthiasm@0
|
263 d.isQuantized = false;
|
matthiasm@0
|
264 d.sampleType = OutputDescriptor::FixedSampleRate;
|
matthiasm@0
|
265 d.sampleRate = (m_inputSampleRate / m_stepSize);
|
matthiasm@0
|
266 d.hasDuration = false;
|
matthiasm@0
|
267 outputs.push_back(d);
|
matthiasm@0
|
268 m_oVoicedProb = outputNumber++;
|
matthiasm@0
|
269
|
matthiasm@0
|
270 d.identifier = "candidatesalience";
|
matthiasm@0
|
271 d.name = "Candidate Salience";
|
matthiasm@0
|
272 d.description = "Candidate Salience";
|
matthiasm@0
|
273 d.hasFixedBinCount = true;
|
matthiasm@0
|
274 d.binCount = m_blockSize / 2;
|
matthiasm@0
|
275 d.hasKnownExtents = true;
|
matthiasm@0
|
276 d.minValue = 0;
|
matthiasm@0
|
277 d.maxValue = 1;
|
matthiasm@0
|
278 d.isQuantized = false;
|
matthiasm@0
|
279 d.sampleType = OutputDescriptor::FixedSampleRate;
|
matthiasm@0
|
280 d.sampleRate = (m_inputSampleRate / m_stepSize);
|
matthiasm@0
|
281 d.hasDuration = false;
|
matthiasm@0
|
282 outputs.push_back(d);
|
matthiasm@0
|
283 m_oCandidateSalience = outputNumber++;
|
matthiasm@0
|
284
|
matthiasm@0
|
285 d.identifier = "smoothedpitchtrack";
|
matthiasm@0
|
286 d.name = "Smoothed Pitch Track";
|
matthiasm@0
|
287 d.description = ".";
|
matthiasm@0
|
288 d.unit = "Hz";
|
matthiasm@0
|
289 d.hasFixedBinCount = true;
|
matthiasm@0
|
290 d.binCount = 1;
|
matthiasm@0
|
291 d.hasKnownExtents = false;
|
matthiasm@0
|
292 // d.minValue = 0;
|
matthiasm@0
|
293 // d.maxValue = 1;
|
matthiasm@0
|
294 d.isQuantized = false;
|
matthiasm@0
|
295 d.sampleType = OutputDescriptor::FixedSampleRate;
|
matthiasm@0
|
296 d.sampleRate = (m_inputSampleRate / m_stepSize);
|
matthiasm@0
|
297 d.hasDuration = false;
|
matthiasm@0
|
298 outputs.push_back(d);
|
matthiasm@0
|
299 m_oSmoothedPitchTrack = outputNumber++;
|
matthiasm@0
|
300
|
matthiasm@0
|
301 d.identifier = "notes";
|
matthiasm@0
|
302 d.name = "Notes";
|
matthiasm@0
|
303 d.description = "Derived fixed-pitch note frequencies";
|
matthiasm@0
|
304 // d.unit = "MIDI unit";
|
matthiasm@0
|
305 d.unit = "Hz";
|
matthiasm@0
|
306 d.hasFixedBinCount = true;
|
matthiasm@0
|
307 d.binCount = 1;
|
matthiasm@0
|
308 d.hasKnownExtents = false;
|
matthiasm@0
|
309 d.isQuantized = false;
|
matthiasm@0
|
310 d.sampleType = OutputDescriptor::VariableSampleRate;
|
matthiasm@0
|
311 d.sampleRate = (m_inputSampleRate / m_stepSize);
|
matthiasm@0
|
312 d.hasDuration = true;
|
matthiasm@0
|
313 outputs.push_back(d);
|
matthiasm@0
|
314 m_oNotes = outputNumber++;
|
matthiasm@0
|
315
|
matthiasm@0
|
316 return outputs;
|
matthiasm@0
|
317 }
|
matthiasm@0
|
318
|
matthiasm@0
|
319 bool
|
matthiasm@36
|
320 PYinVamp::initialise(size_t channels, size_t stepSize, size_t blockSize)
|
matthiasm@0
|
321 {
|
matthiasm@0
|
322 if (channels < getMinChannelCount() ||
|
matthiasm@0
|
323 channels > getMaxChannelCount()) return false;
|
matthiasm@0
|
324
|
Chris@9
|
325 /*
|
matthiasm@36
|
326 std::cerr << "PYinVamp::initialise: channels = " << channels
|
matthiasm@0
|
327 << ", stepSize = " << stepSize << ", blockSize = " << blockSize
|
matthiasm@0
|
328 << std::endl;
|
Chris@9
|
329 */
|
matthiasm@0
|
330 m_channels = channels;
|
matthiasm@0
|
331 m_stepSize = stepSize;
|
matthiasm@0
|
332 m_blockSize = blockSize;
|
matthiasm@0
|
333
|
matthiasm@0
|
334 reset();
|
matthiasm@0
|
335
|
matthiasm@0
|
336 return true;
|
matthiasm@0
|
337 }
|
matthiasm@0
|
338
|
matthiasm@0
|
339 void
|
matthiasm@36
|
340 PYinVamp::reset()
|
matthiasm@0
|
341 {
|
matthiasm@0
|
342 m_yin.setThresholdDistr(m_threshDistr);
|
matthiasm@0
|
343 m_yin.setFrameSize(m_blockSize);
|
matthiasm@0
|
344
|
matthiasm@0
|
345 m_pitchProb.clear();
|
matthiasm@0
|
346 m_timestamp.clear();
|
Chris@9
|
347 /*
|
matthiasm@36
|
348 std::cerr << "PYinVamp::reset"
|
matthiasm@0
|
349 << ", blockSize = " << m_blockSize
|
matthiasm@0
|
350 << std::endl;
|
Chris@9
|
351 */
|
matthiasm@0
|
352 }
|
matthiasm@0
|
353
|
matthiasm@36
|
354 PYinVamp::FeatureSet
|
matthiasm@36
|
355 PYinVamp::process(const float *const *inputBuffers, RealTime timestamp)
|
matthiasm@0
|
356 {
|
matthiasm@60
|
357 timestamp = timestamp + Vamp::RealTime::frame2RealTime(m_blockSize/2, lrintf(m_inputSampleRate));
|
matthiasm@0
|
358 FeatureSet fs;
|
matthiasm@0
|
359
|
matthiasm@46
|
360 float rms = 0;
|
matthiasm@46
|
361
|
matthiasm@0
|
362 double *dInputBuffers = new double[m_blockSize];
|
matthiasm@46
|
363 for (size_t i = 0; i < m_blockSize; ++i) {
|
matthiasm@46
|
364 dInputBuffers[i] = inputBuffers[0][i];
|
matthiasm@46
|
365 rms += inputBuffers[0][i] * inputBuffers[0][i];
|
matthiasm@46
|
366 }
|
matthiasm@46
|
367 rms /= m_blockSize;
|
matthiasm@46
|
368 rms = sqrt(rms);
|
matthiasm@58
|
369 float lowAmp = 0.05;
|
matthiasm@50
|
370 bool isLowAmplitude = (rms < lowAmp);
|
matthiasm@0
|
371
|
matthiasm@0
|
372 Yin::YinOutput yo = m_yin.processProbabilisticYin(dInputBuffers);
|
matthiasm@27
|
373 delete [] dInputBuffers;
|
matthiasm@27
|
374
|
matthiasm@27
|
375 // First, get the things out of the way that we don't want to output
|
matthiasm@27
|
376 // immediately, but instead save for later.
|
matthiasm@27
|
377 vector<pair<double, double> > tempPitchProb;
|
matthiasm@27
|
378 for (size_t iCandidate = 0; iCandidate < yo.freqProb.size(); ++iCandidate)
|
matthiasm@27
|
379 {
|
matthiasm@27
|
380 double tempPitch = 12 * std::log(yo.freqProb[iCandidate].first/440)/std::log(2.) + 69;
|
matthiasm@50
|
381 if (!isLowAmplitude)
|
matthiasm@46
|
382 tempPitchProb.push_back(pair<double, double>
|
matthiasm@46
|
383 (tempPitch, yo.freqProb[iCandidate].second));
|
matthiasm@46
|
384 else
|
matthiasm@46
|
385 tempPitchProb.push_back(pair<double, double>
|
matthiasm@58
|
386 (tempPitch, yo.freqProb[iCandidate].second*((rms+0.01*lowAmp)/(1.01*lowAmp))));
|
matthiasm@27
|
387 }
|
matthiasm@27
|
388 m_pitchProb.push_back(tempPitchProb);
|
matthiasm@27
|
389 m_timestamp.push_back(timestamp);
|
matthiasm@27
|
390
|
matthiasm@27
|
391 // F0 CANDIDATES
|
matthiasm@0
|
392 Feature f;
|
matthiasm@0
|
393 f.hasTimestamp = true;
|
matthiasm@0
|
394 f.timestamp = timestamp;
|
matthiasm@0
|
395 for (size_t i = 0; i < yo.freqProb.size(); ++i)
|
matthiasm@0
|
396 {
|
matthiasm@0
|
397 f.values.push_back(yo.freqProb[i].first);
|
matthiasm@0
|
398 }
|
matthiasm@0
|
399 fs[m_oF0Candidates].push_back(f);
|
matthiasm@0
|
400
|
matthiasm@27
|
401 // VOICEDPROB
|
matthiasm@0
|
402 f.values.clear();
|
matthiasm@0
|
403 float voicedProb = 0;
|
matthiasm@0
|
404 for (size_t i = 0; i < yo.freqProb.size(); ++i)
|
matthiasm@0
|
405 {
|
matthiasm@0
|
406 f.values.push_back(yo.freqProb[i].second);
|
matthiasm@0
|
407 voicedProb += yo.freqProb[i].second;
|
matthiasm@0
|
408 }
|
matthiasm@0
|
409 fs[m_oF0Probs].push_back(f);
|
matthiasm@0
|
410
|
matthiasm@0
|
411 f.values.push_back(voicedProb);
|
matthiasm@0
|
412 fs[m_oVoicedProb].push_back(f);
|
matthiasm@0
|
413
|
matthiasm@27
|
414 // SALIENCE -- maybe this should eventually disappear
|
matthiasm@0
|
415 f.values.clear();
|
matthiasm@0
|
416 float salienceSum = 0;
|
matthiasm@0
|
417 for (size_t iBin = 0; iBin < yo.salience.size(); ++iBin)
|
matthiasm@0
|
418 {
|
matthiasm@0
|
419 f.values.push_back(yo.salience[iBin]);
|
matthiasm@0
|
420 salienceSum += yo.salience[iBin];
|
matthiasm@0
|
421 }
|
matthiasm@0
|
422 fs[m_oCandidateSalience].push_back(f);
|
matthiasm@0
|
423
|
matthiasm@0
|
424 return fs;
|
matthiasm@0
|
425 }
|
matthiasm@0
|
426
|
matthiasm@36
|
427 PYinVamp::FeatureSet
|
matthiasm@36
|
428 PYinVamp::getRemainingFeatures()
|
matthiasm@0
|
429 {
|
matthiasm@0
|
430 FeatureSet fs;
|
matthiasm@0
|
431 Feature f;
|
matthiasm@0
|
432 f.hasTimestamp = true;
|
matthiasm@0
|
433 f.hasDuration = false;
|
matthiasm@0
|
434
|
Chris@4
|
435 if (m_pitchProb.empty()) {
|
Chris@4
|
436 return fs;
|
Chris@4
|
437 }
|
Chris@4
|
438
|
matthiasm@0
|
439 // MONO-PITCH STUFF
|
matthiasm@0
|
440 MonoPitch mp;
|
matthiasm@0
|
441 vector<float> mpOut = mp.process(m_pitchProb);
|
matthiasm@0
|
442 for (size_t iFrame = 0; iFrame < mpOut.size(); ++iFrame)
|
matthiasm@0
|
443 {
|
matthiasm@0
|
444 if (mpOut[iFrame] < 0 && (m_outputUnvoiced==0)) continue;
|
matthiasm@0
|
445 f.timestamp = m_timestamp[iFrame];
|
matthiasm@0
|
446 f.values.clear();
|
matthiasm@0
|
447 if (m_outputUnvoiced == 1)
|
matthiasm@0
|
448 {
|
matthiasm@26
|
449 f.values.push_back(fabs(mpOut[iFrame]));
|
matthiasm@0
|
450 } else {
|
matthiasm@0
|
451 f.values.push_back(mpOut[iFrame]);
|
matthiasm@0
|
452 }
|
matthiasm@0
|
453
|
matthiasm@0
|
454 fs[m_oSmoothedPitchTrack].push_back(f);
|
matthiasm@0
|
455 }
|
matthiasm@0
|
456
|
matthiasm@1
|
457 // MONO-NOTE STUFF
|
Chris@63
|
458 // std::cerr << "Mono Note Stuff" << std::endl;
|
matthiasm@1
|
459 MonoNote mn;
|
matthiasm@1
|
460 std::vector<std::vector<std::pair<double, double> > > smoothedPitch;
|
matthiasm@1
|
461 for (size_t iFrame = 0; iFrame < mpOut.size(); ++iFrame) {
|
matthiasm@1
|
462 std::vector<std::pair<double, double> > temp;
|
matthiasm@1
|
463 if (mpOut[iFrame] > 0)
|
matthiasm@1
|
464 {
|
matthiasm@1
|
465 double tempPitch = 12 * std::log(mpOut[iFrame]/440)/std::log(2.) + 69;
|
matthiasm@1
|
466 temp.push_back(std::pair<double,double>(tempPitch, .9));
|
matthiasm@1
|
467 }
|
matthiasm@1
|
468 smoothedPitch.push_back(temp);
|
matthiasm@1
|
469 }
|
matthiasm@0
|
470 // vector<MonoNote::FrameOutput> mnOut = mn.process(m_pitchProb);
|
matthiasm@1
|
471 vector<MonoNote::FrameOutput> mnOut = mn.process(smoothedPitch);
|
matthiasm@1
|
472
|
matthiasm@6
|
473 // turning feature into a note feature
|
matthiasm@1
|
474 f.hasTimestamp = true;
|
matthiasm@1
|
475 f.hasDuration = true;
|
matthiasm@1
|
476 f.values.clear();
|
matthiasm@6
|
477
|
matthiasm@6
|
478 int onsetFrame = 0;
|
matthiasm@6
|
479 bool isVoiced = 0;
|
matthiasm@6
|
480 bool oldIsVoiced = 0;
|
matthiasm@6
|
481 size_t nFrame = m_pitchProb.size();
|
matthiasm@1
|
482
|
matthiasm@6
|
483 std::vector<float> notePitchTrack; // collects pitches for one note at a time
|
matthiasm@6
|
484 for (size_t iFrame = 0; iFrame < nFrame; ++iFrame)
|
matthiasm@1
|
485 {
|
matthiasm@6
|
486 isVoiced = mnOut[iFrame].noteState < 3 && smoothedPitch[iFrame].size() > 0;
|
matthiasm@6
|
487 if (isVoiced && iFrame != nFrame-1)
|
matthiasm@1
|
488 {
|
matthiasm@6
|
489 if (oldIsVoiced == 0) // beginning of a note
|
matthiasm@1
|
490 {
|
matthiasm@6
|
491 onsetFrame = iFrame;
|
matthiasm@6
|
492 notePitchTrack.clear();
|
matthiasm@1
|
493 }
|
matthiasm@6
|
494 float pitch = smoothedPitch[iFrame][0].first;
|
matthiasm@6
|
495 notePitchTrack.push_back(pitch); // add to the note's pitch track
|
matthiasm@6
|
496 } else { // not currently voiced
|
matthiasm@6
|
497 if (oldIsVoiced == 1 && notePitchTrack.size() > 4) // end of the note
|
matthiasm@6
|
498 {
|
matthiasm@1
|
499 std::sort(notePitchTrack.begin(), notePitchTrack.end());
|
matthiasm@6
|
500 float medianPitch = notePitchTrack[notePitchTrack.size()/2];
|
matthiasm@6
|
501 float medianFreq = std::pow(2,(medianPitch - 69) / 12) * 440;
|
matthiasm@6
|
502 f.values.clear();
|
matthiasm@6
|
503 f.values.push_back(medianFreq);
|
matthiasm@6
|
504 f.timestamp = m_timestamp[onsetFrame];
|
matthiasm@6
|
505 f.duration = m_timestamp[iFrame] - m_timestamp[onsetFrame];
|
matthiasm@5
|
506 fs[m_oNotes].push_back(f);
|
matthiasm@1
|
507 }
|
matthiasm@1
|
508 }
|
matthiasm@6
|
509 oldIsVoiced = isVoiced;
|
matthiasm@1
|
510 }
|
matthiasm@0
|
511 return fs;
|
matthiasm@0
|
512 }
|