annotate dsp/tonal/TonalEstimator.h @ 96:88f3cfcff55f

A threshold (delta) is added in the peak picking parameters structure (PPickParams). It is used as an offset when computing the smoothed detection function. A constructor for the structure PPickParams is also added to set the parameters to 0 when a structure instance is created. Hence programmes using the peak picking parameter structure and which do not set the delta parameter (e.g. QM Vamp note onset detector) won't be affected by the modifications. Functions modified: - dsp/onsets/PeakPicking.cpp - dsp/onsets/PeakPicking.h - dsp/signalconditioning/DFProcess.cpp - dsp/signalconditioning/DFProcess.h
author mathieub <mathieu.barthet@eecs.qmul.ac.uk>
date Mon, 20 Jun 2011 19:01:48 +0100
parents e5907ae6de17
children e4a57215ddee
rev   line source
cannam@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@0 2
cannam@0 3 /*
cannam@0 4 QM DSP Library
cannam@0 5
cannam@0 6 Centre for Digital Music, Queen Mary, University of London.
cannam@0 7 This file copyright 2006 Martin Gasser.
Chris@84 8
Chris@84 9 This program is free software; you can redistribute it and/or
Chris@84 10 modify it under the terms of the GNU General Public License as
Chris@84 11 published by the Free Software Foundation; either version 2 of the
Chris@84 12 License, or (at your option) any later version. See the file
Chris@84 13 COPYING included with this distribution for more information.
cannam@0 14 */
cannam@0 15
cannam@0 16 #ifndef _TONALESTIMATOR_
cannam@0 17 #define _TONALESTIMATOR_
cannam@0 18
cannam@0 19
cannam@0 20 #include <valarray>
cannam@0 21 #include <numeric>
cannam@0 22 #include <algorithm>
cannam@0 23 #include <iostream>
cannam@0 24
cannam@0 25 class ChromaVector : public std::valarray<double>
cannam@0 26 {
cannam@0 27 public:
cannam@0 28 ChromaVector(size_t uSize = 12) : std::valarray<double>()
cannam@0 29 { resize(uSize, 0.0f); }
cannam@0 30
cannam@0 31 virtual ~ChromaVector() {};
cannam@0 32
cannam@0 33 void printDebug()
cannam@0 34 {
cannam@0 35 for (int i = 0; i < size(); i++)
cannam@0 36 {
cannam@0 37 std::cout << (*this)[i] << ";";
cannam@0 38 }
cannam@0 39
cannam@0 40 std::cout << std::endl;
cannam@0 41 }
cannam@0 42
cannam@0 43 void normalizeL1()
cannam@0 44 {
cannam@0 45 // normalize the chroma vector (L1 norm)
cannam@0 46 double dSum = 0.0;
cannam@0 47
cannam@60 48 for (size_t i = 0; i < 12; (dSum += std::abs((*this)[i++]))) ;
cannam@60 49 for (size_t i = 0; i < 12; dSum > 0.0000001?((*this)[i] /= dSum):(*this)[i]=0.0, i++) ;
cannam@0 50
cannam@0 51 }
cannam@74 52
cannam@74 53 void clear()
cannam@74 54 {
cannam@74 55 for (size_t i = 0; i < 12; ++i) (*this)[i] = 0.0;
cannam@74 56 }
cannam@74 57
cannam@0 58
cannam@0 59 };
cannam@0 60
cannam@0 61 class TCSVector : public std::valarray<double>
cannam@0 62 {
cannam@0 63 public:
cannam@0 64 TCSVector() : std::valarray<double>()
cannam@0 65 { resize(6, 0.0f); }
cannam@0 66
cannam@0 67 virtual ~TCSVector() {};
cannam@0 68
cannam@0 69 void printDebug()
cannam@0 70 {
cannam@0 71 for (int i = 0; i < size(); i++)
cannam@0 72 {
cannam@0 73 std::cout << (*this)[i] << ";";
cannam@0 74 }
cannam@0 75
cannam@0 76 std::cout << std::endl;
cannam@0 77 }
cannam@0 78
cannam@0 79 double magnitude() const
cannam@0 80 {
cannam@0 81 double dMag = 0.0;
cannam@0 82
cannam@0 83 for (size_t i = 0; i < 6; i++)
cannam@0 84 {
cannam@0 85 dMag += std::pow((*this)[i], 2.0);
cannam@0 86 }
cannam@0 87
cannam@0 88 return std::sqrt(dMag);
cannam@0 89 }
cannam@0 90
cannam@0 91 };
cannam@0 92
cannam@0 93
cannam@0 94
cannam@0 95 class TonalEstimator
cannam@0 96 {
cannam@0 97 public:
cannam@0 98 TonalEstimator();
cannam@0 99 virtual ~TonalEstimator();
cannam@0 100 TCSVector transform2TCS(const ChromaVector& rVector);
cannam@0 101 protected:
cannam@0 102 std::valarray< std::valarray<double> > m_Basis;
cannam@0 103 };
cannam@0 104
cannam@0 105 #endif // _TONALESTIMATOR_