mirror of
https://github.com/LX3JL/xlxd.git
synced 2026-04-06 06:53:37 +00:00
Back to block processing, more efficient and does not introduce delay
This commit is contained in:
parent
1770dc188f
commit
042188770b
9 changed files with 85 additions and 57 deletions
|
|
@ -62,27 +62,33 @@ float CAGC::GetGain()
|
|||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// process
|
||||
|
||||
inline float CAGC::ProcessSample(float input)
|
||||
inline void CAGC::ProcessSampleBlock(uint8* voice, int length)
|
||||
{
|
||||
//apply AGC
|
||||
// apply gain to input sample
|
||||
float output = input * m_Gain;
|
||||
for(int i = 0; i < length; i += 2)
|
||||
{
|
||||
float input = (float)(short)MAKEWORD(voice[i+1], voice[i]);
|
||||
//apply AGC
|
||||
// apply gain to input sample
|
||||
float output = input * m_Gain;
|
||||
|
||||
// compute output signal energy, scaled to 0 to 1
|
||||
float instantEnergy = abs(output) / m_targetEnergy;
|
||||
// compute output signal energy, scaled to 0 to 1
|
||||
float instantEnergy = abs(output) / m_targetEnergy;
|
||||
|
||||
// smooth energy estimate using single-pole low-pass filter
|
||||
m_EnergyPrime = (1.0f - m_Alpha) * m_EnergyPrime + m_Alpha * instantEnergy;
|
||||
// smooth energy estimate using single-pole low-pass filter
|
||||
m_EnergyPrime = (1.0f - m_Alpha) * m_EnergyPrime + m_Alpha * instantEnergy;
|
||||
|
||||
// update gain according to output energy
|
||||
if (m_EnergyPrime > 1e-6f)
|
||||
m_Gain *= exp( -0.5f * m_Alpha * log(m_EnergyPrime) );
|
||||
// update gain according to output energy
|
||||
if (m_EnergyPrime > 1e-6f)
|
||||
m_Gain *= exp( -0.5f * m_Alpha * log(m_EnergyPrime) );
|
||||
|
||||
// clamp gain
|
||||
if (m_Gain > m_GainMax)
|
||||
m_Gain = m_GainMax;
|
||||
else if(m_Gain < m_GainMin)
|
||||
m_Gain = m_GainMin;
|
||||
// clamp gain
|
||||
if (m_Gain > m_GainMax)
|
||||
m_Gain = m_GainMax;
|
||||
else if(m_Gain < m_GainMin)
|
||||
m_Gain = m_GainMin;
|
||||
|
||||
return output;
|
||||
//write processed sample back
|
||||
voice[i] = HIBYTE((short)output);
|
||||
voice[i+1] = LOBYTE((short)output);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue