Marsyas  0.5.0-beta1
/Users/jleben/code/marsyas/src/marsyas/marsystems/F0Analysis.h
Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 1998-2006 George Tzanetakis <gtzan@cs.uvic.ca>
00003 **
00004 ** This program is free software; you can redistribute it and/or modify
00005 ** it under the terms of the GNU General Public License as published by
00006 ** the Free Software Foundation; either version 2 of the License, or
00007 ** (at your option) any later version.
00008 **
00009 ** This program is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 ** GNU General Public License for more details.
00013 **
00014 ** You should have received a copy of the GNU General Public License
00015 ** along with this program; if not, write to the Free Software
00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 */
00018 
00019 #ifndef MARSYAS_F0ANALYSIS_H
00020 #define MARSYAS_F0ANALYSIS_H
00021 
00022 #include <marsyas/system/MarSystem.h>
00023 #include <functional>
00024 
00025 namespace Marsyas
00026 {
00042 class F0Analysis: public MarSystem
00043 {
00044 public:
00045   F0Analysis(mrs_string inName);
00046   F0Analysis(const F0Analysis& inToCopy);
00047 
00048   ~F0Analysis();
00049 
00050   MarSystem* clone() const;
00051 
00052   void addControls();
00053   void myUpdate(MarControlPtr inSender);
00054   void myProcess(realvec& inVec, realvec& outVec);
00055 
00056 private:
00057   // Pointer to MarControllers
00058   MarControlPtr ctrl_SampleRate_;
00059   MarControlPtr ctrl_NrOfHarmonics_;
00060   MarControlPtr ctrl_F0Weight_;
00061   MarControlPtr ctrl_Attenuation_;
00062   MarControlPtr ctrl_Tolerance_;
00063   MarControlPtr ctrl_LowestF0_;
00064   MarControlPtr ctrl_Compression_;
00065 
00066   // Member variable
00067   mrs_real SampleRate_;     // Sample rate of the input vectors
00068   mrs_natural NrOfHarmonics_;   // Nr. of harmonics taken into account (excl. F0)
00069   mrs_real F0Weight_;           // Balance between F0 and higher harmonics
00070   mrs_real Attenuation_;        // Attenuation of higher harmonics
00071   mrs_real Tolerance_;      // Tolerance for harmonics to be assigned to F0
00072   mrs_real LowestF0_;           // Lowest possible F0
00073   mrs_real Compression_;
00074 
00075   mrs_real ChordEvidence_;  // Evidence that last input spectrum includes chord
00076 
00077   // Help functions
00078   typedef std::map<double,double,std::less<double> > FreqMap;       // freq -> float
00079   typedef std::map<double,double,std::greater<float> > HarmMap; // harm sum -> freq
00080   typedef std::map<double,std::vector<double>,std::less<double> > F2Fs;
00081 
00082   bool FindCandidateF0s(const realvec& inPeaks,
00083                         HarmMap& outHarmSums, F2Fs& outF0ToFks) const;
00084   bool SelectUnrelatedF0s(const realvec& inPeaks, const HarmMap inHarmSums,
00085                           const F2Fs& inF0ToFks, realvec& outNoteEvidences);
00086 
00087   mrs_real ComputePowerOfF0(const FreqMap inPeaks, const F2Fs& inF0ToFks, double inF0) const;
00088   mrs_real ComputePowerOfInput(const FreqMap inPeaks) const;
00089   mrs_real ComputePowerOfHyp(const FreqMap inPeaks, const F2Fs& inF0ToFks,
00090                              realvec& inNoteEvidence) const;
00091 };
00092 
00093 }
00094 
00095 #endif