Xeno-rat
Loading...
Searching...
No Matches
NAudio.Dsp.EnvelopeGenerator Class Reference

Envelope generator (ADSR) More...

Collaboration diagram for NAudio.Dsp.EnvelopeGenerator:

Public Types

enum  EnvelopeState {
  Idle = 0 , Attack , Decay , Sustain ,
  Release
}
 Envelope State. More...
 

Public Member Functions

 EnvelopeGenerator ()
 Creates and Initializes an Envelope Generator.
 
float Process ()
 Processes the envelope state and returns the output value.
 
void Gate (bool gate)
 Sets the envelope state based on the gate condition.
 
void Reset ()
 Resets the state of the envelope and sets the output to 0.0f.
 
float GetOutput ()
 Gets the output value.
 

Properties

float AttackRate [get, set]
 Attack Rate (seconds * SamplesPerSecond)
 
float DecayRate [get, set]
 Decay Rate (seconds * SamplesPerSecond)
 
float ReleaseRate [get, set]
 Release Rate (seconds * SamplesPerSecond)
 
float SustainLevel [get, set]
 Sustain Level (1 = 100%)
 
EnvelopeState State [get]
 Current envelope state.
 

Private Member Functions

void SetTargetRatioAttack (float targetRatio)
 Sets the target ratio for attack and updates the attack base.
 
void SetTargetRatioDecayRelease (float targetRatio)
 Sets the target ratio for decay and release and calculates the decay and release bases.
 

Static Private Member Functions

static float CalcCoef (float rate, float targetRatio)
 Calculates the coefficient using the given rate and target ratio and returns the result.
 

Private Attributes

EnvelopeState state
 
float output
 
float attackRate
 
float decayRate
 
float releaseRate
 
float attackCoef
 
float decayCoef
 
float releaseCoef
 
float sustainLevel
 
float targetRatioAttack
 
float targetRatioDecayRelease
 
float attackBase
 
float decayBase
 
float releaseBase
 

Detailed Description

Envelope generator (ADSR)

Member Enumeration Documentation

◆ EnvelopeState

Envelope State.

Enumerator
Idle 

Idle.

Attack 

Attack.

Decay 

Decay.

Sustain 

Sustain.

Release 

Release.

Constructor & Destructor Documentation

◆ EnvelopeGenerator()

NAudio.Dsp.EnvelopeGenerator.EnvelopeGenerator ( )
inline

Creates and Initializes an Envelope Generator.

Here is the call graph for this function:

Member Function Documentation

◆ CalcCoef()

static float NAudio.Dsp.EnvelopeGenerator.CalcCoef ( float rate,
float targetRatio )
inlinestaticprivate

Calculates the coefficient using the given rate and target ratio and returns the result.

Parameters
rateThe rate used in the calculation.
targetRatioThe target ratio used in the calculation.
Returns
The calculated coefficient based on the provided rate and targetRatio .

This method calculates the coefficient using the formula: coefficient = (float)Math.Exp(-Math.Log((1.0f + targetRatio) / targetRatio) / rate).

◆ Gate()

void NAudio.Dsp.EnvelopeGenerator.Gate ( bool gate)
inline

Sets the envelope state based on the gate condition.

Parameters
gateThe condition to set the envelope state. If true, sets the state to EnvelopeState.Attack; otherwise, sets the state to EnvelopeState.Release if the current state is not EnvelopeState.Idle.

This method sets the envelope state based on the gate condition. If the gate is true, it sets the state to attack. If the gate is false and the current state is not idle, it sets the state to release.

Here is the caller graph for this function:

◆ GetOutput()

float NAudio.Dsp.EnvelopeGenerator.GetOutput ( )
inline

Gets the output value.

Returns
The output value.

◆ Process()

float NAudio.Dsp.EnvelopeGenerator.Process ( )
inline

Processes the envelope state and returns the output value.

Returns
The output value after processing the envelope state.

This method processes the envelope state based on the current state and coefficients for attack, decay, sustain, and release. It updates the output value according to the state transitions and coefficient calculations. The method returns the final output value after processing the envelope state.

Here is the caller graph for this function:

◆ Reset()

void NAudio.Dsp.EnvelopeGenerator.Reset ( )
inline

Resets the state of the envelope and sets the output to 0.0f.

Here is the caller graph for this function:

◆ SetTargetRatioAttack()

void NAudio.Dsp.EnvelopeGenerator.SetTargetRatioAttack ( float targetRatio)
inlineprivate

Sets the target ratio for attack and updates the attack base.

Parameters
targetRatioThe target ratio for attack.

If the targetRatio is less than 0.000000001f, it is set to 0.000000001f (-180 dB). The targetRatio is then assigned to targetRatioAttack and the attackBase is updated using the formula: (1.0f + targetRatioAttack) * (1.0f - attackCoef).

Here is the caller graph for this function:

◆ SetTargetRatioDecayRelease()

void NAudio.Dsp.EnvelopeGenerator.SetTargetRatioDecayRelease ( float targetRatio)
inlineprivate

Sets the target ratio for decay and release and calculates the decay and release bases.

Parameters
targetRatioThe target ratio for decay and release.

If the targetRatio is less than 0.000000001f, it is set to 0.000000001f (-180 dB). The decay base is calculated as (sustainLevel - targetRatioDecayRelease) * (1.0f - decayCoef). The release base is calculated as -targetRatioDecayRelease * (1.0f - releaseCoef).

Here is the caller graph for this function:

Member Data Documentation

◆ attackBase

float NAudio.Dsp.EnvelopeGenerator.attackBase
private

◆ attackCoef

float NAudio.Dsp.EnvelopeGenerator.attackCoef
private

◆ attackRate

float NAudio.Dsp.EnvelopeGenerator.attackRate
private

◆ decayBase

float NAudio.Dsp.EnvelopeGenerator.decayBase
private

◆ decayCoef

float NAudio.Dsp.EnvelopeGenerator.decayCoef
private

◆ decayRate

float NAudio.Dsp.EnvelopeGenerator.decayRate
private

◆ output

float NAudio.Dsp.EnvelopeGenerator.output
private

◆ releaseBase

float NAudio.Dsp.EnvelopeGenerator.releaseBase
private

◆ releaseCoef

float NAudio.Dsp.EnvelopeGenerator.releaseCoef
private

◆ releaseRate

float NAudio.Dsp.EnvelopeGenerator.releaseRate
private

◆ state

EnvelopeState NAudio.Dsp.EnvelopeGenerator.state
private

◆ sustainLevel

float NAudio.Dsp.EnvelopeGenerator.sustainLevel
private

◆ targetRatioAttack

float NAudio.Dsp.EnvelopeGenerator.targetRatioAttack
private

◆ targetRatioDecayRelease

float NAudio.Dsp.EnvelopeGenerator.targetRatioDecayRelease
private

Property Documentation

◆ AttackRate

float NAudio.Dsp.EnvelopeGenerator.AttackRate
getset

Attack Rate (seconds * SamplesPerSecond)

◆ DecayRate

float NAudio.Dsp.EnvelopeGenerator.DecayRate
getset

Decay Rate (seconds * SamplesPerSecond)

◆ ReleaseRate

float NAudio.Dsp.EnvelopeGenerator.ReleaseRate
getset

Release Rate (seconds * SamplesPerSecond)

◆ State

EnvelopeState NAudio.Dsp.EnvelopeGenerator.State
get

Current envelope state.

◆ SustainLevel

float NAudio.Dsp.EnvelopeGenerator.SustainLevel
getset

Sustain Level (1 = 100%)


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