Fix for FileWvIn and FileLoop classes so that files are closed unless chunking.

This commit is contained in:
Gary Scavone
2016-02-03 16:37:51 -05:00
parent f0f6668f25
commit 83b75ed339
4 changed files with 33 additions and 28 deletions

View File

@@ -98,6 +98,10 @@ void FileWvIn :: openFile( std::string fileName, bool raw, bool doNormalize )
// Resize our lastFrame container.
lastFrame_.resize( 1, file_.channels() );
// Close the file unless chunking
fileSize_ = file_.fileSize();
if ( !chunking_ ) file_.close();
// Set default rate based on file sampling rate.
this->setRate( data_.dataRate() / Stk::sampleRate() );
@@ -146,7 +150,7 @@ void FileWvIn :: setRate( StkFloat rate )
// If negative rate and at beginning of sound, move pointer to end
// of sound.
if ( (rate_ < 0) && (time_ == 0.0) ) time_ = file_.fileSize() - 1.0;
if ( (rate_ < 0) && (time_ == 0.0) ) time_ = fileSize_ - 1.0;
if ( fmod( rate_, 1.0 ) != 0.0 ) interpolate_ = true;
else interpolate_ = false;
@@ -158,8 +162,8 @@ void FileWvIn :: addTime( StkFloat time )
time_ += time;
if ( time_ < 0.0 ) time_ = 0.0;
if ( time_ > file_.fileSize() - 1.0 ) {
time_ = file_.fileSize() - 1.0;
if ( time_ > fileSize_ - 1.0 ) {
time_ = fileSize_ - 1.0;
for ( unsigned int i=0; i<lastFrame_.size(); i++ ) lastFrame_[i] = 0.0;
finished_ = true;
}
@@ -176,7 +180,7 @@ StkFloat FileWvIn :: tick( unsigned int channel )
if ( finished_ ) return 0.0;
if ( time_ < 0.0 || time_ > (StkFloat) ( file_.fileSize() - 1.0 ) ) {
if ( time_ < 0.0 || time_ > (StkFloat) ( fileSize_ - 1.0 ) ) {
for ( unsigned int i=0; i<lastFrame_.size(); i++ ) lastFrame_[i] = 0.0;
finished_ = true;
return 0.0;
@@ -195,8 +199,8 @@ StkFloat FileWvIn :: tick( unsigned int channel )
}
while ( time_ > (StkFloat) ( chunkPointer_ + chunkSize_ - 1 ) ) { // positive rate
chunkPointer_ += chunkSize_ - 1; // overlap chunks by one frame
if ( chunkPointer_ + chunkSize_ > file_.fileSize() ) // at end of file
chunkPointer_ = file_.fileSize() - chunkSize_;
if ( chunkPointer_ + chunkSize_ > fileSize_ ) // at end of file
chunkPointer_ = fileSize_ - chunkSize_;
}
// Load more data.