00001 #ifndef INCLUDE_ANALYZER_H
00002 #define INCLUDE_ANALYZER_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 #include <memory>
00036 #include <vector>
00037 #include "LinearEnvelope.h"
00038 #include "Partial.h"
00039 #include "PartialList.h"
00040
00041
00042
00043 namespace Loris {
00044
00045 class Envelope;
00046 class LinearEnvelopeBuilder;
00047
00048
00049
00050 struct SpectralPeak;
00051 typedef std::vector< SpectralPeak > Peaks;
00052
00053
00054
00055
00103
00104 class Analyzer
00105 {
00106
00107 public:
00108
00109
00110
00117 explicit Analyzer( double resolutionHz );
00118
00128 Analyzer( double resolutionHz, double windowWidthHz );
00129
00139 Analyzer( const Envelope & resolutionEnv, double windowWidthHz );
00140
00146 Analyzer( const Analyzer & other );
00147
00149 ~Analyzer( void );
00150
00156 Analyzer & operator=( const Analyzer & rhs );
00157
00158
00159
00167 void configure( double resolutionHz );
00168
00185 void configure( double resolutionHz, double windowWidthHz );
00186
00204
00205 void configure( const Envelope & resolutionEnv, double windowWidthHz );
00206
00207
00208
00215 void analyze( const std::vector<double> & vec, double srate );
00216
00225 void analyze( const double * bufBegin, const double * bufEnd, double srate );
00226
00227
00228
00238 void analyze( const std::vector<double> & vec, double srate,
00239 const Envelope & reference );
00240
00252 void analyze( const double * bufBegin, const double * bufEnd, double srate,
00253 const Envelope & reference );
00254
00255
00256
00259 double ampFloor( void ) const;
00260
00265 double cropTime( void ) const;
00266
00269 double freqDrift( void ) const;
00270
00273 double freqFloor( void ) const;
00274
00282 double freqResolution( double time = 0.0 ) const;
00283
00287 double hopTime( void ) const;
00288
00295 double sidelobeLevel( void ) const;
00296
00299 double windowWidth( void ) const;
00300
00307 bool phaseCorrect( void ) const;
00308
00309
00310
00311
00316 void setAmpFloor( double x );
00317
00324 void setCropTime( double x );
00325
00330 void setFreqDrift( double x );
00331
00336 void setFreqFloor( double x );
00337
00343 void setFreqResolution( double x );
00344
00350 void setFreqResolution( const Envelope & e );
00351
00356 void setHopTime( double x );
00357
00366 void setSidelobeLevel( double x );
00367
00372 void setWindowWidth( double x );
00373
00380 void setPhaseCorrect( bool TF = true );
00381
00382
00383
00384
00385 enum { Default_ResidueBandwidth_RegionWidth = 2000,
00386 Default_ConvergenceBandwidth_TolerancePct = 10 };
00387
00398 void storeResidueBandwidth( double regionWidth = Default_ResidueBandwidth_RegionWidth );
00399
00412 void storeConvergenceBandwidth( double tolerancePct =
00413 0.01 * (double)Default_ConvergenceBandwidth_TolerancePct );
00414
00417 void storeNoBandwidth( void );
00418
00422 bool bandwidthIsResidue( void ) const;
00423
00427 bool bandwidthIsConvergence( void ) const;
00428
00433 double bwRegionWidth( void ) const;
00434
00439 double bwConvergenceTolerance( void ) const;
00440
00445 bool associateBandwidth( void ) const
00446 { return bandwidthIsResidue() || bandwidthIsConvergence(); }
00447
00449 void setBwRegionWidth( double x )
00450 {
00451 if ( x != 0 )
00452 {
00453 storeResidueBandwidth( x );
00454 }
00455 else
00456 {
00457 storeNoBandwidth();
00458 }
00459 }
00460
00461
00462
00463
00466 PartialList & partials( void );
00467
00470 const PartialList & partials( void ) const;
00471
00472
00473
00474 enum { Default_FundamentalEnv_ThreshDb = -60,
00475 Default_FundamentalEnv_ThreshHz = 8000 };
00476
00494 void buildFundamentalEnv( double fmin, double fmax,
00495 double threshDb = Default_FundamentalEnv_ThreshDb,
00496 double threshHz = Default_FundamentalEnv_ThreshHz );
00497
00498
00505 const LinearEnvelope & fundamentalEnv( void ) const;
00506
00511 const LinearEnvelope & ampEnv( void ) const;
00512
00513
00514
00515
00516
00517
00518
00519 void buildAmpEnv( bool TF = true ) { TF = TF; }
00520 void buildFundamentalEnv( bool TF = true ) { TF = TF; }
00521
00522
00523
00524 private:
00525
00526 std::auto_ptr< Envelope > m_freqResolutionEnv;
00530
00531 double m_ampFloor;
00532
00533
00534 double m_windowWidth;
00535
00536
00537
00538
00539
00540 double m_freqFloor;
00541
00542
00543 double m_freqDrift;
00544
00545
00546
00547 double m_hopTime;
00548
00549
00550 double m_cropTime;
00551
00552
00553
00554 double m_bwAssocParam;
00555
00556
00557
00558
00559
00560
00561 double m_sidelobeLevel;
00562
00563
00564 bool m_phaseCorrect;
00565
00566
00567 PartialList m_partials;
00568
00571 std::auto_ptr< LinearEnvelopeBuilder > m_f0Builder;
00572
00575 std::auto_ptr< LinearEnvelopeBuilder > m_ampEnvBuilder;
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00588
00589
00592
00593
00596
00597
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611 Peaks::iterator thinPeaks( Peaks & peaks, double frameTime );
00612
00613
00614
00615
00616
00617
00618
00619
00620 void fixBandwidth( Peaks & peaks );
00621
00622 };
00623
00624 }
00625
00626 #endif