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 class 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
00304 bool phaseCorrect( void ) const;
00305
00306
00307
00308
00313 void setAmpFloor( double x );
00314
00321 void setCropTime( double x );
00322
00327 void setFreqDrift( double x );
00328
00333 void setFreqFloor( double x );
00334
00340 void setFreqResolution( double x );
00341
00347 void setFreqResolution( const Envelope & e );
00348
00353 void setHopTime( double x );
00354
00363 void setSidelobeLevel( double x );
00364
00369 void setWindowWidth( double x );
00370
00377 void setPhaseCorrect( bool TF = true );
00378
00379
00380
00381
00382 enum { Default_ResidueBandwidth_RegionWidth = 2000,
00383 Default_ConvergenceBandwidth_TolerancePct = 10 };
00384
00395 void storeResidueBandwidth( double regionWidth = Default_ResidueBandwidth_RegionWidth );
00396
00409 void storeConvergenceBandwidth( double tolerancePct =
00410 0.01 * (double)Default_ConvergenceBandwidth_TolerancePct );
00411
00414 void storeNoBandwidth( void );
00415
00419 bool bandwidthIsResidue( void ) const;
00420
00424 bool bandwidthIsConvergence( void ) const;
00425
00430 double bwRegionWidth( void ) const;
00431
00436 double bwConvergenceTolerance( void ) const;
00437
00442 bool associateBandwidth( void ) const
00443 { return bandwidthIsResidue() || bandwidthIsConvergence(); }
00444
00446 void setBwRegionWidth( double x )
00447 {
00448 if ( x != 0 )
00449 {
00450 storeResidueBandwidth( x );
00451 }
00452 else
00453 {
00454 storeNoBandwidth();
00455 }
00456 }
00457
00458
00459
00460
00463 PartialList & partials( void );
00464
00467 const PartialList & partials( void ) const;
00468
00469
00470
00471 enum { Default_FundamentalEnv_ThreshDb = -60,
00472 Default_FundamentalEnv_ThreshHz = 8000 };
00473
00491 void buildFundamentalEnv( double fmin, double fmax,
00492 double threshDb = Default_FundamentalEnv_ThreshDb,
00493 double threshHz = Default_FundamentalEnv_ThreshHz );
00494
00495
00501 const LinearEnvelope & fundamentalEnv( void ) const;
00502
00505 const LinearEnvelope & ampEnv( void ) const;
00506
00507
00508
00509
00510
00511
00512
00513 void buildAmpEnv( bool TF = true ) { TF = TF; }
00514 void buildFundamentalEnv( bool TF = true ) { TF = TF; }
00515
00516
00517
00518 private:
00519
00520 std::auto_ptr< Envelope > m_freqResolutionEnv;
00524
00525 double m_ampFloor;
00526
00527
00528 double m_windowWidth;
00529
00530
00531
00532
00533
00534 double m_freqFloor;
00535
00536
00537 double m_freqDrift;
00538
00539
00540
00541 double m_hopTime;
00542
00543
00544 double m_cropTime;
00545
00546
00547
00548 double m_bwAssocParam;
00549
00550
00551
00552
00553
00554
00555 double m_sidelobeLevel;
00556
00557
00558 bool m_phaseCorrect;
00559
00560
00561 PartialList m_partials;
00562
00565 std::auto_ptr< LinearEnvelopeBuilder > m_f0Builder;
00566
00569 std::auto_ptr< LinearEnvelopeBuilder > m_ampEnvBuilder;
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00582
00583
00586
00587
00590
00591
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605 Peaks::iterator thinPeaks( Peaks & peaks, double frameTime );
00606
00607
00608
00609
00610
00611
00612
00613
00614 void fixBandwidth( Peaks & peaks );
00615
00616 };
00617
00618 }
00619
00620 #endif