SoundFile.h

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 #ifndef CSL_SoundFile_H
00007 #define CSL_SoundFile_H
00008 
00009 #include "CSL_Core.h"
00010 #include <sndfile.h>                // libsndfile header file
00011 
00012 namespace csl {
00013 
00017 
00018 #ifdef CSL_ENUMS
00019 typedef enum {              
00020     kSoundFileRead,
00021     kSoundFileWrite,    
00022     kSoundFileReadWrite
00023 } SoundFileMode;
00024 
00025 typedef enum {                  
00026     kSoundFileFormatWAV,        
00027     kSoundFileFormatAIFF,       
00028     kSoundFileFormatSND,        
00029     kSoundFileFormatEBICSF,         
00030     kSoundFileFormatRaw,        
00031     kSoundFileFormatOther,      
00032 } SoundFileFormat;
00033 #else
00034     #define kSoundFileRead 0
00035     #define kSoundFileWrite 1
00036     #define kSoundFileReadWrite 2
00037     typedef int SoundFileMode;
00038     
00039     #define kSoundFileFormatWAV 0
00040     #define kSoundFileFormatAIFF 1
00041     #define kSoundFileFormatSND 2
00042     #define kSoundFileFormatEBICSF 3
00043     #define kSoundFileFormatRaw 4
00044     #define kSoundFileFormatOther 5
00045     typedef int SoundFileFormat;
00046 #endif
00047 
00051 class SoundFile : public UnitGenerator, public Writeable, public Seekable {
00052 public:
00054     SoundFile(char * path);
00055     SoundFile(string path = "", int start = -1, int stop = -1);
00056     ~SoundFile();
00058     string mPath;                           
00059     SoundFileMode mMode;                    
00060     SF_INFO mSFInfo;                            
00061     SNDFILE *mSndfile;                      
00062     Buffer mSampleBuffer;                   
00063 
00064     unsigned channels() const;              
00065     unsigned rate() const;                  
00066     unsigned duration() const;              
00067     float durationInSecs();                 
00068     SoundFileFormat format() const;         
00069     bool isValid() { return mIsValid; }         
00070 
00071     int startFrame() { return mStart; }         
00072     void setStart(int val);
00073     void setStartSec(float val);
00074     void setStartRatio(float val);
00075     int stopFrame() { return mStop; }           
00076     void setStop(int val);
00077     void setStopSec(float val);
00078     void setStopRatio(float val);
00079     bool isLooping() { return mIsLooping; }     
00080     void setIsLooping(bool isLooping) { mIsLooping = isLooping; }
00081     bool isActive();                            
00082     
00083     void setPath(string path);                  
00084     void openForRead() throw (CException);      
00085 
00086     void openForWrite(SoundFileFormat format = kSoundFileFormatWAV, 
00087                     unsigned channels = 1, 
00088                     unsigned rate = 44100,
00089                     unsigned bitDepth = 16) throw (CException);
00090     void openForReadWrite() throw (CException); 
00091 
00092     unsigned seekTo(int position, SeekPosition whence) throw(CException);
00093     unsigned seekTo(int position) throw(CException) { return seekTo(position, kPositionStart); }; 
00094     void readBufferFromFile(unsigned numFrames);        
00095 
00096     void setToEnd();                                
00097     void trigger();                             
00098     void close();                                   
00099     void freeBuffer();                              
00100 
00101     void nextBuffer(Buffer &outputBuffer) throw (CException);       
00102     void writeBuffer(Buffer &inputBuffer) throw (CException);           
00103 
00104 protected:
00105     bool mIsValid;                              
00106     bool mIsLooping;                                
00107     unsigned mTempCurrentFrame;             
00108     int mStart, mStop;                          
00109     void initFromSndfile();                     
00110     void checkBuffer(unsigned numFrames);       
00111 };
00112 
00116 class SoundCue : public UnitGenerator {
00117 
00118 public:
00119     SoundCue();                         
00120     SoundCue(string name, SoundFile *file = 0, int start = 1, int stop = -1);
00121 //  SoundCue(string name, int start = 1, int stop = -1);
00122     ~SoundCue();
00123 
00124     string mName;                       
00125     SoundFile * mFile;                  
00126     int mStart, mStop, mCurrent;            
00127     UnitGenerator *mReadRate;           
00128 
00129     void readFrom(FILE *input);         
00130     void dump(void);                        
00131 
00132     void nextBuffer(Buffer & outputBuffer) throw(CException);   
00133     bool isActive();
00134     unsigned channels() const { return (mFile->channels()); }
00135     void setToEnd(void);
00136     void trigger(void);
00137     float duration() const { return (mStop - mStart); }         
00138 
00139 protected:
00141     void nextBufferNonInterp(Buffer & outputBuffer) throw(CException);
00142     void nextBufferInterp(Buffer & outputBuffer) throw(CException);
00143     float mFloatCurrent;                    
00144 };
00145 
00146 }
00147 
00148 #endif

Generated on Fri Apr 6 20:18:12 2007 for CSL by  doxygen 1.4.5-20051010