SpectralSurface.h

00001 #ifndef INCLUDE_SPECTRALSURFACE_H
00002 #define INCLUDE_SPECTRALSURFACE_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  * SpectralSurface.h
00026  *
00027  * Definition of class SpectralSurface, a class representing 
00028  * a smoothed time-frequency surface that can be used to 
00029  * perform cross-synthesis, the filtering of one sound by the
00030  * time-varying spectrum of another.
00031  *
00032  * Kelly Fitz, 21 Dec 2005
00033  * loris@cerlsoundgroup.org
00034  *
00035  * http://www.cerlsoundgroup.org/Loris/
00036  *
00037  */
00038 
00039 #include "LorisExceptions.h"
00040 #include "Partial.h"
00041 #include "PartialList.h"
00042 #include "PartialUtils.h"   // for compareLabelLess
00043 
00044 #include <algorithm>        // for sort
00045 #include <vector>
00046 
00047 //  begin namespace
00048 namespace Loris {
00049 
00050 // ---------------------------------------------------------------------------
00051 //  Class SpectralSurface
00052 //
00056 //
00057 class SpectralSurface
00058 {
00059 //  -- public interface --
00060 public:
00061     
00062 //  -- lifecycle --
00063 
00074 #if ! defined(NO_TEMPLATE_MEMBERS)
00075     template<typename Iter>
00076     SpectralSurface( Iter b, Iter e );
00077 #else
00078     inline
00079     SpectralSurface( PartialList::iterator b, PartialList::iterator e );
00080 #endif    
00081 
00082     //  use compiler-generated copy/assign/destroy
00083 
00084 // --- operations ---
00085     
00091     void scaleAmplitudes( Partial & p );
00092 
00111 #if ! defined(NO_TEMPLATE_MEMBERS)
00112     template<typename Iter>
00113     void scaleAmplitudes( Iter b, Iter e );
00114 #else
00115     inline
00116     void scaleAmplitudes( PartialList::iterator b, PartialList::iterator e );
00117 #endif
00118     
00124     void setAmplitudes( Partial & p );
00125     
00146 #if ! defined(NO_TEMPLATE_MEMBERS)
00147     template<typename Iter>
00148     void setAmplitudes( Iter b, Iter e );
00149 #else
00150     inline
00151     void setAmplitudes( PartialList::iterator b, PartialList::iterator e );
00152 #endif
00153     
00154 // --- access/mutation ---
00155 
00161     double frequencyStretch( void ) const;
00162     
00168     double timeStretch( void ) const;
00169     
00176     double effect( void ) const;
00177     
00186     void setFrequencyStretch( double stretch );
00187 
00196     void setTimeStretch( double stretch );
00197     
00209     void setEffect( double effect );
00210     
00211 private:
00212 
00213 //  -- instance variables --
00214 
00215     std::vector< Partial > mPartials;   
00216 
00217     double mStretchFreq;                
00218     double mStretchTime;                
00219     double mEffect;                     
00220 
00221 
00222 
00223     double mMaxSurfaceAmp;              
00224 
00225 
00226     
00227 // --- private helpers ---
00228 
00229     //  helper used by constructor for adding Partials one by one
00230     void addPartialAux( const Partial & p );
00231     
00232 };
00233 
00234 // ---------------------------------------------------------------------------
00235 //    constructor
00236 // ---------------------------------------------------------------------------
00247 //
00248 #if ! defined(NO_TEMPLATE_MEMBERS)
00249 template<typename Iter>
00250 SpectralSurface::SpectralSurface( Iter b, Iter e ) :
00251 #else
00252 inline
00253 SpectralSurface::SpectralSurface( PartialList::iterator b, 
00254                                   PartialList::iterator e ) :
00255 #endif    
00256     mStretchFreq( 1.0 ),
00257     mStretchTime( 1.0 ),
00258     mEffect( 1.0 ),
00259     mMaxSurfaceAmp( 0.0 )
00260 {
00261     //  add only labeled Partials:
00262     while ( b != e )
00263     {
00264         if ( b->label() != 0 )
00265         {
00266             addPartialAux( *b );
00267         }
00268         ++b;
00269     }
00270     
00271     // complain if the Partials were not distilled
00272     if ( mPartials.empty() )
00273     {
00274         Throw( InvalidArgument, "Partals need to be distilled to build a SpectralSurface" );
00275     }
00276 
00277     if ( 0 == mMaxSurfaceAmp )
00278     {
00279         Throw( InvalidArgument, "The SpectralSurface is zero amplitude everywhere!" );
00280     }
00281     
00282     // sort by label
00283     std::sort( mPartials.begin(), mPartials.end(), PartialUtils::compareLabelLess() );
00284 }
00285 
00286 
00287 // ---------------------------------------------------------------------------
00288 //    scaleAmplitudes
00289 // ---------------------------------------------------------------------------
00308 //
00309 #if ! defined(NO_TEMPLATE_MEMBERS)
00310 template<typename Iter>
00311 void SpectralSurface::scaleAmplitudes( Iter b, Iter e )
00312 #else
00313 inline
00314 void SpectralSurface::scaleAmplitudes( PartialList::iterator b, 
00315                                        PartialList::iterator e )
00316 #endif
00317 {   
00318     while ( b != e )
00319     {
00320         // debugger << b->label() << endl;
00321         scaleAmplitudes( *b );
00322         ++b;
00323     }   
00324 }
00325 
00326 // ---------------------------------------------------------------------------
00327 //    setAmplitudes
00328 // ---------------------------------------------------------------------------
00349 //
00350 #if ! defined(NO_TEMPLATE_MEMBERS)
00351 template<typename Iter>
00352 void SpectralSurface::setAmplitudes( Iter b, Iter e )
00353 #else
00354 inline
00355 void SpectralSurface::setAmplitudes( PartialList::iterator b, 
00356                                      PartialList::iterator e )
00357 #endif
00358 {   
00359     while ( b != e )
00360     {
00361         // debugger << b->label() << endl;
00362         setAmplitudes( *b );
00363         ++b;
00364     }   
00365 }
00366 
00367 }   // namespace Loris
00368 
00369 #endif /* ndef INCLUDE_SPECTRALSURFACE_H */
00370 

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