FFmpeg
Loading...
Searching...
No Matches
g723_1.h
Go to the documentation of this file.
1/*
2 * G.723.1 common header and data tables
3 * Copyright (c) 2006 Benjamin Larsson
4 * Copyright (c) 2010 Mohamed Naufal Basheer
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23/**
24 * @file
25 * G.723.1 types, functions and data tables
26 */
27
28#ifndef AVCODEC_G723_1_H
29#define AVCODEC_G723_1_H
30
31#include <stdint.h>
32
33#include "libavutil/log.h"
34
35#define SUBFRAMES 4
36#define SUBFRAME_LEN 60
37#define FRAME_LEN (SUBFRAME_LEN << 2)
38#define HALF_FRAME_LEN (FRAME_LEN / 2)
39#define LPC_FRAME (HALF_FRAME_LEN + SUBFRAME_LEN)
40#define LPC_ORDER 10
41#define LSP_BANDS 3
42#define LSP_CB_SIZE 256
43#define PITCH_MIN 18
44#define PITCH_MAX (PITCH_MIN + 127)
45#define PITCH_ORDER 5
46#define GRID_SIZE 2
47#define PULSE_MAX 6
48#define GAIN_LEVELS 24
49#define COS_TBL_SIZE 512
50
51/**
52 * Bitexact implementation of 2ab scaled by 1/2^16.
53 *
54 * @param a 32 bit multiplicand
55 * @param b 16 bit multiplier
56 */
57#define MULL2(a, b) \
58 ((((a) >> 16) * (b) * 2) + (((a) & 0xffff) * (b) >> 15))
59
60/**
61 * G723.1 frame types
62 */
64 ACTIVE_FRAME, ///< Active speech
65 SID_FRAME, ///< Silence Insertion Descriptor frame
67};
68
69/**
70 * G723.1 rate values
71 */
76
77/**
78 * G723.1 unpacked data subframe
79 */
80typedef struct G723_1_Subframe {
81 int ad_cb_lag; ///< adaptive codebook lag
89
90/**
91 * Pitch postfilter parameters
92 */
93typedef struct PPFParam {
94 int index; ///< postfilter backward/forward lag
95 int16_t opt_gain; ///< optimal gain
96 int16_t sc_gain; ///< scaling gain
97} PPFParam;
98
99/**
100 * Harmonic filter parameters
101 */
102typedef struct HFParam {
103 int index;
104 int gain;
105} HFParam;
106
107/**
108 * Optimized fixed codebook excitation parameters
109 */
118
119typedef struct G723_1_ChannelContext {
125 int pitch_lag[2];
127
135
143 int pf_gain; ///< formant postfilter
144 ///< gain scaling unit memory
146
147 /* encoder */
150
151 int16_t hpf_fir_mem; ///< highpass filter fir
152 int hpf_iir_mem; ///< and iir memories
153 int16_t perf_fir_mem[LPC_ORDER]; ///< perceptual filter fir
154 int16_t perf_iir_mem[LPC_ORDER]; ///< and iir memories
155
158
165
166
167/**
168 * Scale vector contents based on the largest of their absolutes.
169 */
170int ff_g723_1_scale_vector(int16_t *dst, const int16_t *vector, int length);
171
172/**
173 * Calculate the number of left-shifts required for normalizing the input.
174 *
175 * @param num input number
176 * @param width width of the input, 16 bits(0) / 32 bits(1)
177 */
178int ff_g723_1_normalize_bits(int num, int width);
179
180int ff_g723_1_dot_product(const int16_t *a, const int16_t *b, int length);
181
182/**
183 * Get delayed contribution from the previous excitation vector.
184 */
185void ff_g723_1_get_residual(int16_t *residual, int16_t *prev_excitation,
186 int lag);
187
188/**
189 * Generate a train of dirac functions with period as pitch lag.
190 */
191void ff_g723_1_gen_dirac_train(int16_t *buf, int pitch_lag);
192
193
194/**
195 * Generate adaptive codebook excitation.
196 */
197void ff_g723_1_gen_acb_excitation(int16_t *vector, int16_t *prev_excitation,
198 int pitch_lag, G723_1_Subframe *subfrm,
199 enum Rate cur_rate);
200/**
201 * Quantize LSP frequencies by interpolation and convert them to
202 * the corresponding LPC coefficients.
203 *
204 * @param lpc buffer for LPC coefficients
205 * @param cur_lsp the current LSP vector
206 * @param prev_lsp the previous LSP vector
207 */
208void ff_g723_1_lsp_interpolate(int16_t *lpc, int16_t *cur_lsp,
209 int16_t *prev_lsp);
210
211/**
212 * Perform inverse quantization of LSP frequencies.
213 *
214 * @param cur_lsp the current LSP vector
215 * @param prev_lsp the previous LSP vector
216 * @param lsp_index VQ indices
217 * @param bad_frame bad frame flag
218 */
219void ff_g723_1_inverse_quant(int16_t *cur_lsp, int16_t *prev_lsp,
220 uint8_t *lsp_index, int bad_frame);
221
222static const uint8_t frame_size[4] = { 24, 20, 4, 1 };
223
224/**
225 * LSP DC component
226 */
227static const int16_t dc_lsp[LPC_ORDER] = {
228 0x0c3b,
229 0x1271,
230 0x1e0a,
231 0x2a36,
232 0x3630,
233 0x406f,
234 0x4d28,
235 0x56f4,
236 0x638c,
237 0x6c46
238};
239
240/* Cosine table scaled by 2^14 */
241extern const int16_t ff_g723_1_cos_tab[COS_TBL_SIZE + 1];
242#define G723_1_COS_TAB_FIRST_ELEMENT 16384
243
244/**
245 * LSP VQ tables
246 */
247extern const int16_t ff_g723_1_lsp_band0[LSP_CB_SIZE][3];
248extern const int16_t ff_g723_1_lsp_band1[LSP_CB_SIZE][3];
249extern const int16_t ff_g723_1_lsp_band2[LSP_CB_SIZE][4];
250
251/**
252 * Used for the coding/decoding of the pulses positions
253 * for the MP-MLQ codebook
254 */
256
257/**
258 * Number of non-zero pulses in the MP-MLQ excitation
259 */
260static const int8_t pulses[4] = {6, 5, 6, 5};
261
262extern const int16_t ff_g723_1_fixed_cb_gain[GAIN_LEVELS];
263
264extern const int16_t ff_g723_1_adaptive_cb_gain85 [ 85 * 20];
265extern const int16_t ff_g723_1_adaptive_cb_gain170[170 * 20];
266
267#endif /* AVCODEC_G723_1_H */
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
int32_t
long long int64_t
Definition coverity.c:34
#define PULSE_MAX
Definition dss_sp.c:32
#define GRID_SIZE
Definition g723_1.h:46
#define PULSE_MAX
Definition g723_1.h:47
int ff_g723_1_dot_product(const int16_t *a, const int16_t *b, int length)
Definition g723_1.c:1126
Rate
G723.1 rate values.
Definition g723_1.h:72
@ RATE_6300
Definition g723_1.h:73
@ RATE_5300
Definition g723_1.h:74
void ff_g723_1_lsp_interpolate(int16_t *lpc, int16_t *cur_lsp, int16_t *prev_lsp)
Quantize LSP frequencies by interpolation and convert them to the corresponding LPC coefficients.
Definition g723_1.c:1252
int ff_g723_1_normalize_bits(int num, int width)
Calculate the number of left-shifts required for normalizing the input.
Definition g723_1.c:1121
void ff_g723_1_get_residual(int16_t *residual, int16_t *prev_excitation, int lag)
Get delayed contribution from the previous excitation vector.
Definition g723_1.c:1132
#define PITCH_MAX
Definition g723_1.h:44
void ff_g723_1_gen_acb_excitation(int16_t *vector, int16_t *prev_excitation, int pitch_lag, G723_1_Subframe *subfrm, enum Rate cur_rate)
Generate adaptive codebook excitation.
Definition g723_1.c:1158
static const int16_t dc_lsp[LPC_ORDER]
LSP DC component.
Definition g723_1.h:227
void ff_g723_1_gen_dirac_train(int16_t *buf, int pitch_lag)
Generate a train of dirac functions with period as pitch lag.
Definition g723_1.c:1146
#define LSP_BANDS
Definition g723_1.h:41
#define FRAME_LEN
Definition g723_1.h:37
void ff_g723_1_inverse_quant(int16_t *cur_lsp, int16_t *prev_lsp, uint8_t *lsp_index, int bad_frame)
Perform inverse quantization of LSP frequencies.
Definition g723_1.c:1273
#define HALF_FRAME_LEN
Definition g723_1.h:38
#define SUBFRAME_LEN
Definition g723_1.h:36
int ff_g723_1_scale_vector(int16_t *dst, const int16_t *vector, int length)
Scale vector contents based on the largest of their absolutes.
Definition g723_1.c:1104
static const uint8_t frame_size[4]
Definition g723_1.h:222
#define LPC_ORDER
Definition g723_1.h:40
#define LSP_CB_SIZE
Definition g723_1.h:42
FrameType
G723.1 frame types.
Definition g723_1.h:63
@ ACTIVE_FRAME
Active speech.
Definition g723_1.h:64
@ UNTRANSMITTED_FRAME
Definition g723_1.h:66
@ SID_FRAME
Silence Insertion Descriptor frame.
Definition g723_1.h:65
static const int8_t pulses[4]
Number of non-zero pulses in the MP-MLQ excitation.
Definition g723_1.h:260
#define COS_TBL_SIZE
Definition g723_1.h:49
#define GAIN_LEVELS
Definition g723_1.h:48
int a
#define b
Definition input.c:43
const int16_t ff_g723_1_cos_tab[COS_TBL_SIZE+1]
Definition g723_1.c:33
const int16_t ff_g723_1_lsp_band2[LSP_CB_SIZE][4]
Definition g723_1.c:279
const int16_t ff_g723_1_lsp_band0[LSP_CB_SIZE][3]
LSP VQ tables.
Definition g723_1.c:101
const int32_t ff_g723_1_combinatorial_table[PULSE_MAX][SUBFRAME_LEN/GRID_SIZE]
Used for the coding/decoding of the pulses positions for the MP-MLQ codebook.
Definition g723_1.c:410
const int16_t ff_g723_1_fixed_cb_gain[GAIN_LEVELS]
Definition g723_1.c:454
const int16_t ff_g723_1_lsp_band1[LSP_CB_SIZE][3]
Definition g723_1.c:190
const int16_t ff_g723_1_adaptive_cb_gain85[85 *20]
Definition g723_1.c:460
const int16_t ff_g723_1_adaptive_cb_gain170[170 *20]
Definition g723_1.c:676
Describe the class of an AVClass context structure.
Definition log.h:76
Optimized fixed codebook excitation parameters.
Definition g723_1.h:110
int dirac_train
Definition g723_1.h:114
int pulse_sign[PULSE_MAX]
Definition g723_1.h:116
int amp_index
Definition g723_1.h:112
int grid_index
Definition g723_1.h:113
int pulse_pos[PULSE_MAX]
Definition g723_1.h:115
int64_t min_err
Definition g723_1.h:111
int16_t harmonic_mem[PITCH_MAX]
Definition g723_1.h:156
int16_t prev_weight_sig[PITCH_MAX]
Definition g723_1.h:149
int16_t perf_iir_mem[LPC_ORDER]
and iir memories
Definition g723_1.h:154
int pf_gain
formant postfilter gain scaling unit memory
Definition g723_1.h:143
int16_t excitation[PITCH_MAX+FRAME_LEN+4]
Definition g723_1.h:131
int16_t hpf_fir_mem
highpass filter fir
Definition g723_1.h:151
enum FrameType past_frame_type
Definition g723_1.h:122
int16_t prev_data[HALF_FRAME_LEN]
Definition g723_1.h:148
int iir_mem[LPC_ORDER]
Definition g723_1.h:134
int16_t synth_mem[LPC_ORDER]
Definition g723_1.h:132
int16_t prev_lsp[LPC_ORDER]
Definition g723_1.h:128
uint8_t lsp_index[LSP_BANDS]
Definition g723_1.h:124
int hpf_iir_mem
and iir memories
Definition g723_1.h:152
int16_t sid_lsp[LPC_ORDER]
Definition g723_1.h:129
int16_t audio[FRAME_LEN+LPC_ORDER+PITCH_MAX+4]
Definition g723_1.h:145
enum Rate cur_rate
Definition g723_1.h:123
enum FrameType cur_frame_type
Definition g723_1.h:121
int16_t prev_excitation[PITCH_MAX]
Definition g723_1.h:130
int16_t perf_fir_mem[LPC_ORDER]
perceptual filter fir
Definition g723_1.h:153
int16_t fir_mem[LPC_ORDER]
Definition g723_1.h:133
G723_1_Subframe subframe[4]
Definition g723_1.h:120
G723_1_ChannelContext ch[2]
Definition g723_1.h:163
G723.1 unpacked data subframe.
Definition g723_1.h:80
int dirac_train
Definition g723_1.h:83
int ad_cb_lag
adaptive codebook lag
Definition g723_1.h:81
Harmonic filter parameters.
Definition g723_1.h:102
int gain
Definition g723_1.h:104
int index
Definition g723_1.h:103
Pitch postfilter parameters.
Definition g723_1.h:93
int16_t opt_gain
optimal gain
Definition g723_1.h:95
int16_t sc_gain
scaling gain
Definition g723_1.h:96
int index
postfilter backward/forward lag
Definition g723_1.h:94
#define width
Definition dsp.h:89