1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2006 Martin Gasser.
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
16 #ifndef _TONALESTIMATOR_
17 #define _TONALESTIMATOR_
25 class ChromaVector : public std::valarray<double>
28 ChromaVector(size_t uSize = 12) : std::valarray<double>()
29 { resize(uSize, 0.0f); }
31 virtual ~ChromaVector() {};
35 for (int i = 0; i < size(); i++)
37 std::cout << (*this)[i] << ";";
40 std::cout << std::endl;
45 // normalize the chroma vector (L1 norm)
48 for (size_t i = 0; i < 12; (dSum += std::abs((*this)[i++]))) ;
49 for (size_t i = 0; i < 12; dSum > 0.0000001?((*this)[i] /= dSum):(*this)[i]=0.0, i++) ;
55 for (size_t i = 0; i < 12; ++i) (*this)[i] = 0.0;
61 class TCSVector : public std::valarray<double>
64 TCSVector() : std::valarray<double>()
67 virtual ~TCSVector() {};
71 for (int i = 0; i < size(); i++)
73 std::cout << (*this)[i] << ";";
76 std::cout << std::endl;
79 double magnitude() const
83 for (size_t i = 0; i < 6; i++)
85 dMag += std::pow((*this)[i], 2.0);
88 return std::sqrt(dMag);
99 virtual ~TonalEstimator();
100 TCSVector transform2TCS(const ChromaVector& rVector);
102 std::valarray< std::valarray<double> > m_Basis;
105 #endif // _TONALESTIMATOR_