The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Public Member Functions | List of all members
stk::FileRead Class Reference

STK audio file input class. More...

`#include <FileRead.h>`

Inheritance diagram for stk::FileRead:

## 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...
Public Member Functions inherited from stk::Stk
void | ignoreSampleRateChange (bool ignore=true)
| A function to enable/disable the automatic updating of class data when the STK sample rate changes. More...

## Additional Inherited Members
Static Public Member Functions inherited from stk::Stk
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 inherited from stk::Stk
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 inherited from stk::Stk
| Stk (void)
| Default constructor.
virtual | ~Stk (void)
| Class destructor.
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.
void | handleError (StkError::Type type) const
| Internal function for error reporting that assumes message in `oStream_` variable.

## Detailed Description

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.

## Constructor & Destructor Documentation

## ◆ FileRead()

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.

## Member Function Documentation

## ◆ open()

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.

## ◆ fileRate()

StkFloat stk::FileRead::fileRate | ( | void |  | ) | const
| inline

Return the file sample rate in Hz.

WAV, SND, and AIF formatted files specify a sample rate in their headers. By definition, STK RAW files have a sample rate of 22050 Hz. MAT-files are assumed to have a rate of 44100 Hz.

91 { return fileRate_; };

## ◆ read()

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.

The documentation for this class was generated from the following file:

- FileRead.h

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