Arduino STK
4.6.2
|
STK granular synthesis class. More...
#include <Granulate.h>
Public Member Functions | |
Granulate (void) | |
Default constructor. | |
Granulate (unsigned int nVoices, std::string fileName, bool typeRaw=false) | |
Constructor taking input audio file and number of voices arguments. | |
~Granulate (void) | |
Class destructor. | |
void | openFile (std::string fileName, bool typeRaw=false) |
Load a monophonic soundfile to be "granulated". More... | |
void | reset (void) |
Reset the file pointer and all existing grains to the file start. More... | |
void | setVoices (unsigned int nVoices=1) |
Set the number of simultaneous grain "voices" to use. More... | |
void | setStretch (unsigned int stretchFactor=1) |
Set the stretch factor used for grain playback (1 - 1000). More... | |
void | setGrainParameters (unsigned int duration=30, unsigned int rampPercent=50, int offset=0, unsigned int delay=0) |
Set global grain parameters used to determine individual grain settings. More... | |
void | setRandomFactor (StkFloat randomness=0.1) |
This factor is used when setting individual grain parameters (0.0 - 1.0). 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 one sample frame and return the specified channel value. | |
StkFrames & | tick (StkFrames &frames, unsigned int channel=0) |
Fill the StkFrames object with computed sample frames, starting at the specified channel. More... | |
unsigned int | channelsOut (void) const |
Return the number of output channels for the class. | |
const StkFrames & | lastFrame (void) const |
Return an StkFrames reference to the last output sample frame. | |
void | ignoreSampleRateChange (bool ignore=true) |
A function to enable/disable the automatic updating of class data when the STK sample rate changes. More... | |
Static Public 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 Public 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 |
Protected Member Functions | |
void | handleError (StkError::Type type) const |
Internal function for error reporting that assumes message in oStream_ variable. | |
virtual void | sampleRateChanged (StkFloat newRate, StkFloat oldRate) |
This function should be implemented in subclasses that depend on the sample rate. | |
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. | |
STK granular synthesis class.
This class implements a real-time granular synthesis algorithm that operates on an input soundfile. Multi-channel files are supported. Various functions are provided to allow control over voice and grain parameters.
The functionality of this class is based on the program MacPod by Chris Rolfe and Damian Keller, though there are likely to be a number of differences in the actual implementation.
by Gary Scavone, 2005–2019.
void stk::Granulate::openFile | ( | std::string | fileName, |
bool | typeRaw = false |
||
) |
Load a monophonic soundfile to be "granulated".
An StkError will be thrown if the file is not found, its format is unknown or unsupported, or the file has more than one channel.
void stk::Granulate::reset | ( | void | ) |
Reset the file pointer and all existing grains to the file start.
Multiple grains are offset from one another in time by grain duration / nVoices.
void stk::Granulate::setVoices | ( | unsigned int | nVoices = 1 | ) |
Set the number of simultaneous grain "voices" to use.
Multiple grains are offset from one another in time by grain duration / nVoices. For this reason, it is best to set the grain parameters before calling this function (during initialization).
void stk::Granulate::setStretch | ( | unsigned int | stretchFactor = 1 | ) |
Set the stretch factor used for grain playback (1 - 1000).
Granular synthesis allows for time-stetching without affecting the original pitch of a sound. A stretch factor of 4 will produce a resulting sound of length 4 times the orignal sound. The default parameter of 1 produces no stretching.
void stk::Granulate::setGrainParameters | ( | unsigned int | duration = 30 , |
unsigned int | rampPercent = 50 , |
||
int | offset = 0 , |
||
unsigned int | delay = 0 |
||
) |
Set global grain parameters used to determine individual grain settings.
Each grain is defined as having a length of duration milliseconds which must be greater than zero. For values of rampPercent (0 - 100) greater than zero, a linear envelope will be applied to each grain. If rampPercent = 100, the resultant grain "window" is triangular while rampPercent = 50 produces a trapezoidal window. In addition, each grain can have a time delay of length delay and a grain pointer increment of length offset, which can be negative, before the next ramp onset (in milliseconds). The offset parameter controls grain pointer jumps between enveloped grain segments, while the delay parameter causes grain calculations to pause between grains. The actual values calculated for each grain will be randomized by a factor set using the setRandomFactor() function.
void stk::Granulate::setRandomFactor | ( | StkFloat | randomness = 0.1 | ) |
This factor is used when setting individual grain parameters (0.0 - 1.0).
This random factor is applied when all grain state durations are calculated. If set to 0.0, no randomness occurs. When randomness = 1.0, a grain segment of length duration will be randomly augmented by up to +- duration seconds (i.e., a 30 millisecond length will be augmented by an extra length of up to +30 or -30 milliseconds).
|
inline |
Return the specified channel value of the last computed frame.
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.
Fill the StkFrames object with computed sample frames, starting at the specified channel.
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.
Implements stk::Generator.
|
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.
|
inlineinherited |
|
staticinherited |
-128 to +127
|
staticinherited |
-32768 to +32767
|
staticinherited |
Lower 3 bytes of 32-bit signed integer.
|
staticinherited |
-2147483648 to +2147483647.
|
staticinherited |
Normalized between plus/minus 1.0.
|
staticinherited |
Normalized between plus/minus 1.0.