# HG changeset patch # User Mychaela Falconia # Date 1714964697 0 # Node ID 1588a7d9e732c4699bb5c64b6fe1c621b60a3949 # Parent 2a265be82195a7996877950a9284e3dd7d43d729 libtwamr: integrate g_code.c diff -r 2a265be82195 -r 1588a7d9e732 libtwamr/Makefile --- a/libtwamr/Makefile Mon May 06 03:01:15 2024 +0000 +++ b/libtwamr/Makefile Mon May 06 03:04:57 2024 +0000 @@ -6,10 +6,10 @@ d1035pf.o d2_11pf.o d2_9pf.o d3_14pf.o d4_17pf.o d8_31pf.o d_gain_c.o \ d_gain_p.o d_plsf.o d_plsf_3.o d_plsf_5.o dec_gain.o dec_lag3.o \ dec_lag6.o dhf_check.o dhf_tables.o e_homing.o ec_gains.o enc_lag3.o \ - enc_lag6.o ex_ctrl.o g_adapt.o gains_tab.o gc_pred.o gmed_n.o graytab.o\ - inv_sqrt.o log2.o lsp_lsf.o oper_32b.o pow2.o prmno.o q_plsf3_tab.o \ - q_plsf5_tab.o qua_gain_tab.o reorder.o s10_8pf.o set_sign.o sqrt_l.o \ - tls_flags.o window.o + enc_lag6.o ex_ctrl.o g_adapt.o g_code.o gains_tab.o gc_pred.o gmed_n.o \ + graytab.o inv_sqrt.o log2.o lsp_lsf.o oper_32b.o pow2.o prmno.o \ + q_plsf3_tab.o q_plsf5_tab.o qua_gain_tab.o reorder.o s10_8pf.o \ + set_sign.o sqrt_l.o tls_flags.o window.o HDRS= namespace.h LIB= libtwamr.a diff -r 2a265be82195 -r 1588a7d9e732 libtwamr/g_code.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libtwamr/g_code.c Mon May 06 03:04:57 2024 +0000 @@ -0,0 +1,114 @@ +/* +******************************************************************************** +* +* 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 : g_code.c +* Purpose : Compute the innovative codebook gain. +* +******************************************************************************** +*/ +/* +******************************************************************************** +* MODULE INCLUDE FILE AND VERSION ID +******************************************************************************** +*/ +#include "namespace.h" +#include "g_code.h" + +/* +******************************************************************************** +* INCLUDE FILES +******************************************************************************** +*/ +#include "typedef.h" +#include "basic_op.h" +#include "no_count.h" +#include "cnst.h" + +/* +******************************************************************************** +* LOCAL VARIABLES AND TABLES +******************************************************************************** +*/ + +/* +******************************************************************************** +* PUBLIC PROGRAM CODE +******************************************************************************** +*/ +/************************************************************************* + * + * FUNCTION: G_code + * + * PURPOSE: Compute the innovative codebook gain. + * + * DESCRIPTION: + * The innovative codebook gain is given by + * + * g = / + * + * where x[] is the target vector, y[] is the filtered innovative + * codevector, and <> denotes dot product. + * + *************************************************************************/ +Word16 G_code ( /* out : Gain of innovation code */ + Word16 xn2[], /* in : target vector */ + Word16 y2[] /* in : filtered innovation vector */ +) +{ + Word16 i; + Word16 xy, yy, exp_xy, exp_yy, gain; + Word16 scal_y2[L_SUBFR]; + Word32 s; + + /* Scale down Y[] by 2 to avoid overflow */ + + for (i = 0; i < L_SUBFR; i++) + { + scal_y2[i] = shr (y2[i], 1); move16 (); + } + + /* Compute scalar product */ + + s = 1L; move32 (); /* Avoid case of all zeros */ + for (i = 0; i < L_SUBFR; i++) + { + s = L_mac (s, xn2[i], scal_y2[i]); + } + exp_xy = norm_l (s); + xy = extract_h (L_shl (s, exp_xy)); + + /* If (xy < 0) gain = 0 */ + + test (); + if (xy <= 0) + return ((Word16) 0); + + /* Compute scalar product */ + + s = 0L; move32 (); + for (i = 0; i < L_SUBFR; i++) + { + s = L_mac (s, scal_y2[i], scal_y2[i]); + } + exp_yy = norm_l (s); + yy = extract_h (L_shl (s, exp_yy)); + + /* compute gain = xy/yy */ + + xy = shr (xy, 1); /* Be sure xy < yy */ + gain = div_s (xy, yy); + + /* Denormalization of division */ + i = add (exp_xy, 5); /* 15-1+9-18 = 5 */ + i = sub (i, exp_yy); + + gain = shl (shr (gain, i), 1); /* Q0 -> Q1 */ + + return (gain); +} diff -r 2a265be82195 -r 1588a7d9e732 libtwamr/g_code.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libtwamr/g_code.h Mon May 06 03:04:57 2024 +0000 @@ -0,0 +1,41 @@ +/* +******************************************************************************** +* +* 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 : g_code.h +* Purpose : Compute the innovative codebook gain. +* +******************************************************************************** +*/ +#ifndef g_code_h +#define g_code_h "$Id $" + +/* +******************************************************************************** +* INCLUDE FILES +******************************************************************************** +*/ +#include "typedef.h" + +/* +******************************************************************************** +* DEFINITION OF DATA TYPES +******************************************************************************** +*/ + +/* +******************************************************************************** +* DECLARATION OF PROTOTYPES +******************************************************************************** +*/ +Word16 G_code ( /* out : Gain of innovation code. */ + Word16 xn[], /* in : target vector */ + Word16 y2[] /* in : filtered inovation vector */ +); + +#endif diff -r 2a265be82195 -r 1588a7d9e732 libtwamr/namespace.list --- a/libtwamr/namespace.list Mon May 06 03:01:15 2024 +0000 +++ b/libtwamr/namespace.list Mon May 06 03:04:57 2024 +0000 @@ -20,7 +20,7 @@ Convolve Dec_gain Dec_lag3 Dec_lag6 D_plsf_reset D_plsf_5 D_plsf_3 Init_D_plsf_3 -Enc_lag3 Enc_lag6 Ex_ctrl +Enc_lag3 Enc_lag6 Ex_ctrl G_code Lsf_lsp Lsp_lsf Reorder_lsf agc agc2 agc_reset