CSL  5.2
FileIO.h
Go to the documentation of this file.
1 //
2 // FileIO.h -- IO using a sound file for writing data to sound files
3 //
4 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT
5 //
6 
7 #ifndef CSL_FileIO_H
8 #define CSL_FileIO_H
9 
10 #include "CSL_Includes.h"
11 #include "ThreadUtilities.h" // PThread utilities
12 
13 namespace csl {
14 
15 ///
16 /// FileIO.h -- IO using a sound file for storing output sample data
17 ///
18 
19 class FileIO : public IO {
20 public:
21  ///< the path name determines the file type, e.g., xx.aiff, zz.snd, or yy.wav
22  FileIO(char *path = NULL);
23  ~FileIO();
24 
25  bool mIsPlaying; ///< whether or not it's playing
26  bool mIsThreadRunning; ///< is the background thread running?
27  unsigned mDuration; ///< the file's buffer rate;
28  void open() throw(CException);
29  /// seconds is optional. If not passed, starts a background thread,
30  /// playing and writing, otherwise run for x seconds
31  /// (so it doesn't return until done).
32  void start(float seconds = 0) throw(CException);
33  void stop() throw(CException);
34  void close() throw(CException);
35  void test() throw(CException) { }; ///< test the IO's graph
36  ///< Get the current input from the sound card
37  Buffer & getInput() throw(CException) { return mInBuffer; };
38  Buffer & getInput(unsigned numFrames, unsigned numChannels) throw(CException) { return mInBuffer; };
39 
40 protected:
41  string mPath; // the output file name
42  SoundFile * mFile; // the output sound file
43  CThread * mThread; // the background thread
44  static void *threadFunction(void *); // the background thread function
45 
46  Buffer mInBuffer; // buffer we use for input
47  Buffer mOutBuffer; // buffer we use for output
48  void writeNextBuffer();
49 };
50 
51 }
52 
53 #endif