libg722_1 0.0.1
g722_1/g722_1.h
1/*
2 * g722_1 - a library for the G.722.1 and Annex C codecs
3 *
4 * g722_1.h
5 *
6 * Adapted by Steve Underwood <steveu@coppice.org> from the reference
7 * code supplied with ITU G.722.1, which is:
8 *
9 * (C) 2004 Polycom, Inc.
10 * All rights reserved.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 */
16
17#if !defined(_G722_1_G722_1_H_)
18#define _G722_1_G722_1_H_
19
20typedef enum
21{
22 /*! \brief Basic G.722.1 sampling rate */
23 G722_1_SAMPLE_RATE_16000 = 16000,
24 /*! \brief G.722.1 Annex C sampling rate */
25 G722_1_SAMPLE_RATE_32000 = 32000
26} g722_1_sample_rates_t;
27
28typedef enum
29{
30 /*! \brief Bit rate usable at either sampling rate. */
31 G722_1_BIT_RATE_24000 = 24000,
32 /*! \brief Bit rate usable at either sampling rate. */
33 G722_1_BIT_RATE_32000 = 32000,
34 /*! \brief Bit rate usable at 32000 samples per second. */
35 G722_1_BIT_RATE_48000 = 48000
36} g722_1_bit_rates_t;
37
38#define MAX_SAMPLE_RATE 32000
39/* Frames are 20ms */
40#define MAX_FRAME_SIZE (MAX_SAMPLE_RATE/50)
41#define MAX_DCT_LENGTH 640
42
43/* Max bit rate is 48000 bits/sec. */
44#define MAX_BITS_PER_FRAME 960
45
46#define NUMBER_OF_REGIONS 14
47#define MAX_NUMBER_OF_REGIONS 28
48
49/*! Bitstream handler state */
50typedef struct
51{
52 /*! The bit stream. */
53 uint32_t bitstream;
54 /*! The residual bits in bitstream. */
57
58typedef struct
59{
60 int16_t code_bit_count; /* bit count of the current word */
61 int16_t current_word; /* current word in the bitstream being processed */
62 uint16_t *code_word_ptr; /* pointer to the bitstream */
64
65typedef struct
66{
67 int16_t seed0;
68 int16_t seed1;
69 int16_t seed2;
70 int16_t seed3;
72
73typedef struct
74{
75 int bit_rate;
76 int sample_rate;
77 int frame_size;
78 int number_of_regions;
79 int number_of_bits_per_frame;
80 int bytes_per_frame;
81 int number_of_16bit_words_per_frame;
82#if defined(G722_1_USE_FIXED_POINT)
83 int16_t history[MAX_FRAME_SIZE];
84#else
85 float history[MAX_FRAME_SIZE];
86 float scale_factor;
87#endif
90
91typedef struct
92{
93 int bit_rate;
94 int sample_rate;
95 int frame_size;
96 int number_of_regions;
97 int number_of_bits_per_frame;
98 int bytes_per_frame;
99 int number_of_16bit_words_per_frame;
100 int16_t words;
101 int16_t old_mag_shift;
102#if defined(G722_1_USE_FIXED_POINT)
103 int16_t old_decoder_mlt_coefs[MAX_DCT_LENGTH];
104 int16_t old_samples[MAX_DCT_LENGTH >> 1];
105#else
106 float old_decoder_mlt_coefs[MAX_DCT_LENGTH];
107 float old_samples[MAX_DCT_LENGTH >> 1];
108#endif
109 g722_1_bitstream_t bitobj;
110 g722_1_bitstream_state_t bitstream;
111 const uint8_t *code_ptr;
112 int16_t number_of_bits_left;
113 g722_1_rand_t randobj;
115
116#if defined(__cplusplus)
117extern "C"
118{
119#endif
120
121/*! Initialise a G.722.1 encode context.
122 \param s The G.722.1 encode context.
123 \param bit_rate The required bit rate for the G.722.1 data.
124 The valid rates are 48000, 32000 and 24000.
125 \param sample_rate The required sampling rate.
126 The valid rates are 16000 and 32000.
127 \return A pointer to the G.722.1 encode context, or NULL for error. */
128g722_1_encode_state_t *g722_1_encode_init(g722_1_encode_state_t *s, int bit_rate, int sample_rate);
129
130/*! Release a G.722.1 encode context.
131 \param s The G.722.1 encode context.
132 \return 0. */
134
135/*! Encode a buffer of linear PCM data to G.722.1
136 \param s The G.722.1 encode context.
137 \param g722_1_data The G.722.1 data produced.
138 \param amp The audio sample buffer.
139 \param len The number of samples in the buffer.
140 \return The number of bytes of G.722.1 data produced. */
141int g722_1_encode(g722_1_encode_state_t *s, uint8_t g722_1_data[], const int16_t amp[], int len);
142
143/*! Change the bit rate for an G.722.1 decode context.
144 \param s The G.722.1 decode context.
145 \param bit_rate The required bit rate for the G.722.1 data.
146 The valid rates are 48000, 32000 and 24000.
147 \return 0 for OK, or -1 for a bad parameter. */
149
150/*! Initialise a G.722.1 decode context.
151 \param s The G.722.1 decode context.
152 \param bit_rate The required bit rate for the G.722.1 data.
153 The valid rates are 48000, 32000 and 24000.
154 \param sample_rate The required sampling rate.
155 The valid rates are 16000 and 32000.
156 \return A pointer to the G.722.1 decode context, or NULL for error. */
157g722_1_decode_state_t *g722_1_decode_init(g722_1_decode_state_t *s, int bit_rate, int sample_rate);
158
159/*! Release a G.722.1 decode context.
160 \param s The G.722.1 decode context.
161 \return 0. */
163
164/*! Decode a buffer of G.722.1 data to linear PCM.
165 \param s The G.722.1 decode context.
166 \param amp The audio sample buffer.
167 \param g722_1_data
168 \param len
169 \return The number of samples returned. */
170int g722_1_decode(g722_1_decode_state_t *s, int16_t amp[], const uint8_t g722_1_data[], int len);
171
172/*! Produce linear PCM data to fill in where received G.722.1 data is missing.
173 \param s The G.722.1 decode context.
174 \param amp The audio sample buffer.
175 \param g722_1_data
176 \param len
177 \return The number of samples returned. */
178int g722_1_fillin(g722_1_decode_state_t *s, int16_t amp[], const uint8_t g722_1_data[], int len);
179
180/*! Change the bit rate for an G.722.1 decode context.
181 \param s The G.722.1 decode context.
182 \param bit_rate The required bit rate for the G.722.1 data.
183 The valid rates are 48000, 32000 and 24000.
184 \return 0 for OK, or -1 for a bad parameter. */
186
187#if defined(__cplusplus)
188}
189#endif
190
191#endif
192/*- End of file ------------------------------------------------------------*/
int g722_1_decode_set_rate(g722_1_decode_state_t *s, int bit_rate)
Definition decoder.c:649
int g722_1_decode_release(g722_1_decode_state_t *s)
Definition decoder.c:709
g722_1_decode_state_t * g722_1_decode_init(g722_1_decode_state_t *s, int bit_rate, int sample_rate)
Definition decoder.c:660
int g722_1_fillin(g722_1_decode_state_t *s, int16_t amp[], const uint8_t g722_1_data[], int len)
Definition decoderf.c:608
int g722_1_decode(g722_1_decode_state_t *s, int16_t amp[], const uint8_t g722_1_data[], int len)
Definition decoderf.c:573
g722_1_encode_state_t * g722_1_encode_init(g722_1_encode_state_t *s, int bit_rate, int sample_rate)
Definition encoder.c:652
int g722_1_encode_release(g722_1_encode_state_t *s)
Definition encoder.c:696
int g722_1_encode_set_rate(g722_1_encode_state_t *s, int bit_rate)
Definition encoder.c:641
int g722_1_encode(g722_1_encode_state_t *s, uint8_t g722_1_data[], const int16_t amp[], int len)
Definition encoderf.c:488
Definition g722_1/g722_1.h:51
uint32_t bitstream
Definition g722_1/g722_1.h:53
int residue
Definition g722_1/g722_1.h:55
Definition g722_1/g722_1.h:59
Definition g722_1/g722_1.h:92
Definition g722_1/g722_1.h:74
Definition g722_1/g722_1.h:66