Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

FileWvIn.h
1#ifndef STK_FILEWVIN_H
2#define STK_FILEWVIN_H
3
4#include "WvIn.h"
5#include "FileRead.h"
6
7 namespace stk {
8
9/***************************************************/
50/***************************************************/
51
52 class FileWvIn : public WvIn
53{
54 public:
56 FileWvIn( unsigned long chunkThreshold = 1000000, unsigned long chunkSize = 1024 );
57
59
63 FileWvIn( std::string fileName, bool raw = false, bool doNormalize = true,
64 unsigned long chunkThreshold = 1000000, unsigned long chunkSize = 1024,
65 bool doInt2FloatScaling = true );
66
68 ~FileWvIn( void );
69
71
81 virtual void openFile( std::string fileName, bool raw = false, bool doNormalize = true, bool doInt2FloatScaling = true );
82
84 virtual void closeFile( void );
85
87 virtual void reset( void );
88
90
94 virtual void normalize( void );
95
97
101 virtual void normalize( StkFloat peak );
102
104 virtual unsigned long getSize( void ) const { return fileSize_; };
105
107
112 virtual StkFloat getFileRate( void ) const { return data_.dataRate(); };
113
115 bool isOpen( void ) { return file_.isOpen(); };
116
118 bool isFinished( void ) const { return finished_; };
119
121
124 virtual void setRate( StkFloat rate );
125
127
130 virtual void addTime( StkFloat time );
131
133
139 void setInterpolate( bool doInterpolate ) { interpolate_ = doInterpolate; };
140
142
151 StkFloat lastOut( unsigned int channel = 0 );
152
154
163 virtual StkFloat tick( unsigned int channel = 0 );
164
166
173 virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
174
175 protected:
176
177 void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
178
179 FileRead file_;
180 bool finished_;
181 bool interpolate_;
182 bool int2floatscaling_;
183 bool chunking_;
184 StkFloat time_;
185 StkFloat rate_;
186 unsigned long fileSize_;
187 unsigned long chunkThreshold_;
188 unsigned long chunkSize_;
189 long chunkPointer_;
190
191};
192
193 inline StkFloat FileWvIn :: lastOut( unsigned int channel )
194{
195#if defined(_STK_DEBUG_)
196 if ( channel >= data_.channels() ) {
197 oStream_ << "FileWvIn::lastOut(): channel argument and soundfile data are incompatible!";
198 handleError( StkError::FUNCTION_ARGUMENT );
199 }
200#endif
201
202 if ( finished_ ) return 0.0;
203 return lastFrame_[channel];
204}
205
206} // stk namespace
207
208#endif
stk::FileRead
STK audio file input class.
Definition FileRead.h:42
stk::FileWvIn::FileWvIn
FileWvIn(unsigned long chunkThreshold=1000000, unsigned long chunkSize=1024)
Default constructor.
stk::FileWvIn::getFileRate
virtual StkFloat getFileRate(void) const
Return the input file sample rate in Hz (not the data read rate).
Definition FileWvIn.h:112
stk::FileWvIn::setInterpolate
void setInterpolate(bool doInterpolate)
Turn linear interpolation on/off.
Definition FileWvIn.h:139
stk::FileWvIn::getSize
virtual unsigned long getSize(void) const
Return the file size in sample frames.
Definition FileWvIn.h:104
stk::FileWvIn::normalize
virtual void normalize(StkFloat peak)
Normalize data to a maximum of +-peak.
stk::FileWvIn::openFile
virtual void openFile(std::string fileName, bool raw=false, bool doNormalize=true, bool doInt2FloatScaling=true)
Open the specified file and load its data.
stk::FileWvIn::isOpen
bool isOpen(void)
Query whether a file is open.
Definition FileWvIn.h:115
stk::FileWvIn::setRate
virtual void setRate(StkFloat rate)
Set the data read rate in samples. The rate can be negative.
stk::FileWvIn::normalize
virtual void normalize(void)
Normalize data to a maximum of +-1.0.
stk::FileWvIn::addTime
virtual void addTime(StkFloat time)
Increment the read pointer by time samples.
stk::FileWvIn::reset
virtual void reset(void)
Clear outputs and reset time (file) pointer to zero.
stk::FileWvIn::lastOut
StkFloat lastOut(unsigned int channel=0)
Return the specified channel value of the last computed frame.
Definition FileWvIn.h:193
stk::FileWvIn::~FileWvIn
~FileWvIn(void)
Class destructor.
stk::FileWvIn::tick
virtual StkFloat tick(unsigned int channel=0)
Compute a sample frame and return the specified channel value.
stk::FileWvIn::tick
virtual StkFrames & tick(StkFrames &frames, unsigned int channel=0)
Fill the StkFrames object with computed sample frames, starting at the specified channel and return t...
stk::FileWvIn::closeFile
virtual void closeFile(void)
Close a file if one is open.
stk::FileWvIn::FileWvIn
FileWvIn(std::string fileName, bool raw=false, bool doNormalize=true, unsigned long chunkThreshold=1000000, unsigned long chunkSize=1024, bool doInt2FloatScaling=true)
Overloaded constructor for file input.
stk::FileWvIn::isFinished
bool isFinished(void) const
Query whether reading is complete.
Definition FileWvIn.h:118
stk::StkFrames
An STK class to handle vectorized audio data.
Definition Stk.h:279
stk::Stk::handleError
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
stk::WvIn
STK audio input abstract base class.
Definition WvIn.h:20
stk
The STK namespace.
Definition ADSR.h:6

The Synthesis ToolKit in C++ (STK)
©1995--2023 Perry R. Cook and Gary P. Scavone. All Rights Reserved.