annotate reid.c @ 5:59fc7fc126d0

mv utils.c reid.c In the original GSM 06.06 code drop, reid.c resides in the "utilities" collection (Dir_UTIL.zip), but there is also a copy of reid.c named utils.c in the "C" collection (Dir_C.zip), even though it is never compiled or linked as such. When I originally created the present Hg repository, I did not intend to include REID, only the main body of the codec - but I overlooked that utils.c copy, so it got imported. In the present time, however, it has become useful to have REID code in Hg for easier public study and discussion - so let's have it under its proper name.
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 22 Jul 2024 18:43:12 +0000
parents utils.c@9008dbc8ca74
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*___________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 | Residual Error Insertion Device |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 | File : REID.C |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 | Date : February 03, 1995 |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 | Version: 4.1 |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 | Description: |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 | ------------ |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 | This routine transforms the output file format of the GSM Half |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 | Rate Encoder module consisting of: |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 | * 18 speech parameters (see GSM TS 06.20) |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 | * 1 speech flag SP (see GSM TS 06.41) |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 | * 1 voice activity flag VAD (see GSM TS 06.42) |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 | to the input file format of the GSM Half Rate Decoder module |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 | requiring: |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 | * 18 speech parameters (see GSM TS 06.20) |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 | * 1 channel condition flag BFI (see GSM TS 06.21, 05.05) |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 | * 1 channel condition flag UFI (see GSM TS 06.21, 05.05) |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 | * 1 SID flag (2 bits) (see GSM TS 06.41, 05.05) |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 | * 1 time alignment flag TAF (see GSM TS 06.41) |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 | Between SID updates the speech parameters are replaced by random |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 | values simulating an interrupted transmission on the air interface |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 | The actual implementation only supports error free transmission (EP0)|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 | The shell for the future use of error patterns (residual error |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 | pattern insertion) is already included. If necessary, byte swapping |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 | is performed on the input speech parameters so that they are always |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 | represented internally in PC byte order (assuming that the byte |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 | order of the input file is compatible with the machine on which the |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 | program is run). However, byte swapping is not done on the flag |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 | words (input: SP and VAD, output: BFI, UFI, SID, and TAF). Thus, |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 | the residual error pattern insertion code may be written to handle |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 | the speech parameter words on a byte basis, but the flag words must |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 | always be handled on a word basis. |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 |___________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 /*___________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 | Creation: 19.12.94 |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 | Changes: |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 | 22.12.94: Removal of BCI flag, instead: determination of SID flag |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 | 12.01.95: SID update period = 12 (instead of 24) |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 | 13.01.95: When in CNI mode, the parameters between SID updates are |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 | random values. This simulates the interrupted transmission|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 | 03.02.95: Longword main( Longword...) replaced by int main(int ...),|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 | initial value of swTAFCnt set to 1 |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 |___________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 /*___________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 | Include-Files |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 |___________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 #include <stdlib.h>
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 #include <stdio.h>
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 #include <string.h>
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 #include <ctype.h>
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 #ifdef VAX
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 # define OPEN_WI "wb","mrs=512","rfm=fix","ctx=stm"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 # define OPEN_RI "rb","mrs=512","rfm=fix","ctx=stm"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 # define OPEN_WB "wb","mrs=512","rfm=fix","ctx=stm"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 # define OPEN_RB "rb","mrs=2","rfm=fix","ctx=stm"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 # define OPEN_WT "w","mrs=256","rat=cr","rfm=var"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 # define OPEN_RT "r","mrs=256","rat=cr","rfm=var"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 #else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 # define OPEN_WB "wb"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 # define OPEN_RB "rb"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 # define OPEN_WI "wb"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 # define OPEN_RI "rb"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 # define OPEN_WT "wt"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 # define OPEN_RT "rt"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 #endif
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 #define LW_SIGN (long)0x80000000 /* sign bit */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 #define LW_MIN (long)0x80000000
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 #define LW_MAX (long)0x7fffffff
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 #define SW_MIN (short)0x8000 /* smallest Ram */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 #define SW_MAX (short)0x7fff /* largest Ram */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 typedef char Byte;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 typedef long int Longword; /* 32 bit "accumulator" (L_*) */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 typedef short int Shortword; /* 16 bit "register" (sw*) */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 /*___________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 | local Functions |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 |___________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 static Longword error_free( FILE *infile, FILE *outfile);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 static void SwapBytes( Shortword buffer[], Longword len );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 static Longword ByteOrder( void );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 static size_t ReadInputFile( Shortword buffer[], FILE *fp );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 static size_t WriteOutputFile( Shortword buffer[], FILE *fp );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 static Longword EncoderInterface( FILE *infile, Shortword swInPara[] );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 static Shortword swSidDetection(Shortword pswParameters[],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 Shortword pswErrorFlag[]);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 static void RandomParameters(Shortword pswParameters[]);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 static Shortword getPnBits(Shortword iBits, Longword *pL_PNSeed);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 FILE *OpenBinfile( char *name, char *mode );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 Longword Strincmp( const char *s, const char *t, size_t max );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 Longword Stricmp( const char *s, const char *t );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 Longword L_shr(Longword L_var1, Shortword var2); /* 2 ops */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 Longword L_shl(Longword L_var1, Shortword var2); /* 2 ops */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 Shortword shr(Shortword var1, Shortword var2); /* 1 ops */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 Shortword shl(Shortword var1, Shortword var2); /* 1 ops */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 /*___________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 | Subroutines |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 |___________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 static Longword error_free( FILE *infile, FILE *outfile)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 #define SPEECH 1
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 #define CNIFIRSTSID 2
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 #define CNICONT 3
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 #define VALIDSID 11
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 #define GOODSPEECH 33
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 static Shortword swDecoMode = {SPEECH};
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 static Shortword swTAFCnt = {1};
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 Shortword swInPara[20], i, swFrameType;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 Shortword swOutPara[22],pswErrorFlag[3];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 if( EncoderInterface( infile, swInPara )) return( 1 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 /* Copy input parameters to output parameters (error free transmission) */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 /* -------------------------------------------------------------------- */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 for (i=0;i<18;i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 swOutPara[i] = swInPara[i];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 /* Set channel status flags (error free transmission) */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 /* -------------------------------------------------- */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 swOutPara[18] = 0; /* BFI flag */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 swOutPara[19] = 0; /* UFI flag */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 /* Evaluate SID flag */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 /* ----------------- */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 pswErrorFlag[0] = 0; /* BFI flag */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 pswErrorFlag[1] = 0; /* UFI flag */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 pswErrorFlag[2] = 0; /* BCI flag */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 swOutPara[20] = swSidDetection(swOutPara, pswErrorFlag);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 /* Evaluate TAF flag */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 /* ----------------- */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 if (swTAFCnt == 0) swOutPara[21] = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 else swOutPara[21] = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 swTAFCnt = (swTAFCnt + 1) % 12;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 /* Frame classification: */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 /* Since the transmission is error free, the received frames are either */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 /* valid speech or valid SID frames */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 /* -------------------------------------------------------------------- */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 if ( swOutPara[20] == 2) swFrameType = VALIDSID;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 else if ( swOutPara[20] == 0) swFrameType = GOODSPEECH;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 else {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 printf( "Error in SID detection\n" );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 return( 1 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 /* Update of decoder state */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 /* ----------------------- */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 if (swDecoMode == SPEECH) {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 if (swFrameType == VALIDSID) swDecoMode = CNIFIRSTSID;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 else if (swFrameType == GOODSPEECH) swDecoMode = SPEECH;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 else { /* comfort noise insertion mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 if (swFrameType == VALIDSID) swDecoMode = CNICONT;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 else if (swFrameType == GOODSPEECH) swDecoMode = SPEECH;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 /* Replace parameters by random data if in CNICONT-mode and TAF=0 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 /* -------------------------------------------------------------- */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 if ((swDecoMode == CNICONT) && (swOutPara[21] == 0)){
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 RandomParameters(swOutPara);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 /* Set flags such, that an "unusable frame" is produced */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 swOutPara[18] = 1; /* BFI flag */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 swOutPara[19] = 1; /* UFI flag */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 swOutPara[20] = 0; /* SID flag */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 if( outfile ) {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 if( WriteOutputFile( swOutPara, outfile )) {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 printf( "Error writing File\n" );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 return( 1 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 return( 0 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 static Longword EncoderInterface( FILE *infile, Shortword swInPara[] )
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 size_t i = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 i = ReadInputFile( swInPara, infile );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 return(( i == 0 ) ? 1 : 0 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 static size_t ReadInputFile( Shortword buffer[], FILE *fp )
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 size_t i;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 i = fread( buffer, sizeof( Shortword ), 20, fp );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 SwapBytes( buffer, 18 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 return( i );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 static size_t WriteOutputFile( Shortword buffer[], FILE *fp )
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 size_t i;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 SwapBytes( buffer, 18 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 i = fwrite( buffer, sizeof( Shortword ), 22, fp );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 return( ( i == 22 ) ? 0 : 1 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 static void SwapBytes( Shortword buffer[], Longword len )
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 Byte *pc, tmp;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 Longword i;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 if( !ByteOrder())
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 return;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 pc = (Byte *)buffer;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 for( i = 0; i < len; i++ ) {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 tmp = pc[0];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 pc[0] = pc[1];
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 pc[1] = tmp;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 pc += 2;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 static Longword ByteOrder( void )
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 Shortword si;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 Byte *pc;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 si = 0x1234;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 pc = (Byte *)&si;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 if (pc[1] == 0x12 && pc[0] == 0x34 )
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 return( 0 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 if (pc[0] == 0x12 && pc[1] == 0x34 )
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 return( 1 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 printf( "Error in ByteOrder: %X, %X\n", (int)pc[0], (int)pc[1] );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 exit( 1 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 return( 2 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 FILE *OpenBinfile( char *name, char *mode )
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 FILE *fp;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275 if( toupper( *mode ) == 'W' ) { /* Write access */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 if(( fp = fopen( name, OPEN_WB )) == NULL ) {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
277 printf( "Can't open output file '%s'\n", name );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
278 exit( 1 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280 } else { /* Read access */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281 if(( fp = fopen( name, OPEN_RB )) == NULL ) {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
282 printf( "Can't open file '%s'\n", name );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283 exit( 1 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286 return( fp );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
289 Longword Strincmp( const char *s, const char *t, size_t max )
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
290 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
291 for( ; max > 1; ++s, ++t, --max ) {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
292 if( toupper( *s ) != toupper( *t ))
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
293 break;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
294 if( *s == '\0' )
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
295 return( 0 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
296 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
297 return( toupper( *s ) - toupper( *t ));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
298 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
299
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
300 Longword Stricmp( const char *s, const char *t )
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
301 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
302 for(; toupper( *s ) == toupper( *t ); ++s, ++t ) {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
303 if( *s == '\0' )
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
304 return( 0 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
305 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
306 return( toupper( *s ) - toupper( *t ));
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
307 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
308
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
309 /*************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
310 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
311 * FUNCTION NAME: getPnBits
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
312 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
313 * PURPOSE:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
314 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
315 * Generate iBits pseudo-random bits using *pL_PNSeed as the
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
316 * pn-generators seed.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
317 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
318 * INPUTS:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
319 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
320 * iBits - integer indicating how many random bits to return.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
321 * range [0,15], 0 yields 1 bit output
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
322 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
323 * *pL_PNSeed - 32 bit seed (changed by function)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
324 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
325 * OUTPUTS:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
326 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
327 * *pL_PNSeed - 32 bit seed, modified.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
328 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
329 * RETURN VALUE:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
330 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
331 * random bits in iBits LSB's.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
332 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
333 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
334 * IMPLEMENTATION:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
335 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
336 * implementation of x**31 + x**3 + 1 == PN_XOR_REG | PN_XOR_ADD a
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
337 * PN sequence generator using Longwords generating a 2**31 -1
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
338 * length pn-sequence.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
339 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
340 *************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
341
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
342 static Shortword getPnBits(Shortword iBits, Longword *pL_PNSeed){
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
343
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
344 #define PN_XOR_REG (Longword)0x00000005L
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
345 #define PN_XOR_ADD (Longword)0x40000000L
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
346
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
347 Shortword swPnBits=0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
348 Longword L_Taps,L_FeedBack;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
349 Shortword i;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
350
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
351 for (i=0; i < iBits; i++){
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
352
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
353 /* update the state */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
354 /********************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
355
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
356 L_Taps = *pL_PNSeed & PN_XOR_REG;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
357 L_FeedBack = L_Taps; /* Xor tap bits to yield feedback bit */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
358 L_Taps = L_shr(L_Taps,1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
359
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
360 while(L_Taps){
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
361 L_FeedBack = L_FeedBack ^ L_Taps;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
362 L_Taps = L_shr(L_Taps,1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
363 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
364
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
365 /* LSB of L_FeedBack is next MSB of PN register */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
366
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
367 *pL_PNSeed = L_shr(*pL_PNSeed,1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
368 if (L_FeedBack & 1)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
369 *pL_PNSeed = *pL_PNSeed | PN_XOR_ADD;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
370
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
371 /* State update complete.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
372 Get the output bit from the state, add/or it into output */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
373
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
374 swPnBits = shl(swPnBits,1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
375 swPnBits = swPnBits | (*pL_PNSeed & 1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
376
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
377 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
378 return(swPnBits);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
379 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
380
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
381
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
382 /***************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
383 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
384 * FUNCTION NAME: L_shl
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
385 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
386 * PURPOSE:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
387 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
388 * Arithmetic shift left (or right).
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
389 * Arithmetically shift the input left by var2. If var2 is
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
390 * negative then an arithmetic shift right (L_shr) of L_var1 by
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
391 * -var2 is performed.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
392 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
393 * INPUTS:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
394 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
395 * var2
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
396 * 16 bit short signed integer (Shortword) whose value
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
397 * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
398 * L_var1
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
399 * 32 bit long signed integer (Longword) whose value
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
400 * falls in the range
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
401 * 0x8000 0000 <= L_var1 <= 0x7fff ffff.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
402 * OUTPUTS:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
403 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
404 * none
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
405 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
406 * RETURN VALUE:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
407 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
408 * L_Out
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
409 * 32 bit long signed integer (Longword) whose value
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
410 * falls in the range
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
411 * 0x8000 0000 <= L_var1 <= 0x7fff ffff.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
412 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
413 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
414 * IMPLEMENTATION:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
415 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
416 * Arithmetically shift the 32 bit input left by var2. This
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
417 * operation maintains the sign of the input number. If var2 is
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
418 * negative then an arithmetic shift right (L_shr) of L_var1 by
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
419 * -var2 is performed. See description of L_shr for details.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
420 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
421 * Equivalent to the Full-Rate GSM ">> n" operation. Note that
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
422 * ANSI-C does not guarantee operation of the C ">>" or "<<"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
423 * operator for negative numbers.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
424 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
425 * KEYWORDS: shift, arithmetic shift left,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
426 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
427 *************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
428
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
429 Longword L_shl(Longword L_var1, Shortword var2)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
430 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
431
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
432 Longword L_Mask,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
433 L_Out;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
434 int i,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
435 iOverflow = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
436
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
437 if (var2 == 0 || L_var1 == 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
438 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
439 L_Out = L_var1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
440 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
441 else if (var2 < 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
442 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
443 if (var2 <= -31)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
444 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
445 if (L_var1 > 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
446 L_Out = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
447 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
448 L_Out = 0xffffffffL;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
449 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
450 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
451 L_Out = L_shr(L_var1, -var2);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
452 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
453 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
454 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
455
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
456 if (var2 >= 31)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
457 iOverflow = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
458
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
459 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
460 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
461
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
462 if (L_var1 < 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
463 L_Mask = LW_SIGN; /* sign bit mask */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
464 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
465 L_Mask = 0x0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
466 L_Out = L_var1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
467 for (i = 0; i < var2 && !iOverflow; i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
468 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
469 /* check the sign bit */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
470 L_Out = (L_Out & 0x7fffffffL) << 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
471 if ((L_Mask ^ L_Out) & LW_SIGN)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
472 iOverflow = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
473 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
474 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
475
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
476 if (iOverflow)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
477 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
478 /* saturate */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
479 if (L_var1 > 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
480 L_Out = LW_MAX;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
481 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
482 L_Out = LW_MIN;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
483 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
484 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
485
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
486 return (L_Out);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
487 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
488
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
489 /***************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
490 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
491 * FUNCTION NAME: L_shr
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
492 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
493 * PURPOSE:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
494 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
495 * Arithmetic shift right (or left).
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
496 * Arithmetically shift the input right by var2. If var2 is
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
497 * negative then an arithmetic shift left (shl) of var1 by
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
498 * -var2 is performed.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
499 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
500 * INPUTS:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
501 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
502 * var2
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
503 * 16 bit short signed integer (Shortword) whose value
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
504 * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
505 * L_var1
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
506 * 32 bit long signed integer (Longword) whose value
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
507 * falls in the range
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
508 * 0x8000 0000 <= L_var1 <= 0x7fff ffff.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
509 * OUTPUTS:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
510 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
511 * none
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
512 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
513 * RETURN VALUE:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
514 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
515 * L_Out
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
516 * 32 bit long signed integer (Longword) whose value
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
517 * falls in the range
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
518 * 0x8000 0000 <= L_var1 <= 0x7fff ffff.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
519 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
520 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
521 * IMPLEMENTATION:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
522 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
523 * Arithmetically shift the input right by var2. This
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
524 * operation maintains the sign of the input number. If var2 is
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
525 * negative then an arithmetic shift left (shl) of L_var1 by
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
526 * -var2 is performed. See description of L_shl for details.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
527 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
528 * The input is a 32 bit number, as is the output.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
529 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
530 * Equivalent to the Full-Rate GSM ">> n" operation. Note that
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
531 * ANSI-C does not guarantee operation of the C ">>" or "<<"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
532 * operator for negative numbers.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
533 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
534 * KEYWORDS: shift, arithmetic shift right,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
535 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
536 *************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
537
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
538 Longword L_shr(Longword L_var1, Shortword var2)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
539 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
540
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
541 Longword L_Mask,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
542 L_Out;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
543
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
544 if (var2 == 0 || L_var1 == 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
545 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
546 L_Out = L_var1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
547 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
548 else if (var2 < 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
549 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
550 /* perform a left shift */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
551 /*----------------------*/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
552 if (var2 <= -31)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
553 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
554 /* saturate */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
555 if (L_var1 > 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
556 L_Out = LW_MAX;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
557 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
558 L_Out = LW_MIN;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
559 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
560 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
561 L_Out = L_shl(L_var1, -var2);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
562 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
563 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
564 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
565
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
566 if (var2 >= 31)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
567 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
568 if (L_var1 > 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
569 L_Out = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
570 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
571 L_Out = 0xffffffffL;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
572 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
573 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
574 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
575 L_Mask = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
576
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
577 if (L_var1 < 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
578 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
579 L_Mask = ~L_Mask << (32 - var2);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
580 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
581
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
582 L_var1 >>= var2;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
583 L_Out = L_Mask | L_var1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
584 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
585 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
586 return (L_Out);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
587 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
588
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
589
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
590 /***************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
591 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
592 * FUNCTION NAME: shl
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
593 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
594 * PURPOSE:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
595 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
596 * Arithmetically shift the input left by var2.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
597 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
598 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
599 * INPUTS:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
600 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
601 * var1
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
602 * 16 bit short signed integer (Shortword) whose value
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
603 * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
604 * var2
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
605 * 16 bit short signed integer (Shortword) whose value
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
606 * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
607 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
608 * OUTPUTS:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
609 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
610 * none
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
611 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
612 * RETURN VALUE:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
613 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
614 * swOut
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
615 * 16 bit short signed integer (Shortword) whose value
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
616 * falls in the range
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
617 * 0xffff 8000 <= swOut <= 0x0000 7fff.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
618 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
619 * IMPLEMENTATION:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
620 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
621 * If Arithmetically shift the input left by var2. If var2 is
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
622 * negative then an arithmetic shift right (shr) of var1 by
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
623 * -var2 is performed. See description of shr for details.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
624 * When an arithmetic shift left is performed the var2 LS bits
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
625 * are zero filled.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
626 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
627 * The only exception is if the left shift causes an overflow
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
628 * or underflow. In this case the LS bits are not modified.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
629 * The number returned is 0x8000 in the case of an underflow or
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
630 * 0x7fff in the case of an overflow.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
631 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
632 * The shl is equivalent to the Full-Rate GSM "<< n" operation.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
633 * Note that ANSI-C does not guarantee operation of the C ">>"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
634 * or "<<" operator for negative numbers - it is not specified
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
635 * whether this shift is an arithmetic or logical shift.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
636 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
637 * KEYWORDS: asl, arithmetic shift left, shift
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
638 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
639 *************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
640
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
641 Shortword shl(Shortword var1, Shortword var2)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
642 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
643 Shortword swOut;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
644 Longword L_Out;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
645
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
646 if (var2 == 0 || var1 == 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
647 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
648 swOut = var1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
649 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
650 else if (var2 < 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
651 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
652
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
653 /* perform a right shift */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
654 /*-----------------------*/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
655
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
656 if (var2 <= -15)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
657 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
658 if (var1 < 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
659 swOut = (Shortword) 0xffff;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
660 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
661 swOut = 0x0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
662 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
663 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
664 swOut = shr(var1, -var2);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
665
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
666 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
667 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
668 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
669 /* var2 > 0 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
670 if (var2 >= 15)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
671 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
672 /* saturate */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
673 if (var1 > 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
674 swOut = SW_MAX;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
675 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
676 swOut = SW_MIN;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
677 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
678 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
679 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
680
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
681 L_Out = (Longword) var1 *(1 << var2);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
682
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
683 swOut = (Shortword) L_Out; /* copy low portion to swOut,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
684 * overflow could have hpnd */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
685 if (swOut != L_Out)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
686 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
687 /* overflow */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
688 if (var1 > 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
689 swOut = SW_MAX; /* saturate */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
690 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
691 swOut = SW_MIN; /* saturate */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
692 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
693 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
694 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
695 return (swOut);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
696 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
697
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
698 /***************************************************************************
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
699 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
700 * FUNCTION NAME: shr
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
701 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
702 * PURPOSE:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
703 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
704 * Arithmetic shift right (or left).
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
705 * Arithmetically shift the input right by var2. If var2 is
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
706 * negative then an arithmetic shift left (shl) of var1 by
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
707 * -var2 is performed.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
708 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
709 * INPUTS:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
710 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
711 * var1
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
712 * 16 bit short signed integer (Shortword) whose value
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
713 * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
714 * var2
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
715 * 16 bit short signed integer (Shortword) whose value
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
716 * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
717 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
718 * OUTPUTS:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
719 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
720 * none
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
721 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
722 * RETURN VALUE:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
723 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
724 * swOut
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
725 * 16 bit short signed integer (Shortword) whose value
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
726 * falls in the range
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
727 * 0xffff 8000 <= swOut <= 0x0000 7fff.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
728 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
729 * IMPLEMENTATION:
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
730 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
731 * Arithmetically shift the input right by var2. This
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
732 * operation maintains the sign of the input number. If var2 is
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
733 * negative then an arithmetic shift left (shl) of var1 by
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
734 * -var2 is performed. See description of shl for details.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
735 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
736 * Equivalent to the Full-Rate GSM ">> n" operation. Note that
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
737 * ANSI-C does not guarantee operation of the C ">>" or "<<"
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
738 * operator for negative numbers.
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
739 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
740 * KEYWORDS: shift, arithmetic shift right,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
741 *
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
742 *************************************************************************/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
743
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
744 Shortword shr(Shortword var1, Shortword var2)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
745 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
746
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
747 Shortword swMask,
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
748 swOut;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
749
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
750 if (var2 == 0 || var1 == 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
751 swOut = var1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
752
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
753 else if (var2 < 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
754 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
755 /* perform an arithmetic left shift */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
756 /*----------------------------------*/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
757 if (var2 <= -15)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
758 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
759 /* saturate */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
760 if (var1 > 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
761 swOut = SW_MAX;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
762 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
763 swOut = SW_MIN;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
764 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
765 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
766 swOut = shl(var1, -var2);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
767 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
768
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
769 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
770 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
771
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
772 /* positive shift count */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
773 /*----------------------*/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
774
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
775 if (var2 >= 15)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
776 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
777 if (var1 < 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
778 swOut = (Shortword) 0xffff;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
779 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
780 swOut = 0x0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
781 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
782 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
783 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
784 /* take care of sign extension */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
785 /*-----------------------------*/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
786
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
787 swMask = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
788 if (var1 < 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
789 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
790 swMask = ~swMask << (16 - var2);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
791 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
792
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
793 var1 >>= var2;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
794 swOut = swMask | var1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
795
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
796 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
797 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
798 return (swOut);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
799 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
800
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
801 /*___________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
802 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
803 | This subroutine calculates the 'SID flag' |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
804 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
805 | Input: pswParameters[18] |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
806 | input parameters of the speech decoder |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
807 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
808 | pswErrorFlag[3] |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
809 | error flags, generated by channel decoder |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
810 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
811 | Return Value: |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
812 | 0: speech frame detected |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
813 | 1: most likely SID frame received |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
814 | 2: SID frame detected |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
815 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
816 |___________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
817 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
818 | History: |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
819 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
820 | 12-Oct-1994: Bug removed: error corrected in case of a mode (unvoiced/|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
821 | voiced) mismatch, if a SID frame was received as an |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
822 | unvoiced frame |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
823 |___________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
824 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
825
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
826 static Shortword swSidDetection(Shortword pswParameters[],
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
827 Shortword pswErrorFlag[])
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
828 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
829 static Shortword ppswIBit[2][18] = {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
830 5, 11,9,8, 1, 2, 7,7,5, 7,7,5, 7,7,5, 7,7,5, /* unvoiced */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
831 5, 11,9,8, 1, 2, 8,9,5, 4,9,5, 4,9,5, 4,9,5}; /* voiced */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
832
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
833 static Shortword ppswCL1pCL2[2][18] = {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
834 0x0001, /* R0 */ /* unvoiced */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
835 0x00ef, /* LPC1 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
836 0x003e, /* LPC2 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
837 0x007f, /* LPC3 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
838 0x0001, /* INT LPC */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
839 0x0003, /* Mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
840 0x001f, /* Code1_1 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
841 0x0072, /* Code2_1 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
842 0x0012, /* GSP0_1 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
843 0x003f, /* Code1_2 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
844 0x007f, /* Code2_2 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
845 0x0008, /* GSP0_2 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
846 0x007f, /* Code1_3 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
847 0x007f, /* Code2_3 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
848 0x0008, /* GSP0_3 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
849 0x007f, /* Code1_4 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
850 0x007f, /* Code2_4 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
851 0x000c, /* GSP0_4 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
852
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
853 0x0000, /* R0 */ /* voiced */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
854 0x0000, /* LPC1 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
855 0x0000, /* LPC2 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
856 0x0000, /* LPC3 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
857 0x0001, /* INT LPC */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
858 0x0003, /* Mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
859 0x00ff, /* Lag_1 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
860 0x01ff, /* Code_1 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
861 0x001f, /* GSP0_1 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
862 0x000f, /* Lag_2 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
863 0x01ff, /* Code_2 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
864 0x001f, /* GSP0_2 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
865 0x000f, /* Lag_3 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
866 0x01ff, /* Code_3 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
867 0x001f, /* GSP0_3 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
868 0x000f, /* Lag_4 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
869 0x01ff, /* Code_4 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
870 0x001f}; /* GSP0_4 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
871
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
872 static Shortword ppswCL2[2][18] = {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
873 0x0000, /* R0 */ /* unvoiced */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
874 0x0000, /* LPC1 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
875 0x0000, /* LPC2 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
876 0x0000, /* LPC3 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
877 0x0000, /* INT LPC */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
878 0x0000, /* Mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
879 0x0000, /* Code1_1 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
880 0x0000, /* Code2_1 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
881 0x0000, /* GSP0_1 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
882 0x0000, /* Code1_2 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
883 0x0000, /* Code2_2 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
884 0x0000, /* GSP0_2 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
885 0x0000, /* Code1_3 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
886 0x0007, /* Code2_3 */ /* 3 bits */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
887 0x0000, /* GSP0_3 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
888 0x007f, /* Code1_4 */ /* 7 bits */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
889 0x007f, /* Code2_4 */ /* 7 bits */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
890 0x0000, /* GSP0_4 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
891
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
892 0x0000, /* R0 */ /* voiced */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
893 0x0000, /* LPC1 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
894 0x0000, /* LPC2 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
895 0x0000, /* LPC3 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
896 0x0000, /* INT LPC */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
897 0x0000, /* Mode */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
898 0x0000, /* Lag_1 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
899 0x0000, /* Code_1 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
900 0x0000, /* GSP0_1 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
901 0x0000, /* Lag_2 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
902 0x0000, /* Code_2 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
903 0x0000, /* GSP0_2 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
904 0x0000, /* Lag_3 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
905 0x00ff, /* Code_3 */ /* 8 bits */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
906 0x0000, /* GSP0_3 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
907 0x0000, /* Lag_4 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
908 0x01ff, /* Code_4 */ /* 9 bits */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
909 0x0000}; /* GSP0_4 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
910
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
911 static int first = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
912
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
913 Shortword swMode, swBitMask;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
914 Shortword swSidN1, swSidN2, swSidN1pN2;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
915 Shortword swSid ;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
916
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
917 short siI, siII;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
918
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
919
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
920 if (first)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
921 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
922 /* Force Sid codewords to be represented */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
923 /* internally in PC byte order */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
924 /* ------------------------------------- */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
925
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
926 SwapBytes(ppswCL1pCL2[0], 18);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
927 SwapBytes(ppswCL1pCL2[1], 18);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
928 SwapBytes(ppswCL2[0], 18);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
929 SwapBytes(ppswCL2[1], 18);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
930
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
931 first = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
932 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
933
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
934
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
935 /* count transmission errors within the SID codeword */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
936 /* count number of bits equal '0' within the SID codeword */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
937 /* ------------------------------------------------------ */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
938
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
939 if (pswParameters[5] == 0)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
940 swMode = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
941 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
942 swMode = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
943
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
944
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
945 swSidN1pN2 = 0; /* N1 + N2 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
946 swSidN2 = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
947 swSidN1 = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
948
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
949 for (siI = 0; siI < 18; siI++) {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
950 swBitMask = 0x0001;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
951 SwapBytes(&swBitMask, 1); /* force swBitMask to PC byte order */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
952 for (siII = 0; siII < ppswIBit[swMode][siI]; siII++) {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
953 if ( (pswParameters[siI] & swBitMask) == 0 ) {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
954 if ( (ppswCL1pCL2[swMode][siI] & swBitMask) != 0 ) swSidN1pN2++;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
955 if ( (ppswCL2[swMode][siI] & swBitMask) != 0 ) swSidN2++;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
956 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
957 SwapBytes(&swBitMask, 1); /* return swBitMask to native byte order */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
958 swBitMask = swBitMask << 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
959 SwapBytes(&swBitMask, 1); /* force swBitMask to PC byte order */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
960 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
961 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
962
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
963 swSidN1 = swSidN1pN2 - swSidN2;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
964
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
965
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
966 /* frame classification */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
967 /* -------------------- */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
968
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
969 if (pswErrorFlag[2]) {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
970
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
971 if (swSidN1 < 3)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
972 swSid = 2;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
973 else if (swSidN1pN2 < 16)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
974 swSid = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
975 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
976 swSid = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
977
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
978 if ( (swSidN1pN2 >= 16) && (swSidN1pN2 <= 25) ) {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
979 pswErrorFlag[0] = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
980 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
981
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
982 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
983 else {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
984
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
985 if (swSidN1 < 3)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
986 swSid = 2;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
987 else if (swSidN1pN2 < 11)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
988 swSid = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
989 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
990 swSid = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
991
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
992 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
993
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
994
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
995 /* in case of a mode mismatch */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
996 /*----------------------------*/
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
997
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
998 if ( (swSid == 2) && (swMode == 0) ) swSid = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
999
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1000 return(swSid);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1001
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1002 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1003
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1004
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1005 /*___________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1006 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1007 | This subroutine sets the 18 speech parameters to random values |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1008 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1009 | Input: pswParameters[18] |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1010 | input parameters of the speech decoder |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1011 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1012 |___________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1013 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1014
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1015 static void RandomParameters(Shortword pswParameters[])
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1016 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1017 static Shortword ppswIBit[2][18] = {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1018 5, 11,9,8, 1, 2, 7,7,5, 7,7,5, 7,7,5, 7,7,5, /* unvoiced */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1019 5, 11,9,8, 1, 2, 8,9,5, 4,9,5, 4,9,5, 4,9,5}; /* voiced */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1020
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1021 static Longword L_PNSeed=(Longword)0x1091988L;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1022 Shortword i,ind;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1023
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1024 /* Determine mode bit */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1025 /* ------------------ */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1026 pswParameters[5] = getPnBits(2, &L_PNSeed);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1027
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1028 /* Switch bit allocation accordingly */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1029 /* --------------------------------- */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1030 ind = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1031 if (pswParameters[5] > 0) ind = 1;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1032
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1033 for (i=0; i < 5; i++){
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1034 pswParameters[i] = getPnBits(ppswIBit[ind][i], &L_PNSeed);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1035 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1036 for (i=6; i < 18; i++){
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1037 pswParameters[i] = getPnBits(ppswIBit[ind][i], &L_PNSeed);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1038 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1039
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1040 /* force random parameters to PC byte order */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1041 /* ---------------------------------------- */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1042
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1043 SwapBytes(pswParameters, 18);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1044 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1045
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1046 /*___________________________________________________________________________
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1047 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1048 | Main - Program |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1049 | |
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1050 |___________________________________________________________________________|
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1051 */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1052 int main( int argc, char *argv[] )
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1053 {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1054 FILE *infile, *outfile;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1055 Shortword errpat, i = 0;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1056
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1057 if( argc < 4 || argc > 4 ) {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1058 fprintf( stderr, "\tUsage: REID input output EPx \n" );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1059 fprintf( stderr, "\tEPx: EP0\n" );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1060 fprintf( stderr, "\t EP1 (not implemented)\n" );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1061 fprintf( stderr, "\t EP2 (not implemented)\n" );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1062 fprintf( stderr, "\t EP3 (not implemented)\n" );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1063 return( 1 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1064 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1065
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1066
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1067 if( !Strincmp( argv[3], "ep", 2 ))
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1068 errpat = atoi( &argv[3][2] );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1069
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1070 printf( " _____________________________________________\n" );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1071 printf( " | |\n" );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1072 printf( " | Residual Error Insertion Device |\n" );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1073 printf( " | for |\n" );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1074 printf( " | GSM Half-Rate Codec Simulation |\n" );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1075 printf( " | |\n" );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1076 printf( " |_____________________________________________|\n\n" );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1077
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1078 printf( " Input File : %s\n", argv[1] );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1079 printf( " Output File : %s\n", argv[2] );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1080 if( errpat ){
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1081 printf( " Error Pattern : EP%d (not implemented)\n", errpat);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1082 return (1);
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1083 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1084 else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1085 printf( " Error Pattern : EP%d (error free)\n", errpat );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1086 printf( "\n" );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1087
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1088 infile = OpenBinfile( argv[1], "r" );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1089 outfile = OpenBinfile( argv[2], "w" );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1090
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1091
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1092 if (errpat == 0) {
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1093 for (i=0;i<6000;i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1094 if( error_free( infile, outfile)) break;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1095 }
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1096 /*else
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1097 for (i=0;i<6000;i++)
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1098 if( residual_error_pattern( infile, outfile)) break;
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1099 EP1-3 not implemented */
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1100
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1101 fclose( infile );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1102 fclose( outfile );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1103
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1104 printf( " %d Frame%s processed \n\n", i,( i != 1 ) ? "s" : "" );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1105 return( 0 );
9008dbc8ca74 import original C code from GSM 06.06
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1106 }