10 FileIO::FileIO(
char * path) :
IO(), mIsPlaying(false), mIsThreadRunning(false), mFile(0) {
44 const char * sPath =
mPath.c_str();
46 char * dot = (
char *) strrchr(sPath,
'.');
48 if (strcmp(dot,
".wav") == 0)
50 else if (strcmp(dot,
".snd") == 0)
53 mFile->openForWrite(format, channels, rate);
54 if ( !
mFile->isValid()) {
59 mDuration = (int)((
float)blockSize / (float)rate * 1000000.0f);
65 mIsThreadRunning =
false;
68 logMsg(
"Starting sound file output loop");
69 while (mNumFramesPlayed < numFrames)
72 logMsg(
"Starting sound file output thread");
73 mThread->createThread(threadFunction,
this);
112 struct timeval *meThen = &me->mThen;
113 struct timeval *meNow = & me->
mNow;
124 sleepTime = me->
mDuration - (((meNow->tv_sec - meThen->tv_sec) * 1000000) + (meNow->tv_usec - meThen->tv_usec));
134 logMsg(
"Stopping sound file output thread");
void logMsg(const char *format,...)
These are the public logging messages.
#define kSoundFileFormatAIFF
long mTimeSum
for printing run-time statistics
unsigned mNumFrames
num frames used in each buffer
bool mAreBuffersAllocated
are the buffers allocated?
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
bool mIsPlaying
whether or not it's playing
static std::string sndFileName()
pick a new sound file name to use based on OUT_SFILE_NAME
static unsigned numOutChannels()
default number of output channels
virtual void nextBuffer(Buffer &outputBuffer)
get a buffer of Frames – this is the core CSL "pull" function; the given buffer can be written into...
void freeBuffers()
fcn to free them
void zeroBuffers()
fill all data with 0
unsigned mDuration
the file's buffer rate;
void setSize(unsigned numChannels, unsigned numFrames)
#define kSoundFileFormatSND
UnitGenerator * mGraph
the root of my client DSP graph, often a mixer or panner
static unsigned blockSize()
the default block size
IO – the abstract I/O scheduling class; subclasses interface to specific I/O APIs.
#define kSoundFileFormatWAV
static unsigned frameRate()
default frame rate
void close()
open/close start/stop methods
unsigned mNumFramesPlayed
counter of frames I've played
void printTimeStatistics(struct timeval *tthen, struct timeval *tnow, long *tsecond, long *ttimeSum, long *ttimeVals)
static CThread * MakeThread()
factory method
FileIO(char *path=NULL)
< the path name determines the file type, e.g., xx.aiff, zz.snd, or yy.wav
bool sleepUsec(float dur)
Misc. global functions in the csl namespace.
struct timeval mThen mNow
used for getting the real time
void allocateBuffers()
fcn to malloc storage buffers
static void * threadFunction(void *)
bool mIsThreadRunning
is the background thread running?
Base class of CSL exceptions (written upper-case). Has a string message.
FileIO.h – IO using a sound file for storing output sample data.