Code: Select all
env = rt * env + (1 - at) * ((fabs - env > 0) ? fbs - env : 0)
Code: Select all
If fabs - env > 0
env = (rt * env + (1 - at)) * (fabs - env)
Else
env = 0
EndIf
Code: Select all
env = rt * env + (1 - at) * ((fabs - env > 0) ? fbs - env : 0)
Code: Select all
If fabs - env > 0
env = (rt * env + (1 - at)) * (fabs - env)
Else
env = 0
EndIf
Code: Select all
If fabs - env > 0
env = rt * env + (1 - at) * (fabs - env)
Else
env = rt * env
EndIf
Code: Select all
((fabs - env > 0) ? fabs - env : 0)
Code: Select all
typedef struct {
double samplerate_; // sample rate(Hz) 48000
double attackTime_; // attack time(seconds) 0.05
double releaseTime_; // release time(seconds)0.02
double holdTime_; // hold time(second) 0.0003
double threshold_; // threshold_(dB) -24
//======
double holdTimeCount; // hold time count (points)
double linearThreshold; // linear threshold
double at; // attack time smoothing coefficient
double rt; // release time smoothing coefficient
double attactCounter = 0; // hold counter for attack time
double releaseCounter = 0; // hold counter for release time
double x_env = 0;
double gca = 0;
double gs[2] = { 0 };
}
NoiseGate_t;
NoiseGate_t* newNoiesGate() {
NoiseGate_t* obj = (NoiseGate_t*)malloc(sizeof(NoiseGate_t));
memset(obj, 0, sizeof(NoiseGate_t));
if (!obj)
{
return NULL;
}
return obj;
}
void setNoiseGate(NoiseGate_t* obj,float attackTime, float releaseTime, float threshold,float holdTime,float samplerate) {
// samplerate sample rate (Hz) 48000
// attackTime attack time (seconds) 0.05
// releaseTime release time (seconds) 0.02
// holdTime hold time (second) 0.0003
// threshold threshold (dB) -24
obj->attackTime_ = attackTime;
obj->releaseTime_ = releaseTime;
obj->threshold_ = threshold;
obj->samplerate_ = samplerate;
obj->holdTime_ = holdTime;
obj->holdTimeCount = obj->holdTime_ * obj->samplerate_;
obj->linearThreshold = powf(10.0f, obj->threshold_ / 20.0f);
obj->at = exp(-logf(9) / (obj->samplerate_ * obj->attackTime_));
obj->rt = exp(-logf(9) / (obj->samplerate_ * obj->releaseTime_));
}
NoiseGate_t* createNoiseGate(float attackTime, float releaseTime, float threshold, float samplerate) {
NoiseGate_t* obj = newNoiesGate();
if (!obj) {
return NULL;
}
setNoiseGate(obj, attackTime, releaseTime, threshold, 0.0003,samplerate);
return obj;
}
float runNoiseGate( NoiseGate_t* obj, float in,float& out) {
double x_abs = in > 0? in : -in;
// envelop detector at = 0.02;rt = 0.01; 0.9977 = exp(-log(9) / (samplerate * 0.02));
//obj->x_env = 0.9977 * obj->x_env + (1 - 0.9553) * ((x_abs - obj->x_env > 0) ? x_abs - obj->x_env : 0);
obj->x_env = obj->rt * obj->x_env + (1 - obj->at) * ((x_abs - obj->x_env > 0) ? x_abs - obj->x_env : 0);
if (obj->x_env < obj->linearThreshold)
{
obj->gca = 0;
}
else
{
obj->gca = 1;
}
if (obj->gca < obj->gs[0])
{
// attack mode
obj->releaseCounter = 0;
if (++obj->attactCounter < obj->holdTimeCount)
{
// hold mode
obj->gs[0] = obj->gs[1];
}
else
{
obj->gs[0] = obj->at * obj->gs[1] + (1 - obj->at) * obj->gca;
}
obj->gs[1] = obj->gs[0];
}
else {
// release mode
obj->attactCounter = 0;
if (++obj->releaseCounter < obj->holdTimeCount)
{
// hold mode
obj->gs[0] = obj->gs[1];
}
else
{
obj->gs[0] = obj->rt * obj->gs[1] + (1 - obj->rt) * obj->gca;
}
obj->gs[1] = obj->gs[0];
}
// apply gain
out = obj->gs[0] * in;
return (obj->gs[0] * in);
}
int freeNoiseGate(NoiseGate_t* obj) {
if (!obj)
{
return -1;
}
free(obj);
return 0;
}
Code: Select all
Structure noisegate
samplerate.f; // sample rate(Hz) 48000
attackTime.f; // attack time(seconds) 0.05
releaseTime.f; // release time(seconds)0.02
holdTime.f; // hold time(second) 0.0003
threshold.f; // threshold_(dB) -24
;//======
holdTimeCount.f; // hold time count (points)
linearThreshold.f; // linear threshold
at.f; // attack time smoothing coefficient
rt.f; // release time smoothing coefficient
attactCounter.f; = 0; // hold counter for attack time
releaseCounter.f; = 0; // hold counter for release time
x_env.f; = 0;
gca.f; = 0;
gs.f[2]; = { 0 };
EndStructure
Procedure setNoiseGate(*obj.noisegate, attackTime.f, releaseTime.f, threshold.f, holdTime.f, samplerate.f)
*obj\attackTime = attackTime
*obj\releaseTime = releaseTime
*obj\threshold = threshold
*obj\samplerate = samplerate
*obj\holdTime = holdTime
*obj\holdTimeCount = *obj\holdTime * *obj\samplerate
*obj\linearThreshold = Pow(10.0, *obj\threshold / 20.0)
*obj\at = Exp(-Log(9) / (*obj\samplerate * *obj\attackTime))
*obj\rt = Exp(-Log(9) / (*obj\samplerate * *obj\releaseTime))
EndProcedure
Procedure.l createNoiseGate(attackTime.f, releaseTime.f, threshold.f, samplerate.f)
*obj = AllocateStructure(noisegate)
If Not *obj
ProcedureReturn #False
EndIf
setNoiseGate(*obj, attackTime, releaseTime, threshold, 0.0003, samplerate)
ProcedureReturn *obj
EndProcedure
Procedure.f runNoiseGate(*obj.noisegate, in.f)
x_abs.f = Abs(in)
;// envelop detector at = 0.02;rt = 0.01; 0.9977 = exp(-log(9) / (samplerate * 0.02));
;//obj->x_env = 0.9977 * obj->x_env + (1 - 0.9553) * ((x_abs - obj->x_env > 0) ? x_abs - obj->x_env : 0);
If x_abs - *obj\x_env > 0
*obj\x_env = (*obj\rt * *obj\x_env + (1 - *obj\at)) * (x_abs - *obj\x_env)
Else
*obj\x_env = *obj\rt * *obj\x_env
EndIf
If *obj\x_env < *obj\linearThreshold
*obj\gca = 0
Else
*obj\gca = 1
EndIf
If *obj\gca < *obj\gs[0]
;// attack mode
*obj\releaseCounter = 0
If *obj\attactCounter+1 < *obj\holdTimeCount
;// hold mode
*obj\gs[0] = *obj\gs[1]
Else
*obj\gs[0] = *obj\at * *obj\gs[1] + (1 - *obj\at) * *obj\gca
EndIf
*obj\gs[1] = *obj\gs[0]
Else
;// release mode
*obj\attactCounter = 0
If *obj\releaseCounter+1 < *obj\holdTimeCount
;// hold mode
*obj\gs[0] = *obj\gs[1]
Else
*obj\gs[0] = *obj\rt * *obj\gs[1] + (1 - *obj\rt) * *obj\gca
EndIf
*obj\gs[1] = *obj\gs[0]
EndIf
;// apply gain
out.f = *obj\gs[0] * in
ProcedureReturn *obj\gs[0] * in
EndProcedure
Procedure.l freeNoiseGate(*obj.noisegate)
If Not *obj
ProcedureReturn #False
EndIf
FreeMemory(*obj)
ProcedureReturn #True
EndProcedure
Code: Select all
Structure NoiseGate
samplerate.d ; sample rate(Hz) 48000
attackTime.d ; attack time(seconds) 0.05
releaseTime.d ; release time(seconds)0.02
holdTime.d ; hold time(second) 0.0003
threshold.d ; threshold_(dB) -24
;======
holdTimeCount.d ; hold time count (points)
linearThreshold.d ; linear threshold
at.d ; attack time smoothing coefficient
rt.d ; release time smoothing coefficient
attactCounter.d ; hold counter for attack time
releaseCounter.d ; hold counter for release time
x_env.d ;
gca.d ;
gs.d[2] ;
EndStructure
Procedure.i newNoiesGate()
Protected *obj.NoiseGate
*obj = AllocateStructure(NoiseGate)
ProcedureReturn *obj
EndProcedure
Procedure setNoiseGate(*obj.noisegate, attackTime.f, releaseTime.f, threshold.f, holdTime.f, samplerate.f)
*obj\attackTime = attackTime
*obj\releaseTime = releaseTime
*obj\threshold = threshold
*obj\samplerate = samplerate
*obj\holdTime = holdTime
*obj\holdTimeCount = *obj\holdTime * *obj\samplerate
*obj\linearThreshold = Pow(10.0, *obj\threshold / 20.0)
*obj\at = Exp(-Log(9) / (*obj\samplerate * *obj\attackTime))
*obj\rt = Exp(-Log(9) / (*obj\samplerate * *obj\releaseTime))
EndProcedure
Procedure.i createNoiseGate(attackTime.f, releaseTime.f, threshold.f, samplerate.f)
*obj = newNoiesGate()
If Not *obj
ProcedureReturn #Null
EndIf
setNoiseGate(*obj, attackTime, releaseTime, threshold, 0.0003, samplerate)
ProcedureReturn *obj
EndProcedure
Procedure.f runNoiseGate(*obj.noisegate, in.f, *out.Float)
Protected x_abs.d
x_abs = Abs(in)
;// envelop detector at = 0.02;rt = 0.01; 0.9977 = exp(-log(9) / (samplerate * 0.02));
;//obj->x_env = 0.9977 * obj->x_env + (1 - 0.9553) * ((x_abs - obj->x_env > 0) ? x_abs - obj->x_env : 0);
If x_abs - *obj\x_env > 0
*obj\x_env = *obj\rt * *obj\x_env + (1 - *obj\at) * (x_abs - *obj\x_env)
Else
*obj\x_env = *obj\rt * *obj\x_env
EndIf
If *obj\x_env < *obj\linearThreshold
*obj\gca = 0
Else
*obj\gca = 1
EndIf
If *obj\gca < *obj\gs[0]
;// attack mode
*obj\releaseCounter = 0
*obj\attactCounter + 1
If *obj\attactCounter < *obj\holdTimeCount
;// hold mode
*obj\gs[0] = *obj\gs[1]
Else
*obj\gs[0] = *obj\at * *obj\gs[1] + (1 - *obj\at) * *obj\gca
EndIf
*obj\gs[1] = *obj\gs[0]
Else
;// release mode
*obj\attactCounter = 0
*obj\releaseCounter + 1
If *obj\releaseCounter < *obj\holdTimeCount
;// hold mode
*obj\gs[0] = *obj\gs[1]
Else
*obj\gs[0] = *obj\rt * *obj\gs[1] + (1 - *obj\rt) * *obj\gca
EndIf
*obj\gs[1] = *obj\gs[0]
EndIf
;// apply gain
*out\f = *obj\gs[0] * in
ProcedureReturn *obj\gs[0] * in
EndProcedure
Procedure.i freeNoiseGate(*obj.noisegate)
If Not *obj
ProcedureReturn #False
EndIf
FreeStructure(*obj)
ProcedureReturn #True
EndProcedure
Code: Select all
if (++obj->attactCounter < obj->holdTimeCount)
Code: Select all
If x_abs - *obj\x_env > 0
*obj\x_env = *obj\rt * *obj\x_env + (1 - *obj\at) * (x_abs - *obj\x_env)
Else
*obj\x_env = 0
EndIf
Code: Select all
env = rt * env + (1 - at) * ((fabs - env > 0) ? fbs - env : 0)
Code: Select all
env = rt * env + (1 - at) * (fbs - env)
Code: Select all
env = rt * env + (1 - at) * (0)
Code: Select all
env = rt * env
Code: Select all
\x_env * \rt + (1 - \at) * Bool(x_abs > \x_env) * (x_abs - \x_env)
Code: Select all
env * rt + (1 - at) * Bool(fabs > env) * (fabs - env)
The Bool() function had always returned 1 for true. This is also the case with C-Backend.
Code: Select all
x = 10
a = Bool(x >= 10)
Debug a
; ASM
; x = 10
; MOV qword [v_x],10
; ; a = Bool(x >= 10)
; MOV r15,qword [v_x]
; CMP r15,10
; _Bool0:
; JL .False
; MOV rax,1
; JMP .True
; .False:
; XOR rax,rax
; .True:
; MOV qword [v_a],rax
; ;
; C-Backend
; // x = 10
; v_x=10;
; // a = Bool(x >= 10)
; v_a=(((v_x>=10))?1:0);
; /
Syntax
Bool(<boolean expression>)
Description
Bool can be used to evaluate a boolean expression outside of regular conditional operator like If, While, Until etc. If the boolean expression is true, it will return #True, otherwise it will return #False.
Code: Select all
Macro EquToIf(a, b) ; if a is true returns b eval
Bool(a) * (b) ; the parenthesis over b
EndMacro
Code: Select all
Bool(a.d)
Code: Select all
Bool(a.d = b.d) ; dangerous also
Bool(a.d <> b.d) ; dangerous also
Code: Select all
Bool(a.d < b.d)
; or
Bool(a.d > b.d)
Code: Select all
Bool(a.d < b.d) ; returns 1 if a is near below b, else returns 0.
Code: Select all
Macro Ternary(a, b, c)
Bool(a) * (b) + (1 - Bool(a) ) * (c)
EndMacro
Code: Select all
Macro iTernary(a, b, c) ; only for integers !!!
(0 - Bool(a) ) & (b) | (Bool(a) - 1) & (c)
EndMacro
But it is not.If the boolean expression is true, it will return 1, otherwise it will return 0.
Code: Select all
while x < 100
x + #True
wend
Code: Select all
#cTrue = ~0
Debug Bool(#cTrue) ; returns 1 (Long term support)