📄 enc_util.c
字号:
*
* b[3] = {0.989501953f, -1.979003906f, 0.989501953f};
* a[3] = {1.000000000F, 1.978881836f,-0.966308594f};
*
*
* Returns:
* void
*/
void E_UTIL_hp50_12k8(Float32 signal[], Word32 lg, Float32 mem[])
{
Word32 i;
Float32 x0, x1, x2, y0, y1, y2;
y1 = mem[0];
y2 = mem[1];
x0 = mem[2];
x1 = mem[3];
for(i = 0; i < lg; i++)
{
x2 = x1;
x1 = x0;
x0 = signal[i];
y0 = y1 * 1.978881836F + y2 * -0.979125977F + x0 * 0.989501953F +
x1 * -1.979003906F + x2 * 0.989501953F;
signal[i] = y0;
y2 = y1;
y1 = y0;
}
mem[0] = ((y1 > 1e-10) | (y1 < -1e-10)) ? y1 : 0;
mem[1] = ((y2 > 1e-10) | (y2 < -1e-10)) ? y2 : 0;
mem[2] = ((x0 > 1e-10) | (x0 < -1e-10)) ? x0 : 0;
mem[3] = ((x1 > 1e-10) | (x1 < -1e-10)) ? x1 : 0;
return;
}
/*
* E_UTIL_hp400_12k8
*
* Parameters:
* signal I/O: signal
* lg I: lenght of signal
* mem I/O: filter memory [4]
*
* Function:
* 2nd order high pass filter with cut off frequency at 400 Hz.
*
* Algorithm:
*
* y[i] = b[0]*x[i] + b[1]*x[i-1] + b[2]*x[i-2]
* + a[1]*y[i-1] + a[2]*y[i-2];
*
* b[3] = {0.893554687, -1.787109375, 0.893554687};
* a[3] = {1.000000000, 1.787109375, -0.864257812};
*
*
* Returns:
* void
*/
static void E_UTIL_hp400_12k8(Float32 signal[], Word32 lg, Float32 mem[])
{
Word32 i;
Float32 x0, x1, x2;
Float32 y0, y1, y2;
y1 = mem[0];
y2 = mem[1];
x0 = mem[2];
x1 = mem[3];
for(i = 0; i < lg; i++)
{
x2 = x1;
x1 = x0;
x0 = signal[i];
y0 = y1 * 1.787109375F + y2 * -0.864257812F + x0 * 0.893554687F + x1 * -
1.787109375F + x2 * 0.893554687F;
signal[i] = y0;
y2 = y1;
y1 = y0;
}
mem[0] = y1;
mem[1] = y2;
mem[2] = x0;
mem[3] = x1;
return;
}
/*
* E_UTIL_bp_6k_7k
*
* Parameters:
* signal I/O: signal
* lg I: lenght of signal
* mem I/O: filter memory [4]
*
* Function:
* 15th order band pass 6kHz to 7kHz FIR filter.
*
* Returns:
* void
*/
static void E_UTIL_bp_6k_7k(Float32 signal[], Word32 lg, Float32 mem[])
{
Float32 x[L_SUBFR16k + 30];
Float32 s0, s1, s2, s3;
Float32 *px;
Word32 i, j;
memcpy(x, mem, 30 * sizeof(Float32));
memcpy(x + 30, signal, lg * sizeof(Float32));
px = x;
for(i = 0; i < lg; i++)
{
s0 = 0;
s1 = px[0] * E_ROM_fir_6k_7k[0];
s2 = px[1] * E_ROM_fir_6k_7k[1];
s3 = px[2] * E_ROM_fir_6k_7k[2];
for(j = 3; j < 31; j += 4)
{
s0 += px[j] * E_ROM_fir_6k_7k[j];
s1 += px[j + 1] * E_ROM_fir_6k_7k[j + 1];
s2 += px[j + 2] * E_ROM_fir_6k_7k[j + 2];
s3 += px[j + 3] * E_ROM_fir_6k_7k[j + 3];
}
px++;
signal[i] = (Float32)((s0 + s1 + s2 + s3) * 0.25F); /* gain of coef = 4.0 */
}
memcpy(mem, x + lg, 30 * sizeof(Float32));
return;
}
/*
* E_UTIL_preemph
*
* Parameters:
* x I/O: signal
* mu I: preemphasis factor
* lg I: vector size
* mem I/O: memory (x[-1])
*
* Function:
* Filtering through 1 - mu z^-1
*
*
* Returns:
* void
*/
void E_UTIL_preemph(Word16 x[], Word16 mu, Word32 lg, Word16 *mem)
{
Word32 i, L_tmp;
Word16 temp;
temp = x[lg - 1];
for (i = lg - 1; i > 0; i--)
{
L_tmp = x[i] << 15;
L_tmp -= x[i - 1] * mu;
x[i] = (Word16)((L_tmp + 0x4000) >> 15);
}
L_tmp = (x[0] << 15);
L_tmp -= *mem * mu;
x[0] = (Word16)((L_tmp + 0x4000) >> 15);
*mem = temp;
return;
}
void E_UTIL_f_preemph(Float32 *signal, Float32 mu, Word32 L, Float32 *mem)
{
Word32 i;
Float32 temp;
temp = signal[L - 1];
for (i = L - 1; i > 0; i--)
{
signal[i] = signal[i] - mu * signal[i - 1];
}
signal[0] -= mu * (*mem);
*mem = temp;
return;
}
/*
* E_UTIL_deemph
*
* Parameters:
* signal I/O: signal
* mu I: deemphasis factor
* L I: vector size
* mem I/O: memory (signal[-1])
*
* Function:
* Filtering through 1/(1-mu z^-1)
* Signal is divided by 2.
*
* Returns:
* void
*/
void E_UTIL_deemph(Float32 *signal, Float32 mu, Word32 L, Float32 *mem)
{
Word32 i;
signal[0] = signal[0] + mu * (*mem);
for (i = 1; i < L; i++)
{
signal[i] = signal[i] + mu * signal[i - 1];
}
*mem = signal[L - 1];
if ((*mem < 1e-10) & (*mem > -1e-10))
{
*mem = 0;
}
return;
}
/*
* E_UTIL_synthesis
*
* Parameters:
* a I: LP filter coefficients
* m I: order of LP filter
* x I: input signal
* y O: output signal
* lg I: size of filtering
* mem I/O: initial filter states
* update_m I: update memory flag
*
* Function:
* Perform the synthesis filtering 1/A(z).
* Memory size is always M.
*
* Returns:
* void
*/
void E_UTIL_synthesis(Float32 a[], Float32 x[], Float32 y[], Word32 l,
Float32 mem[], Word32 update_m)
{
Float32 buf[L_FRAME16k + M16k]; /* temporary synthesis buffer */
Float32 s;
Float32 *yy;
Word32 i, j;
/* copy initial filter states into synthesis buffer */
memcpy(buf, mem, M * sizeof(Float32));
yy = &buf[M];
for (i = 0; i < l; i++)
{
s = x[i];
for (j = 1; j <= M; j += 4)
{
s -= a[j] * yy[i - j];
s -= a[j + 1] * yy[i - (j + 1)];
s -= a[j + 2] * yy[i - (j + 2)];
s -= a[j + 3] * yy[i - (j + 3)];
}
yy[i] = s;
y[i] = s;
}
/* Update memory if required */
if (update_m)
{
memcpy(mem, &yy[l - M], M * sizeof(Float32));
}
return;
}
void E_UTIL_synthesisPlus(Float32 a[], Word32 m, Float32 x[], Float32 y[], Word32 l,
Float32 mem[], Word32 update_m)
{
Float32 buf[L_FRAME16k + M16k]; /* temporary synthesis buffer */
Float32 s;
Float32 *yy;
Word32 i, j;
/* copy initial filter states into synthesis buffer */
memcpy(buf, mem, m * sizeof(Float32));
yy = &buf[m];
for (i = 0; i < l; i++)
{
s = x[i];
for (j = 1; j <= m; j++)
{
s -= a[j] * yy[i - j];
}
yy[i] = s;
y[i] = s;
}
/* Update memory if required */
if (update_m)
{
memcpy(mem, &yy[l - m], m * sizeof(Float32));
}
return;
}
/*
* E_UTIL_down_samp
*
* Parameters:
* res I: signal to down sample
* res_d O: down sampled signal
* L_frame_d I: length of output
*
* Function:
* Down sample to 4/5
*
* Returns:
* void
*/
static void E_UTIL_down_samp(Float32 *res, Float32 *res_d, Word32 L_frame_d)
{
Word32 i, j, frac;
Float32 pos, fac;
fac = 0.8F;
pos = 0;
for(i = 0; i < L_frame_d; i++)
{
j = (Word32)pos; /* j = (Word32)( (Float32)i * inc); */
frac = (Word32)(((pos - (Float32)j) * 4) + 0.5);
res_d[i] = fac * E_UTIL_interpol(&res[j], frac, 4, 15);
pos += 1.25F;
}
return;
}
/*
* E_UTIL_decim_12k8
*
* Parameters:
* sig16k I: signal to decimate
* lg I: length of input
* sig12k8 O: decimated signal
* mem I/O: memory (2*15)
*
* Function:
* Decimation of 16kHz signal to 12.8kHz.
*
* Returns:
* void
*/
void E_UTIL_decim_12k8(Float32 sig16k[], Word32 lg, Float32 sig12k8[],
Float32 mem[])
{
Float32 signal[(2 * 15) + L_FRAME16k];
memcpy(signal, mem, 2 * 15 * sizeof(Float32));
memcpy(&signal[2 * 15], sig16k, lg * sizeof(Float32));
E_UTIL_down_samp(signal + 15, sig12k8, lg * 4 / 5);
memcpy(mem, &signal[lg], 2 * 15 * sizeof(Float32));
return;
}
/*
* E_UTIL_residu
*
* Parameters:
* a I: LP filter coefficients (Q12)
* x I: input signal (usually speech)
* y O: output signal (usually residual)
* l I: size of filtering
*
* Function:
* Compute the LP residual by filtering the input speech through A(z).
* Order of LP filter = M.
*
* Returns:
* void
*/
void E_UTIL_residu(Float32 *a, Float32 *x, Float32 *y, Word32 l)
{
Float32 s;
Word32 i;
for (i = 0; i < l; i++)
{
s = x[i];
s += a[1] * x[i - 1];
s += a[2] * x[i - 2];
s += a[3] * x[i - 3];
s += a[4] * x[i - 4];
s += a[5] * x[i - 5];
s += a[6] * x[i - 6];
s += a[7] * x[i - 7];
s += a[8] * x[i - 8];
s += a[9] * x[i - 9];
s += a[10] * x[i - 10];
s += a[11] * x[i - 11];
s += a[12] * x[i - 12];
s += a[13] * x[i - 13];
s += a[14] * x[i - 14];
s += a[15] * x[i - 15];
s += a[16] * x[i - 16];
y[i] = s;
}
return;
}
/* This is a modified residu to suppot AMR-WB+ */
void E_UTIL_residuPlus(Float32 *a, Word32 m, Float32 *x, Float32 *y, Word32 l)
{
Float32 s;
Word32 i, j;
for (i = 0; i < l; i++)
{
s = x[i];
for (j = 1; j <= m; j++) {
s += a[j]*x[i-j];
}
y[i] = s;
}
return;
}
/*
* E_UTIL_convolve
*
* Parameters:
* x I: input vector
* h I: impulse response (or second input vector) (Q15)
* y O: output vetor (result of convolution)
*
* Function:
* Perform the convolution between two vectors x[] and h[] and
* write the result in the vector y[]. All vectors are of length L.
* Only the first L samples of the convolution are considered.
* Vector size = L_SUBFR
*
* Returns:
* void
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -