Morpher.h

00001 #ifndef INCLUDE_MORPHER_H
00002 #define INCLUDE_MORPHER_H
00003 /*
00004  * This is the Loris C++ Class Library, implementing analysis, 
00005  * manipulation, and synthesis of digitized sounds using the Reassigned 
00006  * Bandwidth-Enhanced Additive Sound Model.
00007  *
00008  * Loris is Copyright (c) 1999-2007 by Kelly Fitz and Lippold Haken
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY, without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  *
00025  * Morpher.h
00026  *
00027  * Definition of class Morpher.
00028  *
00029  * Kelly Fitz, 15 Oct 1999
00030  * loris@cerlsoundgroup.org
00031  *
00032  * http://www.cerlsoundgroup.org/Loris/
00033  *
00034  */
00035 #include "PartialList.h"
00036 #include "Partial.h"
00037 
00038 #include <memory>   // for auto_ptr
00039 
00040 //  begin namespace
00041 namespace Loris {
00042 
00043 class Envelope;
00044 
00045 // ---------------------------------------------------------------------------
00046 //  Class Morpher
00047 //
00066 //
00067 class Morpher
00068 {
00069 //  -- instance variables --
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 _ampMorphShape;          
00088 
00089 
00090 
00091 
00092 
00093 
00094 
00095 
00096 
00097 
00098                                                             
00099     double _minBreakpointGapSec;    
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 //  -- public interface --
00108 public:
00109 //  -- construction --
00110 
00116     Morpher( const Envelope & f );
00117 
00124     Morpher( const Envelope & ff, const Envelope & af, const Envelope & bwf );
00125 
00129     Morpher( const Morpher & rhs );
00130     
00132     ~Morpher( void );
00133     
00137     Morpher & operator= ( const Morpher & rhs );
00138 
00139 //  -- morphed parameter computation --
00140 
00141 //  -- Partial morphing --
00142 
00159     Partial morphPartials( Partial src, Partial tgt, int assignLabel );
00160     
00163     Partial morphPartial( Partial src, Partial tgt, int assignLabel )
00164         { return morphPartials( src, tgt, assignLabel ); }
00165 
00186     void morph( PartialList::const_iterator beginSrc, 
00187                 PartialList::const_iterator endSrc,
00188                 PartialList::const_iterator beginTgt, 
00189                 PartialList::const_iterator endTgt );
00190 
00216     void crossfade( PartialList::const_iterator beginSrc, 
00217                     PartialList::const_iterator endSrc,
00218                     PartialList::const_iterator beginTgt, 
00219                     PartialList::const_iterator endTgt,
00220                     Partial::label_type label = 0 );
00221 
00222 
00234     //
00235     Breakpoint
00236     morphBreakpoints( Breakpoint srcBkpt, Breakpoint tgtBkpt, 
00237                       double time  ) const;
00238                                
00255     Breakpoint 
00256     morphSrcBreakpoint( const Breakpoint & bp, const Partial & tgtPartial, 
00257                         double time ) const;
00258 
00275     Breakpoint 
00276     morphTgtBreakpoint( const Breakpoint & bp, const Partial & srcPartial, 
00277                         double time ) const;
00278 
00289     Breakpoint fadeSrcBreakpoint( Breakpoint bp, double time ) const;
00290 
00301     Breakpoint fadeTgtBreakpoint( Breakpoint bp, double time ) const;
00302     
00303 //  -- morphing function access/mutation --
00304 
00306     void setFrequencyFunction( const Envelope & f );
00307     
00309     void setAmplitudeFunction( const Envelope & f );
00310     
00312     void setBandwidthFunction( const Envelope & f );
00313 
00315     const Envelope & frequencyFunction( void ) const;
00316     
00318     const Envelope & amplitudeFunction( void ) const;
00319     
00321     const Envelope & bandwidthFunction( void ) const;
00322     
00336     double amplitudeShape( void ) const;
00337     
00353     void setAmplitudeShape( double x );
00354     
00362     double minBreakpointGap( void ) const;
00363 
00375     void setMinBreakpointGap( double x );
00376 
00377 
00378 //  -- reference Partial label access/mutation --
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 //  -- PartialList access --
00475 
00477     PartialList & partials( void ); 
00478 
00480     const PartialList & partials( void ) const; 
00481 
00482 //  -- global morphing defaults and constants --
00483 
00488     static const double DefaultFixThreshold;
00489 
00498     static const double DefaultAmpShape;    
00499 
00503     static const double DefaultBreakpointGap;
00504 
00505 private:
00506     
00507 //  -- helper --
00508 
00509     //  PartialCorrespondence represents a map from non-zero Partial 
00510     //  labels to pairs of pointers to Partials that should be morphed 
00511     //  into a single Partial that is assigned that label. 
00512     //  MorphingPair is a pair of pointers to Partials that are
00513     //  initialized to zero, and it is the element type for the
00514     //  PartialCorrespondence map.
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 
00570 };  //  end of class Morpher
00571 
00572 }   //  end of namespace Loris
00573 
00574 #endif /* ndef INCLUDE_MORPHER_H */

Generated on Sat Jan 19 19:02:50 2008 for Loris by  doxygen 1.5.2