g722_1/g722_1.h

00001 /*
00002  * g722_1 - a library for the G.722.1 and Annex C codecs
00003  *
00004  * g722_1.h
00005  *
00006  * Adapted by Steve Underwood <steveu@coppice.org> from the reference
00007  * code supplied with ITU G.722.1, which is:
00008  *
00009  *   (C) 2004 Polycom, Inc.
00010  *   All rights reserved.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00015  */
00016 
00017 #if !defined(_G722_1_G722_1_H_)
00018 #define _G722_1_G722_1_H_
00019 
00020 typedef enum
00021 {
00022     /*! \brief Basic G.722.1 sampling rate */
00023     G722_1_SAMPLE_RATE_16000 = 16000,
00024     /*! \brief G.722.1 Annex C sampling rate */
00025     G722_1_SAMPLE_RATE_32000 = 32000
00026 } g722_1_sample_rates_t;
00027 
00028 typedef enum
00029 {
00030     /*! \brief Bit rate usable at either sampling rate. */
00031     G722_1_BIT_RATE_24000 = 24000,
00032     /*! \brief Bit rate usable at either sampling rate. */
00033     G722_1_BIT_RATE_32000 = 32000,
00034     /*! \brief Bit rate usable at 32000 samples per second. */
00035     G722_1_BIT_RATE_48000 = 48000
00036 } g722_1_bit_rates_t;
00037 
00038 #define MAX_SAMPLE_RATE         32000
00039 /* Frames are 20ms */
00040 #define MAX_FRAME_SIZE          (MAX_SAMPLE_RATE/50)
00041 #define MAX_DCT_LENGTH          640
00042 
00043 /* Max bit rate is 48000 bits/sec. */
00044 #define MAX_BITS_PER_FRAME      960
00045 
00046 #define NUMBER_OF_REGIONS       14
00047 #define MAX_NUMBER_OF_REGIONS   28
00048 
00049 /*! Bitstream handler state */
00050 typedef struct
00051 {
00052     /*! The bit stream. */
00053     uint32_t bitstream;
00054     /*! The residual bits in bitstream. */
00055     int residue;
00056 } g722_1_bitstream_state_t;
00057 
00058 typedef struct
00059 {
00060     int16_t code_bit_count;      /* bit count of the current word */
00061     int16_t current_word;        /* current word in the bitstream being processed */
00062     uint16_t *code_word_ptr;     /* pointer to the bitstream */
00063 } g722_1_bitstream_t;
00064 
00065 typedef struct
00066 {
00067     int16_t seed0;
00068     int16_t seed1;
00069     int16_t seed2;
00070     int16_t seed3;
00071 } g722_1_rand_t;
00072 
00073 typedef struct
00074 {
00075     int bit_rate;
00076     int sample_rate;
00077     int frame_size;
00078     int number_of_regions;
00079     int number_of_bits_per_frame;
00080     int bytes_per_frame;
00081     int number_of_16bit_words_per_frame;
00082 #if defined(G722_1_USE_FIXED_POINT)
00083     int16_t history[MAX_FRAME_SIZE];
00084 #else
00085     float history[MAX_FRAME_SIZE];
00086     float scale_factor;
00087 #endif
00088     g722_1_bitstream_state_t bitstream;
00089 } g722_1_encode_state_t;
00090 
00091 typedef struct
00092 {
00093     int bit_rate;
00094     int sample_rate;
00095     int frame_size;
00096     int number_of_regions;
00097     int number_of_bits_per_frame;
00098     int bytes_per_frame;
00099     int number_of_16bit_words_per_frame;
00100     int16_t words;
00101     int16_t old_mag_shift;
00102 #if defined(G722_1_USE_FIXED_POINT)
00103     int16_t old_decoder_mlt_coefs[MAX_DCT_LENGTH];
00104     int16_t old_samples[MAX_DCT_LENGTH >> 1];
00105 #else
00106     float old_decoder_mlt_coefs[MAX_DCT_LENGTH];
00107     float old_samples[MAX_DCT_LENGTH >> 1];
00108 #endif
00109     g722_1_bitstream_t bitobj;
00110     g722_1_bitstream_state_t bitstream;
00111     const uint8_t *code_ptr;
00112     int16_t number_of_bits_left;
00113     g722_1_rand_t randobj;
00114 } g722_1_decode_state_t;
00115 
00116 #if defined(__cplusplus)
00117 extern "C"
00118 {
00119 #endif
00120 
00121 /*! Initialise a G.722.1 encode context.
00122     \param s The G.722.1 encode context.
00123     \param bit_rate The required bit rate for the G.722.1 data.
00124            The valid rates are 48000, 32000 and 24000.
00125     \param sample_rate The required sampling rate.
00126            The valid rates are 16000 and 32000.
00127     \return A pointer to the G.722.1 encode context, or NULL for error. */
00128 g722_1_encode_state_t *g722_1_encode_init(g722_1_encode_state_t *s, int bit_rate, int sample_rate);
00129 
00130 /*! Release a G.722.1 encode context.
00131     \param s The G.722.1 encode context.
00132     \return 0. */
00133 int g722_1_encode_release(g722_1_encode_state_t *s);
00134 
00135 /*! Encode a buffer of linear PCM data to G.722.1
00136     \param s The G.722.1 encode context.
00137     \param g722_1_data The G.722.1 data produced.
00138     \param amp The audio sample buffer.
00139     \param len The number of samples in the buffer.
00140     \return The number of bytes of G.722.1 data produced. */
00141 int g722_1_encode(g722_1_encode_state_t *s, uint8_t g722_1_data[], const int16_t amp[], int len);
00142 
00143 /*! Change the bit rate for an G.722.1 decode context.
00144     \param s The G.722.1 decode context.
00145     \param bit_rate The required bit rate for the G.722.1 data.
00146            The valid rates are 48000, 32000 and 24000.
00147     \return 0 for OK, or -1 for a bad parameter. */
00148 int g722_1_encode_set_rate(g722_1_encode_state_t *s, int bit_rate);
00149 
00150 /*! Initialise a G.722.1 decode context.
00151     \param s The G.722.1 decode context.
00152     \param bit_rate The required bit rate for the G.722.1 data.
00153            The valid rates are 48000, 32000 and 24000.
00154     \param sample_rate The required sampling rate.
00155            The valid rates are 16000 and 32000.
00156     \return A pointer to the G.722.1 decode context, or NULL for error. */
00157 g722_1_decode_state_t *g722_1_decode_init(g722_1_decode_state_t *s, int bit_rate, int sample_rate);
00158 
00159 /*! Release a G.722.1 decode context.
00160     \param s The G.722.1 decode context.
00161     \return 0. */
00162 int g722_1_decode_release(g722_1_decode_state_t *s);
00163 
00164 /*! Decode a buffer of G.722.1 data to linear PCM.
00165     \param s The G.722.1 decode context.
00166     \param amp The audio sample buffer.
00167     \param g722_1_data
00168     \param len
00169     \return The number of samples returned. */
00170 int g722_1_decode(g722_1_decode_state_t *s, int16_t amp[], const uint8_t g722_1_data[], int len);
00171 
00172 /*! Produce linear PCM data to fill in where received G.722.1 data is missing.
00173     \param s The G.722.1 decode context.
00174     \param amp The audio sample buffer.
00175     \param g722_1_data
00176     \param len
00177     \return The number of samples returned. */
00178 int g722_1_fillin(g722_1_decode_state_t *s, int16_t amp[], const uint8_t g722_1_data[], int len);
00179 
00180 /*! Change the bit rate for an G.722.1 decode context.
00181     \param s The G.722.1 decode context.
00182     \param bit_rate The required bit rate for the G.722.1 data.
00183            The valid rates are 48000, 32000 and 24000.
00184     \return 0 for OK, or -1 for a bad parameter. */
00185 int g722_1_decode_set_rate(g722_1_decode_state_t *s, int bit_rate);
00186 
00187 #if defined(__cplusplus)
00188 }
00189 #endif
00190 
00191 #endif
00192 /*- End of file ------------------------------------------------------------*/

Generated on 29 Mar 2018 for libg722_1 by  doxygen 1.6.1