Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

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

STK file looping / oscillator class. More...

`#include <FileLoop.h>`

Inheritance diagram for stk::FileLoop:

## 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, bool doInt2FloatScaling=true)
| Class constructor that opens a specified file.
| ~FileLoop (void)
| Class destructor.
void | openFile (std::string fileName, bool raw=false, bool doNormalize=true, bool doInt2FloatScaling=true)
| Open the specified file and load its data. More...
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. More...
void | normalize (StkFloat peak)
| Normalize data to a maximum of +-peak. More...
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). More...
void | setRate (StkFloat rate)
| Set the data read rate in samples. The rate can be negative. More...
void | setFrequency (StkFloat frequency)
| Set the data interpolation rate based on a looping frequency. More...
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. More...
void | addPhaseOffset (StkFloat angle)
| Add a phase offset to the current read pointer. More...
StkFloat | lastOut (unsigned int channel=0)
| Return the specified channel value of the last computed frame. More...
StkFloat | tick (unsigned int channel=0)
| Compute a sample frame and return the specified `channel` value. More...
virtual StkFrames & | tick (StkFrames &frames, unsigned int channel=0)
| Fill the StkFrames object with computed sample frames, starting at the specified channel and return the same reference. More...

## Additional Inherited Members
Protected Member Functions inherited from stk::FileWvIn
| 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, bool doInt2FloatScaling=true)
| Overloaded constructor for file input. More...
| ~FileWvIn (void)
| Class destructor.
bool | isOpen (void)
| Query whether a file is open.
bool | isFinished (void) const
| Query whether reading is complete.
void | setInterpolate (bool doInterpolate)
| Turn linear interpolation on/off. More...
StkFloat | lastOut (unsigned int channel=0)
| Return the specified channel value of the last computed frame. More...
Static Protected 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 Protected 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

## 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–2017.

## Member Function Documentation

void stk::FileLoop::openFile | ( | std::string | fileName,
|  | bool | raw = `false`,
|  | bool | doNormalize = `true`,
|  | bool | doInt2FloatScaling = `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 length is less than the chunkThreshold limit and doNormalize is true, the file data will be normalized with respect to the maximum absolute value of the data. If the doInt2FloatScaling flag is true and the input data is fixed-point, a scaling will be applied with respect to the fixed-point limits.

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.

67 { 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.

74 { 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.

85 { 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.

100 { this->setRate( 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.

131 { 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.

virtual StkFrames& stk::FileLoop::tick | ( | StkFrames & | frames,
|  | unsigned int | channel = `0`
| ) |  |
| virtual

Fill the StkFrames object with computed sample frames, starting at the specified channel and return the same reference.

The `channel` argument plus the number of output channels must be less than the number of channels in the StkFrames argument (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.

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

- FileLoop.h

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