Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

Synthesizer.h

00001 #ifndef INCLUDE_SYNTHESIZER_H
00002 #define INCLUDE_SYNTHESIZER_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-2004 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  * Synthesizer.h
00026  *
00027  * Definition of class Loris::Synthesizer, a renderer of 
00028  * bandwidth-enhanced Partials.
00029  *
00030  * Kelly Fitz, 16 Aug 1999
00031  * loris@cerlsoundgroup.org
00032  *
00033  * http://www.cerlsoundgroup.org/Loris/
00034  *
00035  */
00036 
00037 #include "Oscillator.h"
00038 #include "PartialList.h"
00039 #include "PartialUtils.h"
00040 
00041 #include <vector>
00042 
00043 //  begin namespace
00044 namespace Loris {
00045 
00046 // ---------------------------------------------------------------------------
00047 //  class Synthesizer
00048 //
00059 //
00060 class Synthesizer
00061 {
00062 //  -- public interface --
00063 public:
00064 //  -- construction --
00065 
00082     Synthesizer( double srate, std::vector<double> & buffer, double fadeTime = .001 );
00083     
00084     //  Compiler can generate copy, assign, and destroy.
00085     //  Synthesizer( const Synthesizer & other );
00086     //  ~Synthesizer( void );
00087     //  Synthesizer & operator= ( const Synthesizer & other );
00088      
00089 //  -- synthesis --
00090 
00107     void synthesize( const Partial & p );   
00108      
00110     void operator() ( const Partial & p ) { synthesize( p ) ; }
00111 
00112      
00132 #if ! defined(NO_TEMPLATE_MEMBERS)
00133     template< typename Iter >
00134     void synthesize( Iter begin_partials, Iter end_partials );
00135 #else
00136     inline
00137     void synthesize( PartialList::iterator begin_partials, 
00138                      PartialList::iterator end_partials );  
00139 #endif
00140      
00143 #if ! defined(NO_TEMPLATE_MEMBERS)
00144     template< typename Iter >
00145     void operator() ( Iter begin_partials, Iter end_partials );
00146 #else
00147     inline
00148     void operator() ( PartialList::iterator begin_partials, 
00149                       PartialList::iterator end_partials );
00150 #endif
00151     
00152 //  -- access --
00154     double fadeTime( void ) const;
00155      
00157     double sampleRate( void ) const;
00158 
00161     const std::vector<double> samples( void ) const;
00162 
00165     std::vector<double> samples( void );
00166     
00167 //  -- mutation --
00168 
00174     void setFadeTime( double t );
00175      
00176 //  -- implementation --
00177 private:
00178     Oscillator osc;
00179     std::vector< double > * sampleBuffer;   //  samples are computed and stored here
00180     double tfade;                          // Partial fade in/out time in seconds
00181     double srate;                          //   sample rate in Hz
00182     
00183 };  //  end of class Synthesizer
00184 
00185 
00186 // ---------------------------------------------------------------------------
00187 //  synthesize 
00188 // ---------------------------------------------------------------------------
00207 //
00208 #if ! defined(NO_TEMPLATE_MEMBERS)
00209 template<typename Iter>
00210 void 
00211 Synthesizer::synthesize( Iter begin_partials, Iter end_partials ) 
00212 #else
00213 inline void 
00214 Synthesizer::synthesize( PartialList::iterator begin_partials, 
00215                          PartialList::iterator end_partials ) 
00216 #endif
00217 { 
00218     //  grow the sample buffer if necessary
00219     typedef std::vector< double >::size_type Sz_Type;
00220     Sz_Type Nsamps = 1 +  
00221         Sz_Type( PartialUtils::timeSpan( begin_partials, end_partials ).second * srate );
00222     if ( sampleBuffer->size() < Nsamps )
00223     {
00224     sampleBuffer->resize( Nsamps );
00225    }
00226    
00227     while ( begin_partials != end_partials ) 
00228    {
00229         synthesize( *(begin_partials++) ); 
00230    }
00231 }
00232 
00233 // ---------------------------------------------------------------------------
00234 //  operator() 
00235 // ---------------------------------------------------------------------------
00238 //
00239 #if ! defined(NO_TEMPLATE_MEMBERS)
00240 template<typename Iter>
00241 void
00242 Synthesizer::operator() ( Iter begin_partials, Iter end_partials ) 
00243 #else
00244 inline void
00245 Synthesizer::operator() ( PartialList::iterator begin_partials, 
00246                           PartialList::iterator end_partials ) 
00247 #endif
00248 { 
00249     synthesize( begin_partials, end_partials ); 
00250 }
00251 
00252 }   //  end of namespace Loris
00253 
00254 #endif /* ndef INCLUDE_SYNTHESIZER_H */

Generated on Thu Apr 14 22:01:55 2005 for Loris by doxygen 1.3.4