- work on evs decoder

This commit is contained in:
2020-06-15 15:40:54 +03:00
parent 9ec2f734d8
commit 46c355e29a
661 changed files with 173606 additions and 252743 deletions

341
src/libs/libevs/lib_com/codec_tcx_common.cpp Executable file → Normal file
View File

@@ -1,288 +1,173 @@
/*====================================================================================
EVS Codec 3GPP TS26.442 Apr 03, 2018. Version 12.11.0 / 13.6.0 / 14.2.0
EVS Codec 3GPP TS26.443 Nov 13, 2018. Version 12.11.0 / 13.7.0 / 14.3.0 / 15.1.0
====================================================================================*/
#include <assert.h>
#include "prot_fx.h"
#include <math.h>
#include "prot.h"
#include "options.h"
#include "stl.h"
#include "prot_fx.h"
#include "basop_util.h"
#include "rom_basop_util.h"
#define inv_int InvIntTable
/*-------------------------------------------------------------------*
* tcxGetNoiseFillingTilt()
*
*
*-------------------------------------------------------------------*/
Word16 tcxGetNoiseFillingTilt(Word16 A[], Word16 lpcorder, Word16 L_frame, Word16 mode, Word16 *noiseTiltFactor)
int tcxGetNoiseFillingTilt(
float A[],
int L_frame,
int mode,
float *noiseTiltFactor
)
{
Word16 firstLine;
Word32 tmp;
Word16 As[M+1];
int firstLine;
IF (mode != 0)
if (mode)
{
firstLine = idiv1616U(L_frame, 6);
*noiseTiltFactor = 18432/*0.5625f Q15*/;
move16();
firstLine = L_frame / 6;
*noiseTiltFactor = 0.5625f;
}
ELSE
else
{
firstLine = shr(L_frame, 3);
Copy_Scale_sig( A, As, lpcorder+1, sub(norm_s(A[0]),2) );
tmp = get_gain(As+1, As, lpcorder);
BASOP_SATURATE_WARNING_OFF;
*noiseTiltFactor = add(round_fx(L_shl(tmp, 15)), 3072/*0.09375f Q15*/);
move16();
BASOP_SATURATE_WARNING_ON;
firstLine = L_frame / 8;
*noiseTiltFactor = get_gain( A+1, A, M, NULL );
*noiseTiltFactor = min(1.0f, (*noiseTiltFactor) + 0.09375f);
}
return firstLine;
}
/*-------------------------------------------------------------------*
* tcxFormantEnhancement()
*
*
*-------------------------------------------------------------------*/
void tcxFormantEnhancement(
Word16 xn_buf[],
Word16 gainlpc[], Word16 gainlpc_e[],
Word32 spectrum[], Word16 *spectrum_e,
Word16 L_frame,
Word16 L_frameTCX
float xn_buf[],
float gainlpc[],
float spectrum[],
int L_frame
)
{
Word16 i, j, k, l, n;
Word16 fac, fac0, fac1, fac_e, d, tmp;
Word16 xn_buf_e, xn_one, m, e;
int k;
int i, j, l = 0;
float fac, step;
k = shr(L_frame, 6); /* FDNS_NPTS = 64 */
l = 0;
move16();
/* get exponent */
xn_buf_e = 0;
move16();
FOR (i = 0; i < FDNS_NPTS; i++)
{
xn_buf_e = s_max(xn_buf_e, gainlpc_e[i]);
}
xn_buf_e = shr(add(xn_buf_e, 1), 1); /* max exponent after sqrt */
xn_one = shr(0x4000, sub(xn_buf_e, 1)); /* 1.0 scaled to xn_buf_e */
k = L_frame / FDNS_NPTS;
/* Formant enhancement via square root of the LPC gains */
e = gainlpc_e[0];
move16();
m = Sqrt16(gainlpc[0], &e);
xn_buf[0] = shl(m, sub(e, xn_buf_e));
move16();
xn_buf[0] = (float)sqrt(gainlpc[0]);
xn_buf[1] = (float)sqrt(gainlpc[1]);
fac = 1.0f / min(xn_buf[0], xn_buf[1]);
e = gainlpc_e[1];
move16();
m = Sqrt16(gainlpc[1], &e);
xn_buf[1] = shl(m, sub(e, xn_buf_e));
move16();
fac0 = s_min(xn_buf[0], xn_buf[1]);
fac_e = xn_buf_e;
move16();
fac0 = Inv16(fac0, &fac_e);
FOR (i = 1; i < FDNS_NPTS-1; i++)
for (i = 1; i < FDNS_NPTS - 1; i++)
{
e = gainlpc_e[i+1];
move16();
m = Sqrt16(gainlpc[i+1], &e);
xn_buf[i+1] = shl(m, sub(e, xn_buf_e));
move16();
xn_buf[i+1] = (float)sqrt(gainlpc[i+1]);
test();
IF ((sub(xn_buf[i-1], xn_buf[i]) <= 0) && (sub(xn_buf[i+1], xn_buf[i]) <= 0))
if ((xn_buf[i-1] <= xn_buf[i]) && (xn_buf[i+1] <= xn_buf[i]))
{
m = s_max(xn_buf[i-1], xn_buf[i+1]);
e = xn_buf_e;
move16();
m = Inv16(m, &e);
fac1 = m;
move16();
tmp = sub(e, fac_e);
if (tmp > 0) fac0 = shr(fac0, tmp);
if (tmp < 0) fac1 = shl(fac1, tmp);
if (tmp > 0)
step = max(xn_buf[i-1], xn_buf[i+1]);
step = (1.0f / step - fac) / (float)(i - l);
xn_buf[l] = 1.0f;
fac += step;
for (j = l + 1; j < i; j++)
{
fac_e = e;
move16();
xn_buf[j] = min(1.0f, xn_buf[j] * fac);
fac += step;
}
d = sub(fac1, fac0);
n = sub(i, l);
assert(n <= 64);
xn_buf[l] = xn_one;
move16();
FOR (j = 1; j < n; j++)
{
fac = add(fac0, mult(d, extract_l(L_mult0(j, inv_int[n]))));
BASOP_SATURATE_WARNING_OFF;
xn_buf[l+j] = s_min(xn_one, shl(mult(xn_buf[l+j], fac), fac_e));
move16();
BASOP_SATURATE_WARNING_ON;
}
l = i;
move16();
fac0 = m;
move16();
fac_e = e;
move16();
}
}
/* i = FDNS_NPTS - 1; Completing changes to gains */
m = s_min(xn_buf[i-1], xn_buf[i]);
e = xn_buf_e;
move16();
m = Inv16(m, &e);
fac1 = m;
move16();
tmp = sub(e, fac_e);
if (tmp > 0) fac0 = shr(fac0, tmp);
if (tmp < 0) fac1 = shl(fac1, tmp);
if (tmp > 0)
/* i = tcx_cfg->fdns_npts - 1; Completing changes to gains */
step = min(xn_buf[i-1], xn_buf[i]);
step = (1.0f / step - fac) / (float)(i - l);
xn_buf[l] = 1.0f;
fac += step;
for (j = l + 1; j < i; j++)
{
fac_e = e;
move16();
xn_buf[j] = min(1.0f, xn_buf[j] * fac);
fac += step;
}
d = sub(fac1, fac0);
n = sub(i, l);
assert(n <= 64);
xn_buf[l] = xn_one;
move16();
FOR (j = 1; j < n; j++)
{
fac = add(fac0, mult(d, extract_l(L_mult0(j, inv_int[n]))));
BASOP_SATURATE_WARNING_OFF;
xn_buf[l+j] = s_min(xn_one, shl(mult(xn_buf[l+j], fac), fac_e));
move16();
BASOP_SATURATE_WARNING_ON;
}
xn_buf[i] = xn_one;
move16();
xn_buf[i] = 1.0f;
/* Application of changed gains onto decoded MDCT lines */
FOR (i = 0; i < L_frame; i += k)
for (i = j = 0; i < L_frame; j++)
{
FOR (l = 0; l < k; l++)
for (l = 0; l < k; i++, l++)
{
*spectrum = Mpy_32_16_1(*spectrum, *xn_buf);
move32();
spectrum++;
spectrum[i] *= xn_buf[j];
}
xn_buf++;
}
tmp = sub(L_frameTCX, L_frame);
FOR (i = 0; i < tmp; i++)
{
spectrum[i] = L_shr(spectrum[i], xn_buf_e);
move32();
}
*spectrum_e = add(*spectrum_e, xn_buf_e);
move16();
return;
}
void tcxInvertWindowGrouping(TCX_config *tcx_cfg,
Word32 xn_buf[],
Word32 spectrum[],
Word16 L_frame,
Word8 fUseTns,
Word16 last_core,
Word16 index,
Word16 frame_cnt,
Word16 bfi)
/*-------------------------------------------------------------------*
* tcxGetNoiseFillingTilt()
*
*
*-------------------------------------------------------------------*/
void tcxInvertWindowGrouping(
TCX_config *tcx_cfg,
float xn_buf[],
float spectrum[],
int L_frame,
int fUseTns,
int last_core,
int index,
int frame_cnt,
int bfi
)
{
Word16 i, L_win, L_spec;
Word32 *p;
short i, w, t_integer;
int L_win, L_spec;
L_win = shr(L_frame, 1);
L_spec = tcx_cfg->tnsConfig[0][0].iFilterBorders[0];
move16();
test();
test();
if ((frame_cnt != 0) && (bfi == 0) && (last_core != ACELP_CORE)) /* fix sub-window overlap */
if (frame_cnt && !bfi && last_core!=0)
{
/* fix sub-window overlap */
tcx_cfg->tcx_last_overlap_mode = tcx_cfg->tcx_curr_overlap_mode;
move16();
}
test();
test();
test();
test();
test();
test();
test();
IF (((bfi==0) &&((tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) ||
((tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP) && (frame_cnt == 0) && (index == 0))))
||
((bfi!=0) &&((tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) &&
!(tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP))))
if (((!bfi) &&((tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) ||
((tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP) && (frame_cnt == 0) && (index == 0))))
||
((bfi) &&((tcx_cfg->tcx_last_overlap_mode != FULL_OVERLAP) &&
!(tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP))))
{
/* ungroup sub-windows: deinterleave MDCT bins into separate windows */
p = xn_buf;
FOR (i = 1; i < L_win; i += 2)
for (t_integer = w = 0; w < 2; w++)
{
*p++ = spectrum[i];
move32();
}
p = spectrum;
FOR (i = 0; i < L_frame; i += 2)
{
*p++ = spectrum[i];
move32();
}
p = spectrum + L_frame - 1;
FOR (i = sub(L_frame, 1); i > L_win; i -= 2)
{
*p-- = spectrum[i];
move32();
}
Copy32(xn_buf, spectrum + L_win, shr(L_win, 1));
test();
test();
IF ((tcx_cfg->fIsTNSAllowed != 0) && (bfi == 0) && (fUseTns != 0))
{
/* rearrange LF sub-window lines prior to TNS synthesis filtering */
IF (sub(L_spec, L_frame) < 0)
for (i = w; i < L_frame; i += 2)
{
Copy32(spectrum+8, spectrum+16, sub(shr(L_spec,1),8));
Copy32(spectrum+L_frame/2, spectrum+8, 8);
Copy32(spectrum+L_frame/2+8, spectrum+L_spec/2+8, sub(shr(L_spec,1),8));
xn_buf[t_integer++] = spectrum[i];
}
ELSE
}
mvr2r( xn_buf, spectrum, L_frame );
if( tcx_cfg->fIsTNSAllowed && !bfi && fUseTns )
{
L_win = L_frame >> 1;
L_spec = tcx_cfg->tnsConfig[0][0].iFilterBorders[0];
/* rearrange LF sub-window lines prior to TNS synthesis filtering */
if( L_spec < L_frame )
{
Copy32(spectrum+L_win, xn_buf, 8);
Copy32(spectrum+8, spectrum+16, sub(L_win, 8));
Copy32(xn_buf, spectrum+8, 8);
mvr2r( spectrum+8, spectrum+16, L_spec/2-8 );
mvr2r( spectrum+L_frame/2, spectrum+8, 8 );
mvr2r( spectrum+L_frame/2+8, spectrum+L_spec/2+8, L_spec/2-8 );
}
else
{
mvr2r( spectrum+8, xn_buf, L_win );
mvr2r( xn_buf, spectrum+16, L_win-8 );
mvr2r( xn_buf+L_win-8, spectrum+8, 8);
}
}
}
return;
}