FreeCalypso > hg > gsm-codec-lib
changeset 379:176a44ff94a1
libtwamr: integrate hp_max.c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 06 May 2024 05:10:03 +0000 |
parents | ccba5812fa44 |
children | 2ed325c9a507 |
files | libtwamr/Makefile libtwamr/hp_max.c libtwamr/hp_max.h libtwamr/namespace.list |
diffstat | 4 files changed, 180 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/libtwamr/Makefile Mon May 06 04:38:55 2024 +0000 +++ b/libtwamr/Makefile Mon May 06 05:10:03 2024 +0000 @@ -7,11 +7,11 @@ 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 g_pitch.o gain_q.o gains_tab.o \ - gc_pred.o gmed_n.o graytab.o inv_sqrt.o log2.o lsfwt.o lsp_lsf.o \ - mac_32.o oper_32b.o pow2.o prmno.o q_gain_c.o q_gain_p.o q_plsf.o \ - q_plsf3_tab.o q_plsf5_tab.o q_plsf_3.o q_plsf_5.o qgain475.o qgain795.o\ - qua_gain.o qua_gain_tab.o reorder.o s10_8pf.o set_sign.o sqrt_l.o \ - tls_flags.o window.o + gc_pred.o gmed_n.o graytab.o hp_max.o inv_sqrt.o log2.o lsfwt.o \ + lsp_lsf.o mac_32.o oper_32b.o pow2.o prmno.o q_gain_c.o q_gain_p.o \ + q_plsf.o q_plsf3_tab.o q_plsf5_tab.o q_plsf_3.o q_plsf_5.o qgain475.o \ + qgain795.o qua_gain.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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libtwamr/hp_max.c Mon May 06 05:10:03 2024 +0000 @@ -0,0 +1,121 @@ +/* +******************************************************************************** +* +* 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 : hp_max.c +* Purpose : Find the maximum correlation of scal_sig[] in a given +* delay range. +* +******************************************************************************** +*/ + +/* +******************************************************************************** +* MODULE INCLUDE FILE AND VERSION ID +******************************************************************************** +*/ +#include "namespace.h" +#include "hp_max.h" + +/* +******************************************************************************** +* INCLUDE FILES +******************************************************************************** +*/ +#include "typedef.h" +#include "basic_op.h" +#include "oper_32b.h" +#include "no_count.h" +#include "cnst.h" + +/* +******************************************************************************** +* PUBLIC PROGRAM CODE +******************************************************************************** +*/ +Word16 hp_max ( + Word32 corr[], /* i : correlation vector. */ + Word16 scal_sig[], /* i : scaled signal. */ + Word16 L_frame, /* i : length of frame to compute pitch */ + Word16 lag_max, /* i : maximum lag */ + Word16 lag_min, /* i : minimum lag */ + Word16 *cor_hp_max) /* o : max high-pass filtered norm. correlation */ +{ + Word16 i; + Word16 *p, *p1; + Word32 max, t0, t1; + Word16 max16, t016, cor_max; + Word16 shift, shift1, shift2; + + max = MIN_32; move32 (); + t0 = 0L; move32 (); + + for (i = lag_max-1; i > lag_min; i--) + { + /* high-pass filtering */ + t0 = L_sub (L_sub(L_shl(corr[-i], 1), corr[-i-1]), corr[-i+1]); + t0 = L_abs (t0); + + test (); + if (L_sub (t0, max) >= 0) + { + max = t0; move32 (); + } + } + + /* compute energy */ + p = scal_sig; move16 (); + p1 = &scal_sig[0]; move16 (); + t0 = 0L; move32 (); + for (i = 0; i < L_frame; i++, p++, p1++) + { + t0 = L_mac (t0, *p, *p1); + } + + p = scal_sig; move16 (); + p1 = &scal_sig[-1]; move16 (); + t1 = 0L; move32 (); + for (i = 0; i < L_frame; i++, p++, p1++) + { + t1 = L_mac (t1, *p, *p1); + } + + /* high-pass filtering */ + t0 = L_sub(L_shl(t0, 1), L_shl(t1, 1)); + t0 = L_abs (t0); + + /* max/t0 */ + shift1 = sub(norm_l(max), 1); + max16 = extract_h(L_shl(max, shift1)); + shift2 = norm_l(t0); + t016 = extract_h(L_shl(t0, shift2)); + + test (); + if (t016 != 0) + { + cor_max = div_s(max16, t016); + } + else + { + cor_max = 0; move16 (); + } + + shift = sub(shift1, shift2); + + test (); + if (shift >= 0) + { + *cor_hp_max = shr(cor_max, shift); move16 (); /* Q15 */ + } + else + { + *cor_hp_max = shl(cor_max, negate(shift)); move16 (); /* Q15 */ + } + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libtwamr/hp_max.h Mon May 06 05:10:03 2024 +0000 @@ -0,0 +1,53 @@ +/* +******************************************************************************** +* +* 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 : hp_max.h +* Purpose : Find the maximum correlation of scal_sig[] in a given +* delay range. +* +******************************************************************************** +*/ +#ifndef hp_max_h +#define hp_max_h "$Id $" + +/* +******************************************************************************** +* INCLUDE FILES +******************************************************************************** +*/ +#include "typedef.h" + +/* +******************************************************************************** +* DECLARATION OF PROTOTYPES +******************************************************************************** +*/ +/************************************************************************* + * + * FUNCTION: hp_max + * + * PURPOSE: Find the maximum high-pass filtered correlation of + * signal scal_sig[] in a given delay range. + * + * DESCRIPTION: + * The correlation is given by + * corr[t] = <scal_sig[n],scal_sig[n-t]>, t=lag_min,...,lag_max + * The functions outputs the maximum high-pass filtered correlation + * after normalization. + * + *************************************************************************/ +Word16 hp_max ( + Word32 corr[], /* i : correlation vector. */ + Word16 scal_sig[], /* i : scaled signal. */ + Word16 L_frame, /* i : length of frame to compute pitch */ + Word16 lag_max, /* i : maximum lag */ + Word16 lag_min, /* i : minimum lag */ + Word16 *cor_hp_max /* o : max high-pass filtered norm. correlation */ + ); +#endif
--- a/libtwamr/namespace.list Mon May 06 04:38:55 2024 +0000 +++ b/libtwamr/namespace.list Mon May 06 05:10:03 2024 +0000 @@ -36,7 +36,7 @@ gain_adapt gain_adapt_reset gainQuant gainQuant_reset gc_pred gc_pred_copy gc_pred_reset gc_pred_update gc_pred_average_limited -gmed_n +gmed_n hp_max q_gain_code q_gain_pitch Bits2prm Prm2bits