Resampler.h

00001 #ifndef INCLUDE_RESAMPLER_H
00002 #define INCLUDE_RESAMPLER_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  * Resampler.h
00026  *
00027  * Definition of class Resampler, for converting reassigned Partial envelopes
00028  * into more conventional additive synthesis envelopes, having data points
00029  * at regular time intervals. The benefits of reassigned analysis are NOT
00030  * lost in this process, since the elimination of unreliable data and the
00031  * reduction of temporal smearing are reflected in the resampled data.
00032  *
00033  * Lippold, 7 Aug 2003
00034  * loris@cerlsoundgroup.org
00035  *
00036  * http://www.cerlsoundgroup.org/Loris/
00037  *
00038  */
00039 
00040 #include "PartialList.h"
00041 
00042 //  begin namespace
00043 namespace Loris {
00044 
00045 class Partial;
00046 
00047 // ---------------------------------------------------------------------------
00048 //  class Resampler
00049 //
00057 //
00058 class Resampler
00059 {
00060 //  --- public interface ---
00061 public:
00062 //  --- lifecycle ---
00063 
00071     explicit Resampler( double sampleInterval );
00072 
00073     // use compiler-generated copy/assign/destroy
00074     
00075 //  --- parameters ---
00076 
00085     void setDenseResampling( bool useDense );
00086     
00097     void setPhaseCorrect( bool correctPhase );
00098         
00099 //  --- resampling ---
00100 
00113     void resample( Partial & p ) const;
00114 
00116     void operator() ( Partial & p ) const 
00117     { 
00118         resample( p ); 
00119     }
00120      
00139 #if ! defined(NO_TEMPLATE_MEMBERS)
00140     template<typename Iter>
00141     void resample( Iter begin, Iter end ) const;
00142 #else
00143    inline 
00144     void resample( PartialList::iterator begin, PartialList::iterator end  ) const;
00145 #endif   
00146 
00148 #if ! defined(NO_TEMPLATE_MEMBERS)
00149     template<typename Iter>
00150     void operator()( Iter begin, Iter end ) const
00151 #else
00152     void operator()( PartialList::iterator begin, PartialList::iterator end  ) const
00153 #endif   
00154     { 
00155        resample( begin, end ); 
00156     }
00157          
00158 // -- static members --
00159 
00183 #if ! defined(NO_TEMPLATE_MEMBERS)
00184     template< typename Iter >
00185     static 
00186     void resample( Iter begin, Iter end, double sampleInterval, 
00187                    bool denseResampling = false );
00188 #else
00189     static inline 
00190     void resample( PartialList::iterator begin, PartialList::iterator end,
00191                   double sampleInterval, bool denseResampling = false );
00192 #endif   
00193 
00194 //  --- instance variables ---
00195 private:
00196 
00198     double interval_;   
00199 
00202     bool dense_;
00203     
00206     bool phaseCorrect_;
00207     
00208 };  //  end of class Resampler
00209 
00210 // ---------------------------------------------------------------------------
00211 //  resample (sequence of Partials)
00212 // ---------------------------------------------------------------------------
00228 //
00229 #if ! defined(NO_TEMPLATE_MEMBERS)
00230 template<typename Iter>
00231 void Resampler::resample( Iter begin, Iter end ) const
00232 #else
00233 inline 
00234 void Resampler::resample( PartialList::iterator begin, PartialList::iterator end  ) const
00235 #endif   
00236 {
00237     while ( begin != end )
00238     {
00239         resample( *begin++ );
00240     }
00241 }
00242 
00243 // ---------------------------------------------------------------------------
00244 //  resample (static)
00245 // ---------------------------------------------------------------------------
00269 //
00270 #if ! defined(NO_TEMPLATE_MEMBERS)
00271 template< typename Iter >
00272 void Resampler::resample( Iter begin, Iter end, double sampleInterval, 
00273                           bool denseResampling )
00274 #else
00275 inline
00276 void Resampler::resample( PartialList::iterator begin, PartialList::iterator end,
00277                           double sampleInterval, bool denseResampling )
00278 #endif   
00279 {
00280     Resampler instance( sampleInterval );
00281     instance.setDenseResampling( denseResampling ); 
00282     instance.resample( begin, end );
00283 }
00284 
00285 }   //  end of namespace Loris
00286 
00287 #endif /* ndef INCLUDE_RESAMPLER_H */
00288 

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