Arduino STK  4.6.2
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Static Protected Attributes | List of all members
stk::MemoryLoop Class Reference

STK looping / oscillator class using a simple memory array as input. More...

#include <MemoryLoop.h>

Inheritance diagram for stk::MemoryLoop:
stk::FileLoop stk::FileWvIn stk::WvIn stk::Stk

Public Member Functions

 MemoryLoop (unsigned long chunkSize=256)
 Default constructor.
 
 MemoryLoop (const char *fileName, const unsigned char *data, size_t size, unsigned long chunkSize=256)
 Class constructor that opens a specified file.
 
 MemoryLoop (const char *fileName, unsigned long chunkSize=256)
 Class constructor that opens a specified file. The file must have been registered.
 
 MemoryLoop (MemoryFS *data, unsigned long chunkSize=256)
 Class constructor that uses a MemoryFS.
 
 ~MemoryLoop (void)
 Class destructor.
 
virtual void openFile (std::string fileName, bool raw=true, bool doNormalize=true, bool doInt2FloatScaling=true)
 Open the specified file and load its data. More...
 
virtual void openFile (const char *fileName, bool raw=true, bool doNormalize=true, bool doInt2FloatScaling=true)
 Open the specified file and load its data. More...
 
void addPhaseOffset (StkFloat angle)
 Add a phase offset to the current read pointer. More...
 
void closeFile (void)
 Close the actual file. More...
 
bool isOpen (void)
 Query whether a file is open. More...
 
StkFloat getFileRate (void)
 Return the input file sample rate in Hz (not the data read rate). More...
 
virtual 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...
 
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 StkFramestick (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...
 

Protected Member Functions

virtual bool isFinished (void) const
 Query whether reading is complete.
 
void setInterpolate (bool doInterpolate)
 Turn linear interpolation on/off. More...
 
const StkFrameslastFrame (void) const
 Return an StkFrames reference to the last computed sample frame. More...
 
void ignoreSampleRateChange (bool ignore=true)
 A function to enable/disable the automatic updating of class data when the STK sample rate changes. More...
 
void handleError (StkError::Type type) const
 Internal function for error reporting that assumes message in oStream_ variable.
 
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.
 

Static Protected Member Functions

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

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 looping / oscillator class using a simple memory array as input.

A 'virtual' file can be registered so that a fileOpen call with a file name is working like in the corresponding FileWvIn class

This is basically a simplified version of the FileLoop

Phil Schatzmann

Member Function Documentation

◆ openFile() [1/2]

virtual void stk::MemoryLoop::openFile ( std::string  fileName,
bool  raw = true,
bool  doNormalize = true,
bool  doInt2FloatScaling = true 
)
virtual

Open the specified file and load its data.

This method is provided to be compatible with the FileWvIn

Reimplemented from stk::FileLoop.

◆ openFile() [2/2]

virtual void stk::MemoryLoop::openFile ( const char *  fileName,
bool  raw = true,
bool  doNormalize = true,
bool  doInt2FloatScaling = true 
)
virtual

Open the specified file and load its data.

This method is provided to be compatible with the FileWvIn

◆ addPhaseOffset()

void stk::MemoryLoop::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.

◆ closeFile()

void stk::MemoryLoop::closeFile ( void  )
virtual

Close the actual file.

This method is provided to be compatible with the FileWvIn

Reimplemented from stk::FileLoop.

◆ isOpen()

bool stk::MemoryLoop::isOpen ( void  )
virtual

Query whether a file is open.

This does not have any importance since the data is available in the memory anyhow.

Reimplemented from stk::FileWvIn.

◆ getFileRate() [1/2]

StkFloat stk::MemoryLoop::getFileRate ( void  )

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

STK RAW files have a sample rate of 22050 Hz

◆ normalize() [1/2]

void stk::FileLoop::normalize ( void  )
inlinevirtualinherited

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 ); };
virtual void normalize(void)
Normalize data to a maximum of +-1.0.

◆ normalize() [2/2]

void stk::FileLoop::normalize ( StkFloat  peak)
inlinevirtualinherited

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 ); };

◆ getFileRate() [2/2]

StkFloat stk::FileLoop::getFileRate ( void  ) const
inlinevirtualinherited

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.

86 { return data_.dataRate(); };
StkFloat dataRate(void) const
Return the sample rate associated with the StkFrames data.
Definition: Stk.h:432

◆ setRate()

void stk::FileLoop::setRate ( StkFloat  rate)
virtualinherited

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.

◆ setFrequency()

void stk::FileLoop::setFrequency ( StkFloat  frequency)
inlineinherited

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.

101 { this->setRate( fileSize_ * frequency / Stk::sampleRate() ); };
void setRate(StkFloat rate)
Set the data read rate in samples. The rate can be negative.
static StkFloat sampleRate(void)
Static method that returns the current STK sample rate.
Definition: Stk.h:156

◆ addPhase()

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

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.

◆ lastOut()

StkFloat stk::FileLoop::lastOut ( unsigned int  channel = 0)
inlineinherited

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.

132 { return FileWvIn::lastOut( channel ); };
StkFloat lastOut(unsigned int channel=0)
Return the specified channel value of the last computed frame.
Definition: FileWvIn.h:194

◆ tick() [1/2]

StkFloat stk::FileLoop::tick ( unsigned int  channel = 0)
virtualinherited

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.

◆ tick() [2/2]

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

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.

◆ setInterpolate()

void stk::FileWvIn::setInterpolate ( bool  doInterpolate)
inlineinherited

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.

139 { interpolate_ = doInterpolate; };

◆ lastFrame()

const StkFrames& stk::WvIn::lastFrame ( void  ) const
inlineinherited

Return an StkFrames reference to the last computed sample frame.

If no file data is loaded, an empty container is returned.

29 { return lastFrame_; };

◆ setSampleRate()

static void stk::Stk::setSampleRate ( StkFloat  rate)
staticinherited

Static method that sets the STK sample rate.

The sample rate set using this method is queried by all STK classes that depend on its value. It is initialized to the default SRATE set in Stk.h. Many STK classes use the sample rate during instantiation. Therefore, if you wish to use a rate that is different from the default rate, it is imperative that it be set BEFORE STK objects are instantiated. A few classes that make use of the global STK sample rate are automatically notified when the rate changes so that internal class data can be appropriately updated. However, this has not been fully implemented. Specifically, classes that appropriately update their own data when either a setFrequency() or noteOn() function is called do not currently receive the automatic notification of rate change. If the user wants a specific class instance to ignore such notifications, perhaps in a multi-rate context, the function Stk::ignoreSampleRateChange() should be called.

◆ ignoreSampleRateChange()

void stk::Stk::ignoreSampleRateChange ( bool  ignore = true)
inlineinherited

A function to enable/disable the automatic updating of class data when the STK sample rate changes.

This function allows the user to enable or disable class data updates in response to global sample rate changes on a class by class basis.

184 { ignoreSampleRateChange_ = ignore; };

Member Data Documentation

◆ STK_SINT8

const StkFormat stk::Stk::STK_SINT8
staticinherited

-128 to +127

◆ STK_SINT16

const StkFormat stk::Stk::STK_SINT16
staticinherited

-32768 to +32767

◆ STK_SINT24

const StkFormat stk::Stk::STK_SINT24
staticinherited

Lower 3 bytes of 32-bit signed integer.

◆ STK_SINT32

const StkFormat stk::Stk::STK_SINT32
staticinherited

-2147483648 to +2147483647.

◆ STK_FLOAT32

const StkFormat stk::Stk::STK_FLOAT32
staticinherited

Normalized between plus/minus 1.0.

◆ STK_FLOAT64

const StkFormat stk::Stk::STK_FLOAT64
staticinherited

Normalized between plus/minus 1.0.


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