# HG changeset patch # User Mychaela Falconia # Date 1714964938 0 # Node ID bd4f660eb75ac149d5e82dff5d045a636b7fca3c # Parent 1588a7d9e732c4699bb5c64b6fe1c621b60a3949 libtwamr: integrate g_pitch.c diff -r 1588a7d9e732 -r bd4f660eb75a libtwamr/Makefile --- a/libtwamr/Makefile Mon May 06 03:04:57 2024 +0000 +++ b/libtwamr/Makefile Mon May 06 03:08:58 2024 +0000 @@ -6,9 +6,9 @@ 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 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 \ + enc_lag6.o ex_ctrl.o g_adapt.o g_code.o g_pitch.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 1588a7d9e732 -r bd4f660eb75a libtwamr/g_pitch.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libtwamr/g_pitch.c Mon May 06 03:08:58 2024 +0000 @@ -0,0 +1,169 @@ +/* +******************************************************************************** +* +* 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_pitch.c +* Purpose : Compute the pitch (adaptive codebook) gain. +* +******************************************************************************** +*/ +/* +******************************************************************************** +* MODULE INCLUDE FILE AND VERSION ID +******************************************************************************** +*/ +#include "namespace.h" +#include "g_pitch.h" + +/* +******************************************************************************** +* INCLUDE FILES +******************************************************************************** +*/ +#include "tw_amr.h" +#include "typedef.h" +#include "basic_op.h" +#include "oper_32b.h" +#include "no_count.h" +#include "cnst.h" + +/* +******************************************************************************** +* PUBLIC PROGRAM CODE +******************************************************************************** +*/ +/************************************************************************* + * + * FUNCTION: G_pitch + * + * PURPOSE: Compute the pitch (adaptive codebook) gain. + * Result in Q14 (NOTE: 12.2 bit exact using Q12) + * + * DESCRIPTION: + * The adaptive codebook gain is given by + * + * g = / + * + * where x[] is the target vector, y[] is the filtered adaptive + * codevector, and <> denotes dot product. + * The gain is limited to the range [0,1.2] (=0..19661 Q14) + * + *************************************************************************/ +Word16 G_pitch ( /* o : Gain of pitch lag saturated to 1.2 */ + enum Mode mode, /* i : AMR mode */ + Word16 xn[], /* i : Pitch target. */ + Word16 y1[], /* i : Filtered adaptive codebook. */ + Word16 g_coeff[], /* i : Correlations need for gain quantization */ + Word16 L_subfr /* i : Length of subframe. */ +) +{ + Word16 i; + Word16 xy, yy, exp_xy, exp_yy, gain; + Word32 s; + + Word16 scaled_y1[L_SUBFR]; /* Usually dynamic allocation of (L_subfr) */ + + /* divide "y1[]" by 4 to avoid overflow */ + + for (i = 0; i < L_subfr; i++) + { + scaled_y1[i] = shr (y1[i], 2); move16 (); + } + + /* Compute scalar product */ + + /* Q12 scaling / MR122 */ + Overflow = 0; move16 (); + s = 1L; move32 (); /* Avoid case of all zeros */ + for (i = 0; i < L_subfr; i++) + { + s = L_mac (s, y1[i], y1[i]); + } + test (); + if (Overflow == 0) /* Test for overflow */ + { + exp_yy = norm_l (s); + yy = round (L_shl (s, exp_yy)); + } + else + { + s = 1L; move32 (); /* Avoid case of all zeros */ + for (i = 0; i < L_subfr; i++) + { + s = L_mac (s, scaled_y1[i], scaled_y1[i]); + } + exp_yy = norm_l (s); + yy = round (L_shl (s, exp_yy)); + exp_yy = sub (exp_yy, 4); + } + + /* Compute scalar product */ + + Overflow = 0; move16 (); + s = 1L; move32 (); /* Avoid case of all zeros */ + + for (i = 0; i < L_subfr; i++) + { + s = L_mac(s, xn[i], y1[i]); + } + test (); + if (Overflow == 0) + { + exp_xy = norm_l (s); + xy = round (L_shl (s, exp_xy)); + } + else + { + s = 1L; move32 (); /* Avoid case of all zeros */ + for (i = 0; i < L_subfr; i++) + { + s = L_mac (s, xn[i], scaled_y1[i]); + } + exp_xy = norm_l (s); + xy = round (L_shl (s, exp_xy)); + exp_xy = sub (exp_xy, 2); + } + + g_coeff[0] = yy; move16 (); + g_coeff[1] = sub (15, exp_yy); move16 (); + g_coeff[2] = xy; move16 (); + g_coeff[3] = sub (15, exp_xy); move16 (); + + /* If (xy < 4) gain = 0 */ + + i = sub (xy, 4); + + test (); + if (i < 0) + return ((Word16) 0); + + /* compute gain = xy/yy */ + + xy = shr (xy, 1); /* Be sure xy < yy */ + gain = div_s (xy, yy); + + i = sub (exp_xy, exp_yy); /* Denormalization of division */ + gain = shr (gain, i); + + /* if(gain >1.2) gain = 1.2 */ + + test (); + if (sub (gain, 19661) > 0) + { + gain = 19661; move16 (); + } + + test (); + if (sub(mode, MR122) == 0) + { + /* clear 2 LSBits */ + gain = gain & 0xfffC; logic16 (); + } + + return (gain); +} diff -r 1588a7d9e732 -r bd4f660eb75a libtwamr/g_pitch.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libtwamr/g_pitch.h Mon May 06 03:08:58 2024 +0000 @@ -0,0 +1,40 @@ +/* +******************************************************************************** +* +* 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_pitch.h +* Purpose : Compute the pitch (adaptive codebook) gain. +* +******************************************************************************** +*/ +#ifndef g_pitch_h +#define g_pitch_h "$Id $" + +/* +******************************************************************************** +* INCLUDE FILES +******************************************************************************** +*/ +#include "tw_amr.h" +#include "typedef.h" + +/* +******************************************************************************** +* DECLARATION OF PROTOTYPES +******************************************************************************** +*/ +Word16 G_pitch ( /* o : Gain of pitch lag saturated to 1.2 */ + enum Mode mode, /* i : AMR mode */ + Word16 xn[], /* i : Pitch target. */ + Word16 y1[], /* i : Filtered adaptive codebook. */ + Word16 g_coeff[], /* i : Correlations need for gain quantization. + (7.4 only). Pass NULL if not needed */ + Word16 L_subfr /* i : Length of subframe. */ +); + +#endif diff -r 1588a7d9e732 -r bd4f660eb75a libtwamr/namespace.list --- a/libtwamr/namespace.list Mon May 06 03:04:57 2024 +0000 +++ b/libtwamr/namespace.list Mon May 06 03:08:58 2024 +0000 @@ -20,7 +20,8 @@ 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 G_code +Enc_lag3 Enc_lag6 Ex_ctrl +G_code G_pitch Lsf_lsp Lsp_lsf Reorder_lsf agc agc2 agc_reset