00001 #ifndef INCLUDE_SYNTHESIZER_H
00002 #define INCLUDE_SYNTHESIZER_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 #include "Oscillator.h"
00038 #include "PartialList.h"
00039 #include "PartialUtils.h"
00040
00041 #include <vector>
00042
00043
00044 namespace Loris {
00045
00046
00047
00048
00059
00060 class Synthesizer
00061 {
00062
00063 public:
00064
00065
00082 Synthesizer( double srate, std::vector<double> & buffer, double fadeTime = .001 );
00083
00084
00085
00086
00087
00088
00089
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
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
00168
00174 void setFadeTime( double t );
00175
00176
00177 private:
00178 Oscillator osc;
00179 std::vector< double > * sampleBuffer;
00180 double tfade;
00181 double srate;
00182
00183 };
00184
00185
00186
00187
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
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
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 }
00253
00254 #endif