Arduino STK
4.6.2
|
STK audio file input class. More...
#include <FileRead.h>
Public Member Functions | |
FileRead (void) | |
Default constructor. | |
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. More... | |
~FileRead (void) | |
Class destructor. | |
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. More... | |
void | close (void) |
If a file is open, close it. | |
bool | isOpen (void) |
Returns true if a file is currently open. | |
unsigned long | fileSize (void) const |
Return the file size in sample frames. | |
unsigned int | channels (void) const |
Return the number of audio channels in the file. | |
StkFormat | format (void) const |
Return the data format of the file. | |
StkFloat | fileRate (void) const |
Return the file sample rate in Hz. More... | |
void | read (StkFrames &buffer, unsigned long startFrame=0, bool doNormalize=true) |
Read sample frames from the file into an StkFrames object. More... | |
void | ignoreSampleRateChange (bool ignore=true) |
A function to enable/disable the automatic updating of class data when the STK sample rate changes. More... | |
Static Public Member Functions | |
static StkFloat | sampleRate (void) |
Static method that returns the current STK sample rate. | |
static void | setSampleRate (StkFloat rate) |
Static method that sets the STK sample rate. More... | |
static void | clear_alertList () |
Static method that frees memory from alertList_. | |
static std::string | rawwavePath (void) |
Static method that returns the current rawwave path. | |
static void | setRawwavePath (std::string path) |
Static method that sets the STK rawwave path. | |
static void | swap16 (unsigned char *ptr) |
Static method that byte-swaps a 16-bit data type. | |
static void | swap32 (unsigned char *ptr) |
Static method that byte-swaps a 32-bit data type. | |
static void | swap64 (unsigned char *ptr) |
Static method that byte-swaps a 64-bit data type. | |
static void | sleep (unsigned long milliseconds) |
Static cross-platform method to sleep for a number of milliseconds. | |
static bool | inRange (StkFloat value, StkFloat min, StkFloat max) |
Static method to check whether a value is within a specified range. | |
static void | handleError (const char *message, StkError::Type type) |
Static function for error reporting and handling using c-strings. | |
static void | handleError (std::string message, StkError::Type type) |
Static function for error reporting and handling using c++ strings. | |
static void | showWarnings (bool status) |
Toggle display of WARNING and STATUS messages. | |
static void | printErrors (bool status) |
Toggle display of error messages before throwing exceptions. | |
Static Public Attributes | |
static const StkFormat | STK_SINT8 |
static const StkFormat | STK_SINT16 |
static const StkFormat | STK_SINT24 |
static const StkFormat | STK_SINT32 |
static const StkFormat | STK_FLOAT32 |
static const StkFormat | STK_FLOAT64 |
Protected Member Functions | |
void | handleError (StkError::Type type) const |
Internal function for error reporting that assumes message in oStream_ variable. | |
virtual void | sampleRateChanged (StkFloat newRate, StkFloat oldRate) |
This function should be implemented in subclasses that depend on the sample rate. | |
void | addSampleRateAlert (Stk *ptr) |
Add class pointer to list for sample rate change notification. | |
void | removeSampleRateAlert (Stk *ptr) |
Remove class pointer from list for sample rate change notification. | |
STK audio file input class.
This class provides input support for various audio file formats. Multi-channel (>2) soundfiles are supported. The file data is returned via an external StkFrames object passed to the read() function. This class does not store its own copy of the file data, rather the data is read directly from disk.
FileRead currently supports uncompressed WAV, AIFF/AIFC, SND (AU), MAT-file (Matlab), and STK RAW file formats. Signed integer (8-, 16-, 24-, and 32-bit) and floating-point (32- and 64-bit) data types are supported. Compressed data types are not supported.
STK RAW files have no header and are assumed to contain a monophonic stream of 16-bit signed integers in big-endian byte order at a sample rate of 22050 Hz. MAT-file data should be saved in an array with each data channel filling a matrix row. The sample rate for MAT-files should be specified in a variable named "fs". If no such variable is found, the sample rate is assumed to be 44100 Hz.
by Perry R. Cook and Gary P. Scavone, 1995–2019.
stk::FileRead::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 StkError will be thrown if the file is not found or its format is unknown or unsupported. The optional arguments allow a headerless file type to be supported. If typeRaw
is false (the default), the subsequent parameters are ignored.
void stk::FileRead::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.
An StkError will be thrown if the file is not found or its format is unknown or unsupported. The optional arguments allow a headerless file type to be supported. If typeRaw
is false (the default), the subsequent parameters are ignored.
|
inline |
void stk::FileRead::read | ( | StkFrames & | buffer, |
unsigned long | startFrame = 0 , |
||
bool | doNormalize = true |
||
) |
Read sample frames from the file into an StkFrames object.
The number of sample frames to read will be determined from the number of frames of the StkFrames argument. If this size is larger than the available data in the file (given the file size and starting frame index), the extra frames will be unaffected (the StkFrames object will not be resized). Optional parameters are provided to specify the starting sample frame within the file (default = 0) and whether to normalize the data with respect to fixed-point limits (default = true). An StkError will be thrown if a file error occurs or if the number of channels in the StkFrames argument is not equal to that in the file.
|
staticinherited |
Static method that sets the STK sample rate.
The sample rate set using this method is queried by all STK classes that depend on its value. It is initialized to the default SRATE set in Stk.h. Many STK classes use the sample rate during instantiation. Therefore, if you wish to use a rate that is different from the default rate, it is imperative that it be set BEFORE STK objects are instantiated. A few classes that make use of the global STK sample rate are automatically notified when the rate changes so that internal class data can be appropriately updated. However, this has not been fully implemented. Specifically, classes that appropriately update their own data when either a setFrequency() or noteOn() function is called do not currently receive the automatic notification of rate change. If the user wants a specific class instance to ignore such notifications, perhaps in a multi-rate context, the function Stk::ignoreSampleRateChange() should be called.
|
inlineinherited |
|
staticinherited |
-128 to +127
|
staticinherited |
-32768 to +32767
|
staticinherited |
Lower 3 bytes of 32-bit signed integer.
|
staticinherited |
-2147483648 to +2147483647.
|
staticinherited |
Normalized between plus/minus 1.0.
|
staticinherited |
Normalized between plus/minus 1.0.