root/src/g711.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. alaw_to_ulaw
  2. ulaw_to_alaw

   1 /*
   2  * SpanDSP - a series of DSP components for telephony
   3  *
   4  * g711.c - A-law and u-law transcoding routines
   5  *
   6  * Written by Steve Underwood <steveu@coppice.org>
   7  *
   8  * Copyright (C) 2006 Steve Underwood
   9  *
  10  *  Despite my general liking of the GPL, I place this code in the
  11  *  public domain for the benefit of all mankind - even the slimy
  12  *  ones who might try to proprietize my work and use it to my
  13  *  detriment.
  14  *
  15  * $Id: g711.c,v 1.1 2006/06/07 15:46:39 steveu Exp $
  16  */
  17 
  18 /*! \file */
  19 
  20 #ifdef HAVE_CONFIG_H
  21 #include <config.h>
  22 #endif
  23 
  24 #include <stdlib.h>
  25 #include <stdio.h>
  26 #include <string.h>
  27 #include <assert.h>
  28 #ifndef _MSC_VER
  29 #include <inttypes.h>
  30 #ifdef HAVE_TGMATH_H
  31 #include <tgmath.h>
  32 #endif
  33 #endif
  34 
  35 #include "g711.h"
  36 
  37 /* Copied from the CCITT G.711 specification */
  38 static const uint8_t ulaw_to_alaw_table[256] =
  39         {
  40                 42,  43,  40,  41,  46,  47,  44,  45,  34,  35,  32,  33,  38,  39,  36,  37,
  41                 58,  59,  56,  57,  62,  63,  60,  61,  50,  51,  48,  49,  54,  55,  52,  53,
  42                 10,  11,   8,   9,  14,  15,  12,  13,   2,   3,   0,   1,   6,   7,   4,  26,
  43                 27,  24,  25,  30,  31,  28,  29,  18,  19,  16,  17,  22,  23,  20,  21, 106,
  44                 104, 105, 110, 111, 108, 109,  98,  99,  96,  97, 102, 103, 100, 101, 122, 120,
  45                 126, 127, 124, 125, 114, 115, 112, 113, 118, 119, 116, 117,  75,  73,  79,  77,
  46                 66,  67,  64,  65,  70,  71,  68,  69,  90,  91,  88,  89,  94,  95,  92,  93,
  47                 82,  82,  83,  83,  80,  80,  81,  81,  86,  86,  87,  87,  84,  84,  85,  85,
  48                 170, 171, 168, 169, 174, 175, 172, 173, 162, 163, 160, 161, 166, 167, 164, 165,
  49                 186, 187, 184, 185, 190, 191, 188, 189, 178, 179, 176, 177, 182, 183, 180, 181,
  50                 138, 139, 136, 137, 142, 143, 140, 141, 130, 131, 128, 129, 134, 135, 132, 154,
  51                 155, 152, 153, 158, 159, 156, 157, 146, 147, 144, 145, 150, 151, 148, 149, 234,
  52                 232, 233, 238, 239, 236, 237, 226, 227, 224, 225, 230, 231, 228, 229, 250, 248,
  53                 254, 255, 252, 253, 242, 243, 240, 241, 246, 247, 244, 245, 203, 201, 207, 205,
  54                 194, 195, 192, 193, 198, 199, 196, 197, 218, 219, 216, 217, 222, 223, 220, 221,
  55                 210, 210, 211, 211, 208, 208, 209, 209, 214, 214, 215, 215, 212, 212, 213, 213
  56         };
  57 
  58 /* These transcoding tables are copied from the CCITT G.711 specification. To achieve
  59    optimal results, do not change them. */
  60 
  61 static const uint8_t alaw_to_ulaw_table[256] =
  62         {
  63                 42,  43,  40,  41,  46,  47,  44,  45,  34,  35,  32,  33,  38,  39,  36,  37,
  64                 57,  58,  55,  56,  61,  62,  59,  60,  49,  50,  47,  48,  53,  54,  51,  52,
  65                 10,  11,   8,   9,  14,  15,  12,  13,   2,   3,   0,   1,   6,   7,   4,   5,
  66                 26,  27,  24,  25,  30,  31,  28,  29,  18,  19,  16,  17,  22,  23,  20,  21,
  67                 98,  99,  96,  97, 102, 103, 100, 101,  93,  93,  92,  92,  95,  95,  94,  94,
  68                 116, 118, 112, 114, 124, 126, 120, 122, 106, 107, 104, 105, 110, 111, 108, 109,
  69                 72,  73,  70,  71,  76,  77,  74,  75,  64,  65,  63,  63,  68,  69,  66,  67,
  70                 86,  87,  84,  85,  90,  91,  88,  89,  79,  79,  78,  78,  82,  83,  80,  81,
  71                 170, 171, 168, 169, 174, 175, 172, 173, 162, 163, 160, 161, 166, 167, 164, 165,
  72                 185, 186, 183, 184, 189, 190, 187, 188, 177, 178, 175, 176, 181, 182, 179, 180,
  73                 138, 139, 136, 137, 142, 143, 140, 141, 130, 131, 128, 129, 134, 135, 132, 133,
  74                 154, 155, 152, 153, 158, 159, 156, 157, 146, 147, 144, 145, 150, 151, 148, 149,
  75                 226, 227, 224, 225, 230, 231, 228, 229, 221, 221, 220, 220, 223, 223, 222, 222,
  76                 244, 246, 240, 242, 252, 254, 248, 250, 234, 235, 232, 233, 238, 239, 236, 237,
  77                 200, 201, 198, 199, 204, 205, 202, 203, 192, 193, 191, 191, 196, 197, 194, 195,
  78                 214, 215, 212, 213, 218, 219, 216, 217, 207, 207, 206, 206, 210, 211, 208, 209
  79         };
  80 
  81 uint8_t alaw_to_ulaw(uint8_t alaw)
  82 {
  83     return alaw_to_ulaw_table[alaw];
  84 }
  85 /*- End of function --------------------------------------------------------*/
  86 
  87 uint8_t ulaw_to_alaw(uint8_t ulaw)
  88 {
  89     return ulaw_to_alaw_table[ulaw];
  90 }
  91 /*- End of function --------------------------------------------------------*/
  92 /*- End of file ------------------------------------------------------------*/
  93 
  94 /* For Emacs:
  95  * Local Variables:
  96  * mode:c
  97  * indent-tabs-mode:t
  98  * tab-width:4
  99  * c-basic-offset:4
 100  * End:
 101  * For VIM:
 102  * vim:set softtabstop=4 shiftwidth=4 tabstop=4:
 103  */
 104 

/* [<][>][^][v][top][bottom][index][help] */