comparison src/Silvet.cpp @ 38:5164bccf3064

Return pitch activation matrix
author Chris Cannam
date Fri, 04 Apr 2014 19:05:47 +0100
parents 947996aac974
children 2b254fc68e81
comparison
equal deleted inserted replaced
37:947996aac974 38:5164bccf3064
30 using std::endl; 30 using std::endl;
31 31
32 static int processingSampleRate = 44100; 32 static int processingSampleRate = 44100;
33 static int processingBPO = 60; 33 static int processingBPO = 60;
34 static int processingHeight = 545; 34 static int processingHeight = 545;
35 static int processingNotes = 88;
35 36
36 Silvet::Silvet(float inputSampleRate) : 37 Silvet::Silvet(float inputSampleRate) :
37 Plugin(inputSampleRate), 38 Plugin(inputSampleRate),
38 m_resampler(0), 39 m_resampler(0),
39 m_cq(0) 40 m_cq(0)
201 d.sampleRate = 25; 202 d.sampleRate = 25;
202 d.hasDuration = false; 203 d.hasDuration = false;
203 m_cqOutputNo = list.size(); 204 m_cqOutputNo = list.size();
204 list.push_back(d); 205 list.push_back(d);
205 206
207 d.identifier = "pitchdistribution";
208 d.name = "Pitch distribution";
209 d.description = "The estimated pitch contribution matrix";
210 d.unit = "";
211 d.hasFixedBinCount = true;
212 d.binCount = processingNotes;
213 d.binNames.clear();
214 for (int i = 0; i < processingNotes; ++i) {
215 d.binNames.push_back(noteName(i));
216 }
217 d.hasKnownExtents = false;
218 d.isQuantized = false;
219 d.sampleType = OutputDescriptor::FixedSampleRate;
220 d.sampleRate = 25;
221 d.hasDuration = false;
222 m_pitchOutputNo = list.size();
223 list.push_back(d);
224
206 return list; 225 return list;
226 }
227
228 std::string
229 Silvet::noteName(int i) const
230 {
231 static const char *names[] = {
232 "A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"
233 };
234
235 const char *n = names[i % 12];
236
237 int oct = (i + 9) / 12;
238
239 char buf[20];
240 sprintf(buf, "%s%d", n, oct);
241
242 return buf;
207 } 243 }
208 244
209 bool 245 bool
210 Silvet::initialise(size_t channels, size_t stepSize, size_t blockSize) 246 Silvet::initialise(size_t channels, size_t stepSize, size_t blockSize)
211 { 247 {
308 EM em; 344 EM em;
309 for (int j = 0; j < iterations; ++j) { 345 for (int j = 0; j < iterations; ++j) {
310 em.iterate(filtered[i]); 346 em.iterate(filtered[i]);
311 } 347 }
312 348
349 vector<double> pitches = em.getPitchDistribution();
350 Feature f;
351 for (int j = 0; j < (int)pitches.size(); ++j) {
352 f.values.push_back(float(pitches[i]));
353 }
354 fs[m_pitchOutputNo].push_back(f);
355
313 //!!! now do something with the results from em! 356 //!!! now do something with the results from em!
314 em.report(); 357 em.report();
315 } 358 }
316 359
317 return fs; 360 return fs;