gsm_decode.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 
00011 #include "gsm.h"
00012 #include "proto.h"
00013 
00014 int gsm_decode P3((s, c, target), gsm s, gsm_byte * c, gsm_signal * target)
00015 {
00016    word     LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4];
00017 
00018 #ifdef WAV49
00019    if (s->wav_fmt) {
00020 
00021       uword sr = 0;
00022 
00023       s->frame_index = !s->frame_index;
00024       if (s->frame_index) {
00025 
00026          sr = *c++;
00027          LARc[0] = sr & 0x3f;  sr >>= 6;
00028          sr |= (uword)*c++ << 2;
00029          LARc[1] = sr & 0x3f;  sr >>= 6;
00030          sr |= (uword)*c++ << 4;
00031          LARc[2] = sr & 0x1f;  sr >>= 5;
00032          LARc[3] = sr & 0x1f;  sr >>= 5;
00033          sr |= (uword)*c++ << 2;
00034          LARc[4] = sr & 0xf;  sr >>= 4;
00035          LARc[5] = sr & 0xf;  sr >>= 4;
00036          sr |= (uword)*c++ << 2;       /* 5 */
00037          LARc[6] = sr & 0x7;  sr >>= 3;
00038          LARc[7] = sr & 0x7;  sr >>= 3;
00039          sr |= (uword)*c++ << 4;
00040          Nc[0] = sr & 0x7f;  sr >>= 7;
00041          bc[0] = sr & 0x3;  sr >>= 2;
00042          Mc[0] = sr & 0x3;  sr >>= 2;
00043          sr |= (uword)*c++ << 1;
00044          xmaxc[0] = sr & 0x3f;  sr >>= 6;
00045          xmc[0] = sr & 0x7;  sr >>= 3;
00046          sr = *c++;
00047          xmc[1] = sr & 0x7;  sr >>= 3;
00048          xmc[2] = sr & 0x7;  sr >>= 3;
00049          sr |= (uword)*c++ << 2;
00050          xmc[3] = sr & 0x7;  sr >>= 3;
00051          xmc[4] = sr & 0x7;  sr >>= 3;
00052          xmc[5] = sr & 0x7;  sr >>= 3;
00053          sr |= (uword)*c++ << 1;       /* 10 */
00054          xmc[6] = sr & 0x7;  sr >>= 3;
00055          xmc[7] = sr & 0x7;  sr >>= 3;
00056          xmc[8] = sr & 0x7;  sr >>= 3;
00057          sr = *c++;
00058          xmc[9] = sr & 0x7;  sr >>= 3;
00059          xmc[10] = sr & 0x7;  sr >>= 3;
00060          sr |= (uword)*c++ << 2;
00061          xmc[11] = sr & 0x7;  sr >>= 3;
00062          xmc[12] = sr & 0x7;  sr >>= 3;
00063          sr |= (uword)*c++ << 4;
00064          Nc[1] = sr & 0x7f;  sr >>= 7;
00065          bc[1] = sr & 0x3;  sr >>= 2;
00066          Mc[1] = sr & 0x3;  sr >>= 2;
00067          sr |= (uword)*c++ << 1;
00068          xmaxc[1] = sr & 0x3f;  sr >>= 6;
00069          xmc[13] = sr & 0x7;  sr >>= 3;
00070          sr = *c++;           /* 15 */
00071          xmc[14] = sr & 0x7;  sr >>= 3;
00072          xmc[15] = sr & 0x7;  sr >>= 3;
00073          sr |= (uword)*c++ << 2;
00074          xmc[16] = sr & 0x7;  sr >>= 3;
00075          xmc[17] = sr & 0x7;  sr >>= 3;
00076          xmc[18] = sr & 0x7;  sr >>= 3;
00077          sr |= (uword)*c++ << 1;
00078          xmc[19] = sr & 0x7;  sr >>= 3;
00079          xmc[20] = sr & 0x7;  sr >>= 3;
00080          xmc[21] = sr & 0x7;  sr >>= 3;
00081          sr = *c++;
00082          xmc[22] = sr & 0x7;  sr >>= 3;
00083          xmc[23] = sr & 0x7;  sr >>= 3;
00084          sr |= (uword)*c++ << 2;
00085          xmc[24] = sr & 0x7;  sr >>= 3;
00086          xmc[25] = sr & 0x7;  sr >>= 3;
00087          sr |= (uword)*c++ << 4;       /* 20 */
00088          Nc[2] = sr & 0x7f;  sr >>= 7;
00089          bc[2] = sr & 0x3;  sr >>= 2;
00090          Mc[2] = sr & 0x3;  sr >>= 2;
00091          sr |= (uword)*c++ << 1;
00092          xmaxc[2] = sr & 0x3f;  sr >>= 6;
00093          xmc[26] = sr & 0x7;  sr >>= 3;
00094          sr = *c++;
00095          xmc[27] = sr & 0x7;  sr >>= 3;
00096          xmc[28] = sr & 0x7;  sr >>= 3;
00097          sr |= (uword)*c++ << 2;
00098          xmc[29] = sr & 0x7;  sr >>= 3;
00099          xmc[30] = sr & 0x7;  sr >>= 3;
00100          xmc[31] = sr & 0x7;  sr >>= 3;
00101          sr |= (uword)*c++ << 1;
00102          xmc[32] = sr & 0x7;  sr >>= 3;
00103          xmc[33] = sr & 0x7;  sr >>= 3;
00104          xmc[34] = sr & 0x7;  sr >>= 3;
00105          sr = *c++;           /* 25 */
00106          xmc[35] = sr & 0x7;  sr >>= 3;
00107          xmc[36] = sr & 0x7;  sr >>= 3;
00108          sr |= (uword)*c++ << 2;
00109          xmc[37] = sr & 0x7;  sr >>= 3;
00110          xmc[38] = sr & 0x7;  sr >>= 3;
00111          sr |= (uword)*c++ << 4;
00112          Nc[3] = sr & 0x7f;  sr >>= 7;
00113          bc[3] = sr & 0x3;  sr >>= 2;
00114          Mc[3] = sr & 0x3;  sr >>= 2;
00115          sr |= (uword)*c++ << 1;
00116          xmaxc[3] = sr & 0x3f;  sr >>= 6;
00117          xmc[39] = sr & 0x7;  sr >>= 3;
00118          sr = *c++;
00119          xmc[40] = sr & 0x7;  sr >>= 3;
00120          xmc[41] = sr & 0x7;  sr >>= 3;
00121          sr |= (uword)*c++ << 2;       /* 30 */
00122          xmc[42] = sr & 0x7;  sr >>= 3;
00123          xmc[43] = sr & 0x7;  sr >>= 3;
00124          xmc[44] = sr & 0x7;  sr >>= 3;
00125          sr |= (uword)*c++ << 1;
00126          xmc[45] = sr & 0x7;  sr >>= 3;
00127          xmc[46] = sr & 0x7;  sr >>= 3;
00128          xmc[47] = sr & 0x7;  sr >>= 3;
00129          sr = *c++;
00130          xmc[48] = sr & 0x7;  sr >>= 3;
00131          xmc[49] = sr & 0x7;  sr >>= 3;
00132          sr |= (uword)*c++ << 2;
00133          xmc[50] = sr & 0x7;  sr >>= 3;
00134          xmc[51] = sr & 0x7;  sr >>= 3;
00135 
00136          s->frame_chain = sr & 0xf;
00137       }
00138       else {
00139          sr = s->frame_chain;
00140          sr |= (uword)*c++ << 4;       /* 1 */
00141          LARc[0] = sr & 0x3f;  sr >>= 6;
00142          LARc[1] = sr & 0x3f;  sr >>= 6;
00143          sr = *c++;
00144          LARc[2] = sr & 0x1f;  sr >>= 5;
00145          sr |= (uword)*c++ << 3;
00146          LARc[3] = sr & 0x1f;  sr >>= 5;
00147          LARc[4] = sr & 0xf;  sr >>= 4;
00148          sr |= (uword)*c++ << 2;
00149          LARc[5] = sr & 0xf;  sr >>= 4;
00150          LARc[6] = sr & 0x7;  sr >>= 3;
00151          LARc[7] = sr & 0x7;  sr >>= 3;
00152          sr = *c++;           /* 5 */
00153          Nc[0] = sr & 0x7f;  sr >>= 7;
00154          sr |= (uword)*c++ << 1;
00155          bc[0] = sr & 0x3;  sr >>= 2;
00156          Mc[0] = sr & 0x3;  sr >>= 2;
00157          sr |= (uword)*c++ << 5;
00158          xmaxc[0] = sr & 0x3f;  sr >>= 6;
00159          xmc[0] = sr & 0x7;  sr >>= 3;
00160          xmc[1] = sr & 0x7;  sr >>= 3;
00161          sr |= (uword)*c++ << 1;
00162          xmc[2] = sr & 0x7;  sr >>= 3;
00163          xmc[3] = sr & 0x7;  sr >>= 3;
00164          xmc[4] = sr & 0x7;  sr >>= 3;
00165          sr = *c++;
00166          xmc[5] = sr & 0x7;  sr >>= 3;
00167          xmc[6] = sr & 0x7;  sr >>= 3;
00168          sr |= (uword)*c++ << 2;       /* 10 */
00169          xmc[7] = sr & 0x7;  sr >>= 3;
00170          xmc[8] = sr & 0x7;  sr >>= 3;
00171          xmc[9] = sr & 0x7;  sr >>= 3;
00172          sr |= (uword)*c++ << 1;
00173          xmc[10] = sr & 0x7;  sr >>= 3;
00174          xmc[11] = sr & 0x7;  sr >>= 3;
00175          xmc[12] = sr & 0x7;  sr >>= 3;
00176          sr = *c++;
00177          Nc[1] = sr & 0x7f;  sr >>= 7;
00178          sr |= (uword)*c++ << 1;
00179          bc[1] = sr & 0x3;  sr >>= 2;
00180          Mc[1] = sr & 0x3;  sr >>= 2;
00181          sr |= (uword)*c++ << 5;
00182          xmaxc[1] = sr & 0x3f;  sr >>= 6;
00183          xmc[13] = sr & 0x7;  sr >>= 3;
00184          xmc[14] = sr & 0x7;  sr >>= 3;
00185          sr |= (uword)*c++ << 1;       /* 15 */
00186          xmc[15] = sr & 0x7;  sr >>= 3;
00187          xmc[16] = sr & 0x7;  sr >>= 3;
00188          xmc[17] = sr & 0x7;  sr >>= 3;
00189          sr = *c++;
00190          xmc[18] = sr & 0x7;  sr >>= 3;
00191          xmc[19] = sr & 0x7;  sr >>= 3;
00192          sr |= (uword)*c++ << 2;
00193          xmc[20] = sr & 0x7;  sr >>= 3;
00194          xmc[21] = sr & 0x7;  sr >>= 3;
00195          xmc[22] = sr & 0x7;  sr >>= 3;
00196          sr |= (uword)*c++ << 1;
00197          xmc[23] = sr & 0x7;  sr >>= 3;
00198          xmc[24] = sr & 0x7;  sr >>= 3;
00199          xmc[25] = sr & 0x7;  sr >>= 3;
00200          sr = *c++;
00201          Nc[2] = sr & 0x7f;  sr >>= 7;
00202          sr |= (uword)*c++ << 1;       /* 20 */
00203          bc[2] = sr & 0x3;  sr >>= 2;
00204          Mc[2] = sr & 0x3;  sr >>= 2;
00205          sr |= (uword)*c++ << 5;
00206          xmaxc[2] = sr & 0x3f;  sr >>= 6;
00207          xmc[26] = sr & 0x7;  sr >>= 3;
00208          xmc[27] = sr & 0x7;  sr >>= 3;
00209          sr |= (uword)*c++ << 1; 
00210          xmc[28] = sr & 0x7;  sr >>= 3;
00211          xmc[29] = sr & 0x7;  sr >>= 3;
00212          xmc[30] = sr & 0x7;  sr >>= 3;
00213          sr = *c++;
00214          xmc[31] = sr & 0x7;  sr >>= 3;
00215          xmc[32] = sr & 0x7;  sr >>= 3;
00216          sr |= (uword)*c++ << 2;
00217          xmc[33] = sr & 0x7;  sr >>= 3;
00218          xmc[34] = sr & 0x7;  sr >>= 3;
00219          xmc[35] = sr & 0x7;  sr >>= 3;
00220          sr |= (uword)*c++ << 1;       /* 25 */
00221          xmc[36] = sr & 0x7;  sr >>= 3;
00222          xmc[37] = sr & 0x7;  sr >>= 3;
00223          xmc[38] = sr & 0x7;  sr >>= 3;
00224          sr = *c++;
00225          Nc[3] = sr & 0x7f;  sr >>= 7;
00226          sr |= (uword)*c++ << 1;    
00227          bc[3] = sr & 0x3;  sr >>= 2;
00228          Mc[3] = sr & 0x3;  sr >>= 2;
00229          sr |= (uword)*c++ << 5;
00230          xmaxc[3] = sr & 0x3f;  sr >>= 6;
00231          xmc[39] = sr & 0x7;  sr >>= 3;
00232          xmc[40] = sr & 0x7;  sr >>= 3;
00233          sr |= (uword)*c++ << 1;
00234          xmc[41] = sr & 0x7;  sr >>= 3;
00235          xmc[42] = sr & 0x7;  sr >>= 3;
00236          xmc[43] = sr & 0x7;  sr >>= 3;
00237          sr = *c++;           /* 30 */
00238          xmc[44] = sr & 0x7;  sr >>= 3;
00239          xmc[45] = sr & 0x7;  sr >>= 3;
00240          sr |= (uword)*c++ << 2;
00241          xmc[46] = sr & 0x7;  sr >>= 3;
00242          xmc[47] = sr & 0x7;  sr >>= 3;
00243          xmc[48] = sr & 0x7;  sr >>= 3;
00244          sr |= (uword)*c++ << 1;
00245          xmc[49] = sr & 0x7;  sr >>= 3;
00246          xmc[50] = sr & 0x7;  sr >>= 3;
00247          xmc[51] = sr & 0x7;  sr >>= 3;
00248       }
00249    }
00250    else
00251 #endif
00252    {
00253       /* GSM_MAGIC  = (*c >> 4) & 0xF; */
00254 
00255       if (((*c >> 4) & 0x0F) != GSM_MAGIC) return -1;
00256 
00257       LARc[0]  = (*c++ & 0xF) << 2;    /* 1 */
00258       LARc[0] |= (*c >> 6) & 0x3;
00259       LARc[1]  = *c++ & 0x3F;
00260       LARc[2]  = (*c >> 3) & 0x1F;
00261       LARc[3]  = (*c++ & 0x7) << 2;
00262       LARc[3] |= (*c >> 6) & 0x3;
00263       LARc[4]  = (*c >> 2) & 0xF;
00264       LARc[5]  = (*c++ & 0x3) << 2;
00265       LARc[5] |= (*c >> 6) & 0x3;
00266       LARc[6]  = (*c >> 3) & 0x7;
00267       LARc[7]  = *c++ & 0x7;
00268       Nc[0]  = (*c >> 1) & 0x7F;
00269       bc[0]  = (*c++ & 0x1) << 1;
00270       bc[0] |= (*c >> 7) & 0x1;
00271       Mc[0]  = (*c >> 5) & 0x3;
00272       xmaxc[0]  = (*c++ & 0x1F) << 1;
00273       xmaxc[0] |= (*c >> 7) & 0x1;
00274       xmc[0]  = (*c >> 4) & 0x7;
00275       xmc[1]  = (*c >> 1) & 0x7;
00276       xmc[2]  = (*c++ & 0x1) << 2;
00277       xmc[2] |= (*c >> 6) & 0x3;
00278       xmc[3]  = (*c >> 3) & 0x7;
00279       xmc[4]  = *c++ & 0x7;
00280       xmc[5]  = (*c >> 5) & 0x7;
00281       xmc[6]  = (*c >> 2) & 0x7;
00282       xmc[7]  = (*c++ & 0x3) << 1;     /* 10 */
00283       xmc[7] |= (*c >> 7) & 0x1;
00284       xmc[8]  = (*c >> 4) & 0x7;
00285       xmc[9]  = (*c >> 1) & 0x7;
00286       xmc[10]  = (*c++ & 0x1) << 2;
00287       xmc[10] |= (*c >> 6) & 0x3;
00288       xmc[11]  = (*c >> 3) & 0x7;
00289       xmc[12]  = *c++ & 0x7;
00290       Nc[1]  = (*c >> 1) & 0x7F;
00291       bc[1]  = (*c++ & 0x1) << 1;
00292       bc[1] |= (*c >> 7) & 0x1;
00293       Mc[1]  = (*c >> 5) & 0x3;
00294       xmaxc[1]  = (*c++ & 0x1F) << 1;
00295       xmaxc[1] |= (*c >> 7) & 0x1;
00296       xmc[13]  = (*c >> 4) & 0x7;
00297       xmc[14]  = (*c >> 1) & 0x7;
00298       xmc[15]  = (*c++ & 0x1) << 2;
00299       xmc[15] |= (*c >> 6) & 0x3;
00300       xmc[16]  = (*c >> 3) & 0x7;
00301       xmc[17]  = *c++ & 0x7;
00302       xmc[18]  = (*c >> 5) & 0x7;
00303       xmc[19]  = (*c >> 2) & 0x7;
00304       xmc[20]  = (*c++ & 0x3) << 1;
00305       xmc[20] |= (*c >> 7) & 0x1;
00306       xmc[21]  = (*c >> 4) & 0x7;
00307       xmc[22]  = (*c >> 1) & 0x7;
00308       xmc[23]  = (*c++ & 0x1) << 2;
00309       xmc[23] |= (*c >> 6) & 0x3;
00310       xmc[24]  = (*c >> 3) & 0x7;
00311       xmc[25]  = *c++ & 0x7;
00312       Nc[2]  = (*c >> 1) & 0x7F;
00313       bc[2]  = (*c++ & 0x1) << 1;      /* 20 */
00314       bc[2] |= (*c >> 7) & 0x1;
00315       Mc[2]  = (*c >> 5) & 0x3;
00316       xmaxc[2]  = (*c++ & 0x1F) << 1;
00317       xmaxc[2] |= (*c >> 7) & 0x1;
00318       xmc[26]  = (*c >> 4) & 0x7;
00319       xmc[27]  = (*c >> 1) & 0x7;
00320       xmc[28]  = (*c++ & 0x1) << 2;
00321       xmc[28] |= (*c >> 6) & 0x3;
00322       xmc[29]  = (*c >> 3) & 0x7;
00323       xmc[30]  = *c++ & 0x7;
00324       xmc[31]  = (*c >> 5) & 0x7;
00325       xmc[32]  = (*c >> 2) & 0x7;
00326       xmc[33]  = (*c++ & 0x3) << 1;
00327       xmc[33] |= (*c >> 7) & 0x1;
00328       xmc[34]  = (*c >> 4) & 0x7;
00329       xmc[35]  = (*c >> 1) & 0x7;
00330       xmc[36]  = (*c++ & 0x1) << 2;
00331       xmc[36] |= (*c >> 6) & 0x3;
00332       xmc[37]  = (*c >> 3) & 0x7;
00333       xmc[38]  = *c++ & 0x7;
00334       Nc[3]  = (*c >> 1) & 0x7F;
00335       bc[3]  = (*c++ & 0x1) << 1;
00336       bc[3] |= (*c >> 7) & 0x1;
00337       Mc[3]  = (*c >> 5) & 0x3;
00338       xmaxc[3]  = (*c++ & 0x1F) << 1;
00339       xmaxc[3] |= (*c >> 7) & 0x1;
00340       xmc[39]  = (*c >> 4) & 0x7;
00341       xmc[40]  = (*c >> 1) & 0x7;
00342       xmc[41]  = (*c++ & 0x1) << 2;
00343       xmc[41] |= (*c >> 6) & 0x3;
00344       xmc[42]  = (*c >> 3) & 0x7;
00345       xmc[43]  = *c++ & 0x7;        /* 30  */
00346       xmc[44]  = (*c >> 5) & 0x7;
00347       xmc[45]  = (*c >> 2) & 0x7;
00348       xmc[46]  = (*c++ & 0x3) << 1;
00349       xmc[46] |= (*c >> 7) & 0x1;
00350       xmc[47]  = (*c >> 4) & 0x7;
00351       xmc[48]  = (*c >> 1) & 0x7;
00352       xmc[49]  = (*c++ & 0x1) << 2;
00353       xmc[49] |= (*c >> 6) & 0x3;
00354       xmc[50]  = (*c >> 3) & 0x7;
00355       xmc[51]  = *c & 0x7;       /* 33 */
00356    }
00357 
00358    Gsm_Decoder(s, LARc, Nc, bc, Mc, xmaxc, xmc, target);
00359 
00360    return 0;
00361 }

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