# HG changeset patch # User Mychaela Falconia # Date 1713461950 0 # Node ID 5401aaf7acb07d87320a90704493107652e044d4 # Parent 15c354f75110ebc7a1d7fe27667ab26fefa44d18 libtwamr: integrate cor_h.c diff -r 15c354f75110 -r 5401aaf7acb0 libtwamr/Makefile --- a/libtwamr/Makefile Thu Apr 18 16:58:25 2024 +0000 +++ b/libtwamr/Makefile Thu Apr 18 17:39:10 2024 +0000 @@ -1,8 +1,8 @@ CC= gcc CFLAGS= -O2 OBJS= a_refl.o agc.o autocorr.o az_lsp.o b_cn_cod.o basicop2.o bgnscd.o \ - bitno.o bits2prm.o gmed_n.o inv_sqrt.o oper_32b.o prmno.o set_sign.o \ - sqrt_l.o tls_flags.o window.o + bitno.o bits2prm.o cor_h.o gmed_n.o inv_sqrt.o oper_32b.o prmno.o \ + set_sign.o sqrt_l.o tls_flags.o window.o LIB= libtwamr.a INSTALL_PREFIX= /usr/local diff -r 15c354f75110 -r 5401aaf7acb0 libtwamr/cor_h.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libtwamr/cor_h.c Thu Apr 18 17:39:10 2024 +0000 @@ -0,0 +1,194 @@ +/* +***************************************************************************** +* +* GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 +* R99 Version 3.3.0 +* REL-4 Version 4.1.0 +* +****************************************************************************** +* +* File : cor_h.c +* Purpose : correlation functions for codebook search +* +***************************************************************************** +*/ +/* +***************************************************************************** +* MODULE INCLUDE FILE AND VERSION ID +***************************************************************************** +*/ +#include "namespace.h" +#include "cor_h.h" +/* +***************************************************************************** +* INCLUDE FILES +***************************************************************************** +*/ +#include "typedef.h" +#include "basic_op.h" +#include "no_count.h" +#include "inv_sqrt.h" +#include "cnst.h" + +/* +***************************************************************************** +* PUBLIC PROGRAM CODE +***************************************************************************** +*/ +/************************************************************************* + * + * FUNCTION: cor_h_x() + * + * PURPOSE: Computes correlation between target signal "x[]" and + * impulse response"h[]". + * + * DESCRIPTION: + * The correlation is given by: + * d[n] = sum_{i=n}^{L-1} x[i] h[i-n] n=0,...,L-1 + * + * d[n] is normalized such that the sum of 5 maxima of d[n] corresponding + * to each position track does not saturate. + * + *************************************************************************/ +void cor_h_x ( + Word16 h[], /* (i): impulse response of weighted synthesis filter */ + Word16 x[], /* (i): target */ + Word16 dn[], /* (o): correlation between target and h[] */ + Word16 sf /* (i): scaling factor: 2 for 12.2, 1 for others */ +) +{ + cor_h_x2(h, x, dn, sf, NB_TRACK, STEP); +} + +/************************************************************************* + * + * FUNCTION: cor_h_x2() + * + * PURPOSE: Computes correlation between target signal "x[]" and + * impulse response"h[]". + * + * DESCRIPTION: + * See cor_h_x, d[n] can be normalized regards to sum of the + * five MR122 maxima or the four MR102 maxima. + * + *************************************************************************/ +void cor_h_x2 ( + Word16 h[], /* (i): impulse response of weighted synthesis filter */ + Word16 x[], /* (i): target */ + Word16 dn[], /* (o): correlation between target and h[] */ + Word16 sf, /* (i): scaling factor: 2 for 12.2, 1 for others */ + Word16 nb_track,/* (i): the number of ACB tracks */ + Word16 step /* (i): step size from one pulse position to the next + in one track */ +) +{ + Word16 i, j, k; + Word32 s, y32[L_CODE], max, tot; + + /* first keep the result on 32 bits and find absolute maximum */ + + tot = 5; move32 (); + + for (k = 0; k < nb_track; k++) + { + max = 0; move32 (); + for (i = k; i < L_CODE; i += step) + { + s = 0; move32 (); + for (j = i; j < L_CODE; j++) + s = L_mac (s, x[j], h[j - i]); + + y32[i] = s; move32 (); + + s = L_abs (s); + test (); + if (L_sub (s, max) > (Word32) 0L) + max = s; move32 (); + } + tot = L_add (tot, L_shr (max, 1)); + } + + j = sub (norm_l (tot), sf); + + for (i = 0; i < L_CODE; i++) + { + dn[i] = round (L_shl (y32[i], j)); move16 (); + } +} + +/************************************************************************* + * + * FUNCTION: cor_h() + * + * PURPOSE: Computes correlations of h[] needed for the codebook search; + * and includes the sign information into the correlations. + * + * DESCRIPTION: The correlations are given by + * rr[i][j] = sum_{n=i}^{L-1} h[n-i] h[n-j]; i>=j; i,j=0,...,L-1 + * + * and the sign information is included by + * rr[i][j] = rr[i][j]*sign[i]*sign[j] + * + *************************************************************************/ + +void cor_h ( + Word16 h[], /* (i) : impulse response of weighted synthesis + filter */ + Word16 sign[], /* (i) : sign of d[n] */ + Word16 rr[][L_CODE] /* (o) : matrix of autocorrelation */ +) +{ + Word16 i, j, k, dec, h2[L_CODE]; + Word32 s; + + /* Scaling for maximum precision */ + + s = 2; move32 (); + for (i = 0; i < L_CODE; i++) + s = L_mac (s, h[i], h[i]); + + j = sub (extract_h (s), 32767); + test (); + if (j == 0) + { + for (i = 0; i < L_CODE; i++) + { + h2[i] = shr (h[i], 1); move16 (); + } + } + else + { + s = L_shr (s, 1); + k = extract_h (L_shl (Inv_sqrt (s), 7)); + k = mult (k, 32440); /* k = 0.99*k */ + + for (i = 0; i < L_CODE; i++) + { + h2[i] = round (L_shl (L_mult (h[i], k), 9)); + move16 (); + } + } + + /* build matrix rr[] */ + s = 0; move32 (); + i = L_CODE - 1; + for (k = 0; k < L_CODE; k++, i--) + { + s = L_mac (s, h2[k], h2[k]); + rr[i][i] = round (s); move16 (); + } + + for (dec = 1; dec < L_CODE; dec++) + { + s = 0; move32 (); + j = L_CODE - 1; + i = sub (j, dec); + for (k = 0; k < (L_CODE - dec); k++, i--, j--) + { + s = L_mac (s, h2[k], h2[k + dec]); + rr[j][i] = mult (round (s), mult (sign[i], sign[j])); + move16 (); + rr[i][j] = rr[j][i]; move16 (); + } + } +} diff -r 15c354f75110 -r 5401aaf7acb0 libtwamr/cor_h.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libtwamr/cor_h.h Thu Apr 18 17:39:10 2024 +0000 @@ -0,0 +1,58 @@ +/* +***************************************************************************** +* +* GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 +* R99 Version 3.3.0 +* REL-4 Version 4.1.0 +* +***************************************************************************** +* +* File : cor_h.h +* Purpose : correlation functions for codebook search +* +***************************************************************************** +*/ +/* +***************************************************************************** +* MODULE INCLUDE FILE AND VERSION ID +***************************************************************************** +*/ +#ifndef cor_h_h +#define cor_h_h "@(#)$Id $" +/* +***************************************************************************** +* INCLUDE FILES +***************************************************************************** +*/ +#include "typedef.h" +#include "cnst.h" + +/* +***************************************************************************** +* DECLARATION OF PROTOTYPES +***************************************************************************** +*/ +void cor_h_x ( + Word16 h[], /* (i) : impulse response of weighted synthesis filter */ + Word16 x[], /* (i) : target */ + Word16 dn[], /* (o) : correlation between target and h[] */ + Word16 sf /* (i) : scaling factor: 2 for 12.2, 1 for 7.4 */ +); + +void cor_h_x2 ( + Word16 h[], /* (i) : impulse response of weighted synthesis filter */ + Word16 x[], /* (i) : target */ + Word16 dn[], /* (o) : correlation between target and h[] */ + Word16 sf, /* (i) : scaling factor: 2 for 12.2, 1 for 7.4 */ + Word16 nb_track,/* (i) : the number of ACB tracks */ + Word16 step /* (i) : step size from one pulse position to the next + in one track */ +); + +void cor_h ( + Word16 h[], /* (i) : impulse response of weighted synthesis filter */ + Word16 sign[], /* (i) : sign of d[n] */ + Word16 rr[][L_CODE] /* (o) : matrix of autocorrelation */ +); + +#endif diff -r 15c354f75110 -r 5401aaf7acb0 libtwamr/namespace.h --- a/libtwamr/namespace.h Thu Apr 18 16:58:25 2024 +0000 +++ b/libtwamr/namespace.h Thu Apr 18 17:39:10 2024 +0000 @@ -74,6 +74,9 @@ #define sqrt_l_exp AMR__sqrt_l_exp #define set_sign AMR__set_sign #define set_sign12k2 AMR__set_sign12k2 +#define cor_h AMR__cor_h +#define cor_h_x AMR__cor_h_x +#define cor_h_x2 AMR__cor_h_x2 #define Bits2prm AMR__Bits2prm #define Prm2bits AMR__Prm2bits