FreeCalypso > hg > gsm-codec-lib
annotate libgsmefr/enc_lag6.c @ 56:902bc4b64cc6
libgsmefr: az_lsp.c compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 25 Nov 2022 17:15:08 +0000 |
parents | 49dd1ac8e75b |
children | e109d8752d60 |
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 * FUNCTION: Enc_lag6 |
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: Encoding of fractional pitch lag with 1/6 resolution. |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * DESCRIPTION: |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 * First and third subframes: |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * -------------------------- |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * The pitch range is divided as follows: |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * 17 3/6 to 94 3/6 resolution 1/6 |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 * 95 to 143 resolution 1 |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 * |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 * The period is encoded with 9 bits. |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 * For the range with fractions: |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 * index = (T-17)*6 + frac - 3; |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 * where T=[17..94] and frac=[-2,-1,0,1,2,3] |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 * and for the integer only range |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 * index = (T - 95) + 463; where T=[95..143] |
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 * Second and fourth subframes: |
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 * For the 2nd and 4th subframes a resolution of 1/6 is always used, |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 * and the search range is relative to the lag in previous subframe. |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 * If t0 is the lag in the previous subframe then |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 * t_min=t0-5 and t_max=t0+4 and the range is given by |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 * (t_min-1) 3/6 to (t_max) 3/6 |
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 * The period in the 2nd (and 4th) subframe is encoded with 6 bits: |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 * index = (T-(t_min-1))*6 + frac - 3; |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 * where T=[t_min-1..t_max] and frac=[-2,-1,0,1,2,3] |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 * |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 * Note that only 61 values are used. If the decoder receives 61, 62, |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 * or 63 as the relative pitch index, it means that a transmission |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 * error occurred and the pitch from previous subframe should be used. |
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 *************************************************************************/ |
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 #include "typedef.h" |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 #include "basic_op.h" |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 #include "count.h" |
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 Word16 Enc_lag6 ( /* output: Return index of encoding */ |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 Word16 T0, /* input : Pitch delay */ |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 Word16 *T0_frac, /* in/out: Fractional pitch delay */ |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 Word16 *T0_min, /* in/out: Minimum search delay */ |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 Word16 *T0_max, /* in/out: Maximum search delay */ |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 Word16 pit_min, /* input : Minimum pitch delay */ |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 Word16 pit_max, /* input : Maximum pitch delay */ |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 Word16 pit_flag /* input : Flag for 1st or 3rd subframe */ |
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 { |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 Word16 index, i; |
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 test (); |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 if (pit_flag == 0) /* if 1st or 3rd subframe */ |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 { |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 /* encode pitch delay (with fraction) */ |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 |
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 if (sub (T0, 94) <= 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 /* index = T0*6 - 105 + *T0_frac */ |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 i = add (add (T0, T0), T0); |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 index = add (sub (add (i, i), 105), *T0_frac); |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } else |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 { /* set fraction to 0 for delays > 94 */ |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 *T0_frac = 0; move16 (); |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 index = add (T0, 368); |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 } |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 /* find T0_min and T0_max for second (or fourth) subframe */ |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 *T0_min = sub (T0, 5); move16 (); |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 test (); |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 if (sub (*T0_min, pit_min) < 0) |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 { |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 *T0_min = pit_min; move16 (); |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 } |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 *T0_max = add (*T0_min, 9); |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 test (); |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 if (sub (*T0_max, pit_max) > 0) |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 { |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 *T0_max = pit_max; move16 (); |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 *T0_min = sub (*T0_max, 9); move16 (); |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 } |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 } else |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 /* if second or fourth subframe */ |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 { |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 /* index = 6*(T0-*T0_min) + 3 + *T0_frac */ |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 i = sub (T0, *T0_min); |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 i = add (add (i, i), i); |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 index = add (add (add (i, i), 3), *T0_frac); |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 } |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 return index; |
49dd1ac8e75b
libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 } |