1 // Copyright 2004 "Gilles Degottex"
3 // This file is part of "Music"
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.
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.
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
20 #ifndef _BubbleAlgo_h_
21 #define _BubbleAlgo_h_
29 #include "Algorithm.h"
30 #include "Correlation.h"
34 class BubbleAlgo : public Algorithm
41 Type m_error_threshold;
42 Type m_conv_threshold;
56 Bubble(size_t as=0) : s(as), count(0), score(0.0), err(0.0), conv(complex<double>(0.0,0.0)), n(0), todrop(false), gcd_count(0) {}
59 vector<Bubble> m_bubbles;
60 vector< vector<complex<double> > > m_waves;
61 vector< vector<double> > m_waves_best;
62 map<Type,list<size_t> > m_sort;
63 map<Type,list<size_t> > m_best_set;
65 Type diff(const deque<double>& buff, size_t i, size_t j) {return abs(buff[i] - buff[j]);}
67 void setMinMaxLength(size_t min_length, size_t max_length)
68 {m_min_length=min_length; m_max_length=max_length;}
72 virtual void AFreqChanged() {init();}
73 virtual void samplingRateChanged() {init();}
74 virtual void semitoneBoundsChanged() {init();}
79 virtual int getSampleAlgoLatency() const {return 2*m_waves.back().size();}
81 void apply(const deque<double>& buff);
83 virtual bool hasNoteRecognized() const {return m_wave_length!=0;}
84 virtual int getFondamentalWaveLength() const {return m_wave_length;}
85 void setErrorThreshold(double threshold) {m_error_threshold = threshold;}
86 void setConvolutionThreshold(double threshold) {m_conv_threshold = threshold;}
88 virtual ~BubbleAlgo() {}