The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# stk::FileWvIn Class Reference

STK audio file input class. More...

`#include <FileWvIn.h>`

Inheritance diagram for stk::FileWvIn:

List of all members.

## Public Member Functions
| FileWvIn (unsigned long chunkThreshold=1000000, unsigned long chunkSize=1024)
| Default constructor.
| FileWvIn (std::string fileName, bool raw=false, bool doNormalize=true, unsigned long chunkThreshold=1000000, unsigned long chunkSize=1024)
| Overloaded constructor for file input.
| ~FileWvIn (void)
| Class destructor.
virtual void | openFile (std::string fileName, bool raw=false, bool doNormalize=true)
| Open the specified file and load its data.
virtual void | closeFile (void)
| Close a file if one is open.
virtual void | reset (void)
| Clear outputs and reset time (file) pointer to zero.
virtual void | normalize (void)
| Normalize data to a maximum of +-1.0.
virtual void | normalize (StkFloat peak)
| Normalize data to a maximum of +-peak.
virtual unsigned long | getSize (void) const
| Return the file size in sample frames.
virtual StkFloat | getFileRate (void) const
| Return the input file sample rate in Hz (not the data read rate).
bool | isOpen (void)
| Query whether a file is open.
bool | isFinished (void) const
| Query whether reading is complete.
virtual void | setRate (StkFloat rate)
| Set the data read rate in samples. The rate can be negative.
virtual void | addTime (StkFloat time)
| Increment the read pointer by time samples.
void | setInterpolate (bool doInterpolate)
| Turn linear interpolation on/off.
StkFloat | lastOut (unsigned int channel=0)
| Return the specified channel value of the last computed frame.
virtual StkFloat | tick (unsigned int channel=0)
| Compute a sample frame and return the specified `channel` value.
virtual StkFrames & | tick (StkFrames &frames)
| Fill the StkFrames argument with computed frames and return the same reference.

## Detailed Description

STK audio file input class.

This class inherits from WvIn. It provides a "tick-level" interface to the FileRead class. It also provides variable-rate playback functionality. Audio file support is provided by the FileRead class. Linear interpolation is used for fractional read rates.

FileWvIn supports multi-channel data. It is important to distinguish the tick() method that computes a single frame (and returns only the specified sample of a multi-channel frame) from the overloaded one that takes an StkFrames object for multi-channel and/or multi-frame data.

FileWvIn will either load the entire content of an audio file into local memory or incrementally read file data from disk in chunks. This behavior is controlled by the optional constructor arguments chunkThreshold and chunkSize. File sizes greater than chunkThreshold (in sample frames) will be read incrementally in chunks of chunkSize each (also in sample frames).

When the file end is reached, subsequent calls to the tick() functions return zeros and isFinished() returns true.

See the FileRead class for a description of the supported audio file formats.

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

## Constructor & Destructor Documentation

stk::FileWvIn::FileWvIn | ( | std::string | fileName,
|  | bool | raw = `false`,
|  | bool | doNormalize = `true`,
|  | unsigned long | chunkThreshold = `1000000`,
|  | unsigned long | chunkSize = `1024` |
| ) |  |  |

Overloaded constructor for file input.

An StkError will be thrown if the file is not found, its format is unknown, or a read error occurs.

## Member Function Documentation

virtual void stk::FileWvIn::openFile | ( | std::string | fileName,
|  | bool | raw = `false`,
|  | bool | doNormalize = `true` |
| ) |  |  | `[virtual]`

Open the specified file and load its data.

Data from a previously opened file will be overwritten by this function. An StkError will be thrown if the file is not found, its format is unknown, or a read error occurs. If the file data is to be loaded incrementally from disk and normalization is specified, a scaling will be applied with respect to fixed-point limits. If the data format is floating-point, no scaling is performed.

Reimplemented in stk::FileLoop.

virtual void stk::FileWvIn::normalize | ( | void |  | ) | `[virtual]`

Normalize data to a maximum of +-1.0.

This function has no effect when data is incrementally loaded from disk.

Reimplemented in stk::FileLoop.

virtual void stk::FileWvIn::normalize | ( | StkFloat | peak | ) | `[virtual]`

Normalize data to a maximum of +-peak.

This function has no effect when data is incrementally loaded from disk.

Reimplemented in stk::FileLoop.

virtual StkFloat stk::FileWvIn::getFileRate | ( | void |  | ) | const`[inline, virtual]`

Return the input file sample rate in Hz (not the data read rate).

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

Reimplemented in stk::FileLoop.

    00100 { return data_.dataRate(); };

virtual void stk::FileWvIn::setRate | ( | StkFloat | rate | ) | `[virtual]`

Set the data read rate in samples. The rate can be negative.

If the rate value is negative, the data is read in reverse order.

Reimplemented in stk::FileLoop.

virtual void stk::FileWvIn::addTime | ( | StkFloat | time | ) | `[virtual]`

Increment the read pointer by time samples.

Note that this function will not modify the interpolation flag status.

Reimplemented in stk::FileLoop.

void stk::FileWvIn::setInterpolate | ( | bool | doInterpolate | ) | `[inline]`

Turn linear interpolation on/off.

Interpolation is automatically off when the read rate is an integer value. If interpolation is turned off for a fractional rate, the time index is truncated to an integer value.

    00127 { interpolate_ = doInterpolate; };

StkFloat stk::FileWvIn::lastOut | ( | unsigned int | channel = `0` | ) | `[inline]`

Return the specified channel value of the last computed frame.

If no file is loaded, the returned value is 0.0. The `channel` argument must be less than the number of output channels, which can be determined with the channelsOut() function (the first channel is specified by 0). However, range checking is only performed if _STK_DEBUG_ is defined during compilation, in which case an out-of-range value will trigger an StkError exception.

See also:
  lastFrame()

Reimplemented in stk::FileLoop.

    00182 {
    00183 #if defined(_STK_DEBUG_)
    00184   if ( channel >= data_.channels() ) {
    00185     oStream_ << "FileWvIn::lastOut(): channel argument and soundfile data are incompatible!";
    00186     handleError( StkError::FUNCTION_ARGUMENT );
    00187   }
    00188 #endif
    00189
    00190   if ( finished_ ) return 0.0;
    00191   return lastFrame_[channel];
    00192 }

virtual StkFloat stk::FileWvIn::tick | ( | unsigned int | channel = `0` | ) | `[virtual]`

Compute a sample frame and return the specified `channel` value.

For multi-channel files, use the lastFrame() function to get all values from the computed frame. If no file data is loaded, the returned value is 0.0. The `channel` argument must be less than the number of channels in the file data (the first channel is specified by 0). However, range checking is only performed if _STK_DEBUG_ is defined during compilation, in which case an out-of-range value will trigger an StkError exception.

Implements stk::WvIn.

Reimplemented in stk::FileLoop.

virtual StkFrames& stk::FileWvIn::tick | ( | StkFrames & | frames | ) | `[virtual]`

Fill the StkFrames argument with computed frames and return the same reference.

The number of channels in the StkFrames argument must equal the number of channels in the file data. However, this is only checked if _STK_DEBUG_ is defined during compilation, in which case an incompatibility will trigger an StkError exception. If no file data is loaded, the function does nothing (a warning will be issued if _STK_DEBUG_ is defined during compilation).

Implements stk::WvIn.

Reimplemented in stk::FileLoop.

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

- FileWvIn.h

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