SpcFile.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-2007 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  * SpcFile.h
00024  *
00025  * Definition of SpcFile class for Partial import and export for
00026  * real-time synthesis in Kyma.
00027  *
00028  * Spc files always represent a number of Partials that is a power of
00029  * two. This is not necessary for purely-sinusoidal files, but might be
00030  * (not clear) for enhanced data to be properly processed in Kyma. 
00031  *
00032  * All of this is kind of disgusting right now. This code has evolved 
00033  * somewhat randomly, and we are awaiting full support for bandwidth-
00034  * enhanced data in Kyma..
00035  *
00036  * Kelly Fitz, 8 Jan 2003 
00037  * loris@cerlsoundgroup.org
00038  *
00039  * http://www.cerlsoundgroup.org/Loris/
00040  *
00041  */
00042 #include "Marker.h"
00043 #include "Partial.h"
00044 
00045 #if defined(NO_TEMPLATE_MEMBERS)
00046 #include "PartialList.h"
00047 #endif
00048  
00049 #include <string>
00050 #include <vector>
00051 
00052 //  begin namespace
00053 namespace Loris {
00054 
00055 // ---------------------------------------------------------------------------
00056 //  class SpcFile
00057 //
00063 //  
00064 class SpcFile
00065 {
00066 //  -- public interface --
00067 public:
00068 
00069 //  -- types --
00070 
00073     typedef std::vector< Marker > markers_type;     
00074     
00077     typedef std::vector< Partial > partials_type;   
00078 
00079 //  -- construction --
00080 
00085     explicit SpcFile( const std::string & filename );
00086 
00099 #if !defined(NO_TEMPLATE_MEMBERS)
00100     template<typename Iter>
00101     SpcFile( Iter begin_partials, Iter end_partials, double midiNoteNum = 60  );
00102 #else
00103     SpcFile( PartialList::const_iterator begin_partials, 
00104              PartialList::const_iterator end_partials,
00105              double midiNoteNum = 60  );
00106 #endif
00107 
00113     explicit SpcFile( double midiNoteNum = 60 );
00114      
00115     //  copy, assign, and delete are compiler-generated
00116     
00117 //  -- access --
00118 
00120     markers_type & markers( void );
00121     
00123     const markers_type & markers( void ) const;
00124      
00127     double midiNoteNumber( void ) const;
00128     
00131     const partials_type & partials( void ) const;
00132     
00136     double sampleRate( void ) const;
00137     
00138 //  -- mutation --
00139 
00152     void addPartial( const Loris::Partial & p );
00153      
00168     void addPartial( const Loris::Partial & p, int label );
00169      
00188 #if !defined(NO_TEMPLATE_MEMBERS)
00189     template<typename Iter>
00190     void addPartials( Iter begin_partials, Iter end_partials  );
00191 #else
00192     void addPartials( PartialList::const_iterator begin_partials, 
00193                       PartialList::const_iterator end_partials  );
00194 #endif
00195 
00199     void setMidiNoteNumber( double nn );
00200 
00206     void setSampleRate( double rate );
00207         
00208 //  -- export --
00209 
00226     void write( const std::string & filename, double endApproachTime = 0 );
00227 
00244     void writeSinusoidal( const std::string & filename, double endApproachTime = 0 );
00245 
00268     void write( const std::string & filename, bool enhanced,
00269                 double endApproachTime = 0 );
00270 
00271 private:
00272 //  -- implementation --
00273     partials_type partials_;    
00274     markers_type markers_;      
00275 
00276     double notenum_;            
00277     double rate_;               
00278 
00279     
00280     static const int MinNumPartials;    
00281 
00282 
00283 
00284 
00285     static const double DefaultRate;    
00286 
00287 //  -- helpers --
00288     void readSpcData( const std::string & filename );
00289     void growPartials( partials_type::size_type sz );
00290     
00291 };  //  end of class SpcFile
00292 
00293 
00294 // ---------------------------------------------------------------------------
00295 //  constructor from Partial range
00296 // ---------------------------------------------------------------------------
00309 #if !defined(NO_TEMPLATE_MEMBERS)
00310 template< typename Iter >
00311 SpcFile::SpcFile( Iter begin_partials, Iter end_partials, double midiNoteNum  ) :
00312 #else
00313 SpcFile::SpcFile( PartialList::const_iterator begin_partials, 
00314                   PartialList::const_iterator end_partials,
00315                   double midiNoteNum ) :
00316 #endif
00317 //  initializers:
00318     notenum_( midiNoteNum ),
00319     rate_( DefaultRate )
00320 {
00321     growPartials( MinNumPartials );
00322     addPartials( begin_partials, end_partials );
00323 }
00324 
00325 // ---------------------------------------------------------------------------
00326 //  addPartials 
00327 // ---------------------------------------------------------------------------
00346 #if !defined(NO_TEMPLATE_MEMBERS)
00347 template<typename Iter>
00348 void SpcFile::addPartials( Iter begin_partials, Iter end_partials  )
00349 #else
00350 void SpcFile::addPartials( PartialList::const_iterator begin_partials, 
00351                            PartialList::const_iterator end_partials  )
00352 #endif
00353 {
00354     while ( begin_partials != end_partials )
00355     {
00356         // do not try to add unlabeled Partials, or 
00357         // Partials labeled beyond 256:
00358         if ( 0 != begin_partials->label() && 257 > begin_partials->label() )
00359         {
00360             addPartial( *begin_partials );
00361         }
00362         ++begin_partials;
00363     }
00364 }
00365 
00366 }   //  end of namespace Loris
00367 
00368 

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