diff options
author | Robin Gareus <robin@gareus.org> | 2016-10-06 00:16:44 +0200 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2016-10-06 00:57:53 +0200 |
commit | f68d2e06bcfb81efda107d3b4c3aa7dbc2d73bc2 (patch) | |
tree | 286d5b2b1c3573c2fbfc77b4d29b0b2a6bfa9686 /libs/qm-dsp/dsp/tonal | |
parent | 2a27cc475867612afd261e5bf3b2a1a42b9c75cc (diff) |
update qm-dsp library
Diffstat (limited to 'libs/qm-dsp/dsp/tonal')
-rw-r--r-- | libs/qm-dsp/dsp/tonal/ChangeDetectionFunction.cpp | 36 | ||||
-rw-r--r-- | libs/qm-dsp/dsp/tonal/ChangeDetectionFunction.h | 2 | ||||
-rw-r--r-- | libs/qm-dsp/dsp/tonal/TCSgram.cpp | 8 | ||||
-rw-r--r-- | libs/qm-dsp/dsp/tonal/TCSgram.h | 2 | ||||
-rw-r--r-- | libs/qm-dsp/dsp/tonal/TonalEstimator.cpp | 22 | ||||
-rw-r--r-- | libs/qm-dsp/dsp/tonal/TonalEstimator.h | 24 |
6 files changed, 47 insertions, 47 deletions
diff --git a/libs/qm-dsp/dsp/tonal/ChangeDetectionFunction.cpp b/libs/qm-dsp/dsp/tonal/ChangeDetectionFunction.cpp index 9b1a3219ac..bcc661dd1d 100644 --- a/libs/qm-dsp/dsp/tonal/ChangeDetectionFunction.cpp +++ b/libs/qm-dsp/dsp/tonal/ChangeDetectionFunction.cpp @@ -16,7 +16,7 @@ #include "ChangeDetectionFunction.h" #ifndef PI -#define PI (3.14159265358979323846) +#define PI (3.14159265358979232846) #endif @@ -34,20 +34,20 @@ ChangeDetectionFunction::~ChangeDetectionFunction() void ChangeDetectionFunction::setFilterWidth(const int iWidth) { m_iFilterWidth = iWidth*2+1; - + // it is assumed that the gaussian is 0 outside of +/- FWHM // => filter width = 2*FWHM = 2*2.3548*sigma m_dFilterSigma = double(m_iFilterWidth) / double(2*2.3548); m_vaGaussian.resize(m_iFilterWidth); - + double dScale = 1.0 / (m_dFilterSigma*sqrt(2*PI)); - + for (int x = -(m_iFilterWidth-1)/2; x <= (m_iFilterWidth-1)/2; x++) { double w = dScale * std::exp ( -(x*x)/(2*m_dFilterSigma*m_dFilterSigma) ); m_vaGaussian[x + (m_iFilterWidth-1)/2] = w; } - + #ifdef DEBUG_CHANGE_DETECTION_FUNCTION std::cerr << "Filter sigma: " << m_dFilterSigma << std::endl; std::cerr << "Filter width: " << m_iFilterWidth << std::endl; @@ -59,37 +59,37 @@ ChangeDistance ChangeDetectionFunction::process(const TCSGram& rTCSGram) { ChangeDistance retVal; retVal.resize(rTCSGram.getSize(), 0.0); - + TCSGram smoothedTCSGram; for (int iPosition = 0; iPosition < rTCSGram.getSize(); iPosition++) { int iSkipLower = 0; - + int iLowerPos = iPosition - (m_iFilterWidth-1)/2; int iUpperPos = iPosition + (m_iFilterWidth-1)/2; - + if (iLowerPos < 0) { iSkipLower = -iLowerPos; iLowerPos = 0; } - + if (iUpperPos >= rTCSGram.getSize()) { int iMaxIndex = rTCSGram.getSize() - 1; iUpperPos = iMaxIndex; } - + TCSVector smoothedVector; // for every bin of the vector, calculate the smoothed value for (int iPC = 0; iPC < 6; iPC++) - { + { size_t j = 0; double dSmoothedValue = 0.0; TCSVector rCV; - + for (int i = iLowerPos; i <= iUpperPos; i++) { rTCSGram.getTCSVector(i, rCV); @@ -98,7 +98,7 @@ ChangeDistance ChangeDetectionFunction::process(const TCSGram& rTCSGram) smoothedVector[iPC] = dSmoothedValue; } - + smoothedTCSGram.addTCSVector(smoothedVector); } @@ -109,10 +109,10 @@ ChangeDistance ChangeDetectionFunction::process(const TCSGram& rTCSGram) if the current estimate is not confident enough, look further into the future/the past e.g., High frequency content, zero crossing rate, spectral flatness */ - + TCSVector nextTCS; TCSVector previousTCS; - + int iWindow = 1; // while (previousTCS.magnitude() < 0.1 && (iPosition-iWindow) > 0) @@ -121,9 +121,9 @@ ChangeDistance ChangeDetectionFunction::process(const TCSGram& rTCSGram) // std::cout << previousTCS.magnitude() << std::endl; iWindow++; } - + iWindow = 1; - + // while (nextTCS.magnitude() < 0.1 && (iPosition+iWindow) < (rTCSGram.getSize()-1) ) { smoothedTCSGram.getTCSVector(iPosition+iWindow, nextTCS); @@ -136,7 +136,7 @@ ChangeDistance ChangeDetectionFunction::process(const TCSGram& rTCSGram) { distance += std::pow(nextTCS[j] - previousTCS[j], 2.0); } - + retVal[iPosition] = std::pow(distance, 0.5); } diff --git a/libs/qm-dsp/dsp/tonal/ChangeDetectionFunction.h b/libs/qm-dsp/dsp/tonal/ChangeDetectionFunction.h index 5d041ad769..3a84b3096f 100644 --- a/libs/qm-dsp/dsp/tonal/ChangeDetectionFunction.h +++ b/libs/qm-dsp/dsp/tonal/ChangeDetectionFunction.h @@ -38,7 +38,7 @@ public: ChangeDistance process(const TCSGram& rTCSGram); private: void setFilterWidth(const int iWidth); - + private: valarray<double> m_vaGaussian; double m_dFilterSigma; diff --git a/libs/qm-dsp/dsp/tonal/TCSgram.cpp b/libs/qm-dsp/dsp/tonal/TCSgram.cpp index 954ba03e9b..8840872576 100644 --- a/libs/qm-dsp/dsp/tonal/TCSgram.cpp +++ b/libs/qm-dsp/dsp/tonal/TCSgram.cpp @@ -34,7 +34,7 @@ TCSGram::~TCSGram() void TCSGram::getTCSVector(int iPosition, TCSVector& rTCSVector) const { - if (iPosition < 0) + if (iPosition < 0) rTCSVector = TCSVector(); else if (iPosition >= m_VectorList.size()) rTCSVector = TCSVector(); @@ -52,10 +52,10 @@ void TCSGram::addTCSVector(const TCSVector& rTCSVector) { size_t uSize = m_VectorList.size(); long lMilliSeconds = static_cast<long>(uSize*m_dFrameDurationMS); - std::pair<long, TCSVector> p; + std::pair<long, TCSVector> p; p.first = lMilliSeconds; p.second = rTCSVector; - + m_VectorList.push_back(p); } @@ -68,7 +68,7 @@ long TCSGram::getDuration() const void TCSGram::printDebug() { vectorlist_t::iterator vectorIterator = m_VectorList.begin(); - + while (vectorIterator != m_VectorList.end()) { vectorIterator->second.printDebug(); diff --git a/libs/qm-dsp/dsp/tonal/TCSgram.h b/libs/qm-dsp/dsp/tonal/TCSgram.h index f4825a996a..83e8c93f8b 100644 --- a/libs/qm-dsp/dsp/tonal/TCSgram.h +++ b/libs/qm-dsp/dsp/tonal/TCSgram.h @@ -26,7 +26,7 @@ typedef std::vector<std::pair<long, TCSVector> > vectorlist_t; class TCSGram { -public: +public: TCSGram(); ~TCSGram(); void getTCSVector(int, TCSVector&) const; diff --git a/libs/qm-dsp/dsp/tonal/TonalEstimator.cpp b/libs/qm-dsp/dsp/tonal/TonalEstimator.cpp index 03e22cc804..16d1aa8995 100644 --- a/libs/qm-dsp/dsp/tonal/TonalEstimator.cpp +++ b/libs/qm-dsp/dsp/tonal/TonalEstimator.cpp @@ -19,7 +19,7 @@ #include <iostream> #ifndef PI -#define PI (3.14159265358979323846) +#define PI (3.14159265358979232846) #endif TonalEstimator::TonalEstimator() @@ -27,15 +27,15 @@ TonalEstimator::TonalEstimator() m_Basis.resize(6); int i = 0; - - + + // circle of fifths m_Basis[i].resize(12); for (int iP = 0; iP < 12; iP++) { m_Basis[i][iP] = std::sin( (7.0 / 6.0) * iP * PI); } - + i++; m_Basis[i].resize(12); @@ -43,17 +43,17 @@ TonalEstimator::TonalEstimator() { m_Basis[i][iP] = std::cos( (7.0 / 6.0) * iP * PI); } - + i++; - - + + // circle of major thirds m_Basis[i].resize(12); for (int iP = 0; iP < 12; iP++) { m_Basis[i][iP] = 0.6 * std::sin( (2.0 / 3.0) * iP * PI); } - + i++; m_Basis[i].resize(12); @@ -71,7 +71,7 @@ TonalEstimator::TonalEstimator() { m_Basis[i][iP] = 1.1 * std::sin( (3.0 / 2.0) * iP * PI); } - + i++; m_Basis[i].resize(12); @@ -90,7 +90,7 @@ TCSVector TonalEstimator::transform2TCS(const ChromaVector& rVector) { TCSVector vaRetVal; vaRetVal.resize(6, 0.0); - + for (int i = 0; i < 6; i++) { for (int iP = 0; iP < 12; iP++) @@ -98,6 +98,6 @@ TCSVector TonalEstimator::transform2TCS(const ChromaVector& rVector) vaRetVal[i] += m_Basis[i][iP] * rVector[iP]; } } - + return vaRetVal; } diff --git a/libs/qm-dsp/dsp/tonal/TonalEstimator.h b/libs/qm-dsp/dsp/tonal/TonalEstimator.h index cfb8bba5b6..f555ef9e3b 100644 --- a/libs/qm-dsp/dsp/tonal/TonalEstimator.h +++ b/libs/qm-dsp/dsp/tonal/TonalEstimator.h @@ -27,24 +27,24 @@ class ChromaVector : public std::valarray<double> public: ChromaVector(size_t uSize = 12) : std::valarray<double>() { resize(uSize, 0.0f); } - + virtual ~ChromaVector() {}; - + void printDebug() { for (int i = 0; i < size(); i++) { std::cout << (*this)[i] << ";"; } - + std::cout << std::endl; } - + void normalizeL1() { // normalize the chroma vector (L1 norm) double dSum = 0.0; - + for (size_t i = 0; i < 12; (dSum += std::abs((*this)[i++]))) ; for (size_t i = 0; i < 12; dSum > 0.0000001?((*this)[i] /= dSum):(*this)[i]=0.0, i++) ; @@ -54,8 +54,8 @@ public: { for (size_t i = 0; i < 12; ++i) (*this)[i] = 0.0; } - - + + }; class TCSVector : public std::valarray<double> @@ -63,7 +63,7 @@ class TCSVector : public std::valarray<double> public: TCSVector() : std::valarray<double>() { resize(6, 0.0f); } - + virtual ~TCSVector() {}; void printDebug() @@ -72,19 +72,19 @@ public: { std::cout << (*this)[i] << ";"; } - + std::cout << std::endl; } - + double magnitude() const { double dMag = 0.0; - + for (size_t i = 0; i < 6; i++) { dMag += std::pow((*this)[i], 2.0); } - + return std::sqrt(dMag); } |