Krotos Modules 3
Loading...
Searching...
No Matches
krotos::GranularOscillator Class Reference

Generates sounds by decimating and reconstructing audio samples. More...

#include <GranularOscillator.h>

Inheritance diagram for krotos::GranularOscillator:
krotos::Oscillator

Public Types

enum  GranularParam {
  Start = 0 , StartRand , Size , SizeRand ,
  Rate , RateRand , Width , WidthRand ,
  Pan , PanRand , Detune , DetuneMod ,
  DetuneRand , Level , SamplerLevel , GranularLevel ,
  VehicleLevel , LevelMod , LevelRand , Quench ,
  Robin , SALoop , AutoRate , Autoplay ,
  Shape , GrainLim , Tracking , Cycles ,
  PhaseLock , PhaseSync , Normalise , MuteUp ,
  MuteDown , Smoothing , MovementSensitivity , SizeST ,
  DivST , SprayST , MixST , SizeDY ,
  DivDY , SprayDY , MixDY , Mute ,
  Solo , NUM_PARAMS
}
 

Public Member Functions

 GranularOscillator ()
 
 ~GranularOscillator () override
 
void setSampleRate (double sampleRate) override
 Sets the sample rate which the granular oscillator uses to calculate its output.
 
double getSampleRate () override
 Returns the sample rate which which you set with the setSampleRate method.
 
void setFrequency (float frequency) override
 Sets the target frequency which you want the oscillator to output.
 
float getFrequency () override
 Gets the target frequency which you set with the setFrequency method.
 
void setPhaseOffset (float) override
 
void reset () override
 
void setPhase (double) override
 
double getPhase () override
 
int getNumActiveGrains () override
 Returns the number of grains currently active for this instance of the oscillator.
 
StereoSample getNextStereoSample (size_t sampleIndex) override
 Updates the granular engine and returns the next audio value.
 
void setGranularParameter (size_t paramIndex, const float *newValue)
 Updates the granular engine and returns the next audio value.
 
void setGranularParameters (std::vector< const float * > &newParams)
 Sets multiple internal parameter to new values.
 
void setSampleData (SampleEngine *sampleEngine)
 Sets the oscillator's internal reference to the SampleEngine structure it is to use.
 
void startNote (int midiNote, float velocity, int voiceIndex)
 Starts the oscillator playing, usually called by key down event.
 
const float getVelocity ()
 Returns the value of the velocity as a float in [0...1].
 
void stopNote ()
 Signals the oscillator to begin key up behaviour, usually called by key up event The oscillator may continue playing if it is generating a tail.
 
void clearNote ()
 Signals the oscillator to stop immediately, and return any grains to pool.
 
- Public Member Functions inherited from krotos::Oscillator
virtual ~Oscillator ()=default
 

Private Member Functions

void setGranularOscillatorType (GranularPlaybackMode newType)
 
void flushGranular ()
 
float cube (float val)
 
void setTaggingType (bool isOn)
 
void setTrackingEnable (bool isOn)
 
void setLoopEnableFlag ()
 
void killNANs (StereoSample &sample)
 
GrainlaunchGrain (float paramSize, float paramStart, float paramSpray, Grain::Flavour flavour, float gain=-1.f)
 
double calculatePlayheadPosition (double startPosition, float halfSpray, float referenceGrainsize)
 
StereoSample getNextStereoGranularSamplePhaseLocked ()
 
StereoSample getNextStereoGranular ()
 
StereoSample getNextStereoSampler ()
 
void generateGrainsGranular (StereoSample &sampleAccumulator)
 
void generateGrainsSampler (StereoSample &sampleAccumulator)
 
void setGrainData (Grain *playingGrain)
 
void generateNewFluxFactor ()
 

Private Attributes

juce::Random m_rand {1234}
 
GranularPlaybackMode m_granularOscillatorType {GranularPlaybackMode::MGranular}
 
PhaseGenerator m_grainTimer
 
float m_playbackHz {0.0f}
 
float m_playbackHzDetuned {0.0f}
 
double m_samplerate {48000.0}
 
float m_fluxFactor {0.0f}
 
float m_grainRate {0.0f}
 
float m_startIndex {0.0f}
 
float m_startIndexSearched {0.0f}
 
AudioDescriptor m_closestDescriptor
 
SampleEnginem_sampleEngine {nullptr}
 
std::vector< Grain * > m_activeGrains
 
int m_length {0}
 
std::vector< const float * > m_parameters
 
bool m_stopped {false}
 
bool m_keyDown {false}
 
int m_voiceIndex {-1}
 
volatile float m_directionGating {0.f}
 
SlewLimiter m_channelCrossfade
 
SlewLimiter m_directionGatingSmoother
 
float m_crossfadeValue {0.f}
 
bool m_taggingType {false}
 
bool m_trackingEnable {false}
 
bool m_loopingEnable {false}
 
bool m_normalisationEnable {false}
 
size_t m_sampleIndex {0}
 
float m_velocity {1.0f}
 
bool m_allowAudiosegmentIncrement {false}
 
float m_detuneModVal {0.0f}
 
const float AMPLITUDE_FIDDLE_FACTOR {0.6f}
 
const float FADE_POINT_MIN {0.000001f}
 
bool m_isDrone {false}
 
bool m_autoplayEnabled {false}
 
const float PARAMETER_TRUE_THRESHOLD {0.5f}
 
const float FLUX_PARAM_SKEW {0.3f}
 
const float FLUX_SCALING_POSITIVE {6.0f}
 
const float FLUX_SCALING_NEGATIVE {1.5f}
 
const float RAMP_LENGTH_SECONDS {0.004f}
 
float m_rampSamples {0}
 
float m_rampInc {1.f}
 

Detailed Description

Generates sounds by decimating and reconstructing audio samples.

Member Enumeration Documentation

◆ GranularParam

Enumerates the parameters which are used to control generation of grains

Enumerator
Start 
StartRand 
Size 
SizeRand 
Rate 
RateRand 
Width 
WidthRand 
Pan 
PanRand 
Detune 
DetuneMod 
DetuneRand 
Level 
SamplerLevel 
GranularLevel 
VehicleLevel 
LevelMod 
LevelRand 
Quench 
Robin 
SALoop 
AutoRate 
Autoplay 
Shape 
GrainLim 
Tracking 
Cycles 
PhaseLock 
PhaseSync 
Normalise 
MuteUp 
MuteDown 
Smoothing 
MovementSensitivity 
SizeST 
DivST 
SprayST 
MixST 
SizeDY 
DivDY 
SprayDY 
MixDY 
Mute 
Solo 
NUM_PARAMS 

Constructor & Destructor Documentation

◆ GranularOscillator()

krotos::GranularOscillator::GranularOscillator ( )

GranularOscillator Constructor

◆ ~GranularOscillator()

krotos::GranularOscillator::~GranularOscillator ( )
inlineoverride

GranularOscillator Destructor

Member Function Documentation

◆ calculatePlayheadPosition()

double krotos::GranularOscillator::calculatePlayheadPosition ( double startPosition,
float halfSpray,
float referenceGrainsize )
private

◆ clearNote()

void krotos::GranularOscillator::clearNote ( )

Signals the oscillator to stop immediately, and return any grains to pool.

◆ cube()

float krotos::GranularOscillator::cube ( float val)
inlineprivate

◆ flushGranular()

void krotos::GranularOscillator::flushGranular ( )
private

◆ generateGrainsGranular()

void krotos::GranularOscillator::generateGrainsGranular ( StereoSample & sampleAccumulator)
private

Accumulates audio from all the playing grains

◆ generateGrainsSampler()

void krotos::GranularOscillator::generateGrainsSampler ( StereoSample & sampleAccumulator)
private

◆ generateNewFluxFactor()

void krotos::GranularOscillator::generateNewFluxFactor ( )
private

◆ getFrequency()

float krotos::GranularOscillator::getFrequency ( )
inlineoverridevirtual

Gets the target frequency which you set with the setFrequency method.

Returns
frequency Frequency in Hz

Implements krotos::Oscillator.

◆ getNextStereoGranular()

StereoSample krotos::GranularOscillator::getNextStereoGranular ( )
private

Returns the next stereo sample for Granular mode

◆ getNextStereoGranularSamplePhaseLocked()

StereoSample krotos::GranularOscillator::getNextStereoGranularSamplePhaseLocked ( )
inlineprivate

◆ getNextStereoSample()

StereoSample krotos::GranularOscillator::getNextStereoSample ( size_t sampleIndex)
inlineoverridevirtual

Updates the granular engine and returns the next audio value.

Returns
A stereo pair of samples

Implements krotos::Oscillator.

◆ getNextStereoSampler()

StereoSample krotos::GranularOscillator::getNextStereoSampler ( )
private

Returns the next stereo sample for Sampler mode

◆ getNumActiveGrains()

int krotos::GranularOscillator::getNumActiveGrains ( )
inlineoverridevirtual

Returns the number of grains currently active for this instance of the oscillator.

Returns
frequency Frequency in Hz

Reimplemented from krotos::Oscillator.

◆ getPhase()

double krotos::GranularOscillator::getPhase ( )
inlineoverridevirtual

Implements krotos::Oscillator.

◆ getSampleRate()

double krotos::GranularOscillator::getSampleRate ( )
inlineoverridevirtual

Returns the sample rate which which you set with the setSampleRate method.

Returns
Sample rate in Hz

Implements krotos::Oscillator.

◆ getVelocity()

const float krotos::GranularOscillator::getVelocity ( )

Returns the value of the velocity as a float in [0...1].

◆ killNANs()

void krotos::GranularOscillator::killNANs ( StereoSample & sample)
inlineprivate

◆ launchGrain()

Grain * krotos::GranularOscillator::launchGrain ( float paramSize,
float paramStart,
float paramSpray,
Grain::Flavour flavour,
float gain = -1.f )
private

◆ reset()

void krotos::GranularOscillator::reset ( )
inlineoverridevirtual

Resets the phase offset for PWM to 0

Implements krotos::Oscillator.

◆ setFrequency()

void krotos::GranularOscillator::setFrequency ( float frequency)
inlineoverridevirtual

Sets the target frequency which you want the oscillator to output.

Parameters
frequencyFrequency in Hz

Implements krotos::Oscillator.

◆ setGrainData()

void krotos::GranularOscillator::setGrainData ( Grain * playingGrain)
private

◆ setGranularOscillatorType()

void krotos::GranularOscillator::setGranularOscillatorType ( GranularPlaybackMode newType)
inlineprivate

◆ setGranularParameter()

void krotos::GranularOscillator::setGranularParameter ( size_t paramIndex,
const float * newValue )

Updates the granular engine and returns the next audio value.

Returns
A mono sample

Sets an internal parameter to a new value

Parameters
paramIndexThe index of the parameter (enum GranularParam)
newValueThe new value to set the parameter with

◆ setGranularParameters()

void krotos::GranularOscillator::setGranularParameters ( std::vector< const float * > & newParams)
inline

Sets multiple internal parameter to new values.

Parameters
newParamsA vector containing new parameters, must be ordered as in enum GranularParam

◆ setLoopEnableFlag()

void krotos::GranularOscillator::setLoopEnableFlag ( )
inlineprivate

Read the loop parameter and set the flag

◆ setPhase()

void krotos::GranularOscillator::setPhase ( double )
inlineoverridevirtual

Implements krotos::Oscillator.

◆ setPhaseOffset()

void krotos::GranularOscillator::setPhaseOffset ( float )
inlineoverridevirtual

The following overridden methods are interface methods which are not used in the granular oscillator at present

Implements krotos::Oscillator.

◆ setSampleData()

void krotos::GranularOscillator::setSampleData ( SampleEngine * sampleEngine)

Sets the oscillator's internal reference to the SampleEngine structure it is to use.

Parameters
sampleEnginePointer to an instance of SampleEngine

◆ setSampleRate()

void krotos::GranularOscillator::setSampleRate ( double sampleRate)
inlineoverridevirtual

Sets the sample rate which the granular oscillator uses to calculate its output.

The following overridden methods implement the Oscillator interface

Parameters
sampleRateSample rate in Hz

Implements krotos::Oscillator.

◆ setTaggingType()

void krotos::GranularOscillator::setTaggingType ( bool isOn)
inlineprivate

◆ setTrackingEnable()

void krotos::GranularOscillator::setTrackingEnable ( bool isOn)
inlineprivate

◆ startNote()

void krotos::GranularOscillator::startNote ( int midiNote,
float velocity,
int voiceIndex )

Starts the oscillator playing, usually called by key down event.

Parameters
velocityValue of velocity in [0...1]

◆ stopNote()

void krotos::GranularOscillator::stopNote ( )

Signals the oscillator to begin key up behaviour, usually called by key up event The oscillator may continue playing if it is generating a tail.

Member Data Documentation

◆ AMPLITUDE_FIDDLE_FACTOR

const float krotos::GranularOscillator::AMPLITUDE_FIDDLE_FACTOR {0.6f}
private

◆ FADE_POINT_MIN

const float krotos::GranularOscillator::FADE_POINT_MIN {0.000001f}
private

◆ FLUX_PARAM_SKEW

const float krotos::GranularOscillator::FLUX_PARAM_SKEW {0.3f}
private

◆ FLUX_SCALING_NEGATIVE

const float krotos::GranularOscillator::FLUX_SCALING_NEGATIVE {1.5f}
private

◆ FLUX_SCALING_POSITIVE

const float krotos::GranularOscillator::FLUX_SCALING_POSITIVE {6.0f}
private

◆ m_activeGrains

std::vector<Grain*> krotos::GranularOscillator::m_activeGrains
private

◆ m_allowAudiosegmentIncrement

bool krotos::GranularOscillator::m_allowAudiosegmentIncrement {false}
private

◆ m_autoplayEnabled

bool krotos::GranularOscillator::m_autoplayEnabled {false}
private

◆ m_channelCrossfade

SlewLimiter krotos::GranularOscillator::m_channelCrossfade
private

◆ m_closestDescriptor

AudioDescriptor krotos::GranularOscillator::m_closestDescriptor
private

◆ m_crossfadeValue

float krotos::GranularOscillator::m_crossfadeValue {0.f}
private

◆ m_detuneModVal

float krotos::GranularOscillator::m_detuneModVal {0.0f}
private

◆ m_directionGating

volatile float krotos::GranularOscillator::m_directionGating {0.f}
private

◆ m_directionGatingSmoother

SlewLimiter krotos::GranularOscillator::m_directionGatingSmoother
private

◆ m_fluxFactor

float krotos::GranularOscillator::m_fluxFactor {0.0f}
private

◆ m_grainRate

float krotos::GranularOscillator::m_grainRate {0.0f}
private

◆ m_grainTimer

PhaseGenerator krotos::GranularOscillator::m_grainTimer
private

◆ m_granularOscillatorType

GranularPlaybackMode krotos::GranularOscillator::m_granularOscillatorType {GranularPlaybackMode::MGranular}
private

◆ m_isDrone

bool krotos::GranularOscillator::m_isDrone {false}
private

◆ m_keyDown

bool krotos::GranularOscillator::m_keyDown {false}
private

◆ m_length

int krotos::GranularOscillator::m_length {0}
private

◆ m_loopingEnable

bool krotos::GranularOscillator::m_loopingEnable {false}
private

◆ m_normalisationEnable

bool krotos::GranularOscillator::m_normalisationEnable {false}
private

◆ m_parameters

std::vector<const float*> krotos::GranularOscillator::m_parameters
private

◆ m_playbackHz

float krotos::GranularOscillator::m_playbackHz {0.0f}
private

◆ m_playbackHzDetuned

float krotos::GranularOscillator::m_playbackHzDetuned {0.0f}
private

◆ m_rampInc

float krotos::GranularOscillator::m_rampInc {1.f}
private

◆ m_rampSamples

float krotos::GranularOscillator::m_rampSamples {0}
private

◆ m_rand

juce::Random krotos::GranularOscillator::m_rand {1234}
private

◆ m_sampleEngine

SampleEngine* krotos::GranularOscillator::m_sampleEngine {nullptr}
private

◆ m_sampleIndex

size_t krotos::GranularOscillator::m_sampleIndex {0}
private

◆ m_samplerate

double krotos::GranularOscillator::m_samplerate {48000.0}
private

◆ m_startIndex

float krotos::GranularOscillator::m_startIndex {0.0f}
private

◆ m_startIndexSearched

float krotos::GranularOscillator::m_startIndexSearched {0.0f}
private

◆ m_stopped

bool krotos::GranularOscillator::m_stopped {false}
private

◆ m_taggingType

bool krotos::GranularOscillator::m_taggingType {false}
private

◆ m_trackingEnable

bool krotos::GranularOscillator::m_trackingEnable {false}
private

◆ m_velocity

float krotos::GranularOscillator::m_velocity {1.0f}
private

◆ m_voiceIndex

int krotos::GranularOscillator::m_voiceIndex {-1}
private

◆ PARAMETER_TRUE_THRESHOLD

const float krotos::GranularOscillator::PARAMETER_TRUE_THRESHOLD {0.5f}
private

◆ RAMP_LENGTH_SECONDS

const float krotos::GranularOscillator::RAMP_LENGTH_SECONDS {0.004f}
private

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