Loris 1.5

Channelizer.h

00001 #ifndef INCLUDE_CHANNELIZER_H
00002 #define INCLUDE_CHANNELIZER_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-2010 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  * Channelizer.h
00026  *
00027  * Definition of class Loris::Channelizer.
00028  *
00029  * Kelly Fitz, 21 July 2000
00030  * loris@cerlsoundgroup.org
00031  *
00032  * http://www.cerlsoundgroup.org/Loris/
00033  *
00034  */
00035 
00036 #include "PartialList.h"
00037 
00038 #include <memory>
00039 
00040 //  begin namespace
00041 namespace Loris {
00042 
00043 class Envelope;
00044 class Partial;
00045 
00046 // ---------------------------------------------------------------------------
00047 //  Channelizer
00048 //  
00084 //
00085 class Channelizer
00086 {
00087 //  -- implementaion --
00088     std::auto_ptr< Envelope > _refChannelFreq;  
00089     
00090     int _refChannelLabel;                       
00091 
00092                                                 
00093     double _stretchFactor;                      
00094 
00095 
00096 
00097 
00098 
00099     double _ampWeighting;                       
00100 
00101 
00102 
00103 
00104     
00105 //  -- public interface --
00106 public:
00107 //  -- construction --
00108 
00127     Channelizer( const Envelope & refChanFreq, int refChanLabel, double stretchFactor = 0 );
00128      
00141     Channelizer( double refFreq, double stretchFactor = 0 );
00142          
00148     Channelizer( const Channelizer & other );
00149      
00155     Channelizer & operator=( const Channelizer & rhs );
00156      
00158     ~Channelizer( void );
00159      
00160 //  -- channelizing --
00161 
00166     void channelize( Partial & partial ) const;
00167 
00178 #if ! defined(NO_TEMPLATE_MEMBERS)
00179     template<typename Iter>
00180     void channelize( Iter begin, Iter end ) const;
00181 #else
00182     void channelize( PartialList::iterator begin, PartialList::iterator end ) const;
00183 #endif   
00184 
00186 #if ! defined(NO_TEMPLATE_MEMBERS)
00187     template<typename Iter>
00188     void operator() ( Iter begin, Iter end ) const
00189 #else
00190     inline
00191     void operator() ( PartialList::iterator begin, PartialList::iterator end ) const
00192 #endif
00193          { channelize( begin, end ); }
00194          
00211     double channelFrequencyAt( double time, int channel ) const;
00212 
00229     int computeChannelNumber( double time, double frequency ) const;
00230     
00251     double computeFractionalChannelNumber( double time, double frequency ) const;
00252     
00253     
00263     double referenceFrequencyAt( double time ) const;
00264 
00265 //  -- access/mutation --
00266          
00274     double amplitudeWeighting( void ) const;
00275 
00283     void setAmplitudeWeighting( double expon );
00284 
00296     double stretchFactor( void ) const;
00297         
00314     void setStretchFactor( double stretch );    
00315     
00316          
00317 // -- static members --
00318 
00319      
00345     static double computeStretchFactor( double fm, int m, double fn, int n );
00346 
00347 
00348 // -- simplified interface --
00349 
00366     static 
00367     void channelize( PartialList & partials,
00368                      const Envelope & refChanFreq, int refChanLabel );
00369 
00370      
00371 
00372 // -- DEPRECATED members --
00373 
00398     void setStretchFactor( double fm, int m, double fn, int n );
00399     
00400 
00424 #if ! defined(NO_TEMPLATE_MEMBERS)
00425     template< typename Iter >
00426     static 
00427     void channelize( Iter begin, Iter end, 
00428                      const Envelope & refChanFreq, int refChanLabel );
00429 #else
00430     static inline 
00431     void channelize( PartialList::iterator begin, PartialList::iterator end,
00432                      const Envelope & refChanFreq, int refChanLabel );
00433 #endif   
00434 
00435      
00448     static double computeStretchFactor( double f1, double fn, double n );
00449     
00450 };  //  end of class Channelizer
00451 
00452 // ---------------------------------------------------------------------------
00453 //  channelize (sequence of Partials)
00454 // ---------------------------------------------------------------------------
00465 //
00466 #if ! defined(NO_TEMPLATE_MEMBERS)
00467 template<typename Iter>
00468 void Channelizer::channelize( Iter begin, Iter end ) const
00469 #else
00470 inline
00471 void Channelizer::channelize( PartialList::iterator begin, PartialList::iterator end ) const
00472 #endif
00473 {
00474     while ( begin != end )
00475     {
00476         channelize( *begin++ );
00477     }
00478 }
00479 
00480 // ---------------------------------------------------------------------------
00481 //  channelize (static)
00482 // ---------------------------------------------------------------------------
00506 //
00507 #if ! defined(NO_TEMPLATE_MEMBERS)
00508 template< typename Iter >
00509 void Channelizer::channelize( Iter begin, Iter end, 
00510                               const Envelope & refChanFreq, int refChanLabel )
00511 #else
00512 inline
00513 void Channelizer::channelize( PartialList::iterator begin, PartialList::iterator end,
00514                               const Envelope & refChanFreq, int refChanLabel )
00515 #endif   
00516 {
00517    Channelizer instance( refChanFreq, refChanLabel );
00518     while ( begin != end )
00519     {
00520         instance.channelize( *begin++ );
00521     }
00522 }
00523 
00524 }   //  end of namespace Loris
00525 
00526 #endif /* ndef INCLUDE_CHANNELIZER_H */
 All Classes Functions Variables Typedefs Enumerator Friends