Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# stk::FileRead Class Reference

STK audio file input class. More...

`#include <FileRead.h>`

Inheritance diagram for stk::FileRead:

List of all members.

## 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.
| ~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.
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.
StkFloat | fileRate (void) const
| Return the file sample rate in Hz.
void | read (StkFrames &buffer, unsigned long startFrame=0, bool doNormalize=true)
| Read sample frames from the file into an StkFrames object.

## 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-, 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 is assumed to be 44100 Hz.

by Perry R. Cook and Gary P. Scavone, 1995 - 2010.

## Constructor & Destructor Documentation

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

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.

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.

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-2010 Perry R. Cook and Gary P. Scavone. All Rights Reserved.