Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   Tutorial


WvOut.h

00001 /***************************************************/
00034 /***************************************************/
00035 
00036 #ifndef STK_WVOUT_H
00037 #define STK_WVOUT_H
00038 
00039 #include "Stk.h"
00040 
00041 const unsigned long BUFFER_SIZE = 1024;  // sample frames
00042 
00043 class WvOut : public Stk
00044 {
00045  public:
00046 
00047   typedef unsigned long FILE_TYPE;
00048 
00049   static const FILE_TYPE WVOUT_RAW; 
00050   static const FILE_TYPE WVOUT_WAV; 
00051   static const FILE_TYPE WVOUT_SND; 
00052   static const FILE_TYPE WVOUT_AIF; 
00053   static const FILE_TYPE WVOUT_MAT; 
00055 
00056   WvOut();
00057 
00059 
00062   WvOut( const char *fileName, unsigned int nChannels = 1, FILE_TYPE type = WVOUT_WAV, Stk::StkFormat format = STK_SINT16 );
00063 
00065   virtual ~WvOut();
00066 
00068 
00071   void openFile( const char *fileName, unsigned int nChannels = 1,
00072                  WvOut::FILE_TYPE type = WVOUT_WAV, Stk::StkFormat format = STK_SINT16 );
00073 
00075   void closeFile( void );
00076 
00078   unsigned long getFrames( void ) const;
00079 
00081   StkFloat getTime( void ) const;
00082 
00084   bool getClipStatus( void ) { return clipping_; };
00085 
00087   void resetClipStatus( void ) { clipping_ = false; };
00088 
00090 
00093   virtual void tick(const StkFloat sample);
00094 
00096 
00099   virtual void tick( const StkFloat *vector, unsigned int vectorSize );
00100 
00102 
00108   virtual void tick( const StkFrames& frames, unsigned int channel = 1 );
00109 
00111 
00114   virtual void tickFrame( const StkFloat *frameVector, unsigned int frames = 1);
00115 
00117 
00122   virtual void tickFrame( const StkFrames& frames );
00123 
00124  protected:
00125 
00126   // Initialize class variables.
00127   void init( void );
00128 
00129   // Write data to output file;
00130   virtual void writeData( unsigned long frames );
00131 
00132   // Check for sample clipping and clamp.
00133   void clipTest( StkFloat& sample );
00134 
00135   // Write STK RAW file header.
00136   bool setRawFile( const char *fileName );
00137 
00138   // Write WAV file header.
00139   bool setWavFile( const char *fileName );
00140 
00141   // Close WAV file, updating the header.
00142   void closeWavFile( void );
00143 
00144   // Write SND (AU) file header.
00145   bool setSndFile( const char *fileName );
00146 
00147   // Close SND file, updating the header.
00148   void closeSndFile( void );
00149 
00150   // Write AIFF file header.
00151   bool setAifFile( const char *fileName );
00152 
00153   // Close AIFF file, updating the header.
00154   void closeAifFile( void );
00155 
00156   // Write MAT-file header.
00157   bool setMatFile( const char *fileName );
00158 
00159   // Close MAT-file, updating the header.
00160   void closeMatFile( void );
00161 
00162   FILE *fd_;
00163   std::valarray<StkFloat> data_;
00164   FILE_TYPE fileType_;
00165   StkFormat dataType_;
00166   unsigned int channels_;
00167   unsigned long counter_;
00168   unsigned long totalCount_;
00169   bool byteswap_;
00170   bool clipping_;
00171 
00172 };
00173 
00174 #endif

The Synthesis ToolKit in C++ (STK)
©1995-2004 Perry R. Cook and Gary P. Scavone. All Rights Reserved.