Loris 1.5

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-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  * 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 #include "LinearEnvelope.h"
00042 
00043 //  begin namespace
00044 namespace Loris {
00045 
00046 class Partial;
00047 
00048 // ---------------------------------------------------------------------------
00049 //  class Resampler
00050 //
00058 //
00059 class Resampler
00060 {
00061 //  --- public interface ---
00062 public:
00063 //  --- lifecycle ---
00064 
00082     explicit Resampler( double sampleInterval );
00083 
00084 
00085     // --- use compiler-generated copy/assign/destroy ---
00086     
00087 //  --- parameters ---
00088 
00099     void setPhaseCorrect( bool correctPhase );
00100         
00101 //  --- resampling ---
00102 
00113     void resample( Partial & p ) const;
00114 
00116     void operator() ( Partial & p ) const 
00117     { 
00118         resample( p ); 
00119     }
00120     
00146     void resample( Partial & p, const LinearEnvelope & timingEnv ) const;
00147     
00156     void quantize( Partial & p ) const;
00157 
00158      
00175 #if ! defined(NO_TEMPLATE_MEMBERS)
00176     template<typename Iter>
00177     void resample( Iter begin, Iter end ) const;
00178 #else
00179    inline 
00180     void resample( PartialList::iterator begin, PartialList::iterator end  ) const;
00181 #endif   
00182 
00184 #if ! defined(NO_TEMPLATE_MEMBERS)
00185     template<typename Iter>
00186     void operator()( Iter begin, Iter end ) const
00187 #else
00188     void operator()( PartialList::iterator begin, PartialList::iterator end  ) const
00189 #endif   
00190     { 
00191        resample( begin, end ); 
00192     }
00193  
00221 #if ! defined(NO_TEMPLATE_MEMBERS)
00222     template<typename Iter>
00223     void resample( Iter begin, Iter end, const LinearEnvelope & timingEnv ) const;
00224 #else
00225    inline 
00226     void resample( PartialList::iterator begin, PartialList::iterator end,
00227                    const LinearEnvelope & timingEnv) const;
00228 #endif   
00229 
00241 #if ! defined(NO_TEMPLATE_MEMBERS)
00242     template<typename Iter>
00243     void quantize( Iter begin, Iter end ) const;
00244 #else
00245    inline 
00246     void quantize( PartialList::iterator begin, PartialList::iterator end  ) const;
00247 #endif   
00248      
00249 // -- static members --
00250 
00274 #if ! defined(NO_TEMPLATE_MEMBERS)
00275     template< typename Iter >
00276     static 
00277     void resample( Iter begin, Iter end, double sampleInterval, 
00278                    bool denseResampling = false );
00279 #else
00280     static inline 
00281     void resample( PartialList::iterator begin, PartialList::iterator end,
00282                   double sampleInterval, bool denseResampling = false );
00283 #endif   
00284 
00285 //  --- instance variables ---
00286 private:
00287     
00289     double interval_;   
00290     
00293     bool phaseCorrect_;
00294     
00295 };  //  end of class Resampler
00296 
00297 // ---------------------------------------------------------------------------
00298 //  resample (sequence of Partials)
00299 // ---------------------------------------------------------------------------
00315 //
00316 #if ! defined(NO_TEMPLATE_MEMBERS)
00317 template<typename Iter>
00318 void Resampler::resample( Iter begin, Iter end ) const
00319 #else
00320 inline 
00321 void Resampler::resample( PartialList::iterator begin, PartialList::iterator end  ) const
00322 #endif   
00323 {
00324     while ( begin != end )
00325     {
00326         resample( *begin++ );
00327     }
00328 }
00329 
00330 // ---------------------------------------------------------------------------
00331 //  resample (sequence of Partials, with timing envelope)
00332 // ---------------------------------------------------------------------------
00351 //
00352 #if ! defined(NO_TEMPLATE_MEMBERS)
00353 template<typename Iter>
00354 void Resampler::resample( Iter begin, Iter end, const LinearEnvelope & timingEnv ) const
00355 #else
00356 inline 
00357 void Resampler::resample( PartialList::iterator begin, PartialList::iterator end, 
00358                           const LinearEnvelope & timingEnv  ) const
00359 #endif   
00360 {
00361     while ( begin != end )
00362     {
00363         resample( *begin++, timingEnv );
00364     }
00365 }
00366 
00367 // ---------------------------------------------------------------------------
00368 //  quantize (sequence of Partials)
00369 // ---------------------------------------------------------------------------
00381 //
00382 #if ! defined(NO_TEMPLATE_MEMBERS)
00383 template<typename Iter>
00384 void Resampler::quantize( Iter begin, Iter end ) const
00385 #else
00386 inline 
00387 void Resampler::quantize( PartialList::iterator begin, PartialList::iterator end  ) const
00388 #endif   
00389 {
00390     while ( begin != end )
00391     {
00392         quantize( *begin++ );
00393     }
00394 }
00395 
00396 
00397 // ---------------------------------------------------------------------------
00398 //  resample (static)
00399 // ---------------------------------------------------------------------------
00423 //
00424 #if ! defined(NO_TEMPLATE_MEMBERS)
00425 template< typename Iter >
00426 void Resampler::resample( Iter begin, Iter end, double sampleInterval, 
00427                           bool denseResampling )
00428 #else
00429 inline
00430 void Resampler::resample( PartialList::iterator begin, PartialList::iterator end,
00431                           double sampleInterval, bool denseResampling )
00432 #endif   
00433 {
00434     Resampler instance( sampleInterval );
00435     
00436     if ( denseResampling )
00437     {
00438         instance.resample( begin, end );
00439     }
00440     else
00441     {
00442         instance.quantize( begin, end );
00443     }
00444 }
00445 
00446 }   //  end of namespace Loris
00447 
00448 #endif /* ndef INCLUDE_RESAMPLER_H */
00449 
 All Classes Functions Variables Typedefs Enumerator Friends