annotate libtwamr/lsp_lsf.c @ 451:614ae8dc6807

README: update for libgsmfr2+libgsmefr+libtwamr set
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 10 May 2024 02:36:34 +0000
parents 05a46720af0f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
344
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 ********************************************************************************
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 *
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * R99 Version 3.3.0
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * REL-4 Version 4.1.0
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 *
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 ********************************************************************************
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 *
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * File : lsp_lsf.c
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 * Purpose : Lsp_lsf: Transformation lsp to lsf
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 * : Lsf_lsp: Transformation lsf to lsp
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 *
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 ********************************************************************************
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 */
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 /*
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 ********************************************************************************
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 * MODULE INCLUDE FILE AND VERSION ID
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 ********************************************************************************
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 */
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "namespace.h"
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 #include "lsp_lsf.h"
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 /*
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 ********************************************************************************
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 * INCLUDE FILES
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 ********************************************************************************
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 */
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 #include "typedef.h"
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 #include "basic_op.h"
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 #include "no_count.h"
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 /*
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 ********************************************************************************
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 * LOCAL VARIABLES AND TABLES
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 ********************************************************************************
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 */
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 #include "lsp_lsf.tab" /* Look-up table for transformations */
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 /*
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 ********************************************************************************
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 * PUBLIC PROGRAM CODE
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 ********************************************************************************
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 */
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 /*************************************************************************
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 *
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 * FUNCTIONS: Lsp_lsf and Lsf_lsp
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 *
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 * PURPOSE:
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 * Lsp_lsf: Transformation lsp to lsf
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 * Lsf_lsp: Transformation lsf to lsp
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 *
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 * DESCRIPTION:
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 * lsp[i] = cos(2*pi*lsf[i]) and lsf[i] = arccos(lsp[i])/(2*pi)
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 *
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 * The transformation from lsp[i] to lsf[i] and lsf[i] to lsp[i] are
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 * approximated by a look-up table and interpolation.
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 *
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 *************************************************************************/
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 void Lsf_lsp (
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 Word16 lsf[], /* (i) : lsf[m] normalized (range: 0.0<=val<=0.5) */
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 Word16 lsp[], /* (o) : lsp[m] (range: -1<=val<1) */
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 Word16 m /* (i) : LPC order */
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 )
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 {
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 Word16 i, ind, offset;
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 Word32 L_tmp;
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 for (i = 0; i < m; i++)
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 {
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 ind = shr (lsf[i], 8); /* ind = b8-b15 of lsf[i] */
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 offset = lsf[i] & 0x00ff; logic16 (); /* offset = b0-b7 of lsf[i] */
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 /* lsp[i] = table[ind]+ ((table[ind+1]-table[ind])*offset) / 256 */
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 L_tmp = L_mult (sub (table[ind + 1], table[ind]), offset);
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 lsp[i] = add (table[ind], extract_l (L_shr (L_tmp, 9)));
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 move16 ();
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 }
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 return;
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 }
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 void Lsp_lsf (
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 Word16 lsp[], /* (i) : lsp[m] (range: -1<=val<1) */
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 Word16 lsf[], /* (o) : lsf[m] normalized (range: 0.0<=val<=0.5) */
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 Word16 m /* (i) : LPC order */
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 )
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 {
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 Word16 i, ind;
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 Word32 L_tmp;
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 ind = 63; move16 (); /* begin at end of table -1 */
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 for (i = m - 1; i >= 0; i--)
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 {
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 /* find value in table that is just greater than lsp[i] */
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 test ();
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 while (sub (table[ind], lsp[i]) < 0)
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 {
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 ind--;
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 test ();
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 }
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 /* acos(lsp[i])= ind*256 + ( ( lsp[i]-table[ind] ) *
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 slope[ind] )/4096 */
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 L_tmp = L_mult (sub (lsp[i], table[ind]), slope[ind]);
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 /*(lsp[i]-table[ind])*slope[ind])>>12*/
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 lsf[i] = round (L_shl (L_tmp, 3)); move16 ();
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 lsf[i] = add (lsf[i], shl (ind, 8)); move16 ();
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 }
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 return;
05a46720af0f libtwamr: integrate d_plsf_3.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 }