Fix to FileWvIn / FileLoop for file open issue and normalization.

This commit is contained in:
Gary Scavone
2017-05-04 16:32:53 -04:00
parent 9627701d04
commit 62416d7e3f
4 changed files with 23 additions and 14 deletions

View File

@@ -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:

View File

@@ -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; i<frames.size(); i++ ) {
*samples++ = frames[i];
if ( input->channelsOut() == 1 ) *samples++ = frames[i]; // play mono files in stereo

View File

@@ -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 );

View File

@@ -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