comparison amrconv/param_asm.c @ 211:78d1a6513393

amrconv: new program amr-cod-parse
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 20 Apr 2023 01:30:46 +0000
parents
children
comparison
equal deleted inserted replaced
210:7e490a8efe8a 211:78d1a6513393
1 /*
2 * This C module is common between amr-cod-parse and amr-ietf-parse
3 * utilities. It contains the function that takes an array of bits
4 * in the codec's natural order and reassembles these bits into
5 * an array of codec parameters.
6 */
7
8 #include <stdint.h>
9 #include "amr_defs.h"
10
11 /* parameter sizes (# of bits), one table per mode */
12
13 static const uint8_t bitno_MR475[PRMNO_MR475] = {
14 8, 8, 7, /* LSP VQ */
15 8, 7, 2, 8, /* first subframe */
16 4, 7, 2, /* second subframe */
17 4, 7, 2, 8, /* third subframe */
18 4, 7, 2, /* fourth subframe */
19 };
20
21 static const uint8_t bitno_MR515[PRMNO_MR515] = {
22 8, 8, 7, /* LSP VQ */
23 8, 7, 2, 6, /* first subframe */
24 4, 7, 2, 6, /* second subframe */
25 4, 7, 2, 6, /* third subframe */
26 4, 7, 2, 6, /* fourth subframe */
27 };
28
29 static const uint8_t bitno_MR59[PRMNO_MR59] = {
30 8, 9, 9, /* LSP VQ */
31 8, 9, 2, 6, /* first subframe */
32 4, 9, 2, 6, /* second subframe */
33 8, 9, 2, 6, /* third subframe */
34 4, 9, 2, 6, /* fourth subframe */
35 };
36
37 static const uint8_t bitno_MR67[PRMNO_MR67] = {
38 8, 9, 9, /* LSP VQ */
39 8, 11, 3, 7, /* first subframe */
40 4, 11, 3, 7, /* second subframe */
41 8, 11, 3, 7, /* third subframe */
42 4, 11, 3, 7, /* fourth subframe */
43 };
44
45 static const uint8_t bitno_MR74[PRMNO_MR74] = {
46 8, 9, 9, /* LSP VQ */
47 8, 13, 4, 7, /* first subframe */
48 5, 13, 4, 7, /* second subframe */
49 8, 13, 4, 7, /* third subframe */
50 5, 13, 4, 7, /* fourth subframe */
51 };
52
53 static const uint8_t bitno_MR795[PRMNO_MR795] = {
54 9, 9, 9, /* LSP VQ */
55 8, 13, 4, 4, 5, /* first subframe */
56 6, 13, 4, 4, 5, /* second subframe */
57 8, 13, 4, 4, 5, /* third subframe */
58 6, 13, 4, 4, 5, /* fourth subframe */
59 };
60
61 static const uint8_t bitno_MR102[PRMNO_MR102] = {
62 8, 9, 9, /* LSP VQ */
63 8, 1, 1, 1, 1, 10, 10, 7, 7, /* first subframe */
64 5, 1, 1, 1, 1, 10, 10, 7, 7, /* second subframe */
65 8, 1, 1, 1, 1, 10, 10, 7, 7, /* third subframe */
66 5, 1, 1, 1, 1, 10, 10, 7, 7, /* fourth subframe */
67 };
68
69 static const uint8_t bitno_MR122[PRMNO_MR122] = {
70 7, 8, 9, 8, 6, /* LSP VQ */
71 9, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5, /* first subframe */
72 6, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5, /* second subframe */
73 9, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5, /* third subframe */
74 6, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5 /* fourth subframe */
75 };
76
77 static const uint8_t bitno_MRDTX[PRMNO_MRDTX] = {
78 3,
79 8, 9, 9,
80 6
81 };
82
83 static void
84 bits_to_params(bits, params, table, nparam)
85 const uint8_t *bits;
86 uint16_t *params;
87 const uint8_t *table;
88 unsigned nparam;
89 {
90 const uint8_t *p = bits;
91 const uint8_t *t = table;
92 unsigned n, m, acc;
93
94 for (n = 0; n < nparam; n++) {
95 acc = 0;
96 for (m = 0; m < *t; m++) {
97 acc <<= 1;
98 if (*p)
99 acc |= 1;
100 p++;
101 }
102 params[n] = acc;
103 t++;
104 }
105 }
106
107 reassemble_amr_params(bits, params, mode)
108 const uint8_t *bits;
109 uint16_t *params;
110 unsigned mode;
111 {
112 switch (mode) {
113 case MR475:
114 bits_to_params(bits, params, bitno_MR475, PRMNO_MR475);
115 return(0);
116 case MR515:
117 bits_to_params(bits, params, bitno_MR515, PRMNO_MR515);
118 return(0);
119 case MR59:
120 bits_to_params(bits, params, bitno_MR59, PRMNO_MR59);
121 return(0);
122 case MR67:
123 bits_to_params(bits, params, bitno_MR67, PRMNO_MR67);
124 return(0);
125 case MR74:
126 bits_to_params(bits, params, bitno_MR74, PRMNO_MR74);
127 return(0);
128 case MR795:
129 bits_to_params(bits, params, bitno_MR795, PRMNO_MR795);
130 return(0);
131 case MR102:
132 bits_to_params(bits, params, bitno_MR102, PRMNO_MR102);
133 return(0);
134 case MR122:
135 bits_to_params(bits, params, bitno_MR122, PRMNO_MR122);
136 return(0);
137 case MRDTX:
138 bits_to_params(bits, params, bitno_MRDTX, PRMNO_MRDTX);
139 return(0);
140 default:
141 return(-1);
142 }
143 }