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 /***************************************************/
40 /***************************************************/
41 
42 class FileWvIn : public WvIn
43 {
44 public:
46  FileWvIn( unsigned long chunkThreshold = 1000000, unsigned long chunkSize = 1024 );
47 
49 
53  FileWvIn( std::string fileName, bool raw = false, bool doNormalize = true,
54  unsigned long chunkThreshold = 1000000, unsigned long chunkSize = 1024 );
55 
57  ~FileWvIn( void );
58 
60 
69  virtual void openFile( std::string fileName, bool raw = false, bool doNormalize = true );
70 
72  virtual void closeFile( void );
73 
75  virtual void reset( void );
76 
78 
82  virtual void normalize( void );
83 
85 
89  virtual void normalize( StkFloat peak );
90 
92  virtual unsigned long getSize( void ) const { return file_.fileSize(); };
93 
95 
100  virtual StkFloat getFileRate( void ) const { return data_.dataRate(); };
101 
103  bool isOpen( void ) { return file_.isOpen(); };
104 
106  bool isFinished( void ) const { return finished_; };
107 
109 
112  virtual void setRate( StkFloat rate );
113 
115 
118  virtual void addTime( StkFloat time );
119 
121 
127  void setInterpolate( bool doInterpolate ) { interpolate_ = doInterpolate; };
128 
130 
139  StkFloat lastOut( unsigned int channel = 0 );
140 
142 
151  virtual StkFloat tick( unsigned int channel = 0 );
152 
154 
162  virtual StkFrames& tick( StkFrames& frames );
163 
164 protected:
165 
166  void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
167 
168  FileRead file_;
169  bool finished_;
170  bool interpolate_;
171  bool normalizing_;
172  bool chunking_;
173  StkFloat time_;
174  StkFloat rate_;
175  unsigned long chunkThreshold_;
176  unsigned long chunkSize_;
177  long chunkPointer_;
178 
179 };
180 
181 inline StkFloat FileWvIn :: lastOut( unsigned int channel )
182 {
183 #if defined(_STK_DEBUG_)
184  if ( channel >= data_.channels() ) {
185  oStream_ << "FileWvIn::lastOut(): channel argument and soundfile data are incompatible!";
186  handleError( StkError::FUNCTION_ARGUMENT );
187  }
188 #endif
189 
190  if ( finished_ ) return 0.0;
191  return lastFrame_[channel];
192 }
193 
194 } // stk namespace
195 
196 #endif
bool isFinished(void) const
Query whether reading is complete.
Definition: FileWvIn.h:106
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
virtual void openFile(std::string fileName, bool raw=false, bool doNormalize=true)
Open the specified file and load its data.
StkFloat lastOut(unsigned int channel=0)
Return the specified channel value of the last computed frame.
Definition: FileWvIn.h:181
STK audio file input class.
Definition: FileRead.h:41
STK audio file input class.
Definition: FileWvIn.h:42
FileWvIn(unsigned long chunkThreshold=1000000, unsigned long chunkSize=1024)
Default constructor.
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition: Stk.h:377
The STK namespace.
Definition: ADSR.h:6
bool isOpen(void)
Query whether a file is open.
Definition: FileWvIn.h:103
virtual void closeFile(void)
Close a file if one is open.
virtual void addTime(StkFloat time)
Increment the read pointer by time samples.
STK audio input abstract base class.
Definition: WvIn.h:19
unsigned long fileSize(void) const
Return the file size in sample frames.
Definition: FileRead.h:77
virtual void setRate(StkFloat rate)
Set the data read rate in samples. The rate can be negative.
virtual void reset(void)
Clear outputs and reset time (file) pointer to zero.
bool isOpen(void)
Returns true if a file is currently open.
An STK class to handle vectorized audio data.
Definition: Stk.h:272
virtual StkFloat tick(unsigned int channel=0)
Compute a sample frame and return the specified channel value.
virtual void normalize(void)
Normalize data to a maximum of +-1.0.
void setInterpolate(bool doInterpolate)
Turn linear interpolation on/off.
Definition: FileWvIn.h:127
virtual unsigned long getSize(void) const
Return the file size in sample frames.
Definition: FileWvIn.h:92
virtual StkFloat getFileRate(void) const
Return the input file sample rate in Hz (not the data read rate).
Definition: FileWvIn.h:100
StkFloat dataRate(void) const
Return the sample rate associated with the StkFrames data.
Definition: Stk.h:394
~FileWvIn(void)
Class destructor.

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