📄 chan_enc.c
字号:
5 , 1 , 3 , 12 , 27 , 24 , 60 , 8,
44 , 66 , 62 , 82 , 25 , 61 , 9 , 7,
45 , 67 , 63 , 83 , 78 , 36 , 50 , 40,
46 , 68 , 64 , 84 , 79 , 37 , 51 , 41,
47 , 69 , 65 , 85 , 80 , 38 , 52 , 42,
56 , 99, 159, 185 , 81 , 39 , 53 , 43,
161, 187 , 20, 57 ,100, 160, 186 , 19,
22, 59 ,102, 162, 188 , 21, 58 ,101,
35 , 54 , 70 , 72, 179, 178, 177, 176,
13 , 15 , 23 , 28 , 29 , 32 , 33 , 34,
128, 132, 146, 155, 163, 171, 181, 18,
76 , 86 , 90 , 94 ,103, 108, 112, 116,
129, 133, 147, 156, 164, 172, 182 , 74,
183 , 87 , 91 , 95, 104, 109, 113, 117,
114, 118, 130, 134, 148, 157, 165, 173,
184 , 75 , 77 , 88 , 92 , 96, 105, 110,
115, 119, 131, 135, 149, 158, 166, 174,
136, 124, 120 , 89 , 93 , 97, 106, 111,
151, 141, 137, 125, 121, 144, 150, 140,
127, 123, 145, 152, 142, 138, 126, 122,
-1 , -1 , -1 , -1 , -1, 153, 143, 139};
/* Definition of low rate bitordering table (see Table C3b) */
/* -------------------------------------------------------- */
static const Word16 BitOrder53[NBits5_3] =
{152, 153, 158, 159, 160, 161 , -1 , -1,
69 , 64 , 70 , 91, 145, 140, 147, 146 ,
24 , 15 , 14 , 25 , 46 , 50 , 47, 63,
4 , 6 , 0 , 2 , 11 , 18 , 10, 13 ,
7 , 1 , 3 , 12 , 19 , 16 , 48, 8,
42 , 59 , 55 , 65 , 17 , 49 , 9, 5 ,
43 , 60 , 56 , 66 , 26 , 30 , 34, 38 ,
44 , 61 , 57 , 67 , 27 , 31 , 35, 39 ,
45 , 62 , 58 , 68 , 28 , 32 , 36, 40 ,
51 , 87 ,141, 154 , 29 , 33 , 37, 41 ,
143, 156 , 21, 52 , 88 ,142, 155, 20 ,
23, 54 , 90 ,144, 157 , 22, 53, 89 ,
100, 128 , 96, 104, 151, 150, 149, 148,
132, 112, 116, 136, 108, 120, 124, 92 ,
109, 121, 125 , 93, 101, 129 , 97, 105,
102, 130 , 98, 106, 133, 113, 117, 137 ,
134, 114, 118, 138, 110, 122, 126, 94 ,
111, 123, 127 , 95, 103, 131 , 99, 107,
83 , 79 , 75 , 71, 135, 115, 119, 139 ,
85 , 81 , 77 , 73 , 84 , 80 , 76, 72,
-1 , -1 , -1 , -1 , 86 , 82 , 78, 74};
/* Definition of SID frame bitordering table (see Table C3c) */
/* --------------------------------------------------------- */
static const Word16 BitOrderSID[NBitsSID] =
{ 21, 22, 23, 24, 25, 26, -1, -1,
13, 14, 15, 16, 17, 18, 20, 19,
5, 6, 7, 8, 9, 10, 11, 12,
0, 1, 2, 29, 28, 27, 3, 4};
Word16 i, pw, pb, j;
Word16 BitOrder[NBits6_3], EndLoop;
if( (CInfoBitStream[0] & 0x3) == 0) {
EndLoop = NBits6_3;
for (i=0;i<EndLoop;i++) BitOrder[i] = BitOrder63[i];
}
if( (CInfoBitStream[0] & 0x3) == 1) {
EndLoop = NBits5_3;
for (i=0;i<EndLoop;i++) BitOrder[i] = BitOrder53[i];
}
if( (CInfoBitStream[0] & 0x3) == 2) {
EndLoop = NBitsSID;
for (i=0;i<EndLoop;i++) BitOrder[i] = BitOrderSID[i];
}
/* Reorder */
/* ------- */
for( i=0; i < EndLoop; i++ ) {
pw = i/8;
pb = i - pw*8;
j = (pw*8)+7-pb;
if (BitOrder[j] != (-1)){
info_bit[BitOrder[j]] = ( tstbit( CInfoBitStream[pw], pb )) ? 1 : 0;
}
}
return;
}
/*__________________________________________________________________________
| |
| Determine CRC bits for most sensitive bitclass 0 |
| (section 2.4) |
|__________________________________________________________________________|
*/
static void CrcEncoder(Word16 info_bit[], char mode)
{
Word16 crc_window, EndLoop;
Word16 CrcCarry, ShiftReg, i;
if( (mode & 0x3) == 0) {
crc_window = CrcWindow63;
EndLoop = NInfoBits6_3;
}
if( (mode & 0x3) == 1) {
crc_window = CrcWindow53;
EndLoop = NInfoBits5_3;
}
if( (mode & 0x3) == 2) {
crc_window = CrcWindowSID;
EndLoop = NInfoBitsSID;
}
/* CRC encoder */
/* ----------- */
ShiftReg = 0;
for (i = 0; i < crc_window; ++i) {
CrcCarry = (info_bit[i] ^ ShiftReg) & 1;
ShiftReg = shr(ShiftReg, 1);
if (CrcCarry != 0) ShiftReg = ShiftReg ^ CrcGen;
}
/* Make room for CRC bits */
/* ---------------------- */
for (i=EndLoop-1;i>=crc_window;i--) info_bit[i+CrcLen]=info_bit[i];
/* Copy CRC bits */
/* ------------- */
for (i=CrcLen-1;i>=0;i--){
info_bit[crc_window + i] = ShiftReg & 1;
ShiftReg = shr(ShiftReg, 1);
}
return;
}
/*__________________________________________________________________________
| |
| Enhancement of G.723.1 bitstream robustness |
| (section 2.1) |
|__________________________________________________________________________|
*/
static void channel_encoder_adaptation(char InfoBitStream[],char CInfoBitStream[])
{
Word16 FrType, i, Ftyp;
LINEDEF Line ;
FrType = InfoBitStream[0] & 3;
if (FrType < 2) {
/* Unpack the G.723.1 bitstream */
/* ---------------------------- */
Line = Line_Unpk( InfoBitStream, &Ftyp, (Word16) 0 ) ;
/* Reorder LSP index for enhanced robustness */
/* ----------------------------------------- */
LSP_Reorder_encoder (&Line);
/* Demultiplex gain indexes and repack the robust bitstream */
/* -------------------------------------------------------- */
Line_Pack_Channel( &Line, CInfoBitStream, FrType ) ;
}else{
/* No reordering for SID frames */
/* ---------------------------- */
for (i=0;i<4;i++) CInfoBitStream[i] = InfoBitStream[i];
}
return;
}
/*__________________________________________________________________________
| |
| Reordering of LSP index |
| (section 2.1.2) |
|__________________________________________________________________________|
*/
static void LSP_Reorder_encoder (LINEDEF *Line)
{
/* Reordering table for first subvector (see Table C1a) */
/* ---------------------------------------------------- */
static Word16 tabd2_01[LspCbSize] = {
82, 91, 190, 191, 189, 36, 187, 32,
38, 39, 185, 112, 166, 175, 116, 120,
34, 35, 122, 41, 40, 43, 42, 56,
57, 90, 168, 85, 74, 170, 234, 174,
169, 172, 178, 182, 184, 179, 181, 180,
37, 186, 44, 33, 159, 183, 188, 155,
253, 252, 147, 154, 246, 165, 218, 139,
163, 160, 157, 146, 145, 144, 177, 176,
244, 131, 148, 129, 128, 161, 219, 135,
134, 203, 200, 206, 207, 204, 205, 254,
212, 222, 213, 220, 221, 141, 216, 88,
138, 137, 136, 217, 133, 132, 201, 197,
196, 76, 77, 243, 192, 195, 193, 119,
118, 108, 121, 249, 247, 245, 130, 240,
241, 235, 69, 68, 210, 226, 227, 224,
225, 79, 211, 250, 251, 255, 198, 242,
194, 127, 45, 46, 117, 125, 124, 2,
67, 3, 101, 72, 0, 13, 97, 65,
66, 98, 96, 158, 248, 228, 229, 93,
231, 109, 100, 110, 111, 75, 73, 115,
114, 23, 94, 95, 6, 22, 7, 230,
5, 4, 99, 81, 20, 21, 83, 113,
102, 14, 103, 15, 12, 16, 52, 17,
19, 1, 29, 8, 28, 30, 31, 11,
9, 126, 24, 18, 26, 25, 27, 86,
87, 64, 71, 70, 153, 152, 173, 162,
167, 164, 89, 80, 238, 208, 232, 233,
215, 236, 239, 92, 202, 209, 199, 143,
142, 140, 223, 84, 78, 171, 151, 156,
237, 150, 149, 214, 106, 107, 10, 53,
47, 54, 55, 104, 105, 123, 48, 58,
59, 49, 50, 51, 62, 60, 61, 63
};
/* Reordering table for second subvector (see Table C1b) */
/* ----------------------------------------------------- */
static Word16 tabd1_01[LspCbSize] = {
122, 150, 201, 213, 214, 212, 246, 244,
136, 135, 130, 134, 140, 216, 218, 146,
209, 208, 110, 153, 156, 158, 152, 144,
147, 145, 199, 197, 193, 204, 205, 249,
248, 127, 185, 172, 174, 173, 179, 169,
168, 181, 182, 177, 183, 161, 178, 167,
163, 162, 160, 165, 232, 234, 235, 233,
237, 236, 238, 239, 78, 155, 154, 75,
74, 69, 68, 71, 70, 73, 72, 139,
123, 114, 59, 58, 113, 170, 137, 141,
186, 133, 151, 132, 148, 159, 196, 149,
187, 189, 191, 157, 198, 190, 121, 126,
125, 120, 57, 112, 171, 63, 45, 62,
47, 46, 99, 109, 98, 103, 124, 102,
107, 106, 129, 128, 131, 89, 118, 105,
104, 95, 91, 90, 94, 86, 83, 82,
138, 119, 117, 88, 116, 92, 37, 36,
38, 32, 96, 87, 81, 39, 93, 49,
48, 23, 22, 21, 20, 29, 8, 56,
55, 44, 175, 60, 61, 53, 43, 143,
115, 176, 180, 142, 166, 184, 188, 207,
206, 231, 252, 195, 194, 219, 217, 221,
223, 211, 215, 210, 192, 200, 164, 226,
202, 203, 230, 227, 229, 253, 255, 224,
225, 243, 228, 220, 240, 241, 242, 222,
245, 251, 250, 247, 254, 111, 108, 77,
76, 79, 101, 100, 30, 15, 97, 52,
54, 41, 50, 51, 40, 33, 42, 35,
34, 13, 12, 14, 85, 84, 25, 31,
27, 80, 17, 67, 66, 16, 9, 28,
24, 65, 11, 10, 26, 64, 19, 18,
4, 1, 0, 5, 7, 6, 3, 2
};
/* Reordering table for third subvector (see Table C1c) */
/* ---------------------------------------------------- */
static Word16 tabd0_01[LspCbSize] = {
243, 154, 190, 170, 189, 169, 140, 188,
171, 168, 166, 164, 165, 216, 146, 132,
242, 234, 158, 144, 252, 147, 148, 13,
74, 75, 19, 77, 76, 79, 78, 70,
71, 198, 199, 72, 12, 73, 220, 150,
151, 131, 204, 133, 205, 230, 229, 225,
200, 201, 226, 227, 196, 192, 197, 195,
202, 203, 136, 143, 142, 175, 207, 206,
137, 138, 139, 174, 173, 172, 240, 228,
209, 224, 238, 239, 128, 130, 145, 250,
236, 237, 255, 248, 253, 232, 153, 179,
181, 180, 235, 233, 152, 156, 184, 178,
185, 162, 183, 182, 163, 160, 161, 167,
157, 159, 155, 134, 186, 191, 135, 187,
141, 254, 177, 251, 176, 33, 244, 245,
61, 60, 34, 35, 32, 249, 126, 41,
62, 59, 58, 63, 57, 56, 42, 43,
25, 29, 40, 125, 120, 24, 26, 127,
123, 124, 122, 48, 121, 46, 47, 105,
104, 109, 108, 28, 116, 112, 113, 247,
246, 36, 54, 149, 55, 4, 52, 53,
49, 37, 39, 51, 50, 107, 211, 215,
20, 21, 17, 3, 5, 223, 222, 0,
231, 129, 218, 9, 217, 219, 194, 221,
193, 210, 38, 2, 1, 212, 14, 15,
241, 44, 208, 8, 45, 11, 10, 110,
68, 69, 103, 100, 213, 214, 16, 106,
18, 111, 22, 23, 6, 7, 64, 65,
27, 118, 117, 102, 31, 30, 97, 114,
115, 96, 88, 89, 90, 91, 99, 94,
80, 82, 83, 119, 98, 101, 92, 95,
66, 67, 84, 93, 85, 81, 86, 87
};
Word16 lsp0,lsp1,lsp2;
/* Extract and reorder Band 2 */
/* -------------------------- */
lsp2 = (Word16) (Line->LspId & (Word32) 0x000000FF);
lsp2 = tabd2_01[lsp2];
/* Extract and reorder Band 1 */
/* -------------------------- */
lsp1 = (Word16) ((Line->LspId >> 8) & (Word32) 0x000000FF);
lsp1 = tabd1_01[lsp1];
/* Extract and reorder Band 0 */
/* -------------------------- */
lsp0 = (Word16) ((Line->LspId >> 16) & (Word32) 0x000000FF);
lsp0 = tabd0_01[lsp0];
/* Construct new Line.LspId */
/* ------------------------ */
Line->LspId = (Word32) lsp0;
Line->LspId = (Line->LspId << 8) + (Word32) lsp1;
Line->LspId = (Line->LspId << 8) + (Word32) lsp2;
return;
}
/*__________________________________________________________________________
| |
| Demultiplexing of gain indexes and repacking of new information bitstream|
| (section 2.1.3) |
|__________________________________________________________________________|
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -