mirror of
https://github.com/thestk/stk
synced 2026-01-12 04:21:52 +00:00
Added optional argument to FileWvIn and FileLoop to distinguish int-to-float scaling from data normalization. The default values should produce the same behaviour as before.
This commit is contained in:
@@ -31,7 +31,8 @@ class FileLoop : protected FileWvIn
|
||||
|
||||
//! Class constructor that opens a specified file.
|
||||
FileLoop( std::string fileName, bool raw = false, bool doNormalize = true,
|
||||
unsigned long chunkThreshold = 1000000, unsigned long chunkSize = 1024 );
|
||||
unsigned long chunkThreshold = 1000000, unsigned long chunkSize = 1024,
|
||||
bool doInt2FloatScaling = true );
|
||||
|
||||
//! Class destructor.
|
||||
~FileLoop( void );
|
||||
@@ -40,13 +41,14 @@ class FileLoop : protected FileWvIn
|
||||
/*!
|
||||
Data from a previously opened file will be overwritten by this
|
||||
function. An StkError will be thrown if the file is not found,
|
||||
its format is unknown, or a read error occurs. If the file data
|
||||
is to be loaded incrementally from disk and normalization is
|
||||
specified, a scaling will be applied with respect to fixed-point
|
||||
limits. If the data format is floating-point, no scaling is
|
||||
performed.
|
||||
its format is unknown, or a read error occurs. If the file length
|
||||
is less than the chunkThreshold limit and \e doNormalize is true,
|
||||
the file data will be normalized with respect to the maximum absolute
|
||||
value of the data. If the \e doInt2FloatScaling flag is true and the
|
||||
input data is fixed-point, a scaling will be applied with respect to
|
||||
the fixed-point limits.
|
||||
*/
|
||||
void openFile( std::string fileName, bool raw = false, bool doNormalize = true );
|
||||
void openFile( std::string fileName, bool raw = false, bool doNormalize = true, bool doInt2FloatScaling = true );
|
||||
|
||||
//! Close a file if one is open.
|
||||
void closeFile( void ) { FileWvIn::closeFile(); };
|
||||
|
||||
@@ -29,6 +29,16 @@ namespace stk {
|
||||
chunkThreshold (in sample frames) will be read incrementally in
|
||||
chunks of \e chunkSize each (also in sample frames).
|
||||
|
||||
For file data read completely into local memory, the \e doNormalize
|
||||
flag can be used to normalize all values with respect to the maximum
|
||||
absolute value of the data.
|
||||
|
||||
If the file data format is fixed point, the flag \e doInt2FloatScaling
|
||||
can be used to control whether the values are scaled with respect to
|
||||
the corresponding fixed-point maximum. For example, if reading 16-bit
|
||||
signed integers, the input values will be scaled by 1 / 32768.0. This
|
||||
scaling will not happen for floating-point file data formats.
|
||||
|
||||
When the file end is reached, subsequent calls to the tick()
|
||||
functions return zeros and isFinished() returns \e true.
|
||||
|
||||
@@ -51,7 +61,8 @@ public:
|
||||
unknown, or a read error occurs.
|
||||
*/
|
||||
FileWvIn( std::string fileName, bool raw = false, bool doNormalize = true,
|
||||
unsigned long chunkThreshold = 1000000, unsigned long chunkSize = 1024 );
|
||||
unsigned long chunkThreshold = 1000000, unsigned long chunkSize = 1024,
|
||||
bool doInt2FloatScaling = true );
|
||||
|
||||
//! Class destructor.
|
||||
~FileWvIn( void );
|
||||
@@ -60,13 +71,14 @@ public:
|
||||
/*!
|
||||
Data from a previously opened file will be overwritten by this
|
||||
function. An StkError will be thrown if the file is not found,
|
||||
its format is unknown, or a read error occurs. If the file data
|
||||
is to be loaded incrementally from disk and normalization is
|
||||
specified, a scaling will be applied with respect to fixed-point
|
||||
limits. If the data format is floating-point, no scaling is
|
||||
performed.
|
||||
its format is unknown, or a read error occurs. If the file length
|
||||
is less than the chunkThreshold limit and \e doNormalize is true,
|
||||
the file data will be normalized with respect to the maximum absolute
|
||||
value of the data. If the \e doInt2FloatScaling flag is true and the
|
||||
input data is fixed-point, a scaling will be applied with respect to
|
||||
the fixed-point limits.
|
||||
*/
|
||||
virtual void openFile( std::string fileName, bool raw = false, bool doNormalize = true );
|
||||
virtual void openFile( std::string fileName, bool raw = false, bool doNormalize = true, bool doInt2FloatScaling = true );
|
||||
|
||||
//! Close a file if one is open.
|
||||
virtual void closeFile( void );
|
||||
@@ -167,7 +179,7 @@ protected:
|
||||
FileRead file_;
|
||||
bool finished_;
|
||||
bool interpolate_;
|
||||
bool normalizing_;
|
||||
bool int2floatscaling_;
|
||||
bool chunking_;
|
||||
StkFloat time_;
|
||||
StkFloat rate_;
|
||||
|
||||
@@ -28,10 +28,11 @@ FileLoop :: FileLoop( unsigned long chunkThreshold, unsigned long chunkSize )
|
||||
}
|
||||
|
||||
FileLoop :: FileLoop( std::string fileName, bool raw, bool doNormalize,
|
||||
unsigned long chunkThreshold, unsigned long chunkSize )
|
||||
unsigned long chunkThreshold, unsigned long chunkSize,
|
||||
bool doInt2FloatScaling )
|
||||
: FileWvIn( chunkThreshold, chunkSize ), phaseOffset_(0.0)
|
||||
{
|
||||
this->openFile( fileName, raw, doNormalize );
|
||||
this->openFile( fileName, raw, doNormalize, doInt2FloatScaling );
|
||||
Stk::addSampleRateAlert( this );
|
||||
}
|
||||
|
||||
@@ -40,7 +41,7 @@ FileLoop :: ~FileLoop( void )
|
||||
Stk::removeSampleRateAlert( this );
|
||||
}
|
||||
|
||||
void FileLoop :: openFile( std::string fileName, bool raw, bool doNormalize )
|
||||
void FileLoop :: openFile( std::string fileName, bool raw, bool doNormalize, bool doInt2FloatScaling )
|
||||
{
|
||||
// Call close() in case another file is already open.
|
||||
this->closeFile();
|
||||
@@ -53,8 +54,8 @@ void FileLoop :: openFile( std::string fileName, bool raw, bool doNormalize )
|
||||
chunking_ = true;
|
||||
chunkPointer_ = 0;
|
||||
data_.resize( chunkSize_ + 1, file_.channels() );
|
||||
if ( doNormalize ) normalizing_ = true;
|
||||
else normalizing_ = false;
|
||||
if ( doInt2FloatScaling ) int2floatscaling_ = true;
|
||||
else int2floatscaling_ = false;
|
||||
}
|
||||
else {
|
||||
chunking_ = false;
|
||||
@@ -171,7 +172,7 @@ StkFloat FileLoop :: tick( unsigned int channel )
|
||||
}
|
||||
|
||||
// Load more data.
|
||||
file_.read( data_, chunkPointer_, normalizing_ );
|
||||
file_.read( data_, chunkPointer_, int2floatscaling_ );
|
||||
}
|
||||
|
||||
// Adjust index for the current buffer.
|
||||
|
||||
@@ -44,11 +44,11 @@ FileWvIn :: FileWvIn( unsigned long chunkThreshold, unsigned long chunkSize )
|
||||
}
|
||||
|
||||
FileWvIn :: FileWvIn( std::string fileName, bool raw, bool doNormalize,
|
||||
unsigned long chunkThreshold, unsigned long chunkSize )
|
||||
unsigned long chunkThreshold, unsigned long chunkSize, bool doInt2FloatScaling )
|
||||
: finished_(true), interpolate_(false), time_(0.0), rate_(0.0),
|
||||
chunkThreshold_(chunkThreshold), chunkSize_(chunkSize)
|
||||
{
|
||||
openFile( fileName, raw, doNormalize );
|
||||
openFile( fileName, raw, doNormalize, doInt2FloatScaling );
|
||||
Stk::addSampleRateAlert( this );
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ void FileWvIn :: closeFile( void )
|
||||
lastFrame_.resize( 0, 0 );
|
||||
}
|
||||
|
||||
void FileWvIn :: openFile( std::string fileName, bool raw, bool doNormalize )
|
||||
void FileWvIn :: openFile( std::string fileName, bool raw, bool doNormalize, bool doInt2FloatScaling )
|
||||
{
|
||||
// Call close() in case another file is already open.
|
||||
this->closeFile();
|
||||
@@ -84,8 +84,8 @@ void FileWvIn :: openFile( std::string fileName, bool raw, bool doNormalize )
|
||||
chunking_ = true;
|
||||
chunkPointer_ = 0;
|
||||
data_.resize( chunkSize_, file_.channels() );
|
||||
if ( doNormalize ) normalizing_ = true;
|
||||
else normalizing_ = false;
|
||||
if ( doInt2FloatScaling ) int2floatscaling_ = true;
|
||||
else int2floatscaling_ = false;
|
||||
}
|
||||
else {
|
||||
chunking_ = false;
|
||||
@@ -204,7 +204,7 @@ StkFloat FileWvIn :: tick( unsigned int channel )
|
||||
}
|
||||
|
||||
// Load more data.
|
||||
file_.read( data_, chunkPointer_, normalizing_ );
|
||||
file_.read( data_, chunkPointer_, int2floatscaling_ );
|
||||
}
|
||||
|
||||
// Adjust index for the current buffer.
|
||||
|
||||
Reference in New Issue
Block a user