Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


stk::Granulate Class Reference

STK granular synthesis class. More...

#include <Granulate.h>

Inheritance diagram for stk::Granulate:
stk::Generator stk::Stk

List of all members.

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".
void reset (void)
 Reset the file pointer and all existing grains to the file start.
void setVoices (unsigned int nVoices=1)
 Set the number of simultaneous grain "voices" to use.
void setStretch (unsigned int stretchFactor=1)
 Set the stretch factor used for grain playback (1 - 1000).
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.
void setRandomFactor (StkFloat randomness=0.1)
 This factor is used when setting individual grain parameters (0.0 - 1.0).
StkFloat lastOut (unsigned int channel=0)
 Return the specified channel value of the last computed frame.
StkFloat tick (unsigned int channel=0)
 Compute one sample frame and return the specified channel value.
StkFramestick (StkFrames &frames, unsigned int channel=0)
 Fill the StkFrames object with computed sample frames, starting at the specified channel.

Detailed Description

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


Member Function Documentation

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

StkFloat stk::Granulate::lastOut ( unsigned int  channel = 0  )  [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.

See also:
lastFrame()

00175 {
00176 #if defined(_STK_DEBUG_)
00177   if ( channel >= lastFrame_.channels() ) {
00178     oStream_ << "Granulate::lastOut(): channel argument is invalid!";
00179     handleError( StkError::FUNCTION_ARGUMENT );
00180   }
00181 #endif
00182 
00183   return lastFrame_[channel];
00184 }

StkFrames & stk::Granulate::tick ( StkFrames frames,
unsigned int  channel = 0 
) [inline, virtual]

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.

00187 {
00188   unsigned int nChannels = lastFrame_.channels();
00189 #if defined(_STK_DEBUG_)
00190   if ( channel > frames.channels() - nChannels ) {
00191     oStream_ << "Granulate::tick(): channel and StkFrames arguments are incompatible!";
00192     handleError( StkError::FUNCTION_ARGUMENT );
00193   }
00194 #endif
00195 
00196   StkFloat *samples = &frames[channel];
00197   unsigned int j, hop = frames.channels() - nChannels;
00198   for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
00199     *samples++ = tick();
00200     for ( j=1; j<nChannels; j++ )
00201       *samples++ = lastFrame_[j];
00202   }
00203 
00204   return frames;
00205 }


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

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