Mercurial > hg > svcore
diff data/model/FFTModel.cpp @ 1038:cc27f35aa75c cxx11
Introducing the signed 64-bit frame index type, and fixing build failures from inclusion of -Wconversion with -Werror. Not finished yet.
author | Chris Cannam |
---|---|
date | Tue, 03 Mar 2015 15:18:24 +0000 |
parents | a8aed8a85e09 |
children | a1cd5abcb38b |
line wrap: on
line diff
--- a/data/model/FFTModel.cpp Tue Mar 03 09:33:59 2015 +0000 +++ b/data/model/FFTModel.cpp Tue Mar 03 15:18:24 2015 +0000 @@ -212,7 +212,7 @@ int sampleRate = m_server->getModel()->getSampleRate(); int fftSize = m_server->getFFTSize() >> m_yshift; - frequency = (float(y) * sampleRate) / fftSize; + frequency = float((double(y) * sampleRate) / fftSize); if (x+1 >= getWidth()) return false; @@ -225,14 +225,14 @@ // = 2pi * ((h * b * sr) / (w * sr)) // = 2pi * (h * b) / w. - float oldPhase = getPhaseAt(x, y); - float newPhase = getPhaseAt(x+1, y); + double oldPhase = getPhaseAt(x, y); + double newPhase = getPhaseAt(x+1, y); int incr = getResolution(); - float expectedPhase = oldPhase + (2.0 * M_PI * y * incr) / fftSize; + double expectedPhase = oldPhase + (2.0 * M_PI * y * incr) / fftSize; - float phaseError = princargf(newPhase - expectedPhase); + double phaseError = princarg(newPhase - expectedPhase); // bool stable = (fabsf(phaseError) < (1.1f * (m_windowIncrement * M_PI) / m_fftSize)); @@ -240,8 +240,8 @@ // from assuming the "native" frequency of this bin frequency = - (sampleRate * (expectedPhase + phaseError - oldPhase)) / - (2 * M_PI * incr); + float((sampleRate * (expectedPhase + phaseError - oldPhase)) / + (2 * M_PI * incr)); return true; } @@ -284,8 +284,8 @@ float mean = 0.f; for (int i = 0; i < values.size(); ++i) mean += values[i]; - if (values.size() >0) mean /= values.size(); - + if (values.size() > 0) mean = mean / float(values.size()); + // For peak picking we use a moving median window, picking the // highest value within each continuous region of values that // exceed the median. For pitch adaptivity, we adjust the window @@ -324,7 +324,7 @@ window.pop_front(); } - int actualSize = window.size(); + int actualSize = int(window.size()); if (type == MajorPitchAdaptivePeaks) { if (ymax + halfWin < values.size()) binmax = ymax + halfWin; @@ -333,7 +333,7 @@ std::deque<float> sorted(window); std::sort(sorted.begin(), sorted.end()); - float median = sorted[int(sorted.size() * dist)]; + float median = sorted[int(float(sorted.size()) * dist)]; int centrebin = 0; if (bin > actualSize/2) centrebin = bin - actualSize/2; @@ -381,14 +381,14 @@ if (bin == 0) return 3; int fftSize = m_server->getFFTSize() >> m_yshift; - float binfreq = (float(sampleRate) * bin) / fftSize; - float hifreq = Pitch::getFrequencyForPitch(73, 0, binfreq); + double binfreq = (double(sampleRate) * bin) / fftSize; + double hifreq = Pitch::getFrequencyForPitch(73, 0, binfreq); - int hibin = lrintf((hifreq * fftSize) / sampleRate); + int hibin = int(lrint((hifreq * fftSize) / sampleRate)); int medianWinSize = hibin - bin; if (medianWinSize < 3) medianWinSize = 3; - percentile = 0.5 + (binfreq / sampleRate); + percentile = 0.5f + float(binfreq / sampleRate); return medianWinSize; } @@ -421,16 +421,16 @@ int phaseIndex = 0; for (PeakLocationSet::iterator i = locations.begin(); i != locations.end(); ++i) { - float oldPhase = phases[phaseIndex]; - float newPhase = getPhaseAt(x+1, *i); - float expectedPhase = oldPhase + (2.0 * M_PI * *i * incr) / fftSize; - float phaseError = princargf(newPhase - expectedPhase); - float frequency = + double oldPhase = phases[phaseIndex]; + double newPhase = getPhaseAt(x+1, *i); + double expectedPhase = oldPhase + (2.0 * M_PI * *i * incr) / fftSize; + double phaseError = princarg(newPhase - expectedPhase); + double frequency = (sampleRate * (expectedPhase + phaseError - oldPhase)) / (2 * M_PI * incr); // bool stable = (fabsf(phaseError) < (1.1f * (incr * M_PI) / fftSize)); // if (stable) - peaks[*i] = frequency; + peaks[*i] = float(frequency); ++phaseIndex; }