qm-dsp
1.8
TonalEstimator.h
Go to the documentation of this file.
1
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3
/*
4
QM DSP Library
5
6
Centre for Digital Music, Queen Mary, University of London.
7
This file copyright 2006 Martin Gasser.
8
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.
14
*/
15
16
#ifndef _TONALESTIMATOR_
17
#define _TONALESTIMATOR_
18
19
20
#include <valarray>
21
#include <numeric>
22
#include <algorithm>
23
#include <iostream>
24
25
class
ChromaVector
:
public
std::valarray<double>
26
{
27
public
:
28
ChromaVector
(
size_t
uSize = 12) : std::valarray<double>()
29
{ resize(uSize, 0.0f); }
30
31
virtual
~ChromaVector
() {};
32
33
void
printDebug
()
34
{
35
for
(
int
i = 0; i < size(); i++)
36
{
37
std::cout << (*this)[i] <<
";"
;
38
}
39
40
std::cout << std::endl;
41
}
42
43
void
normalizeL1
()
44
{
45
// normalize the chroma vector (L1 norm)
46
double
dSum = 0.0;
47
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++) ;
50
51
}
52
53
void
clear
()
54
{
55
for
(
size_t
i = 0; i < 12; ++i) (*
this
)[i] = 0.0;
56
}
57
58
59
};
60
61
class
TCSVector
:
public
std::valarray<double>
62
{
63
public
:
64
TCSVector
() : std::valarray<double>()
65
{ resize(6, 0.0f); }
66
67
virtual
~TCSVector
() {};
68
69
void
printDebug
()
70
{
71
for
(
int
i = 0; i < size(); i++)
72
{
73
std::cout << (*this)[i] <<
";"
;
74
}
75
76
std::cout << std::endl;
77
}
78
79
double
magnitude
()
const
80
{
81
double
dMag = 0.0;
82
83
for
(
size_t
i = 0; i < 6; i++)
84
{
85
dMag += std::pow((*
this
)[i], 2.0);
86
}
87
88
return
std::sqrt(dMag);
89
}
90
91
};
92
93
94
95
class
TonalEstimator
96
{
97
public
:
98
TonalEstimator
();
99
virtual
~TonalEstimator
();
100
TCSVector
transform2TCS
(
const
ChromaVector
& rVector);
101
protected
:
102
std::valarray< std::valarray<double> >
m_Basis
;
103
};
104
105
#endif
// _TONALESTIMATOR_
ChromaVector
Definition
TonalEstimator.h:26
ChromaVector::~ChromaVector
virtual ~ChromaVector()
Definition
TonalEstimator.h:31
ChromaVector::normalizeL1
void normalizeL1()
Definition
TonalEstimator.h:43
ChromaVector::clear
void clear()
Definition
TonalEstimator.h:53
ChromaVector::printDebug
void printDebug()
Definition
TonalEstimator.h:33
ChromaVector::ChromaVector
ChromaVector(size_t uSize=12)
Definition
TonalEstimator.h:28
TCSVector
Definition
TonalEstimator.h:62
TCSVector::TCSVector
TCSVector()
Definition
TonalEstimator.h:64
TCSVector::printDebug
void printDebug()
Definition
TonalEstimator.h:69
TCSVector::magnitude
double magnitude() const
Definition
TonalEstimator.h:79
TCSVector::~TCSVector
virtual ~TCSVector()
Definition
TonalEstimator.h:67
TonalEstimator
Definition
TonalEstimator.h:96
TonalEstimator::transform2TCS
TCSVector transform2TCS(const ChromaVector &rVector)
Definition
TonalEstimator.cpp:89
TonalEstimator::~TonalEstimator
virtual ~TonalEstimator()
Definition
TonalEstimator.cpp:85
TonalEstimator::TonalEstimator
TonalEstimator()
Definition
TonalEstimator.cpp:25
TonalEstimator::m_Basis
std::valarray< std::valarray< double > > m_Basis
Definition
TonalEstimator.h:102
dsp
tonal
TonalEstimator.h
Generated by
1.9.8