Refactor common_audio/vad: Removed usage of WEBRTC_SPL_MUL_16_16_RSFT
The macro is defined as
#define WEBRTC_SPL_MUL_16_16_RSFT(a, b, c) \
(WEBRTC_SPL_MUL_16_16(a, b) >> (c))
where the latter macro is in C defined as
#define WEBRTC_SPL_MUL_16_16(a, b) \
((int32_t) (((int16_t)(a)) * ((int16_t)(b))))
(For definitions on ARMv7 and MIPS, see common_audio/signal_processing/include/spl_inl_{armv7,mips}.h)
The replacement consists of
- avoiding casts to int16_t if inputs already are int16_t
- adding explicit cast to <type> if result is assigned to <type> (other than int or int32_t)
- minor cleanups like remove of unnecessary parentheses and style changes
BUG=3347, 3348, 3353
TESTED=locally on Linux for both fixed and floating point and trybots
R=kwiberg@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/44799004
Cr-Commit-Position: refs/heads/master@{#8857}
This commit is contained in:
@@ -293,20 +293,16 @@ static int16_t GmmProbability(VadInstT* self, int16_t* features,
|
|||||||
// (|noise_probability[0]| + |noise_probability[1]|)
|
// (|noise_probability[0]| + |noise_probability[1]|)
|
||||||
|
|
||||||
// (Q14 * Q11 >> 11) = Q14.
|
// (Q14 * Q11 >> 11) = Q14.
|
||||||
delt = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(ngprvec[gaussian],
|
delt = (int16_t)((ngprvec[gaussian] * deltaN[gaussian]) >> 11);
|
||||||
deltaN[gaussian],
|
|
||||||
11);
|
|
||||||
// Q7 + (Q14 * Q15 >> 22) = Q7.
|
// Q7 + (Q14 * Q15 >> 22) = Q7.
|
||||||
nmk2 = nmk + (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(delt,
|
nmk2 = nmk + (int16_t)((delt * kNoiseUpdateConst) >> 22);
|
||||||
kNoiseUpdateConst,
|
|
||||||
22);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Long term correction of the noise mean.
|
// Long term correction of the noise mean.
|
||||||
// Q8 - Q8 = Q8.
|
// Q8 - Q8 = Q8.
|
||||||
ndelt = (feature_minimum << 4) - tmp1_s16;
|
ndelt = (feature_minimum << 4) - tmp1_s16;
|
||||||
// Q7 + (Q8 * Q8) >> 9 = Q7.
|
// Q7 + (Q8 * Q8) >> 9 = Q7.
|
||||||
nmk3 = nmk2 + (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(ndelt, kBackEta, 9);
|
nmk3 = nmk2 + (int16_t)((ndelt * kBackEta) >> 9);
|
||||||
|
|
||||||
// Control that the noise mean does not drift to much.
|
// Control that the noise mean does not drift to much.
|
||||||
tmp_s16 = (int16_t) ((k + 5) << 7);
|
tmp_s16 = (int16_t) ((k + 5) << 7);
|
||||||
@@ -326,13 +322,9 @@ static int16_t GmmProbability(VadInstT* self, int16_t* features,
|
|||||||
// (|speech_probability[0]| + |speech_probability[1]|)
|
// (|speech_probability[0]| + |speech_probability[1]|)
|
||||||
|
|
||||||
// (Q14 * Q11) >> 11 = Q14.
|
// (Q14 * Q11) >> 11 = Q14.
|
||||||
delt = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(sgprvec[gaussian],
|
delt = (int16_t)((sgprvec[gaussian] * deltaS[gaussian]) >> 11);
|
||||||
deltaS[gaussian],
|
|
||||||
11);
|
|
||||||
// Q14 * Q15 >> 21 = Q8.
|
// Q14 * Q15 >> 21 = Q8.
|
||||||
tmp_s16 = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(delt,
|
tmp_s16 = (int16_t)((delt * kSpeechUpdateConst) >> 21);
|
||||||
kSpeechUpdateConst,
|
|
||||||
21);
|
|
||||||
// Q7 + (Q8 >> 1) = Q7. With rounding.
|
// Q7 + (Q8 >> 1) = Q7. With rounding.
|
||||||
smk2 = smk + ((tmp_s16 + 1) >> 1);
|
smk2 = smk + ((tmp_s16 + 1) >> 1);
|
||||||
|
|
||||||
@@ -351,7 +343,7 @@ static int16_t GmmProbability(VadInstT* self, int16_t* features,
|
|||||||
|
|
||||||
tmp_s16 = features[channel] - tmp_s16; // Q4
|
tmp_s16 = features[channel] - tmp_s16; // Q4
|
||||||
// (Q11 * Q4 >> 3) = Q12.
|
// (Q11 * Q4 >> 3) = Q12.
|
||||||
tmp1_s32 = WEBRTC_SPL_MUL_16_16_RSFT(deltaS[gaussian], tmp_s16, 3);
|
tmp1_s32 = (deltaS[gaussian] * tmp_s16) >> 3;
|
||||||
tmp2_s32 = tmp1_s32 - 4096;
|
tmp2_s32 = tmp1_s32 - 4096;
|
||||||
tmp_s16 = sgprvec[gaussian] >> 2;
|
tmp_s16 = sgprvec[gaussian] >> 2;
|
||||||
// (Q14 >> 2) * Q12 = Q24.
|
// (Q14 >> 2) * Q12 = Q24.
|
||||||
@@ -381,7 +373,7 @@ static int16_t GmmProbability(VadInstT* self, int16_t* features,
|
|||||||
// Q4 - (Q7 >> 3) = Q4.
|
// Q4 - (Q7 >> 3) = Q4.
|
||||||
tmp_s16 = features[channel] - (nmk >> 3);
|
tmp_s16 = features[channel] - (nmk >> 3);
|
||||||
// (Q11 * Q4 >> 3) = Q12.
|
// (Q11 * Q4 >> 3) = Q12.
|
||||||
tmp1_s32 = WEBRTC_SPL_MUL_16_16_RSFT(deltaN[gaussian], tmp_s16, 3);
|
tmp1_s32 = (deltaN[gaussian] * tmp_s16) >> 3;
|
||||||
tmp1_s32 -= 4096;
|
tmp1_s32 -= 4096;
|
||||||
|
|
||||||
// (Q14 >> 2) * Q12 = Q24.
|
// (Q14 >> 2) * Q12 = Q24.
|
||||||
@@ -425,8 +417,8 @@ static int16_t GmmProbability(VadInstT* self, int16_t* features,
|
|||||||
|
|
||||||
// |tmp1_s16| = ~0.8 * (kMinimumDifference - diff) in Q7.
|
// |tmp1_s16| = ~0.8 * (kMinimumDifference - diff) in Q7.
|
||||||
// |tmp2_s16| = ~0.2 * (kMinimumDifference - diff) in Q7.
|
// |tmp2_s16| = ~0.2 * (kMinimumDifference - diff) in Q7.
|
||||||
tmp1_s16 = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(13, tmp_s16, 2);
|
tmp1_s16 = (int16_t)((13 * tmp_s16) >> 2);
|
||||||
tmp2_s16 = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(3, tmp_s16, 2);
|
tmp2_s16 = (int16_t)((3 * tmp_s16) >> 2);
|
||||||
|
|
||||||
// Move Gaussian means for speech model by |tmp1_s16| and update
|
// Move Gaussian means for speech model by |tmp1_s16| and update
|
||||||
// |speech_global_mean|. Note that |self->speech_means[channel]| is
|
// |speech_global_mean|. Note that |self->speech_means[channel]| is
|
||||||
|
|||||||
@@ -212,9 +212,8 @@ static void LogOfEnergy(const int16_t* data_in, int data_length,
|
|||||||
|
|
||||||
// |kLogConst| is in Q9, |log2_energy| in Q10 and |tot_rshifts| in Q0.
|
// |kLogConst| is in Q9, |log2_energy| in Q10 and |tot_rshifts| in Q0.
|
||||||
// Note that we in our derivation above have accounted for an output in Q4.
|
// Note that we in our derivation above have accounted for an output in Q4.
|
||||||
*log_energy = (int16_t) (WEBRTC_SPL_MUL_16_16_RSFT(
|
*log_energy = (int16_t)(((kLogConst * log2_energy) >> 19) +
|
||||||
kLogConst, log2_energy, 19) +
|
((tot_rshifts * kLogConst) >> 9));
|
||||||
WEBRTC_SPL_MUL_16_16_RSFT(tot_rshifts, kLogConst, 9));
|
|
||||||
|
|
||||||
if (*log_energy < 0) {
|
if (*log_energy < 0) {
|
||||||
*log_energy = 0;
|
*log_energy = 0;
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ int32_t WebRtcVad_GaussianProbability(int16_t input,
|
|||||||
// Calculate |inv_std2| = 1 / s^2, in Q14.
|
// Calculate |inv_std2| = 1 / s^2, in Q14.
|
||||||
tmp16 = (inv_std >> 2); // Q10 -> Q8.
|
tmp16 = (inv_std >> 2); // Q10 -> Q8.
|
||||||
// Q-domain: (Q8 * Q8) >> 2 = Q14.
|
// Q-domain: (Q8 * Q8) >> 2 = Q14.
|
||||||
inv_std2 = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(tmp16, tmp16, 2);
|
inv_std2 = (int16_t)((tmp16 * tmp16) >> 2);
|
||||||
// TODO(bjornv): Investigate if changing to
|
// TODO(bjornv): Investigate if changing to
|
||||||
// |inv_std2| = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(|inv_std|, |inv_std|, 6);
|
// inv_std2 = (int16_t)((inv_std * inv_std) >> 6);
|
||||||
// gives better accuracy.
|
// gives better accuracy.
|
||||||
|
|
||||||
tmp16 = (input << 3); // Q4 -> Q7
|
tmp16 = (input << 3); // Q4 -> Q7
|
||||||
@@ -54,12 +54,12 @@ int32_t WebRtcVad_GaussianProbability(int16_t input,
|
|||||||
// To be used later, when updating noise/speech model.
|
// To be used later, when updating noise/speech model.
|
||||||
// |delta| = (x - m) / s^2, in Q11.
|
// |delta| = (x - m) / s^2, in Q11.
|
||||||
// Q-domain: (Q14 * Q7) >> 10 = Q11.
|
// Q-domain: (Q14 * Q7) >> 10 = Q11.
|
||||||
*delta = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(inv_std2, tmp16, 10);
|
*delta = (int16_t)((inv_std2 * tmp16) >> 10);
|
||||||
|
|
||||||
// Calculate the exponent |tmp32| = (x - m)^2 / (2 * s^2), in Q10. Replacing
|
// Calculate the exponent |tmp32| = (x - m)^2 / (2 * s^2), in Q10. Replacing
|
||||||
// division by two with one shift.
|
// division by two with one shift.
|
||||||
// Q-domain: (Q11 * Q7) >> 8 = Q10.
|
// Q-domain: (Q11 * Q7) >> 8 = Q10.
|
||||||
tmp32 = WEBRTC_SPL_MUL_16_16_RSFT(*delta, tmp16, 9);
|
tmp32 = (*delta * tmp16) >> 9;
|
||||||
|
|
||||||
// If the exponent is small enough to give a non-zero probability we calculate
|
// If the exponent is small enough to give a non-zero probability we calculate
|
||||||
// |exp_value| ~= exp(-(x - m)^2 / (2 * s^2))
|
// |exp_value| ~= exp(-(x - m)^2 / (2 * s^2))
|
||||||
@@ -67,7 +67,7 @@ int32_t WebRtcVad_GaussianProbability(int16_t input,
|
|||||||
if (tmp32 < kCompVar) {
|
if (tmp32 < kCompVar) {
|
||||||
// Calculate |tmp16| = log2(exp(1)) * |tmp32|, in Q10.
|
// Calculate |tmp16| = log2(exp(1)) * |tmp32|, in Q10.
|
||||||
// Q-domain: (Q12 * Q10) >> 12 = Q10.
|
// Q-domain: (Q12 * Q10) >> 12 = Q10.
|
||||||
tmp16 = (int16_t) WEBRTC_SPL_MUL_16_16_RSFT(kLog2Exp, (int16_t) tmp32, 12);
|
tmp16 = (int16_t)((kLog2Exp * tmp32) >> 12);
|
||||||
tmp16 = -tmp16;
|
tmp16 = -tmp16;
|
||||||
exp_value = (0x0400 | (tmp16 & 0x03FF));
|
exp_value = (0x0400 | (tmp16 & 0x03FF));
|
||||||
tmp16 ^= 0xFFFF;
|
tmp16 ^= 0xFFFF;
|
||||||
|
|||||||
@@ -38,17 +38,15 @@ void WebRtcVad_Downsampling(const int16_t* signal_in,
|
|||||||
for (n = 0; n < half_length; n++) {
|
for (n = 0; n < half_length; n++) {
|
||||||
// All-pass filtering upper branch.
|
// All-pass filtering upper branch.
|
||||||
tmp16_1 = (int16_t) ((tmp32_1 >> 1) +
|
tmp16_1 = (int16_t) ((tmp32_1 >> 1) +
|
||||||
WEBRTC_SPL_MUL_16_16_RSFT(kAllPassCoefsQ13[0], *signal_in, 14));
|
((kAllPassCoefsQ13[0] * *signal_in) >> 14));
|
||||||
*signal_out = tmp16_1;
|
*signal_out = tmp16_1;
|
||||||
tmp32_1 = (int32_t) (*signal_in++) -
|
tmp32_1 = (int32_t)(*signal_in++) - ((kAllPassCoefsQ13[0] * tmp16_1) >> 12);
|
||||||
WEBRTC_SPL_MUL_16_16_RSFT(kAllPassCoefsQ13[0], tmp16_1, 12);
|
|
||||||
|
|
||||||
// All-pass filtering lower branch.
|
// All-pass filtering lower branch.
|
||||||
tmp16_2 = (int16_t) ((tmp32_2 >> 1) +
|
tmp16_2 = (int16_t) ((tmp32_2 >> 1) +
|
||||||
WEBRTC_SPL_MUL_16_16_RSFT(kAllPassCoefsQ13[1], *signal_in, 14));
|
((kAllPassCoefsQ13[1] * *signal_in) >> 14));
|
||||||
*signal_out++ += tmp16_2;
|
*signal_out++ += tmp16_2;
|
||||||
tmp32_2 = (int32_t) (*signal_in++) -
|
tmp32_2 = (int32_t)(*signal_in++) - ((kAllPassCoefsQ13[1] * tmp16_2) >> 12);
|
||||||
WEBRTC_SPL_MUL_16_16_RSFT(kAllPassCoefsQ13[1], tmp16_2, 12);
|
|
||||||
}
|
}
|
||||||
// Store the filter states.
|
// Store the filter states.
|
||||||
filter_state[0] = tmp32_1;
|
filter_state[0] = tmp32_1;
|
||||||
|
|||||||
Reference in New Issue
Block a user