📄 amf_agccompressorcore.c
字号:
// Copyright(c) 2005 Analog Devices, Inc. All Rights Reserved.
// This software is proprietary and confidential to Analog Devices, Inc. and its licensors.
// File : $Id: //depot/development/visualaudio/modules/2.5.0/SHARC/Source/AMF_AGCCompressorCore.c#3 $
// Part of : VisualAudio V2.5.0
// Updated : $Date: 2006/10/12 $ by $Author: Fernando $
#include "AMF_AGCCompressorCore.h"
#include "math.h"
void AMF_AGCCompressorCore_Render(AMF_AGCCompressorCore * restrict instance,float * restrict * buffers,int tickSize);
// NOTE: The C version of this function is for reference only (it is
// intended just to show the general algorithm that the module
// uses), and it may not have been fully tested
#if 0
SEG_MOD_FAST_CODE void AMF_AGCCompressorCore_Render(AMF_AGCCompressorCore * restrict instance,float * restrict * buffers,int tickSize) {
int i;
float *in = buffers[0];
float *out = buffers[1];
float envState = instance->envState;
float attackCoef = instance->attackCoef;
float decayCoef = instance->decayCoef;
float envCoef;
float smoothingState = instance->smoothingState;
float attackCoefSmoothing = instance->attackCoefSmoothing;
float decayCoefSmoothing = instance->decayCoefSmoothing;
float coefSmoothing;
float maxInput;
float tmp;
maxInput = 0;
for(i=0;i<tickSize;i++)
maxInput = fmaxf(maxInput, in[i]);
if(envState < maxInput) {
envCoef = attackCoef;
coefSmoothing = attackCoefSmoothing;
} else {
envCoef = decayCoef;
coefSmoothing = decayCoefSmoothing;
}
// one pole filter for envelope detector, where filter coef is determined above
tmp = envCoef*maxInput + (1.0-envCoef)*envState;
instance->envState = tmp;
// convert env output to log
tmp = AMF_TranslateVeryFastAmpToDB(tmp);
// subtract compression threshold from logEnv
tmp -= instance->threshold;
// max zero
if(tmp < 0)
tmp = 0;
// multiply by slope
tmp = tmp * -instance->slope;
// add gain offset
tmp += instance->gain;
tmp = AMF_TranslateVeryFastDBToAmp(tmp);
// filter output with one pole filter running at sampling rate
for (i=0; i<tickSize; i++) {
out[i] = coefSmoothing*tmp + (1.0-coefSmoothing)*smoothingState;
smoothingState = out[i];
}
instance->smoothingState = smoothingState;
}
#endif
SEG_MOD_SLOW_CONST const AMF_ModuleClass AMFClassAGCCompressorCore = {
/* Flags */
0,
/* Render function */
(AMF_RenderFunction)AMF_AGCCompressorCore_Render, // render function
/* Default bypass */
(void *)0,
/* Input descriptor - 1 input, and it is mono. */
1, 0,
/* Output descriptor - 1 output, and it is mono. */
1, 0,
};
// Class-specific helper functions
SEG_MOD_SLOW_CODE float AMF_AGCCompressorCore_TranslateEnvFollowerT60(float T60, int tickSize, float samplingRate)
{
return 1.0-exp(-1.0 * tickSize / (samplingRate * (0.001*T60)));
}
SEG_MOD_SLOW_CODE float AMF_AGCCompressorCore_TranslateSmoothingFilterT60(float T60, int tickSize, float samplingRate)
{
return 1.0-exp(-1.0 / (samplingRate * (0.001*T60)));
}
SEG_MOD_SLOW_CODE float AMF_AGCCompressorCore_TranslateSlope(float ratio)
{
return 1.0 - (1.0 / ratio);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -