Arduino STK  4.6.2
FileRead.h
1 #ifndef STK_FILEREAD_H
2 #define STK_FILEREAD_H
3 
4 #include "Stk.h"
5 
6 namespace stk {
7 
8 /***************************************************/
39 /***************************************************/
40 
41 class FileRead : public Stk
42 {
43 public:
45  FileRead( void );
46 
48 
54  FileRead( std::string fileName, bool typeRaw = false, unsigned int nChannels = 1,
55  StkFormat format = STK_SINT16, StkFloat rate = 22050.0 );
56 
58  ~FileRead( void );
59 
61 
67  void open( std::string fileName, bool typeRaw = false, unsigned int nChannels = 1,
68  StkFormat format = STK_SINT16, StkFloat rate = 22050.0 );
69 
71  void close( void );
72 
74  bool isOpen( void );
75 
77  unsigned long fileSize( void ) const { return fileSize_; };
78 
80  unsigned int channels( void ) const { return channels_; };
81 
83  StkFormat format( void ) const { return dataType_; };
84 
86 
91  StkFloat fileRate( void ) const { return fileRate_; };
92 
94 
106  void read( StkFrames& buffer, unsigned long startFrame = 0, bool doNormalize = true );
107 
108 protected:
109 
110  // Get STK RAW file information.
111  bool getRawInfo( const char *fileName, unsigned int nChannels,
112  StkFormat format, StkFloat rate );
113 
114  // Get WAV file header information.
115  bool getWavInfo( const char *fileName );
116 
117  // Get SND (AU) file header information.
118  bool getSndInfo( const char *fileName );
119 
120  // Get AIFF file header information.
121  bool getAifInfo( const char *fileName );
122 
123  // Get MAT-file header information.
124  bool getMatInfo( const char *fileName );
125 
126  // Helper function for MAT-file parsing.
127  bool findNextMatArray( SINT32 *chunkSize, SINT32 *rows, SINT32 *columns, SINT32 *nametype );
128 
129  FILE *fd_;
130  bool byteswap_;
131  bool wavFile_;
132  unsigned long fileSize_;
133  unsigned long dataOffset_;
134  unsigned int channels_;
135  StkFormat dataType_;
136  StkFloat fileRate_;
137 };
138 
139 } // stk namespace
140 
141 #endif
STK audio file input class.
Definition: FileRead.h:42
unsigned int channels(void) const
Return the number of audio channels in the file.
Definition: FileRead.h:80
~FileRead(void)
Class destructor.
unsigned long fileSize(void) const
Return the file size in sample frames.
Definition: FileRead.h:77
bool isOpen(void)
Returns true if a file is currently open.
void close(void)
If a file is open, close it.
void read(StkFrames &buffer, unsigned long startFrame=0, bool doNormalize=true)
Read sample frames from the file into an StkFrames object.
FileRead(void)
Default constructor.
StkFloat fileRate(void) const
Return the file sample rate in Hz.
Definition: FileRead.h:91
StkFormat format(void) const
Return the data format of the file.
Definition: FileRead.h:83
void open(std::string fileName, bool typeRaw=false, unsigned int nChannels=1, StkFormat format=STK_SINT16, StkFloat rate=22050.0)
Open the specified file and determine its formatting.
FileRead(std::string fileName, bool typeRaw=false, unsigned int nChannels=1, StkFormat format=STK_SINT16, StkFloat rate=22050.0)
Overloaded constructor that opens a file during instantiation.
An STK class to handle vectorized audio data.
Definition: Stk.h:287
STK base class.
Definition: Stk.h:144
static const StkFormat STK_SINT16
Definition: Stk.h:149
The STK namespace.
Definition: ADSR.h:8