The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# stk::FileLoop Class Reference

STK file looping / oscillator class. More...

`#include <FileLoop.h>`

Inheritance diagram for stk::FileLoop:

List of all members.

## Public Member Functions
| FileLoop (unsigned long chunkThreshold=1000000, unsigned long chunkSize=1024)
| Default constructor.
| FileLoop (std::string fileName, bool raw=false, bool doNormalize=true, unsigned long chunkThreshold=1000000, unsigned long chunkSize=1024)
| Class constructor that opens a specified file.
| ~FileLoop (void)
| Class destructor.
void | openFile (std::string fileName, bool raw=false, bool doNormalize=true)
| Open the specified file and load its data.
void | closeFile (void)
| Close a file if one is open.
void | reset (void)
| Clear outputs and reset time (file) pointer to zero.
unsigned int | channelsOut (void) const
| Return the number of audio channels in the data or stream.
void | normalize (void)
| Normalize data to a maximum of +-1.0.
void | normalize (StkFloat peak)
| Normalize data to a maximum of +-peak.
unsigned long | getSize (void) const
| Return the file size in sample frames.
StkFloat | getFileRate (void) const
| Return the input file sample rate in Hz (not the data read rate).
void | setRate (StkFloat rate)
| Set the data read rate in samples. The rate can be negative.
void | setFrequency (StkFloat frequency)
| Set the data interpolation rate based on a looping frequency.
void | addTime (StkFloat time)
| Increment the read pointer by time samples, modulo file size.
void | addPhase (StkFloat angle)
| Increment current read pointer by angle, relative to a looping frequency.
void | addPhaseOffset (StkFloat angle)
| Add a phase offset to the current read pointer.
StkFloat | lastOut (unsigned int channel=0)
| Return the specified channel value of the last computed frame.
StkFloat | tick (unsigned int channel=0)
| Compute a sample frame and return the specified `channel` value.
StkFrames & | tick (StkFrames &frames)
| Fill the StkFrames argument with computed frames and return the same reference.

## Detailed Description

STK file looping / oscillator class.

This class provides audio file looping functionality. Any audio file that can be loaded by FileRead can be looped using this class.

FileLoop 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.

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

## Member Function Documentation

void stk::FileLoop::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 from stk::FileWvIn.

void stk::FileLoop::normalize | ( | void |  | ) | `[inline, virtual]`

Normalize data to a maximum of +-1.0.

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

Reimplemented from stk::FileWvIn.

    00065 { FileWvIn::normalize( 1.0 ); };

void stk::FileLoop::normalize | ( | StkFloat | peak | ) | `[inline, virtual]`

Normalize data to a maximum of +-peak.

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

Reimplemented from stk::FileWvIn.

    00072 { FileWvIn::normalize( peak ); };

StkFloat stk::FileLoop::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 from stk::FileWvIn.

    00083 { return data_.dataRate(); };

void stk::FileLoop::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 from stk::FileWvIn.

void stk::FileLoop::setFrequency | ( | StkFloat | frequency | ) | `[inline]`

Set the data interpolation rate based on a looping frequency.

This function determines the interpolation rate based on the file size and the current Stk::sampleRate. The frequency value corresponds to file cycles per second. The frequency can be negative, in which case the loop is read in reverse order.

    00098 { this->setRate( file_.fileSize() * frequency / Stk::sampleRate() ); };

void stk::FileLoop::addPhase | ( | StkFloat | angle | ) |

Increment current read pointer by angle, relative to a looping frequency.

This function increments the read pointer based on the file size and the current Stk::sampleRate. The anAngle value is a multiple of file size.

void stk::FileLoop::addPhaseOffset | ( | StkFloat | angle | ) |

Add a phase offset to the current read pointer.

This function determines a time offset based on the file size and the current Stk::sampleRate. The angle value is a multiple of file size.

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

Return the specified channel value of the last computed frame.

For multi-channel files, use the lastFrame() function to get all values from the last 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.

Reimplemented from stk::FileWvIn.

    00129 { return FileWvIn::lastOut( channel ); };

StkFloat stk::FileLoop::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.

Reimplemented from stk::FileWvIn.

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

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

The number of channels in the StkFrames argument should 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 and Stk::showWarnings() has been set to true).

Reimplemented from stk::FileWvIn.

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

- FileLoop.h

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