annotate libgsmefr/lsp_lsf.c @ 53:49dd1ac8e75b

libgsmefr: import most *.c files from ETSI source
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 25 Nov 2022 16:18:21 +0000
parents
children 8d3412b7ec4e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
53
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*************************************************************************
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * FUNCTIONS: Lsp_lsf and Lsf_lsp
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * PURPOSE:
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * Lsp_lsf: Transformation lsp to lsf
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * Lsf_lsp: Transformation lsf to lsp
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 * DESCRIPTION:
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * lsp[i] = cos(2*pi*lsf[i]) and lsf[i] = arccos(lsp[i])/(2*pi)
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 * The transformation from lsp[i] to lsf[i] and lsf[i] to lsp[i] are
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 * approximated by a look-up table and interpolation.
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 *************************************************************************/
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "typedef.h"
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "basic_op.h"
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include "count.h"
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "lsp_lsf.tab" /* Look-up table for transformations */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 void Lsf_lsp (
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 Word16 lsf[], /* (i) : lsf[m] normalized (range: 0.0<=val<=0.5) */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 Word16 lsp[], /* (o) : lsp[m] (range: -1<=val<1) */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 Word16 m /* (i) : LPC order */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 )
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 {
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 Word16 i, ind, offset;
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 Word32 L_tmp;
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 for (i = 0; i < m; i++)
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 {
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 ind = shr (lsf[i], 8); /* ind = b8-b15 of lsf[i] */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 offset = lsf[i] & 0x00ff; logic16 (); /* offset = b0-b7 of lsf[i] */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 /* lsp[i] = table[ind]+ ((table[ind+1]-table[ind])*offset) / 256 */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 L_tmp = L_mult (sub (table[ind + 1], table[ind]), offset);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 lsp[i] = add (table[ind], extract_l (L_shr (L_tmp, 9)));
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 move16 ();
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 return;
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 }
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 void Lsp_lsf (
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 Word16 lsp[], /* (i) : lsp[m] (range: -1<=val<1) */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 Word16 lsf[], /* (o) : lsf[m] normalized (range: 0.0<=val<=0.5) */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 Word16 m /* (i) : LPC order */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 )
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 {
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 Word16 i, ind;
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 Word32 L_tmp;
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 ind = 63; /* begin at end of table -1 */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 for (i = m - 1; i >= 0; i--)
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 {
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 /* find value in table that is just greater than lsp[i] */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 test ();
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 while (sub (table[ind], lsp[i]) < 0)
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 {
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 ind--;
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 test ();
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 /* acos(lsp[i])= ind*256 + ( ( lsp[i]-table[ind] ) *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 slope[ind] )/4096 */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 L_tmp = L_mult (sub (lsp[i], table[ind]), slope[ind]);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 /*(lsp[i]-table[ind])*slope[ind])>>12*/
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 lsf[i] = round (L_shl (L_tmp, 3)); move16 ();
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 lsf[i] = add (lsf[i], shl (ind, 8)); move16 ();
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 return;
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 }