c@225: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ c@225: c@225: /* c@225: QM DSP Library c@225: c@225: Centre for Digital Music, Queen Mary, University of London. c@225: This file copyright 2006 Martin Gasser. c@309: c@309: This program is free software; you can redistribute it and/or c@309: modify it under the terms of the GNU General Public License as c@309: published by the Free Software Foundation; either version 2 of the c@309: License, or (at your option) any later version. See the file c@309: COPYING included with this distribution for more information. c@225: */ c@225: c@225: #ifndef _TONALESTIMATOR_ c@225: #define _TONALESTIMATOR_ c@225: c@225: c@225: #include c@225: #include c@225: #include c@225: #include c@225: c@225: class ChromaVector : public std::valarray c@225: { c@225: public: c@225: ChromaVector(size_t uSize = 12) : std::valarray() c@225: { resize(uSize, 0.0f); } c@225: c@225: virtual ~ChromaVector() {}; c@225: c@225: void printDebug() c@225: { c@414: for (int i = 0; i < int(size()); i++) c@225: { c@225: std::cout << (*this)[i] << ";"; c@225: } c@225: c@225: std::cout << std::endl; c@225: } c@225: c@225: void normalizeL1() c@225: { c@225: // normalize the chroma vector (L1 norm) c@225: double dSum = 0.0; c@225: c@285: for (size_t i = 0; i < 12; (dSum += std::abs((*this)[i++]))) ; c@285: for (size_t i = 0; i < 12; dSum > 0.0000001?((*this)[i] /= dSum):(*this)[i]=0.0, i++) ; c@225: c@225: } c@299: c@299: void clear() c@299: { c@299: for (size_t i = 0; i < 12; ++i) (*this)[i] = 0.0; c@299: } c@299: c@225: c@225: }; c@225: c@225: class TCSVector : public std::valarray c@225: { c@225: public: c@225: TCSVector() : std::valarray() c@225: { resize(6, 0.0f); } c@225: c@225: virtual ~TCSVector() {}; c@225: c@225: void printDebug() c@225: { c@414: for (int i = 0; i < int(size()); i++) c@225: { c@225: std::cout << (*this)[i] << ";"; c@225: } c@225: c@225: std::cout << std::endl; c@225: } c@225: c@225: double magnitude() const c@225: { c@225: double dMag = 0.0; c@225: c@225: for (size_t i = 0; i < 6; i++) c@225: { c@225: dMag += std::pow((*this)[i], 2.0); c@225: } c@225: c@225: return std::sqrt(dMag); c@225: } c@225: c@225: }; c@225: c@225: c@225: c@225: class TonalEstimator c@225: { c@225: public: c@225: TonalEstimator(); c@225: virtual ~TonalEstimator(); c@225: TCSVector transform2TCS(const ChromaVector& rVector); c@225: protected: c@225: std::valarray< std::valarray > m_Basis; c@225: }; c@225: c@225: #endif // _TONALESTIMATOR_