mirror of
https://github.com/thestk/stk
synced 2026-01-11 20:11:52 +00:00
Fix to FileWvIn / FileLoop for file open issue and normalization.
This commit is contained in:
@@ -170,7 +170,7 @@ public:
|
|||||||
performed if _STK_DEBUG_ is defined during compilation, in which
|
performed if _STK_DEBUG_ is defined during compilation, in which
|
||||||
case an out-of-range value will trigger an StkError exception.
|
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:
|
protected:
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
using namespace stk;
|
using namespace stk;
|
||||||
|
|
||||||
// Eewww ... global variables! :-)
|
// Eewww ... global variables! :-)
|
||||||
bool done;
|
bool done = false;
|
||||||
StkFrames frames;
|
StkFrames frames;
|
||||||
static void finish(int ignore){ done = true; }
|
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 )
|
double streamTime, RtAudioStreamStatus status, void *userData )
|
||||||
{
|
{
|
||||||
FileWvIn *input = (FileWvIn *) userData;
|
FileWvIn *input = (FileWvIn *) userData;
|
||||||
register StkFloat *samples = (StkFloat *) outputBuffer;
|
StkFloat *samples = (StkFloat *) outputBuffer;
|
||||||
|
|
||||||
input->tick( frames );
|
input->tick( frames );
|
||||||
|
|
||||||
for ( unsigned int i=0; i<frames.size(); i++ ) {
|
for ( unsigned int i=0; i<frames.size(); i++ ) {
|
||||||
*samples++ = frames[i];
|
*samples++ = frames[i];
|
||||||
if ( input->channelsOut() == 1 ) *samples++ = frames[i]; // play mono files in stereo
|
if ( input->channelsOut() == 1 ) *samples++ = frames[i]; // play mono files in stereo
|
||||||
|
|||||||
@@ -54,16 +54,19 @@ void FileLoop :: openFile( std::string fileName, bool raw, bool doNormalize, boo
|
|||||||
chunking_ = true;
|
chunking_ = true;
|
||||||
chunkPointer_ = 0;
|
chunkPointer_ = 0;
|
||||||
data_.resize( chunkSize_ + 1, file_.channels() );
|
data_.resize( chunkSize_ + 1, file_.channels() );
|
||||||
if ( doInt2FloatScaling ) int2floatscaling_ = true;
|
|
||||||
else int2floatscaling_ = false;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
chunking_ = false;
|
chunking_ = false;
|
||||||
data_.resize( file_.fileSize() + 1, file_.channels() );
|
data_.resize( file_.fileSize() + 1, file_.channels() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( doInt2FloatScaling )
|
||||||
|
int2floatscaling_ = true;
|
||||||
|
else
|
||||||
|
int2floatscaling_ = false;
|
||||||
|
|
||||||
// Load all or part of the data.
|
// 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.
|
if ( chunking_ ) { // If chunking, save the first sample frame for later.
|
||||||
firstFrame_.resize( 1, data_.channels() );
|
firstFrame_.resize( 1, data_.channels() );
|
||||||
@@ -135,6 +138,8 @@ StkFloat FileLoop :: tick( unsigned int channel )
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if ( finished_ ) return 0.0;
|
||||||
|
|
||||||
// Check limits of time address ... if necessary, recalculate modulo
|
// Check limits of time address ... if necessary, recalculate modulo
|
||||||
// fileSize.
|
// fileSize.
|
||||||
while ( time_ < 0.0 )
|
while ( time_ < 0.0 )
|
||||||
@@ -196,7 +201,7 @@ StkFloat FileLoop :: tick( unsigned int channel )
|
|||||||
|
|
||||||
StkFrames& FileLoop :: tick( StkFrames& frames, unsigned int channel)
|
StkFrames& FileLoop :: tick( StkFrames& frames, unsigned int channel)
|
||||||
{
|
{
|
||||||
if ( !file_.isOpen() ) {
|
if ( finished_ ) {
|
||||||
#if defined(_STK_DEBUG_)
|
#if defined(_STK_DEBUG_)
|
||||||
oStream_ << "FileLoop::tick(): no file data is loaded!";
|
oStream_ << "FileLoop::tick(): no file data is loaded!";
|
||||||
handleError( StkError::DEBUG_PRINT );
|
handleError( StkError::DEBUG_PRINT );
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ FileWvIn :: FileWvIn( unsigned long chunkThreshold, unsigned long chunkSize )
|
|||||||
}
|
}
|
||||||
|
|
||||||
FileWvIn :: FileWvIn( std::string fileName, bool raw, bool doNormalize,
|
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),
|
: finished_(true), interpolate_(false), time_(0.0), rate_(0.0),
|
||||||
chunkThreshold_(chunkThreshold), chunkSize_(chunkSize)
|
chunkThreshold_(chunkThreshold), chunkSize_(chunkSize)
|
||||||
{
|
{
|
||||||
@@ -84,16 +85,19 @@ void FileWvIn :: openFile( std::string fileName, bool raw, bool doNormalize, boo
|
|||||||
chunking_ = true;
|
chunking_ = true;
|
||||||
chunkPointer_ = 0;
|
chunkPointer_ = 0;
|
||||||
data_.resize( chunkSize_, file_.channels() );
|
data_.resize( chunkSize_, file_.channels() );
|
||||||
if ( doInt2FloatScaling ) int2floatscaling_ = true;
|
|
||||||
else int2floatscaling_ = false;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
chunking_ = false;
|
chunking_ = false;
|
||||||
data_.resize( (size_t) file_.fileSize(), file_.channels() );
|
data_.resize( (size_t) file_.fileSize(), file_.channels() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( doInt2FloatScaling )
|
||||||
|
int2floatscaling_ = true;
|
||||||
|
else
|
||||||
|
int2floatscaling_ = false;
|
||||||
|
|
||||||
// Load all or part of the data.
|
// Load all or part of the data.
|
||||||
file_.read( data_, 0, doNormalize );
|
file_.read( data_, 0, int2floatscaling_ );
|
||||||
|
|
||||||
// Resize our lastFrame container.
|
// Resize our lastFrame container.
|
||||||
lastFrame_.resize( 1, file_.channels() );
|
lastFrame_.resize( 1, file_.channels() );
|
||||||
@@ -228,9 +232,9 @@ StkFloat FileWvIn :: tick( unsigned int channel )
|
|||||||
|
|
||||||
StkFrames& FileWvIn :: tick( StkFrames& frames, unsigned int channel)
|
StkFrames& FileWvIn :: tick( StkFrames& frames, unsigned int channel)
|
||||||
{
|
{
|
||||||
if ( !file_.isOpen() ) {
|
if ( finished_ ) {
|
||||||
#if defined(_STK_DEBUG_)
|
#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 );
|
handleError( StkError::DEBUG_PRINT );
|
||||||
#endif
|
#endif
|
||||||
return frames;
|
return frames;
|
||||||
@@ -258,7 +262,6 @@ StkFrames& FileWvIn :: tick( StkFrames& frames, unsigned int channel)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return frames;
|
return frames;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // stk namespace
|
} // stk namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user