aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/ber/rtp_gen_map.c
blob: cbf1587fb6b69f8be6c4ee30878efeee5e70c756 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <stdio.h>

#include <osmocom/codec/codec.h>


static int
gen_table_fr(int *tbl)
{
	int i,j;

	tbl[0] = tbl[1] = tbl[2] = tbl[3] = -1;

	for (i=0; i<260; i++)
	{
		j = 4 + gsm610_bitorder[i];
		if (i < 50)
			tbl[j] = 0;	/* Class 1a */
		else if (i < 182)
			tbl[j] = 1;	/* Class 1b */
		else
			tbl[j] = 2;	/* Class 2 */
	}

	return GSM_FR_BYTES * 8;
}

static int
gen_table_efr(int *tbl)
{
	int i, j, k;

	tbl[0] = tbl[1] = tbl[2] = tbl[3] = -1;

	for (i=0; i<260; i++)
	{
		j = gsm660_bitorder[i];

		if (j < 71)
			k = j;
		else if (j < 73)
			k = 71;
		else if (j < 123)
			k = j - 2;
		else if (j < 125)
			k = 119;
		else if (j < 178)
			k = j - 4;
		else if (j < 180)
			k = 172;
		else if (j < 230)
			k = j - 6;
		else if (j < 232)
			k = 222;
		else if (j < 252)
			k = j - 8;
		else
			continue;

		if (i < 50)
			tbl[k] = 0;	/* Class 1a */
		else if (i < 182)
			tbl[k] = 1;	/* Class 1b */
		else
			tbl[k] = 2;	/* Class 2 */
	}

	return GSM_EFR_BYTES * 8;
}

static int
gen_table_amr_12_2(int *tbl)
{
	int i;

	for (i=0; i<16; i++)
		tbl[i] = -1;
	
	for (i=0; i<244; i++)
		tbl[i+16] = i < 81 ? 0 : 1;
	
	for (i=0; i<4; i++)
		tbl[i+16+244] = -1;

	return 8 * 33;
}


static void
print_table(const char  *name, int *tbl, int len)
{
	int i;

	printf("static const int %s[] = {\n", name);

	for (i=0; i<len; i++)
	{
		if ((i & 15) == 0)
			printf("\t");

		printf("%2d", tbl[i]);
		
		if (((i & 15) == 15) || (i == len-1))
			printf(",\n");
		else
			printf(", ");
	}

	printf("};\n\n");
}


int main(int argc, char *argv[])
{
	int tbl[33*8];
	int rv;

	rv = gen_table_fr(tbl);
	print_table("gsm_fr_bitclass", tbl, rv);

	rv = gen_table_efr(tbl);
	print_table("gsm_efr_bitclass", tbl, rv);

	rv = gen_table_amr_12_2(tbl);
	print_table("gsm_amr_12_2_bitclass", tbl, rv);

	return 0;
}