audio_processing/aecm: Added help function for calculating log of energy
The same operation of calculating log of the energy was executed four times. This CL adds a help function LogOfEnergyInQ8() for that. BUG=N/A TESTED=locally on linux and trybots R=kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/22819004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7331 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
23ec8372a6
commit
65e56dba53
@ -709,6 +709,20 @@ static int16_t ExtractFractionPart(uint32_t a, int zeros) {
|
||||
return (int16_t)(((a << zeros) & 0x7FFFFFFF) >> 23);
|
||||
}
|
||||
|
||||
// Calculates and returns the log of |energy| in Q8. The input |energy| is
|
||||
// supposed to be in Q(|q_domain|).
|
||||
static int16_t LogOfEnergyInQ8(uint32_t energy, int q_domain) {
|
||||
static const int16_t kLogLowValue = PART_LEN_SHIFT << 7;
|
||||
int16_t log_energy_q8 = kLogLowValue;
|
||||
if (energy > 0) {
|
||||
int zeros = WebRtcSpl_NormU32(energy);
|
||||
int16_t frac = ExtractFractionPart(energy, zeros);
|
||||
// log2 of |energy| in Q8.
|
||||
log_energy_q8 += ((31 - zeros) << 8) + frac - (q_domain << 8);
|
||||
}
|
||||
return log_energy_q8;
|
||||
}
|
||||
|
||||
// WebRtcAecm_CalcEnergies(...)
|
||||
//
|
||||
// This function calculates the log of energies for nearend, farend and estimated
|
||||
@ -735,13 +749,11 @@ void WebRtcAecm_CalcEnergies(AecmCore_t * aecm,
|
||||
|
||||
int i;
|
||||
|
||||
int16_t zeros, frac;
|
||||
int16_t tmp16;
|
||||
int16_t increase_max_shifts = 4;
|
||||
int16_t decrease_max_shifts = 11;
|
||||
int16_t increase_min_shifts = 11;
|
||||
int16_t decrease_min_shifts = 3;
|
||||
static const int16_t kLogLowValue = PART_LEN_SHIFT << 7;
|
||||
|
||||
// Get log of near end energy and store in buffer
|
||||
|
||||
@ -750,17 +762,7 @@ void WebRtcAecm_CalcEnergies(AecmCore_t * aecm,
|
||||
sizeof(int16_t) * (MAX_BUF_LEN - 1));
|
||||
|
||||
// Logarithm of integrated magnitude spectrum (nearEner)
|
||||
tmp16 = kLogLowValue;
|
||||
if (nearEner)
|
||||
{
|
||||
zeros = WebRtcSpl_NormU32(nearEner);
|
||||
frac = ExtractFractionPart(nearEner, zeros);
|
||||
// log2 in Q8
|
||||
tmp16 += ((31 - zeros) << 8) + frac;
|
||||
tmp16 -= aecm->dfaNoisyQDomain << 8;
|
||||
}
|
||||
aecm->nearLogEnergy[0] = tmp16;
|
||||
// END: Get log of near end energy
|
||||
aecm->nearLogEnergy[0] = LogOfEnergyInQ8(nearEner, aecm->dfaNoisyQDomain);
|
||||
|
||||
WebRtcAecm_CalcLinearEnergies(aecm, far_spectrum, echoEst, &tmpFar, &tmpAdapt, &tmpStored);
|
||||
|
||||
@ -771,40 +773,15 @@ void WebRtcAecm_CalcEnergies(AecmCore_t * aecm,
|
||||
sizeof(int16_t) * (MAX_BUF_LEN - 1));
|
||||
|
||||
// Logarithm of delayed far end energy
|
||||
tmp16 = kLogLowValue;
|
||||
if (tmpFar)
|
||||
{
|
||||
zeros = WebRtcSpl_NormU32(tmpFar);
|
||||
frac = ExtractFractionPart(tmpFar, zeros);
|
||||
// log2 in Q8
|
||||
tmp16 += ((31 - zeros) << 8) + frac;
|
||||
tmp16 -= far_q << 8;
|
||||
}
|
||||
aecm->farLogEnergy = tmp16;
|
||||
aecm->farLogEnergy = LogOfEnergyInQ8(tmpFar, far_q);
|
||||
|
||||
// Logarithm of estimated echo energy through adapted channel
|
||||
tmp16 = kLogLowValue;
|
||||
if (tmpAdapt)
|
||||
{
|
||||
zeros = WebRtcSpl_NormU32(tmpAdapt);
|
||||
frac = ExtractFractionPart(tmpAdapt, zeros);
|
||||
//log2 in Q8
|
||||
tmp16 += ((31 - zeros) << 8) + frac;
|
||||
tmp16 -= (RESOLUTION_CHANNEL16 + far_q) << 8;
|
||||
}
|
||||
aecm->echoAdaptLogEnergy[0] = tmp16;
|
||||
aecm->echoAdaptLogEnergy[0] = LogOfEnergyInQ8(tmpAdapt,
|
||||
RESOLUTION_CHANNEL16 + far_q);
|
||||
|
||||
// Logarithm of estimated echo energy through stored channel
|
||||
tmp16 = kLogLowValue;
|
||||
if (tmpStored)
|
||||
{
|
||||
zeros = WebRtcSpl_NormU32(tmpStored);
|
||||
frac = ExtractFractionPart(tmpStored, zeros);
|
||||
//log2 in Q8
|
||||
tmp16 += ((31 - zeros) << 8) + frac;
|
||||
tmp16 -= (RESOLUTION_CHANNEL16 + far_q) << 8;
|
||||
}
|
||||
aecm->echoStoredLogEnergy[0] = tmp16;
|
||||
aecm->echoStoredLogEnergy[0] =
|
||||
LogOfEnergyInQ8(tmpStored, RESOLUTION_CHANNEL16 + far_q);
|
||||
|
||||
// Update farend energy levels (min, max, vad, mse)
|
||||
if (aecm->farLogEnergy > FAR_ENERGY_MIN)
|
||||
|
Loading…
x
Reference in New Issue
Block a user