comparison LocalCandidatePYIN.cpp @ 141:72bda34e0e64 fixedlag

Merge from branch vamp-fft-revision
author Chris Cannam
date Fri, 24 Mar 2017 14:50:44 +0000
parents 926c292fa3ff d71170f5ba76
children 218bfe953159
comparison
equal deleted inserted replaced
133:83978b93aac1 141:72bda34e0e64
46 m_threshDistr(2.0f), 46 m_threshDistr(2.0f),
47 m_outputUnvoiced(0.0f), 47 m_outputUnvoiced(0.0f),
48 m_preciseTime(0.0f), 48 m_preciseTime(0.0f),
49 m_pitchProb(0), 49 m_pitchProb(0),
50 m_timestamp(0), 50 m_timestamp(0),
51 m_nCandidate(13) 51 m_nCandidate(13),
52 m_yinUtil(0)
52 { 53 {
53 } 54 }
54 55
55 LocalCandidatePYIN::~LocalCandidatePYIN() 56 LocalCandidatePYIN::~LocalCandidatePYIN()
56 { 57 {
58 delete m_yinUtil;
57 } 59 }
58 60
59 string 61 string
60 LocalCandidatePYIN::getIdentifier() const 62 LocalCandidatePYIN::getIdentifier() const
61 { 63 {
224 { 226 {
225 return ""; // no programs 227 return ""; // no programs
226 } 228 }
227 229
228 void 230 void
229 LocalCandidatePYIN::selectProgram(string name) 231 LocalCandidatePYIN::selectProgram(string)
230 { 232 {
231 } 233 }
232 234
233 LocalCandidatePYIN::OutputList 235 LocalCandidatePYIN::OutputList
234 LocalCandidatePYIN::getOutputDescriptors() const 236 LocalCandidatePYIN::getOutputDescriptors() const
266 << std::endl; 268 << std::endl;
267 */ 269 */
268 m_channels = channels; 270 m_channels = channels;
269 m_stepSize = stepSize; 271 m_stepSize = stepSize;
270 m_blockSize = blockSize; 272 m_blockSize = blockSize;
273
274 m_yinUtil = new YinUtil(m_blockSize/2);
271 275
272 reset(); 276 reset();
273 277
274 return true; 278 return true;
275 } 279 }
295 double *dInputBuffers = new double[m_blockSize]; 299 double *dInputBuffers = new double[m_blockSize];
296 for (size_t i = 0; i < m_blockSize; ++i) dInputBuffers[i] = inputBuffers[0][i]; 300 for (size_t i = 0; i < m_blockSize; ++i) dInputBuffers[i] = inputBuffers[0][i];
297 301
298 size_t yinBufferSize = m_blockSize/2; 302 size_t yinBufferSize = m_blockSize/2;
299 double* yinBuffer = new double[yinBufferSize]; 303 double* yinBuffer = new double[yinBufferSize];
300 if (!m_preciseTime) YinUtil::fastDifference(dInputBuffers, yinBuffer, yinBufferSize); 304 if (!m_preciseTime) m_yinUtil->fastDifference(dInputBuffers, yinBuffer);
301 else YinUtil::slowDifference(dInputBuffers, yinBuffer, yinBufferSize); 305 else m_yinUtil->slowDifference(dInputBuffers, yinBuffer);
302 306
303 delete [] dInputBuffers; 307 delete [] dInputBuffers;
304 308
305 YinUtil::cumulativeDifference(yinBuffer, yinBufferSize); 309 m_yinUtil->cumulativeDifference(yinBuffer);
306 310
307 float minFrequency = 60; 311 float minFrequency = 60;
308 float maxFrequency = 900; 312 float maxFrequency = 900;
309 vector<double> peakProbability = YinUtil::yinProb(yinBuffer, 313 vector<double> peakProbability = m_yinUtil->yinProb(yinBuffer,
310 m_threshDistr, 314 m_threshDistr,
311 yinBufferSize, 315 m_inputSampleRate/maxFrequency,
312 m_inputSampleRate/maxFrequency, 316 m_inputSampleRate/minFrequency);
313 m_inputSampleRate/minFrequency);
314 317
315 vector<pair<double, double> > tempPitchProb; 318 vector<pair<double, double> > tempPitchProb;
316 for (size_t iBuf = 0; iBuf < yinBufferSize; ++iBuf) 319 for (size_t iBuf = 0; iBuf < yinBufferSize; ++iBuf)
317 { 320 {
318 if (peakProbability[iBuf] > 0) 321 if (peakProbability[iBuf] > 0)
319 { 322 {
320 double currentF0 = 323 double currentF0 =
321 m_inputSampleRate * (1.0 / 324 m_inputSampleRate * (1.0 /
322 YinUtil::parabolicInterpolation(yinBuffer, iBuf, yinBufferSize)); 325 m_yinUtil->parabolicInterpolation(yinBuffer, iBuf));
323 double tempPitch = 12 * std::log(currentF0/440)/std::log(2.) + 69; 326 double tempPitch = 12 * std::log(currentF0/440)/std::log(2.) + 69;
324 tempPitchProb.push_back(pair<double, double>(tempPitch, peakProbability[iBuf])); 327 tempPitchProb.push_back(pair<double, double>(tempPitch, peakProbability[iBuf]));
325 } 328 }
326 } 329 }
327 m_pitchProb.push_back(tempPitchProb); 330 m_pitchProb.push_back(tempPitchProb);
388 vector<float> mpOut; 391 vector<float> mpOut;
389 392
390 for (size_t iFrame = 0; iFrame < rawPitchPath.size(); ++iFrame) 393 for (size_t iFrame = 0; iFrame < rawPitchPath.size(); ++iFrame)
391 { 394 {
392 float freq = hmm.nearestFreq(rawPitchPath[iFrame], 395 float freq = hmm.nearestFreq(rawPitchPath[iFrame],
393 m_pitchProb[iFrame]); 396 m_pitchProb[iFrame]);
394 mpOut.push_back(freq); // for note processing below 397 mpOut.push_back(freq); // for note processing below
395 } 398 }
396 399
397 float prevFreq = 0; 400 for (size_t iFrame = 0; iFrame < rawPitchPath.size(); ++iFrame)
398 for (size_t iFrame = 0; iFrame < nFrame; ++iFrame)
399 { 401 {
400 if (mpOut[iFrame] > 0) { 402 if (mpOut[iFrame] > 0) {
401 403
402 pitchTracks[iCandidate][iFrame] = mpOut[iFrame]; 404 pitchTracks[iCandidate][iFrame] = mpOut[iFrame];
403 freqSum[iCandidate] += mpOut[iFrame]; 405 freqSum[iCandidate] += mpOut[iFrame];
404 freqNumber[iCandidate]++; 406 freqNumber[iCandidate]++;
405 prevFreq = mpOut[iFrame];
406
407 } 407 }
408 } 408 }
409 freqMean[iCandidate] = freqSum[iCandidate]*1.0/freqNumber[iCandidate]; 409 freqMean[iCandidate] = freqSum[iCandidate]*1.0/freqNumber[iCandidate];
410 } 410 }
411 411