VibroSonics  v1.0.2-mozzi-implementation-309-gf5440e1
Arduino Library for Translating Audio into Vibrations
Loading...
Searching...
No Matches
Grain Class Reference

#include <Grain.h>

Public Member Functions

 Grain ()
 Default constructor to allocate a new grain.
 
 Grain (uint8_t channel, WaveType waveType)
 Overloaded constructor to allocate a new grain with specified channel and wave type.
 
void setAttack (float frequency, float amplitude, int duration)
 Updates grain parameters in the attack state.
 
void setDecay (float frequency, float amplitude, int duration)
 Updates grain parameters in the decay state.
 
void setSustain (float frequency, float amplitude, int duration)
 Updates grain parameters in the sustain state.
 
void setRelease (float frequency, float amplitude, int duration)
 Updates grain parameters in the release state.
 
void setChannel (uint8_t channel)
 Sets the channel of this grain.
 
void setWaveType (WaveType waveType)
 Sets grain wave type (SINE, COSINE, SQUARE, TRIANGLE, SAWTOOTH)
 
grainState getGrainState ()
 Returns the state of a grain (READY, ATTACK, DECAY, SUSTAIN, RELEASE)
 
void transitionTo (grainState newState)
 Helper function to perform necessary operations on grain parameters when transitioning between run states.
 
float getAmplitude ()
 Returns the current amplitude of the grain.
 
float getFrequency ()
 Returns the current frequency of the grain.
 
int getAttackDuration ()
 Returns the attack duration.
 
int getDecayDuration ()
 Returns the decay duration.
 
int getSustainDuration ()
 Returns the sustain duration.
 
int getReleaseDuration ()
 Returns the release duration.
 
void setFreqEnv (FreqEnv freqEnv)
 Sets grain parameters for the frequency envelope.
 
void setAmpEnv (AmpEnv ampEnv)
 Sets grain parameters for the amplitude envelope.
 
FreqEnv getFreqEnv ()
 Returns the frequncy envelope struct containing state data.
 
AmpEnv getAmpEnv ()
 Returns the amplitude envelope struct containing state data.
 
void printGrain ()
 For debugging: Prints a grain's state, frequency, and amplitude.
 

Public Attributes

bool isDynamic
 Flag to check if a grain is dynamic or static.
 
bool markedForDeletion
 Flag to check if a dynamic grain has finished triggering.
 

Friends

class GrainList
 

Detailed Description

This class creates and manages the Ready, Attack, Decay, Sustain, and Release states for individual grains. A grain is a very small segment of an audio sample, allowing for more granular synthesis and management of the waves that are outputted through VibroSonics hardware.

More information about grains and Attack Sustain Decay Release curves can be found at:

https://en.wikipedia.org/wiki/Granular_synthesis

https://en.wikipedia.org/wiki/Envelope_(music)

Constructor & Destructor Documentation

◆ Grain() [1/2]

Grain::Grain ( )

Default constructor to allocate a new grain.

Creates a grain on channel 0 and sine wave type in the ready state.

◆ Grain() [2/2]

Grain::Grain ( uint8_t channel,
WaveType waveType )

Overloaded constructor to allocate a new grain with specified channel and wave type.

Creates a grain on the specified channel and with the inputted wave type in the ready state.

Parameters
channelSpecified channel for output
waveTypeSpecified wave type for output

Member Function Documentation

◆ getAmpEnv()

AmpEnv Grain::getAmpEnv ( )

Returns the amplitude envelope struct containing state data.

◆ getAmplitude()

float Grain::getAmplitude ( )

Returns the current amplitude of the grain.

Returns the current amplitude of the grain

Returns
float

◆ getAttackDuration()

int Grain::getAttackDuration ( )

Returns the attack duration.

Returns the attack window duration

Returns
int

◆ getDecayDuration()

int Grain::getDecayDuration ( )

Returns the decay duration.

Returns the decay window duration

Returns
int

◆ getFreqEnv()

FreqEnv Grain::getFreqEnv ( )

Returns the frequncy envelope struct containing state data.

◆ getFrequency()

float Grain::getFrequency ( )

Returns the current frequency of the grain.

Returns the current frequency of the grain

Returns
float

◆ getGrainState()

grainState Grain::getGrainState ( )

Returns the state of a grain (READY, ATTACK, DECAY, SUSTAIN, RELEASE)

Returns the state of a grain (READY, ATTACK, DECAY, SUSTAIN, RELEASE)

Returns
grainState

◆ getReleaseDuration()

int Grain::getReleaseDuration ( )

Returns the release duration.

Returns the release window duration

Returns
int

◆ getSustainDuration()

int Grain::getSustainDuration ( )

Returns the sustain duration.

Returns the sustain window duration

Returns
int

◆ printGrain()

void Grain::printGrain ( )

For debugging: Prints a grain's state, frequency, and amplitude.

Prints grain debug info.

◆ setAmpEnv()

void Grain::setAmpEnv ( AmpEnv ampEnv)

Sets grain parameters for the amplitude envelope.

Sets state parameters based on the amplitude envelope passed in.

Parameters
freqEnvAmplitude envelope containing new data to update state parameters with.

◆ setAttack()

void Grain::setAttack ( float frequency,
float amplitude,
int duration )

Updates grain parameters in the attack state.

Updates frequency, amplitude, and duration. Also updates sustain frequency and amplitude difference.

Parameters
frequencyUpdated frequncy
amplitudeUpdated amplitude
durationUpdated duration

◆ setChannel()

void Grain::setChannel ( uint8_t channel)

Sets the channel of this grain.

Sets the channel of this grain

Parameters
channelThe channel on specified integer

◆ setDecay()

void Grain::setDecay ( float frequency,
float amplitude,
int duration )

Updates grain parameters in the decay state.

Updates frequency, amplitude, and duration for DECAY.

Parameters
frequencyUpdated frequncy
amplitudeUpdated amplitude
durationUpdated duration

◆ setFreqEnv()

void Grain::setFreqEnv ( FreqEnv freqEnv)

Sets grain parameters for the frequency envelope.

Sets state parameters based on the frequency envelope passed in.

Parameters
freqEnvFrequency envelope containing new data to update state parameters with.

◆ setRelease()

void Grain::setRelease ( float frequency,
float amplitude,
int duration )

Updates grain parameters in the release state.

Updates frequency, amplitude, and duration. Also updates attack and sustain frequency and amplitude difference.

Parameters
frequencyUpdated frequncy
amplitudeUpdated amplitude
durationUpdated duration

◆ setSustain()

void Grain::setSustain ( float frequency,
float amplitude,
int duration )

Updates grain parameters in the sustain state.

Updates frequency, amplitude, and duration. Also updates attack frequency and amplitude difference.

Parameters
frequencyUpdated frequncy
amplitudeUpdated amplitude
durationUpdated duration

◆ setWaveType()

void Grain::setWaveType ( WaveType waveType)

Sets grain wave type (SINE, COSINE, SQUARE, TRIANGLE, SAWTOOTH)

Sets grain wave type (SINE, COSINE, SQUARE, TRIANGLE, SAWTOOTH)

Parameters
waveTypeThe wave type

◆ transitionTo()

void Grain::transitionTo ( grainState newState)

Helper function to perform necessary operations on grain parameters when transitioning between run states.

Helper function for run. Handles skipped states and prepares Grain for the current window without leaving a 1 window gap between grain states.

Parameters
newStateState to transition to.

Friends And Related Symbol Documentation

◆ GrainList

friend class GrainList
friend

Member Data Documentation

◆ isDynamic

bool Grain::isDynamic

Flag to check if a grain is dynamic or static.

◆ markedForDeletion

bool Grain::markedForDeletion

Flag to check if a dynamic grain has finished triggering.


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