Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/midi/pitchfilter.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                         pitchfilter.h  -  description
00003                         -------------------
00004 begin                : Wed May 12 2010
00005 copyright            : (C) 2010 by Sean M. Pappalardo
00006 email                : spappalardo@mixxx.org
00007 
00008 This is essentially just a C++ version of xwax's pitch.h,
00009     which is Copyright (C) 2010 Mark Hills <mark@pogo.org.uk>
00010 ***************************************************************************/
00011 
00012 /***************************************************************************
00013 *                                                                         *
00014 *   This program is free software; you can redistribute it and/or modify  *
00015 *   it under the terms of the GNU General Public License as published by  *
00016 *   the Free Software Foundation; either version 2 of the License, or     *
00017 *   (at your option) any later version.                                   *
00018 *                                                                         *
00019 ***************************************************************************/
00020 
00021 #ifndef PITCHFILTER_H
00022 #define PITCHFILTER_H
00023 
00024 class PitchFilter {
00025     public:
00028         void init(float dt, float v, float alpha = 1.0/512, float beta = (1.0/512)/1024) {
00029             m_dt = dt;
00030             m_x = 0.0;
00031             m_v = v;
00032             m_alpha = alpha;
00033             m_beta = beta;
00034         }
00035         
00041         void observation(float dx) {
00042             float predicted_x, predicted_v, residual_x;
00043             
00044             predicted_x = m_x + m_v * m_dt;
00045             predicted_v = m_v;
00046             
00047             residual_x = dx - predicted_x;
00048             
00049             m_x = predicted_x + residual_x * m_alpha;
00050             m_v = predicted_v + residual_x * (m_beta / m_dt);
00051             
00052             m_x -= dx; /* relative to previous */
00053         }
00054         
00056         float currentPitch() {
00057             return m_v;
00058         }
00059         
00060     protected:
00062         float m_dt, m_x, m_v, m_alpha, m_beta;
00063 };
00064 
00065 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines