comparison libtwamr/lsfwt.c @ 370:8861f41e4507

libtwamr: integrate lsfwt.c
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 06 May 2024 03:38:26 +0000
parents
children
comparison
equal deleted inserted replaced
369:a01de4e40540 370:8861f41e4507
1 /*
2 ********************************************************************************
3 *
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
5 * R99 Version 3.3.0
6 * REL-4 Version 4.1.0
7 *
8 ********************************************************************************
9 *
10 * File : lsfwt.c
11 * Purpose : Compute LSF weighting factors
12 *
13 ********************************************************************************
14 */
15
16 /*
17 ********************************************************************************
18 * MODULE INCLUDE FILE AND VERSION ID
19 ********************************************************************************
20 */
21 #include "namespace.h"
22 #include "lsfwt.h"
23
24 /*
25 ********************************************************************************
26 * INCLUDE FILES
27 ********************************************************************************
28 */
29 #include "typedef.h"
30 #include "basic_op.h"
31 #include "no_count.h"
32 #include "cnst.h"
33
34 /*
35 ********************************************************************************
36 * PUBLIC PROGRAM CODE
37 ********************************************************************************
38 */
39 /****************************************************
40 *
41 * FUNCTION Lsf_wt *
42 * *
43 ****************************************************
44 * Compute LSF weighting factors *
45 * *
46 * d[i] = lsf[i+1] - lsf[i-1] *
47 * *
48 * The weighting factors are approximated by two line segment. *
49 * *
50 * First segment passes by the following 2 points: *
51 * *
52 * d[i] = 0Hz wf[i] = 3.347 *
53 * d[i] = 450Hz wf[i] = 1.8 *
54 * *
55 * Second segment passes by the following 2 points: *
56 * *
57 * d[i] = 450Hz wf[i] = 1.8 *
58 * d[i] = 1500Hz wf[i] = 1.0 *
59 * *
60 * if( d[i] < 450Hz ) *
61 * wf[i] = 3.347 - ( (3.347-1.8) / (450-0)) * d[i] *
62 * else *
63 * wf[i] = 1.8 - ( (1.8-1.0) / (1500-450)) * (d[i] - 450) *
64 * *
65 * *
66 * if( d[i] < 1843) *
67 * wf[i] = 3427 - (28160*d[i])>>15 *
68 * else *
69 * wf[i] = 1843 - (6242*(d[i]-1843))>>15 *
70 * *
71 *--------------------------------------------------------------------------*/
72
73 void Lsf_wt (
74 Word16 *lsf, /* input : LSF vector */
75 Word16 *wf) /* output: square of weighting factors */
76 {
77 Word16 temp;
78 Word16 i;
79 /* wf[0] = lsf[1] - 0 */
80 wf[0] = lsf[1]; move16 ();
81 for (i = 1; i < 9; i++)
82 {
83 wf[i] = sub (lsf[i + 1], lsf[i - 1]); move16 ();
84 }
85 /* wf[9] = 0.5 - lsf[8] */
86 wf[9] = sub (16384, lsf[8]);move16 ();
87
88 for (i = 0; i < 10; i++)
89 {
90 temp = sub (wf[i], 1843);
91 test ();
92 if (temp < 0)
93 {
94 wf[i] = sub (3427, mult (wf[i], 28160)); move16 ();
95 }
96 else
97 {
98 wf[i] = sub (1843, mult (temp, 6242)); move16 ();
99 }
100
101 wf[i] = shl (wf[i], 3); move16 ();
102 }
103 return;
104 }