Distiller.h

00001 #ifndef INCLUDE_DISTILLER_H
00002 #define INCLUDE_DISTILLER_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  * Distiller.h
00026  *
00027  * Definition of class Distiller.
00028  *
00029  * Kelly Fitz, 20 Oct 1999
00030  * loris@cerlsoundgroup.org
00031  *
00032  * http://www.cerlsoundgroup.org/Loris/
00033  *
00034  */
00035 
00036 #include "Partial.h"
00037 #include "PartialList.h"
00038 #include "PartialUtils.h"
00039 
00040 #include "Notifier.h"   //  for debugging only
00041 
00042 #include <algorithm>
00043 
00044 //  begin namespace
00045 namespace Loris {
00046 
00047 // ---------------------------------------------------------------------------
00048 //  class Distiller
00049 //
00068 //
00069 class Distiller
00070 {
00071 //  -- instance variables --
00072 
00073     double _fadeTime, _gapTime;         // distillation parameters
00074         
00075 //  -- public interface --
00076 public:
00077 
00078 //  -- global defaults and constants --
00079 
00082     static const double DefaultFadeTime;
00083     
00086     static const double DefaultSilentTime;
00087 
00088 //  -- construction --
00089 
00110     explicit
00111     Distiller( double partialFadeTime = Distiller::DefaultFadeTime,
00112                double partialSilentTime = Distiller::DefaultSilentTime );
00113      
00114     //  Use compiler-generated copy, assign, and destroy.
00115     
00116 //  -- distillation --
00117 
00143 #if ! defined(NO_TEMPLATE_MEMBERS)
00144     template< typename Container >
00145     typename Container::iterator distill( Container & partials );
00146 #else
00147     inline
00148     PartialList::iterator distill( PartialList & partials );
00149 #endif
00150 
00152 #if ! defined(NO_TEMPLATE_MEMBERS)
00153     template< typename Container >
00154     typename Container::iterator operator() ( Container & partials );
00155 #else
00156     PartialList::iterator operator() ( PartialList & partials );
00157 #endif
00158     
00180 #if ! defined(NO_TEMPLATE_MEMBERS)
00181     template< typename Container >
00182     static typename Container::iterator 
00183     distill( Container & partials, double partialFadeTime,
00184              double partialSilentTime = Distiller::DefaultSilentTime );
00185 #else
00186     static inline PartialList::iterator
00187     distill( PartialList & partials, double partialFadeTime,
00188              double partialSilentTime = Distiller::DefaultSilentTime );
00189 #endif
00190 
00191 private:
00192 
00193 //  -- helpers --
00194 
00214     PartialList::iterator distill_list( PartialList & partials );
00215 
00221     void distillOne( PartialList & partials, Partial::label_type label,
00222                      PartialList & distilled );
00223     
00224 };  //  end of class Distiller
00225 
00226 // ---------------------------------------------------------------------------
00227 //  distill
00228 // ---------------------------------------------------------------------------
00253 //
00254 #if ! defined(NO_TEMPLATE_MEMBERS)
00255 template< typename Container >
00256 typename Container::iterator Distiller::distill( Container & partials )
00257 {
00258     //  This can be done so much more easily and
00259     //  efficiently on a list than on other containers
00260     //  that it is worth copying the Partials to a
00261     //  list for distillation, and then transfering
00262     //  them back.
00263     //
00264     //  See below for a specialization for the case
00265     //  of the Container being a list, so no copy
00266     //  is needed.
00267     PartialList pl( partials.begin(), partials.end() );
00268     PartialList::iterator it = distill_list( pl );
00269         
00270     //  pl has distilled Partials at beginning, and
00271     //  unlabeled Partials at end:
00272     typename Container::iterator beginUnlabeled = 
00273         std::copy( pl.begin(), it, partials.begin() );
00274     
00275     typename Container::iterator endUnlabeled = 
00276         std::copy( it, pl.end(), beginUnlabeled );
00277 
00278     
00279     partials.erase( endUnlabeled, partials.end() );
00280     
00281     return beginUnlabeled;
00282 }
00283 
00284 //  specialization for PartialList container
00285 template< >
00286 inline
00287 PartialList::iterator Distiller::distill( PartialList & partials )
00288 {
00289     debugger << "using PartialList version of distill to avoid copying" << endl;
00290     return distill_list( partials );
00291 }
00292 #else
00293 inline
00294 PartialList::iterator Distiller::distill( PartialList & partials )
00295 {
00296     return distill_list( partials );
00297 }
00298 #endif
00299 
00300 // ---------------------------------------------------------------------------
00301 //  Function call operator 
00302 // ---------------------------------------------------------------------------
00306 //
00307 #if ! defined(NO_TEMPLATE_MEMBERS)
00308 template< typename Container >
00309 typename Container::iterator Distiller::operator()( Container & partials )
00310 #else
00311 inline
00312 PartialList::iterator Distiller::operator()( PartialList & partials )
00313 #endif
00314 { 
00315     return distill( partials );
00316 }
00317 
00318 // ---------------------------------------------------------------------------
00319 //  distill
00320 // ---------------------------------------------------------------------------
00342 //
00343 #if ! defined(NO_TEMPLATE_MEMBERS)
00344 template< typename Container >
00345 typename Container::iterator 
00346 Distiller::distill( Container & partials, double partialFadeTime,
00347                                           double partialSilentTime )
00348 #else
00349 inline
00350 PartialList::iterator 
00351 Distiller::distill( PartialList & partials, double partialFadeTime,
00352                                             double partialSilentTime )
00353 #endif
00354 {
00355     Distiller instance( partialFadeTime, partialSilentTime );
00356     return instance.distill( partials );
00357 }
00358 
00359 }   //  end of namespace Loris
00360 
00361 #endif /* ndef INCLUDE_DISTILLER_H */

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