Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

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-2004 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::label_type _refLabel0;  
00078     Partial::label_type _refLabel1;  
00079 
00080 
00081 
00082     double _freqFixThresholdDb;      
00083 
00084 
00085     
00086     double _ampMorphShape;           
00087 
00088 
00089 
00090 
00091 
00092 
00093 
00094 
00095 
00096 
00097                                                                         
00098     double _minBreakpointGapSec;     
00099 
00100 
00101 
00102 
00103 
00104 
00105 
00106 //  -- public interface --
00107 public:
00108 //  -- construction --
00109 
00115     Morpher( const Envelope & f );
00116 
00123     Morpher( const Envelope & ff, const Envelope & af, const Envelope & bwf );
00124 
00128     Morpher( const Morpher & rhs );
00129     
00131     ~Morpher( void );
00132     
00136     Morpher & operator= ( const Morpher & rhs );
00137 
00138 //  -- morphed parameter computation --
00139 
00140 //  -- Partial morphing --
00141 
00158     Partial morphPartial( const Partial & src, const Partial & tgt, 
00159                           int assignLabel );
00160 
00181     void morph( PartialList::const_iterator beginSrc, 
00182                 PartialList::const_iterator endSrc,
00183                 PartialList::const_iterator beginTgt, 
00184                 PartialList::const_iterator endTgt );
00185 
00211     void crossfade( PartialList::const_iterator beginSrc, 
00212                     PartialList::const_iterator endSrc,
00213                     PartialList::const_iterator beginTgt, 
00214                     PartialList::const_iterator endTgt,
00215                     Partial::label_type label = 0 );
00216 
00217 
00229     //
00230     Breakpoint
00231     morphBreakpoints( const Breakpoint & srcBkpt, const Breakpoint & tgtBkpt, 
00232                       double time  ) const;
00233                                
00248     Breakpoint 
00249     morphSrcBreakpoint( const Breakpoint & bp, const Partial & tgtPartial, 
00250                         double time ) const;
00251 
00266     Breakpoint 
00267     morphTgtBreakpoint( const Breakpoint & bp, const Partial & srcPartial, 
00268                         double time ) const;
00269 
00280     Breakpoint fadeSrcBreakpoint( Breakpoint bp, double time ) const;
00281 
00292     Breakpoint fadeTgtBreakpoint( Breakpoint bp, double time ) const;
00293     
00294 //  -- morphing function access/mutation --
00295 
00297     void setFrequencyFunction( const Envelope & f );
00298     
00300     void setAmplitudeFunction( const Envelope & f );
00301     
00303     void setBandwidthFunction( const Envelope & f );
00304 
00306     const Envelope & frequencyFunction( void ) const;
00307     
00309     const Envelope & amplitudeFunction( void ) const;
00310     
00312     const Envelope & bandwidthFunction( void ) const;
00313     
00327     double amplitudeShape( void ) const;
00328     
00344     void setAmplitudeShape( double x );
00345     
00353     double minBreakpointGap( void ) const;
00354 
00366     void setMinBreakpointGap( double x );
00367 
00368 
00369 //  -- reference Partial label access/mutation --
00370     
00379     Partial::label_type sourceReferenceLabel( void ) const;
00380     
00389     Partial::label_type targetReferenceLabel( void ) const;
00390     
00399     void setSourceReferenceLabel( Partial::label_type l );
00400     
00409     void setTargetReferenceLabel( Partial::label_type l );
00410     
00411 //  -- PartialList access --
00412 
00414     PartialList & partials( void ); 
00415 
00417     const PartialList & partials( void ) const; 
00418                     
00419 private:
00420     
00421 //  -- helper --
00422 
00423     //  PartialCorrespondence represents a map from non-zero Partial 
00424     //  labels to pairs of pointers to Partials that should be morphed 
00425     //  into a single Partial that is assigned that label. 
00426     //  PartialPtrPair is a pair of pointers to Partials that are
00427     //  initialized to zero, and it is the element type for the
00428     //  PartialCorrespondence map.
00429     struct PartialPtrPair
00430     {
00431         const Partial * first;
00432         const Partial * second;
00433         PartialPtrPair( void ) : first(0), second(0) {}
00434     
00435     };
00436     typedef std::map< Partial::label_type, PartialPtrPair > PartialCorrespondence;
00437     
00441     void morph_aux( PartialCorrespondence & correspondence );
00442     
00446     Partial makePartialFromReference( Partial scaleMe, double fscale );
00447 
00465     //
00466     void appendMorphedSrc( const Breakpoint & srcBkpt, const Partial & tgtPartial, 
00467                            double time, Partial & newp  );
00468                            
00486     //
00487     void appendMorphedTgt( const Breakpoint & tgtBkpt, const Partial & srcPartial, 
00488                            double time, Partial & newp  );
00489                            
00490 
00491 };  //  end of class Morpher
00492 
00493 }   //  end of namespace Loris
00494 
00495 #endif /* ndef INCLUDE_MORPHER_H */

Generated on Thu Apr 14 22:01:55 2005 for Loris by doxygen 1.3.4