00001 #ifndef INCLUDE_FUNDAMENTAL_H
00002 #define INCLUDE_FUNDAMENTAL_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "LorisExceptions.h"
00039 #include "Envelope.h"
00040 #include "LinearEnvelope.h"
00041 #include "PartialList.h"
00042
00043
00044 namespace Loris {
00045
00046
00047
00048
00049
00062
00063 class Fundamental : public Envelope
00064 {
00065
00066 PartialList partials_;
00067
00068 double freqMin_, freqMax_;
00069
00070 double ampThreshold_;
00071
00072 double freqResolution_;
00073
00074
00075
00076
00077 public:
00078
00079
00094 #if !defined(NO_TEMPLATE_MEMBERS)
00095 template<typename Iter>
00096 Fundamental( Iter begin_partials, Iter end_partials,
00097 double fmin, double fmax );
00098 #else
00099 Fundamental( PartialList::const_iterator begin_partials,
00100 PartialList::const_iterator end_partials,
00101 double fmin, double fmax );
00102 #endif
00103
00104
00105
00106
00107
00108
00123 double estimateAt( double time ) const;
00124
00135 double operator() ( double time ) const;
00136
00155 LinearEnvelope constructEnvelope( double interval ) const;
00156
00180 LinearEnvelope
00181 constructEnvelope( double t1, double t2, double interval ) const;
00182
00183
00184
00190 double ampThreshold( void ) const { return ampThreshold_; }
00191
00197 void setAmpThreshold( double x );
00198
00204 double freqResolution( void ) const { return freqResolution_; }
00205
00211 void setFreqResolution( double x );
00212
00213
00214
00219 virtual Fundamental * clone( void ) const
00220 { return new Fundamental( *this ); }
00221
00222 virtual double valueAt( double time ) const
00223 { return estimateAt( time ); }
00233
00234
00235
00236 static const double DefaultThreshold;
00237 static const double DefaultResolution;
00238
00239 private:
00240
00241 void preparePartials( void );
00242
00243 };
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257 #if !defined(NO_TEMPLATE_MEMBERS)
00258 template <typename Iter>
00259 Fundamental::Fundamental( Iter begin_partials, Iter end_partials,
00260 double f1, double f2 ) :
00261 #else
00262 inline
00263 Fundamental::Fundamental( PartialList::const_iterator begin_partials,
00264 PartialList::const_iterator end_partials,
00265 double f1, double f2 ) :
00266 #endif
00267
00268 partials_( begin_partials, end_partials ),
00269 freqMin_( (f1<f2)?(f1):(f2) ),
00270 freqMax_( (f1<f2)?(f2):(f1) ),
00271 ampThreshold_( DefaultThreshold ),
00272 freqResolution_( DefaultResolution )
00273 {
00274
00275 if ( f1 == f2 )
00276 {
00277 Throw( InvalidArgument, "Cannot estimate the fundamental over "
00278 "an empty frequency range." );
00279 }
00280 if ( f1 < 0 )
00281 {
00282 Throw( InvalidArgument, "Cannot estimate the fundamental over "
00283 "a negative frequency range." );
00284 }
00285
00286 preparePartials();
00287 }
00288
00289 }
00290
00291 #endif // ndef INCLUDE_FUNDAMENTAL_H