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

AiffFile.h

00001 /*
00002  * This is the Loris C++ Class Library, implementing analysis, 
00003  * manipulation, and synthesis of digitized sounds using the Reassigned 
00004  * Bandwidth-Enhanced Additive Sound Model.
00005  *
00006  * Loris is Copyright (c) 1999-2004 by Kelly Fitz and Lippold Haken
00007  *
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY, without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  *
00023  * AiffFile.h
00024  *
00025  * Definition of AiffFile class for sample import and export in Loris.
00026  *
00027  * Kelly Fitz, 8 Jan 2003 
00028  * loris@cerlsoundgroup.org
00029  *
00030  * http://www.cerlsoundgroup.org/Loris/
00031  *
00032  */
00033 #include "Marker.h"
00034 #include "Synthesizer.h"
00035 
00036 #if defined(NO_TEMPLATE_MEMBERS)
00037 #include "PartialList.h"
00038 #endif
00039 
00040 #include <memory>
00041 #include <string>
00042 #include <vector>
00043 
00044 //  begin namespace
00045 namespace Loris {
00046 
00047 class Partial;
00048 
00049 // ---------------------------------------------------------------------------
00050 //  class AiffFile
00051 //
00057 //  
00058 class AiffFile
00059 {
00060 //  -- public interface --
00061 public:
00062 
00063 //  -- types --
00064 
00066     typedef std::vector< double > samples_type;
00067     
00069     typedef samples_type::size_type size_type;
00070     
00072     typedef std::vector< Marker > markers_type;
00073 
00074 //  -- construction --
00075 
00080     explicit AiffFile( const std::string & filename );
00081 
00099 #if !defined(NO_TEMPLATE_MEMBERS)
00100     template<typename Iter>
00101     AiffFile( Iter begin_partials, Iter end_partials, 
00102               double samplerate, double fadeTime = .001 ); // default fade is 1ms
00103 #else
00104     AiffFile( PartialList::const_iterator begin_partials, 
00105               PartialList::const_iterator end_partials,
00106               double samplerate, double fadeTime = .001 ); // default fade is 1ms
00107 #endif
00108 
00115     explicit AiffFile( double samplerate, size_type numFrames = 0 );
00116     
00123     AiffFile( const double * buffer, size_type bufferlength, double samplerate );
00124      
00130     AiffFile( const std::vector< double > & vec, double samplerate );
00131      
00136     AiffFile( const AiffFile & other );
00137      
00143     AiffFile & operator= ( const AiffFile & rhs );
00144 
00145 //  -- access --
00146 
00149     markers_type & markers( void );
00150 
00153     const markers_type & markers( void ) const;
00154      
00157     double midiNoteNumber( void ) const;
00158 
00163     size_type numFrames( void ) const;
00164 
00167     double sampleRate( void ) const;
00168     
00171     samples_type & samples( void );
00172 
00175     const samples_type & samples( void ) const;
00176 
00177 //  -- mutation --
00178 
00187     void addPartial( const Loris::Partial & p, double fadeTime = .001 /* 1 ms */ );
00188      
00204 #if !defined(NO_TEMPLATE_MEMBERS)
00205     template<typename Iter>
00206     void addPartials( Iter begin_partials, Iter end_partials, double fadeTime = .001 /* 1 ms */  );
00207 #else
00208     void addPartials( PartialList::const_iterator begin_partials, 
00209                       PartialList::const_iterator end_partials,
00210                       double fadeTime = .001 /* 1 ms */  );
00211 #endif
00212 
00217     void setMidiNoteNumber( double nn );
00218      
00219 //  -- export --
00220 
00230     void write( const std::string & filename, unsigned int bps = 16 );
00231 
00232 private:
00233 //  -- implementation --
00234     double notenum_, rate_;     // MIDI note number and sample rate
00235     markers_type markers_;      // AIFF Markers
00236     samples_type samples_;      // floating point samples [-1.0, 1.0]
00237 
00238     std::auto_ptr< Synthesizer > psynth_;   //  Synthesizer for rendering Partials,
00239                                             //  lazy-initialized (not until needed)
00240 
00241 //  -- helpers --
00242     void configureSynthesizer( double fadeTime );
00243     void readAiffData( const std::string & filename );
00244 
00245 };  //  end of class AiffFile
00246 
00247 #pragma mark -- template members --
00248 
00249 // ---------------------------------------------------------------------------
00250 //  constructor from Partial range
00251 // ---------------------------------------------------------------------------
00269 //
00270 #if !defined(NO_TEMPLATE_MEMBERS)
00271 template< typename Iter >
00272  AiffFile::AiffFile( Iter begin_partials, Iter end_partials, 
00273                      double samplerate, double fadeTime ) : // default fade is 1ms
00274 #else
00275  AiffFile::AiffFile( PartialList::const_iterator begin_partials, 
00276                      PartialList::const_iterator end_partials,
00277                      double samplerate, double fadeTime ) : // default fade is 1ms
00278 #endif
00279 //  initializers:
00280     notenum_( 60 ),
00281     rate_( samplerate )
00282 {
00283     addPartials( begin_partials, end_partials, fadeTime );
00284 }
00285 
00286 // ---------------------------------------------------------------------------
00287 //  addPartials 
00288 // ---------------------------------------------------------------------------
00304 //
00305 #if !defined(NO_TEMPLATE_MEMBERS)
00306 template< typename Iter >
00307 void 
00308  AiffFile::addPartials( Iter begin_partials, Iter end_partials, double fadeTime /*= .001  1 ms */  )
00309 #else
00310 void 
00311  AiffFile::addPartials( PartialList::const_iterator begin_partials, 
00312                         PartialList::const_iterator end_partials,
00313                         double fadeTime /* = .001 1 ms */  )
00314 #endif
00315 { 
00316     configureSynthesizer( fadeTime );
00317     psynth_->synthesize( begin_partials, end_partials );
00318 } 
00319 
00320 }   //  end of namespace Loris

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