gsm_encode.c

Go to the documentation of this file.
00001 /*
00002  * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
00003  * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for
00004  * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
00005  */
00006 
00007 /* $Header$ */
00008 
00009 #include "private.h"
00010 #include "gsm.h"
00011 #include "proto.h"
00012 
00013 void gsm_encode P3((s, source, c), gsm s, gsm_signal * source, gsm_byte * c)
00014 {
00015    word     LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4];
00016 
00017    Gsm_Coder(s, source, LARc, Nc, bc, Mc, xmaxc, xmc);
00018 
00019 
00020    /* variable size
00021 
00022       GSM_MAGIC   4
00023 
00024       LARc[0]     6
00025       LARc[1]     6
00026       LARc[2]     5
00027       LARc[3]     5
00028       LARc[4]     4
00029       LARc[5]     4
00030       LARc[6]     3
00031       LARc[7]     3
00032 
00033       Nc[0]    7
00034       bc[0]    2
00035       Mc[0]    2
00036       xmaxc[0] 6
00037       xmc[0]      3
00038       xmc[1]      3
00039       xmc[2]      3
00040       xmc[3]      3
00041       xmc[4]      3
00042       xmc[5]      3
00043       xmc[6]      3
00044       xmc[7]      3
00045       xmc[8]      3
00046       xmc[9]      3
00047       xmc[10]     3
00048       xmc[11]     3
00049       xmc[12]     3
00050 
00051       Nc[1]    7
00052       bc[1]    2
00053       Mc[1]    2
00054       xmaxc[1] 6
00055       xmc[13]     3
00056       xmc[14]     3
00057       xmc[15]     3
00058       xmc[16]     3
00059       xmc[17]     3
00060       xmc[18]     3
00061       xmc[19]     3
00062       xmc[20]     3
00063       xmc[21]     3
00064       xmc[22]     3
00065       xmc[23]     3
00066       xmc[24]     3
00067       xmc[25]     3
00068 
00069       Nc[2]    7
00070       bc[2]    2
00071       Mc[2]    2
00072       xmaxc[2] 6
00073       xmc[26]     3
00074       xmc[27]     3
00075       xmc[28]     3
00076       xmc[29]     3
00077       xmc[30]     3
00078       xmc[31]     3
00079       xmc[32]     3
00080       xmc[33]     3
00081       xmc[34]     3
00082       xmc[35]     3
00083       xmc[36]     3
00084       xmc[37]     3
00085       xmc[38]     3
00086 
00087       Nc[3]    7
00088       bc[3]    2
00089       Mc[3]    2
00090       xmaxc[3] 6
00091       xmc[39]     3
00092       xmc[40]     3
00093       xmc[41]     3
00094       xmc[42]     3
00095       xmc[43]     3
00096       xmc[44]     3
00097       xmc[45]     3
00098       xmc[46]     3
00099       xmc[47]     3
00100       xmc[48]     3
00101       xmc[49]     3
00102       xmc[50]     3
00103       xmc[51]     3
00104    */
00105 
00106 #ifdef WAV49
00107 
00108    if (s->wav_fmt) {
00109       s->frame_index = !s->frame_index;
00110       if (s->frame_index) {
00111 
00112          uword sr;
00113 
00114          sr = 0;
00115          sr = sr >> 6 | LARc[0] << 10;
00116          sr = sr >> 6 | LARc[1] << 10;
00117          *c++ = sr >> 4;
00118          sr = sr >> 5 | LARc[2] << 11;
00119          *c++ = sr >> 7;
00120          sr = sr >> 5 | LARc[3] << 11;
00121          sr = sr >> 4 | LARc[4] << 12;
00122          *c++ = sr >> 6;
00123          sr = sr >> 4 | LARc[5] << 12;
00124          sr = sr >> 3 | LARc[6] << 13;
00125          *c++ = sr >> 7;
00126          sr = sr >> 3 | LARc[7] << 13;
00127          sr = sr >> 7 | Nc[0] << 9;
00128          *c++ = sr >> 5;
00129          sr = sr >> 2 | bc[0] << 14;
00130          sr = sr >> 2 | Mc[0] << 14;
00131          sr = sr >> 6 | xmaxc[0] << 10;
00132          *c++ = sr >> 3;
00133          sr = sr >> 3 | xmc[0] << 13;
00134          *c++ = sr >> 8;
00135          sr = sr >> 3 | xmc[1] << 13;
00136          sr = sr >> 3 | xmc[2] << 13;
00137          sr = sr >> 3 | xmc[3] << 13;
00138          *c++ = sr >> 7;
00139          sr = sr >> 3 | xmc[4] << 13;
00140          sr = sr >> 3 | xmc[5] << 13;
00141          sr = sr >> 3 | xmc[6] << 13;
00142          *c++ = sr >> 6;
00143          sr = sr >> 3 | xmc[7] << 13;
00144          sr = sr >> 3 | xmc[8] << 13;
00145          *c++ = sr >> 8;
00146          sr = sr >> 3 | xmc[9] << 13;
00147          sr = sr >> 3 | xmc[10] << 13;
00148          sr = sr >> 3 | xmc[11] << 13;
00149          *c++ = sr >> 7;
00150          sr = sr >> 3 | xmc[12] << 13;
00151          sr = sr >> 7 | Nc[1] << 9;
00152          *c++ = sr >> 5;
00153          sr = sr >> 2 | bc[1] << 14;
00154          sr = sr >> 2 | Mc[1] << 14;
00155          sr = sr >> 6 | xmaxc[1] << 10;
00156          *c++ = sr >> 3;
00157          sr = sr >> 3 | xmc[13] << 13;
00158          *c++ = sr >> 8;
00159          sr = sr >> 3 | xmc[14] << 13;
00160          sr = sr >> 3 | xmc[15] << 13;
00161          sr = sr >> 3 | xmc[16] << 13;
00162          *c++ = sr >> 7;
00163          sr = sr >> 3 | xmc[17] << 13;
00164          sr = sr >> 3 | xmc[18] << 13;
00165          sr = sr >> 3 | xmc[19] << 13;
00166          *c++ = sr >> 6;
00167          sr = sr >> 3 | xmc[20] << 13;
00168          sr = sr >> 3 | xmc[21] << 13;
00169          *c++ = sr >> 8;
00170          sr = sr >> 3 | xmc[22] << 13;
00171          sr = sr >> 3 | xmc[23] << 13;
00172          sr = sr >> 3 | xmc[24] << 13;
00173          *c++ = sr >> 7;
00174          sr = sr >> 3 | xmc[25] << 13;
00175          sr = sr >> 7 | Nc[2] << 9;
00176          *c++ = sr >> 5;
00177          sr = sr >> 2 | bc[2] << 14;
00178          sr = sr >> 2 | Mc[2] << 14;
00179          sr = sr >> 6 | xmaxc[2] << 10;
00180          *c++ = sr >> 3;
00181          sr = sr >> 3 | xmc[26] << 13;
00182          *c++ = sr >> 8;
00183          sr = sr >> 3 | xmc[27] << 13;
00184          sr = sr >> 3 | xmc[28] << 13;
00185          sr = sr >> 3 | xmc[29] << 13;
00186          *c++ = sr >> 7;
00187          sr = sr >> 3 | xmc[30] << 13;
00188          sr = sr >> 3 | xmc[31] << 13;
00189          sr = sr >> 3 | xmc[32] << 13;
00190          *c++ = sr >> 6;
00191          sr = sr >> 3 | xmc[33] << 13;
00192          sr = sr >> 3 | xmc[34] << 13;
00193          *c++ = sr >> 8;
00194          sr = sr >> 3 | xmc[35] << 13;
00195          sr = sr >> 3 | xmc[36] << 13;
00196          sr = sr >> 3 | xmc[37] << 13;
00197          *c++ = sr >> 7;
00198          sr = sr >> 3 | xmc[38] << 13;
00199          sr = sr >> 7 | Nc[3] << 9;
00200          *c++ = sr >> 5;
00201          sr = sr >> 2 | bc[3] << 14;
00202          sr = sr >> 2 | Mc[3] << 14;
00203          sr = sr >> 6 | xmaxc[3] << 10;
00204          *c++ = sr >> 3;
00205          sr = sr >> 3 | xmc[39] << 13;
00206          *c++ = sr >> 8;
00207          sr = sr >> 3 | xmc[40] << 13;
00208          sr = sr >> 3 | xmc[41] << 13;
00209          sr = sr >> 3 | xmc[42] << 13;
00210          *c++ = sr >> 7;
00211          sr = sr >> 3 | xmc[43] << 13;
00212          sr = sr >> 3 | xmc[44] << 13;
00213          sr = sr >> 3 | xmc[45] << 13;
00214          *c++ = sr >> 6;
00215          sr = sr >> 3 | xmc[46] << 13;
00216          sr = sr >> 3 | xmc[47] << 13;
00217          *c++ = sr >> 8;
00218          sr = sr >> 3 | xmc[48] << 13;
00219          sr = sr >> 3 | xmc[49] << 13;
00220          sr = sr >> 3 | xmc[50] << 13;
00221          *c++ = sr >> 7;
00222          sr = sr >> 3 | xmc[51] << 13;
00223          sr = sr >> 4;
00224          *c = sr >> 8;
00225          s->frame_chain = *c;
00226       }
00227       else {
00228          uword sr;
00229 
00230          sr = 0;
00231          sr = sr >> 4 | s->frame_chain << 12;
00232          sr = sr >> 6 | LARc[0] << 10;
00233          *c++ = sr >> 6;
00234          sr = sr >> 6 | LARc[1] << 10;
00235          *c++ = sr >> 8;
00236          sr = sr >> 5 | LARc[2] << 11;
00237          sr = sr >> 5 | LARc[3] << 11;
00238          *c++ = sr >> 6;
00239          sr = sr >> 4 | LARc[4] << 12;
00240          sr = sr >> 4 | LARc[5] << 12;
00241          *c++ = sr >> 6;
00242          sr = sr >> 3 | LARc[6] << 13;
00243          sr = sr >> 3 | LARc[7] << 13;
00244          *c++ = sr >> 8;
00245          sr = sr >> 7 | Nc[0] << 9;
00246          sr = sr >> 2 | bc[0] << 14;
00247          *c++ = sr >> 7;
00248          sr = sr >> 2 | Mc[0] << 14;
00249          sr = sr >> 6 | xmaxc[0] << 10;
00250          *c++ = sr >> 7;
00251          sr = sr >> 3 | xmc[0] << 13;
00252          sr = sr >> 3 | xmc[1] << 13;
00253          sr = sr >> 3 | xmc[2] << 13;
00254          *c++ = sr >> 6;
00255          sr = sr >> 3 | xmc[3] << 13;
00256          sr = sr >> 3 | xmc[4] << 13;
00257          *c++ = sr >> 8;
00258          sr = sr >> 3 | xmc[5] << 13;
00259          sr = sr >> 3 | xmc[6] << 13;
00260          sr = sr >> 3 | xmc[7] << 13;
00261          *c++ = sr >> 7;
00262          sr = sr >> 3 | xmc[8] << 13;
00263          sr = sr >> 3 | xmc[9] << 13;
00264          sr = sr >> 3 | xmc[10] << 13;
00265          *c++ = sr >> 6;
00266          sr = sr >> 3 | xmc[11] << 13;
00267          sr = sr >> 3 | xmc[12] << 13;
00268          *c++ = sr >> 8;
00269          sr = sr >> 7 | Nc[1] << 9;
00270          sr = sr >> 2 | bc[1] << 14;
00271          *c++ = sr >> 7;
00272          sr = sr >> 2 | Mc[1] << 14;
00273          sr = sr >> 6 | xmaxc[1] << 10;
00274          *c++ = sr >> 7;
00275          sr = sr >> 3 | xmc[13] << 13;
00276          sr = sr >> 3 | xmc[14] << 13;
00277          sr = sr >> 3 | xmc[15] << 13;
00278          *c++ = sr >> 6;
00279          sr = sr >> 3 | xmc[16] << 13;
00280          sr = sr >> 3 | xmc[17] << 13;
00281          *c++ = sr >> 8;
00282          sr = sr >> 3 | xmc[18] << 13;
00283          sr = sr >> 3 | xmc[19] << 13;
00284          sr = sr >> 3 | xmc[20] << 13;
00285          *c++ = sr >> 7;
00286          sr = sr >> 3 | xmc[21] << 13;
00287          sr = sr >> 3 | xmc[22] << 13;
00288          sr = sr >> 3 | xmc[23] << 13;
00289          *c++ = sr >> 6;
00290          sr = sr >> 3 | xmc[24] << 13;
00291          sr = sr >> 3 | xmc[25] << 13;
00292          *c++ = sr >> 8;
00293          sr = sr >> 7 | Nc[2] << 9;
00294          sr = sr >> 2 | bc[2] << 14;
00295          *c++ = sr >> 7;
00296          sr = sr >> 2 | Mc[2] << 14;
00297          sr = sr >> 6 | xmaxc[2] << 10;
00298          *c++ = sr >> 7;
00299          sr = sr >> 3 | xmc[26] << 13;
00300          sr = sr >> 3 | xmc[27] << 13;
00301          sr = sr >> 3 | xmc[28] << 13;
00302          *c++ = sr >> 6;
00303          sr = sr >> 3 | xmc[29] << 13;
00304          sr = sr >> 3 | xmc[30] << 13;
00305          *c++ = sr >> 8;
00306          sr = sr >> 3 | xmc[31] << 13;
00307          sr = sr >> 3 | xmc[32] << 13;
00308          sr = sr >> 3 | xmc[33] << 13;
00309          *c++ = sr >> 7;
00310          sr = sr >> 3 | xmc[34] << 13;
00311          sr = sr >> 3 | xmc[35] << 13;
00312          sr = sr >> 3 | xmc[36] << 13;
00313          *c++ = sr >> 6;
00314          sr = sr >> 3 | xmc[37] << 13;
00315          sr = sr >> 3 | xmc[38] << 13;
00316          *c++ = sr >> 8;
00317          sr = sr >> 7 | Nc[3] << 9;
00318          sr = sr >> 2 | bc[3] << 14;
00319          *c++ = sr >> 7;
00320          sr = sr >> 2 | Mc[3] << 14;
00321          sr = sr >> 6 | xmaxc[3] << 10;
00322          *c++ = sr >> 7;
00323          sr = sr >> 3 | xmc[39] << 13;
00324          sr = sr >> 3 | xmc[40] << 13;
00325          sr = sr >> 3 | xmc[41] << 13;
00326          *c++ = sr >> 6;
00327          sr = sr >> 3 | xmc[42] << 13;
00328          sr = sr >> 3 | xmc[43] << 13;
00329          *c++ = sr >> 8;
00330          sr = sr >> 3 | xmc[44] << 13;
00331          sr = sr >> 3 | xmc[45] << 13;
00332          sr = sr >> 3 | xmc[46] << 13;
00333          *c++ = sr >> 7;
00334          sr = sr >> 3 | xmc[47] << 13;
00335          sr = sr >> 3 | xmc[48] << 13;
00336          sr = sr >> 3 | xmc[49] << 13;
00337          *c++ = sr >> 6;
00338          sr = sr >> 3 | xmc[50] << 13;
00339          sr = sr >> 3 | xmc[51] << 13;
00340          *c++ = sr >> 8;
00341       }
00342    }
00343 
00344    else
00345 
00346 #endif   /* WAV49 */
00347    {
00348 
00349       *c++ =   ((GSM_MAGIC & 0xF) << 4)      /* 1 */
00350              | ((LARc[0] >> 2) & 0xF);
00351       *c++ =   ((LARc[0] & 0x3) << 6)
00352              | (LARc[1] & 0x3F);
00353       *c++ =   ((LARc[2] & 0x1F) << 3)
00354              | ((LARc[3] >> 2) & 0x7);
00355       *c++ =   ((LARc[3] & 0x3) << 6)
00356              | ((LARc[4] & 0xF) << 2)
00357              | ((LARc[5] >> 2) & 0x3);
00358       *c++ =   ((LARc[5] & 0x3) << 6)
00359              | ((LARc[6] & 0x7) << 3)
00360              | (LARc[7] & 0x7);
00361       *c++ =   ((Nc[0] & 0x7F) << 1)
00362              | ((bc[0] >> 1) & 0x1);
00363       *c++ =   ((bc[0] & 0x1) << 7)
00364              | ((Mc[0] & 0x3) << 5)
00365              | ((xmaxc[0] >> 1) & 0x1F);
00366       *c++ =   ((xmaxc[0] & 0x1) << 7)
00367              | ((xmc[0] & 0x7) << 4)
00368              | ((xmc[1] & 0x7) << 1)
00369              | ((xmc[2] >> 2) & 0x1);
00370       *c++ =   ((xmc[2] & 0x3) << 6)
00371              | ((xmc[3] & 0x7) << 3)
00372              | (xmc[4] & 0x7);
00373       *c++ =   ((xmc[5] & 0x7) << 5)         /* 10 */
00374              | ((xmc[6] & 0x7) << 2)
00375              | ((xmc[7] >> 1) & 0x3);
00376       *c++ =   ((xmc[7] & 0x1) << 7)
00377              | ((xmc[8] & 0x7) << 4)
00378              | ((xmc[9] & 0x7) << 1)
00379              | ((xmc[10] >> 2) & 0x1);
00380       *c++ =   ((xmc[10] & 0x3) << 6)
00381              | ((xmc[11] & 0x7) << 3)
00382              | (xmc[12] & 0x7);
00383       *c++ =   ((Nc[1] & 0x7F) << 1)
00384              | ((bc[1] >> 1) & 0x1);
00385       *c++ =   ((bc[1] & 0x1) << 7)
00386              | ((Mc[1] & 0x3) << 5)
00387              | ((xmaxc[1] >> 1) & 0x1F);
00388       *c++ =   ((xmaxc[1] & 0x1) << 7)
00389              | ((xmc[13] & 0x7) << 4)
00390              | ((xmc[14] & 0x7) << 1)
00391              | ((xmc[15] >> 2) & 0x1);
00392       *c++ =   ((xmc[15] & 0x3) << 6)
00393              | ((xmc[16] & 0x7) << 3)
00394              | (xmc[17] & 0x7);
00395       *c++ =   ((xmc[18] & 0x7) << 5)
00396              | ((xmc[19] & 0x7) << 2)
00397              | ((xmc[20] >> 1) & 0x3);
00398       *c++ =   ((xmc[20] & 0x1) << 7)
00399              | ((xmc[21] & 0x7) << 4)
00400              | ((xmc[22] & 0x7) << 1)
00401              | ((xmc[23] >> 2) & 0x1);
00402       *c++ =   ((xmc[23] & 0x3) << 6)
00403              | ((xmc[24] & 0x7) << 3)
00404              | (xmc[25] & 0x7);
00405       *c++ =   ((Nc[2] & 0x7F) << 1)         /* 20 */
00406              | ((bc[2] >> 1) & 0x1);
00407       *c++ =   ((bc[2] & 0x1) << 7)
00408              | ((Mc[2] & 0x3) << 5)
00409              | ((xmaxc[2] >> 1) & 0x1F);
00410       *c++ =   ((xmaxc[2] & 0x1) << 7)
00411              | ((xmc[26] & 0x7) << 4)
00412              | ((xmc[27] & 0x7) << 1)
00413              | ((xmc[28] >> 2) & 0x1);
00414       *c++ =   ((xmc[28] & 0x3) << 6)
00415              | ((xmc[29] & 0x7) << 3)
00416              | (xmc[30] & 0x7);
00417       *c++ =   ((xmc[31] & 0x7) << 5)
00418              | ((xmc[32] & 0x7) << 2)
00419              | ((xmc[33] >> 1) & 0x3);
00420       *c++ =   ((xmc[33] & 0x1) << 7)
00421              | ((xmc[34] & 0x7) << 4)
00422              | ((xmc[35] & 0x7) << 1)
00423              | ((xmc[36] >> 2) & 0x1);
00424       *c++ =   ((xmc[36] & 0x3) << 6)
00425              | ((xmc[37] & 0x7) << 3)
00426              | (xmc[38] & 0x7);
00427       *c++ =   ((Nc[3] & 0x7F) << 1)
00428              | ((bc[3] >> 1) & 0x1);
00429       *c++ =   ((bc[3] & 0x1) << 7)
00430              | ((Mc[3] & 0x3) << 5)
00431              | ((xmaxc[3] >> 1) & 0x1F);
00432       *c++ =   ((xmaxc[3] & 0x1) << 7)
00433              | ((xmc[39] & 0x7) << 4)
00434              | ((xmc[40] & 0x7) << 1)
00435              | ((xmc[41] >> 2) & 0x1);
00436       *c++ =   ((xmc[41] & 0x3) << 6)        /* 30 */
00437              | ((xmc[42] & 0x7) << 3)
00438              | (xmc[43] & 0x7);
00439       *c++ =   ((xmc[44] & 0x7) << 5)
00440              | ((xmc[45] & 0x7) << 2)
00441              | ((xmc[46] >> 1) & 0x3);
00442       *c++ =   ((xmc[46] & 0x1) << 7)
00443              | ((xmc[47] & 0x7) << 4)
00444              | ((xmc[48] & 0x7) << 1)
00445              | ((xmc[49] >> 2) & 0x1);
00446       *c++ =   ((xmc[49] & 0x3) << 6)
00447              | ((xmc[50] & 0x7) << 3)
00448              | (xmc[51] & 0x7);
00449 
00450    }
00451 }

Generated on Thu Apr 16 06:27:36 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6