jni/g722/g722.h
changeset 839 0e5b95573614
parent 823 2036ebfaccda
equal deleted inserted replaced
822:696b2880c994 839:0e5b95573614
       
     1 /*
       
     2  * SpanDSP - a series of DSP components for telephony
       
     3  *
       
     4  * g722.h - The ITU G.722 codec.
       
     5  *
       
     6  * Written by Steve Underwood <steveu@coppice.org>
       
     7  *
       
     8  * Copyright (C) 2005 Steve Underwood
       
     9  *
       
    10  *  Despite my general liking of the GPL, I place my own contributions 
       
    11  *  to this code in the public domain for the benefit of all mankind -
       
    12  *  even the slimy ones who might try to proprietize my work and use it
       
    13  *  to my detriment.
       
    14  *
       
    15  * Based on a single channel G.722 codec which is:
       
    16  *
       
    17  *****    Copyright (c) CMU    1993      *****
       
    18  * Computer Science, Speech Group
       
    19  * Chengxiang Lu and Alex Hauptmann
       
    20  *
       
    21  * $Id: g722.h 48959 2006-12-25 06:42:15Z rizzo $
       
    22  */
       
    23 
       
    24 
       
    25 /*! \file */
       
    26 
       
    27 #if !defined(_G722_H_)
       
    28 #define _G722_H_
       
    29 
       
    30 /*! \page g722_page G.722 encoding and decoding
       
    31 \section g722_page_sec_1 What does it do?
       
    32 The G.722 module is a bit exact implementation of the ITU G.722 specification for all three
       
    33 specified bit rates - 64000bps, 56000bps and 48000bps. It passes the ITU tests.
       
    34 
       
    35 To allow fast and flexible interworking with narrow band telephony, the encoder and decoder
       
    36 support an option for the linear audio to be an 8k samples/second stream. In this mode the
       
    37 codec is considerably faster, and still fully compatible with wideband terminals using G.722.
       
    38 
       
    39 \section g722_page_sec_2 How does it work?
       
    40 ???.
       
    41 */
       
    42 
       
    43 #if !defined(__STDINT_MACROS)
       
    44 typedef signed char int8_t;
       
    45 typedef unsigned char   uint8_t;
       
    46 typedef short  int16_t;
       
    47 typedef unsigned short  uint16_t;
       
    48 typedef int  int32_t;
       
    49 typedef unsigned   uint32_t;
       
    50 typedef long long  int64_t;
       
    51 typedef unsigned long long   uint64_t;
       
    52 #endif
       
    53 
       
    54 enum
       
    55 {
       
    56     G722_SAMPLE_RATE_8000 = 0x0001,
       
    57     G722_PACKED = 0x0002
       
    58 };
       
    59 
       
    60 #ifndef INT16_MAX
       
    61 #define INT16_MAX       32767
       
    62 #endif
       
    63 #ifndef INT16_MIN
       
    64 #define INT16_MIN       (-32768)
       
    65 #endif
       
    66 
       
    67 typedef struct
       
    68 {
       
    69     /*! TRUE if the operating in the special ITU test mode, with the band split filters
       
    70              disabled. */
       
    71     int itu_test_mode;
       
    72     /*! TRUE if the G.722 data is packed */
       
    73     int packed;
       
    74     /*! TRUE if encode from 8k samples/second */
       
    75     int eight_k;
       
    76     /*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
       
    77     int bits_per_sample;
       
    78 
       
    79     /*! Signal history for the QMF */
       
    80     int x[24];
       
    81 
       
    82     struct
       
    83     {
       
    84         int s;
       
    85         int sp;
       
    86         int sz;
       
    87         int r[3];
       
    88         int a[3];
       
    89         int ap[3];
       
    90         int p[3];
       
    91         int d[7];
       
    92         int b[7];
       
    93         int bp[7];
       
    94         int sg[7];
       
    95         int nb;
       
    96         int det;
       
    97     } band[2];
       
    98 
       
    99     unsigned int in_buffer;
       
   100     int in_bits;
       
   101     unsigned int out_buffer;
       
   102     int out_bits;
       
   103 } g722_encode_state_t;
       
   104 
       
   105 typedef struct
       
   106 {
       
   107     /*! TRUE if the operating in the special ITU test mode, with the band split filters
       
   108              disabled. */
       
   109     int itu_test_mode;
       
   110     /*! TRUE if the G.722 data is packed */
       
   111     int packed;
       
   112     /*! TRUE if decode to 8k samples/second */
       
   113     int eight_k;
       
   114     /*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
       
   115     int bits_per_sample;
       
   116 
       
   117     /*! Signal history for the QMF */
       
   118     int x[24];
       
   119 
       
   120     struct
       
   121     {
       
   122         int s;
       
   123         int sp;
       
   124         int sz;
       
   125         int r[3];
       
   126         int a[3];
       
   127         int ap[3];
       
   128         int p[3];
       
   129         int d[7];
       
   130         int b[7];
       
   131         int bp[7];
       
   132         int sg[7];
       
   133         int nb;
       
   134         int det;
       
   135     } band[2];
       
   136     
       
   137     unsigned int in_buffer;
       
   138     int in_bits;
       
   139     unsigned int out_buffer;
       
   140     int out_bits;
       
   141 } g722_decode_state_t;
       
   142 
       
   143 #ifdef __cplusplus
       
   144 extern "C" {
       
   145 #endif
       
   146 
       
   147 g722_encode_state_t *g722_encode_init(g722_encode_state_t *s, int rate, int options);
       
   148 int g722_encode_release(g722_encode_state_t *s);
       
   149 int g722_encode(g722_encode_state_t *s, uint8_t g722_data[], const int16_t amp[], int len);
       
   150 
       
   151 g722_decode_state_t *g722_decode_init(g722_decode_state_t *s, int rate, int options);
       
   152 int g722_decode_release(g722_decode_state_t *s);
       
   153 int g722_decode(g722_decode_state_t *s, int16_t amp[], const uint8_t g722_data[], int len);
       
   154 
       
   155 #ifdef __cplusplus
       
   156 }
       
   157 #endif
       
   158 
       
   159 #endif