33 lines
853 B
C
33 lines
853 B
C
#include "fx_saturation.h"
|
|
#include <math.h>
|
|
|
|
#define FX_SATURATION_DC_BLOCK_R 0.995f
|
|
|
|
void FxSaturation_Init(FxSaturationState *state, FxSaturationParams *params)
|
|
{
|
|
state->dc_block_x1 = 0.0f;
|
|
state->dc_block_y1 = 0.0f;
|
|
|
|
params->enabled = false;
|
|
params->drive = 0.3f;
|
|
params->level = 0.8f;
|
|
}
|
|
|
|
float FxSaturation_Process(FxSaturationState *state, const FxSaturationParams *params, float input)
|
|
{
|
|
if (!params->enabled)
|
|
{
|
|
return input;
|
|
}
|
|
|
|
float driven = input * (1.0f + params->drive * 12.0f);
|
|
float shaped = tanhf(driven);
|
|
|
|
/* Le tanh sur un signal non symetrique introduit un leger DC : filtre bloqueur de DC. */
|
|
float y = shaped - state->dc_block_x1 + FX_SATURATION_DC_BLOCK_R * state->dc_block_y1;
|
|
state->dc_block_x1 = shaped;
|
|
state->dc_block_y1 = y;
|
|
|
|
return y * params->level;
|
|
}
|