| 1 |
// Copyright 2004 "Gilles Degottex" |
| 2 |
|
| 3 |
// This file is part of "Music" |
| 4 |
|
| 5 |
// "Music" is free software; you can redistribute it and/or modify |
| 6 |
// it under the terms of the GNU Lesser General Public License as published by |
| 7 |
// the Free Software Foundation; either version 2.1 of the License, or |
| 8 |
// (at your option) any later version. |
| 9 |
// |
| 10 |
// "Music" is distributed in the hope that it will be useful, |
| 11 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
// GNU Lesser General Public License for more details. |
| 14 |
// |
| 15 |
// You should have received a copy of the GNU Lesser General Public License |
| 16 |
// along with this program; if not, write to the Free Software |
| 17 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 |
|
| 19 |
|
| 20 |
#ifndef _CumulativeDiffAlgo_h_ |
| 21 |
#define _CumulativeDiffAlgo_h_ |
| 22 |
|
| 23 |
#include <vector> |
| 24 |
#include <deque> |
| 25 |
#include <complex> |
| 26 |
using namespace std; |
| 27 |
#include "Algorithm.h" |
| 28 |
#include "CumulativeDiff.h" |
| 29 |
|
| 30 |
namespace Music |
| 31 |
{ |
| 32 |
//! Compute period with a "classical" auto-correlation algorithm |
| 33 |
class CumulativeDiffAlgo : public Algorithm |
| 34 |
{ |
| 35 |
protected: |
| 36 |
double m_noise_threshold; |
| 37 |
|
| 38 |
size_t m_min_length; |
| 39 |
size_t m_max_length; |
| 40 |
|
| 41 |
size_t m_wave_length; |
| 42 |
|
| 43 |
void init(); |
| 44 |
virtual void AFreqChanged() {init();} |
| 45 |
virtual void samplingRateChanged() {init();} |
| 46 |
virtual void semitoneBoundsChanged() {init();} |
| 47 |
|
| 48 |
public: |
| 49 |
CumulativeDiffAlgo(double noise_treshold); |
| 50 |
|
| 51 |
virtual int getSampleAlgoLatency() const {return 2*m_max_length;} |
| 52 |
|
| 53 |
double getNoiseThreshold() const {return m_noise_threshold;} |
| 54 |
void setNoiseThreshold(double noise_threshold) {m_noise_threshold=noise_threshold;} |
| 55 |
void setMinMaxLength(size_t min_length, size_t max_length) |
| 56 |
{m_min_length=min_length; m_max_length=max_length;} |
| 57 |
|
| 58 |
void apply(const deque<double>& buff); |
| 59 |
|
| 60 |
virtual bool hasNoteRecognized() const {return m_wave_length>0;} |
| 61 |
virtual double getFondamentalWaveLength() const {return m_wave_length;} |
| 62 |
|
| 63 |
virtual ~CumulativeDiffAlgo(){} |
| 64 |
}; |
| 65 |
} |
| 66 |
|
| 67 |
#endif |