00001 #ifndef INCLUDE_MORPHER_H
00002 #define INCLUDE_MORPHER_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 "PartialList.h"
00036 #include "Partial.h"
00037
00038 #include <memory>
00039
00040
00041 namespace Loris {
00042
00043 class Envelope;
00044
00045
00046
00047
00066
00067 class Morpher
00068 {
00069
00070
00071 std::auto_ptr< Envelope > _freqFunction;
00072 std::auto_ptr< Envelope > _ampFunction;
00073 std::auto_ptr< Envelope > _bwFunction;
00074
00075 PartialList _partials;
00076
00077 Partial _srcRefPartial;
00078 Partial _tgtRefPartial;
00079
00080
00081
00082
00083 double _freqFixThresholdDb;
00084
00085
00086
00087 double _logMorphShape;
00088
00089
00090
00091
00092
00093
00094
00095
00096 double _minBreakpointGapSec;
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 bool _doLogAmpMorphing;
00107
00108
00109
00110 bool _doLogFreqMorphing;
00111
00112
00113
00114
00115
00116 public:
00117
00118
00124 Morpher( const Envelope & f );
00125
00132 Morpher( const Envelope & ff, const Envelope & af, const Envelope & bwf );
00133
00137 Morpher( const Morpher & rhs );
00138
00140 ~Morpher( void );
00141
00145 Morpher & operator= ( const Morpher & rhs );
00146
00147
00148
00149
00150
00167 Partial morphPartials( Partial src, Partial tgt, int assignLabel );
00168
00171 Partial morphPartial( Partial src, Partial tgt, int assignLabel )
00172 { return morphPartials( src, tgt, assignLabel ); }
00173
00194 void morph( PartialList::const_iterator beginSrc,
00195 PartialList::const_iterator endSrc,
00196 PartialList::const_iterator beginTgt,
00197 PartialList::const_iterator endTgt );
00198
00224 void crossfade( PartialList::const_iterator beginSrc,
00225 PartialList::const_iterator endSrc,
00226 PartialList::const_iterator beginTgt,
00227 PartialList::const_iterator endTgt,
00228 Partial::label_type label = 0 );
00229
00230
00242
00243 Breakpoint
00244 morphBreakpoints( Breakpoint srcBkpt, Breakpoint tgtBkpt,
00245 double time ) const;
00246
00263 Breakpoint
00264 morphSrcBreakpoint( const Breakpoint & bp, const Partial & tgtPartial,
00265 double time ) const;
00266
00283 Breakpoint
00284 morphTgtBreakpoint( const Breakpoint & bp, const Partial & srcPartial,
00285 double time ) const;
00286
00297 Breakpoint fadeSrcBreakpoint( Breakpoint bp, double time ) const;
00298
00309 Breakpoint fadeTgtBreakpoint( Breakpoint bp, double time ) const;
00310
00311
00312
00314 void setFrequencyFunction( const Envelope & f );
00315
00317 void setAmplitudeFunction( const Envelope & f );
00318
00320 void setBandwidthFunction( const Envelope & f );
00321
00323 const Envelope & frequencyFunction( void ) const;
00324
00326 const Envelope & amplitudeFunction( void ) const;
00327
00329 const Envelope & bandwidthFunction( void ) const;
00330
00335 double amplitudeShape( void ) const;
00336
00344 void setAmplitudeShape( double x );
00345
00348 void enableLogAmpMorphing( bool enable = true ) { _doLogAmpMorphing = enable; }
00349
00352 void enableLogFreqMorphing( bool enable = true ) { _doLogFreqMorphing = enable; }
00353
00354
00362 double minBreakpointGap( void ) const;
00363
00375 void setMinBreakpointGap( double x );
00376
00377
00378
00379
00388 const Partial & sourceReferencePartial( void ) const;
00389
00398 Partial & sourceReferencePartial( void );
00399
00408 const Partial & targetReferencePartial( void ) const;
00409
00418 Partial & targetReferencePartial( void );
00419
00429 void setSourceReferencePartial( const Partial & p = Partial() );
00430
00444 void setSourceReferencePartial( const PartialList & partials,
00445 Partial::label_type refLabel );
00446
00456 void setTargetReferencePartial( const Partial & p = Partial() );
00457
00471 void setTargetReferencePartial( const PartialList & partials,
00472 Partial::label_type refLabel );
00473
00474
00475
00477 PartialList & partials( void );
00478
00480 const PartialList & partials( void ) const;
00481
00482
00483
00488 static const double DefaultFixThreshold;
00489
00498 static const double DefaultAmpShape;
00499
00503 static const double DefaultBreakpointGap;
00504
00505 private:
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515 struct MorphingPair
00516 {
00517 Partial src;
00518 Partial tgt;
00519 };
00520 typedef std::map< Partial::label_type, MorphingPair > PartialCorrespondence;
00521
00525 void morph_aux( PartialCorrespondence & correspondence );
00526
00544
00545 void appendMorphedSrc( Breakpoint srcBkpt, const Partial & tgtPartial,
00546 double time, Partial & newp );
00547
00565
00566 void appendMorphedTgt( Breakpoint tgtBkpt, const Partial & srcPartial,
00567 double time, Partial & newp );
00568
00569
00571 Breakpoint
00572 interpolateParameters( const Breakpoint & srcBkpt, const Breakpoint & tgtBkpt,
00573 double fweight, double aweight, double bweight ) const;
00574
00575 double interpolateAmplitude( double srcAmp, double tgtAmp, double alpha ) const;
00576 double interpolateBandwidth( double srcBw, double tgtBw, double alpha ) const;
00577 double interpolateFrequency( double srcFreq, double tgtFreq, double alpha ) const;
00578 double interpolatePhase( double srcphase, double tgtphase, double alpha ) const;
00579
00580
00581
00582
00583
00584 void fixMorphedPhases( Partial & newp ) const;
00585
00586 };
00587
00588 }
00589
00590 #endif