annotate dsp/tonal/TonalEstimator.h @ 414:7e8d1f26b098

Fix compiler warnings with -Wall -Wextra
author Chris Cannam <c.cannam@qmul.ac.uk>
date Mon, 28 Sep 2015 12:33:17 +0100
parents d5014ab8b0e5
children cbe668c7d724
rev   line source
c@225 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
c@225 2
c@225 3 /*
c@225 4 QM DSP Library
c@225 5
c@225 6 Centre for Digital Music, Queen Mary, University of London.
c@225 7 This file copyright 2006 Martin Gasser.
c@309 8
c@309 9 This program is free software; you can redistribute it and/or
c@309 10 modify it under the terms of the GNU General Public License as
c@309 11 published by the Free Software Foundation; either version 2 of the
c@309 12 License, or (at your option) any later version. See the file
c@309 13 COPYING included with this distribution for more information.
c@225 14 */
c@225 15
c@225 16 #ifndef _TONALESTIMATOR_
c@225 17 #define _TONALESTIMATOR_
c@225 18
c@225 19
c@225 20 #include <valarray>
c@225 21 #include <numeric>
c@225 22 #include <algorithm>
c@225 23 #include <iostream>
c@225 24
c@225 25 class ChromaVector : public std::valarray<double>
c@225 26 {
c@225 27 public:
c@225 28 ChromaVector(size_t uSize = 12) : std::valarray<double>()
c@225 29 { resize(uSize, 0.0f); }
c@225 30
c@225 31 virtual ~ChromaVector() {};
c@225 32
c@225 33 void printDebug()
c@225 34 {
c@414 35 for (int i = 0; i < int(size()); i++)
c@225 36 {
c@225 37 std::cout << (*this)[i] << ";";
c@225 38 }
c@225 39
c@225 40 std::cout << std::endl;
c@225 41 }
c@225 42
c@225 43 void normalizeL1()
c@225 44 {
c@225 45 // normalize the chroma vector (L1 norm)
c@225 46 double dSum = 0.0;
c@225 47
c@285 48 for (size_t i = 0; i < 12; (dSum += std::abs((*this)[i++]))) ;
c@285 49 for (size_t i = 0; i < 12; dSum > 0.0000001?((*this)[i] /= dSum):(*this)[i]=0.0, i++) ;
c@225 50
c@225 51 }
c@299 52
c@299 53 void clear()
c@299 54 {
c@299 55 for (size_t i = 0; i < 12; ++i) (*this)[i] = 0.0;
c@299 56 }
c@299 57
c@225 58
c@225 59 };
c@225 60
c@225 61 class TCSVector : public std::valarray<double>
c@225 62 {
c@225 63 public:
c@225 64 TCSVector() : std::valarray<double>()
c@225 65 { resize(6, 0.0f); }
c@225 66
c@225 67 virtual ~TCSVector() {};
c@225 68
c@225 69 void printDebug()
c@225 70 {
c@414 71 for (int i = 0; i < int(size()); i++)
c@225 72 {
c@225 73 std::cout << (*this)[i] << ";";
c@225 74 }
c@225 75
c@225 76 std::cout << std::endl;
c@225 77 }
c@225 78
c@225 79 double magnitude() const
c@225 80 {
c@225 81 double dMag = 0.0;
c@225 82
c@225 83 for (size_t i = 0; i < 6; i++)
c@225 84 {
c@225 85 dMag += std::pow((*this)[i], 2.0);
c@225 86 }
c@225 87
c@225 88 return std::sqrt(dMag);
c@225 89 }
c@225 90
c@225 91 };
c@225 92
c@225 93
c@225 94
c@225 95 class TonalEstimator
c@225 96 {
c@225 97 public:
c@225 98 TonalEstimator();
c@225 99 virtual ~TonalEstimator();
c@225 100 TCSVector transform2TCS(const ChromaVector& rVector);
c@225 101 protected:
c@225 102 std::valarray< std::valarray<double> > m_Basis;
c@225 103 };
c@225 104
c@225 105 #endif // _TONALESTIMATOR_