diff --git a/include/FileWvIn.h b/include/FileWvIn.h index e201fd3..ec8fffc 100644 --- a/include/FileWvIn.h +++ b/include/FileWvIn.h @@ -170,7 +170,7 @@ public: performed if _STK_DEBUG_ is defined during compilation, in which case an out-of-range value will trigger an StkError exception. */ - virtual StkFrames& tick( StkFrames& frames,unsigned int channel = 0 ); + virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 0 ); protected: diff --git a/projects/examples/play.cpp b/projects/examples/play.cpp index e87bbb8..5863823 100644 --- a/projects/examples/play.cpp +++ b/projects/examples/play.cpp @@ -23,7 +23,7 @@ using namespace stk; // Eewww ... global variables! :-) -bool done; +bool done = false; StkFrames frames; static void finish(int ignore){ done = true; } @@ -45,9 +45,10 @@ int tick( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, double streamTime, RtAudioStreamStatus status, void *userData ) { FileWvIn *input = (FileWvIn *) userData; - register StkFloat *samples = (StkFloat *) outputBuffer; + StkFloat *samples = (StkFloat *) outputBuffer; input->tick( frames ); + for ( unsigned int i=0; ichannelsOut() == 1 ) *samples++ = frames[i]; // play mono files in stereo diff --git a/src/FileLoop.cpp b/src/FileLoop.cpp index 1e96935..b64a6b3 100644 --- a/src/FileLoop.cpp +++ b/src/FileLoop.cpp @@ -54,16 +54,19 @@ void FileLoop :: openFile( std::string fileName, bool raw, bool doNormalize, boo chunking_ = true; chunkPointer_ = 0; data_.resize( chunkSize_ + 1, file_.channels() ); - if ( doInt2FloatScaling ) int2floatscaling_ = true; - else int2floatscaling_ = false; } else { chunking_ = false; data_.resize( file_.fileSize() + 1, file_.channels() ); } + if ( doInt2FloatScaling ) + int2floatscaling_ = true; + else + int2floatscaling_ = false; + // Load all or part of the data. - file_.read( data_, 0, doNormalize ); + file_.read( data_, 0, int2floatscaling_ ); if ( chunking_ ) { // If chunking, save the first sample frame for later. firstFrame_.resize( 1, data_.channels() ); @@ -135,6 +138,8 @@ StkFloat FileLoop :: tick( unsigned int channel ) } #endif + if ( finished_ ) return 0.0; + // Check limits of time address ... if necessary, recalculate modulo // fileSize. while ( time_ < 0.0 ) @@ -196,7 +201,7 @@ StkFloat FileLoop :: tick( unsigned int channel ) StkFrames& FileLoop :: tick( StkFrames& frames, unsigned int channel) { - if ( !file_.isOpen() ) { + if ( finished_ ) { #if defined(_STK_DEBUG_) oStream_ << "FileLoop::tick(): no file data is loaded!"; handleError( StkError::DEBUG_PRINT ); diff --git a/src/FileWvIn.cpp b/src/FileWvIn.cpp index f62e7da..e6e3c50 100644 --- a/src/FileWvIn.cpp +++ b/src/FileWvIn.cpp @@ -44,7 +44,8 @@ FileWvIn :: FileWvIn( unsigned long chunkThreshold, unsigned long chunkSize ) } FileWvIn :: FileWvIn( std::string fileName, bool raw, bool doNormalize, - unsigned long chunkThreshold, unsigned long chunkSize, bool doInt2FloatScaling ) + unsigned long chunkThreshold, unsigned long chunkSize, + bool doInt2FloatScaling ) : finished_(true), interpolate_(false), time_(0.0), rate_(0.0), chunkThreshold_(chunkThreshold), chunkSize_(chunkSize) { @@ -84,16 +85,19 @@ void FileWvIn :: openFile( std::string fileName, bool raw, bool doNormalize, boo chunking_ = true; chunkPointer_ = 0; data_.resize( chunkSize_, file_.channels() ); - if ( doInt2FloatScaling ) int2floatscaling_ = true; - else int2floatscaling_ = false; } else { chunking_ = false; data_.resize( (size_t) file_.fileSize(), file_.channels() ); } + if ( doInt2FloatScaling ) + int2floatscaling_ = true; + else + int2floatscaling_ = false; + // Load all or part of the data. - file_.read( data_, 0, doNormalize ); + file_.read( data_, 0, int2floatscaling_ ); // Resize our lastFrame container. lastFrame_.resize( 1, file_.channels() ); @@ -228,9 +232,9 @@ StkFloat FileWvIn :: tick( unsigned int channel ) StkFrames& FileWvIn :: tick( StkFrames& frames, unsigned int channel) { - if ( !file_.isOpen() ) { + if ( finished_ ) { #if defined(_STK_DEBUG_) - oStream_ << "FileWvIn::tick(): no file data is loaded!"; + oStream_ << "FileWvIn::tick(): end of file or no open file!"; handleError( StkError::DEBUG_PRINT ); #endif return frames; @@ -258,7 +262,6 @@ StkFrames& FileWvIn :: tick( StkFrames& frames, unsigned int channel) } } return frames; - } } // stk namespace