VibroSonics
v1.0.2-mozzi-implementation-309-gf5440e1
Arduino Library for Translating Audio into Vibrations
|
#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 |
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:
Grain::Grain | ( | ) |
Default constructor to allocate a new grain.
Creates a grain on channel 0 and sine wave type in the ready state.
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.
channel | Specified channel for output |
waveType | Specified wave type for output |
AmpEnv Grain::getAmpEnv | ( | ) |
Returns the amplitude envelope struct containing state data.
float Grain::getAmplitude | ( | ) |
Returns the current amplitude of the grain.
Returns the current amplitude of the grain
int Grain::getAttackDuration | ( | ) |
Returns the attack duration.
Returns the attack window duration
int Grain::getDecayDuration | ( | ) |
Returns the decay duration.
Returns the decay window duration
FreqEnv Grain::getFreqEnv | ( | ) |
Returns the frequncy envelope struct containing state data.
float Grain::getFrequency | ( | ) |
Returns the current frequency of the grain.
Returns the current frequency of the grain
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)
int Grain::getReleaseDuration | ( | ) |
Returns the release duration.
Returns the release window duration
int Grain::getSustainDuration | ( | ) |
Returns the sustain duration.
Returns the sustain window duration
void Grain::printGrain | ( | ) |
For debugging: Prints a grain's state, frequency, and amplitude.
Prints grain debug info.
void Grain::setAmpEnv | ( | AmpEnv | ampEnv | ) |
Sets grain parameters for the amplitude envelope.
Sets state parameters based on the amplitude envelope passed in.
freqEnv | Amplitude envelope containing new data to update state parameters with. |
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.
frequency | Updated frequncy |
amplitude | Updated amplitude |
duration | Updated duration |
void Grain::setChannel | ( | uint8_t | channel | ) |
Sets the channel of this grain.
Sets the channel of this grain
channel | The channel on specified integer |
void Grain::setDecay | ( | float | frequency, |
float | amplitude, | ||
int | duration ) |
Updates grain parameters in the decay state.
Updates frequency, amplitude, and duration for DECAY.
frequency | Updated frequncy |
amplitude | Updated amplitude |
duration | Updated duration |
void Grain::setFreqEnv | ( | FreqEnv | freqEnv | ) |
Sets grain parameters for the frequency envelope.
Sets state parameters based on the frequency envelope passed in.
freqEnv | Frequency envelope containing new data to update state parameters with. |
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.
frequency | Updated frequncy |
amplitude | Updated amplitude |
duration | Updated duration |
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.
frequency | Updated frequncy |
amplitude | Updated amplitude |
duration | Updated duration |
void Grain::setWaveType | ( | WaveType | waveType | ) |
Sets grain wave type (SINE, COSINE, SQUARE, TRIANGLE, SAWTOOTH)
Sets grain wave type (SINE, COSINE, SQUARE, TRIANGLE, SAWTOOTH)
waveType | The wave type |
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.
newState | State to transition to. |
|
friend |
bool Grain::isDynamic |
Flag to check if a grain is dynamic or static.
bool Grain::markedForDeletion |
Flag to check if a dynamic grain has finished triggering.