00001 #ifndef INCLUDE_RESAMPLER_H
00002 #define INCLUDE_RESAMPLER_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include "PartialList.h"
00041 #include "LinearEnvelope.h"
00042
00043
00044 namespace Loris {
00045
00046 class Partial;
00047
00048
00049
00050
00058
00059 class Resampler
00060 {
00061
00062 public:
00063
00064
00082 explicit Resampler( double sampleInterval );
00083
00084
00085
00086
00087
00088
00099 void setPhaseCorrect( bool correctPhase );
00100
00101
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
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
00286 private:
00287
00289 double interval_;
00290
00293 bool phaseCorrect_;
00294
00295 };
00296
00297
00298
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
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
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
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 }
00447
00448 #endif
00449