Libav
Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
libavcodec
twinvq.h
Go to the documentation of this file.
1
/*
2
* TwinVQ decoder
3
* Copyright (c) 2009 Vitor Sessak
4
*
5
* This file is part of Libav.
6
*
7
* Libav is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
11
*
12
* Libav 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. See the GNU
15
* Lesser General Public License for more details.
16
*
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with Libav; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
*/
21
22
#ifndef AVCODEC_TWINVQ_H
23
#define AVCODEC_TWINVQ_H
24
25
#include <math.h>
26
#include <stdint.h>
27
28
#include "
libavutil/common.h
"
29
#include "
libavutil/float_dsp.h
"
30
#include "
avcodec.h
"
31
#include "
fft.h
"
32
#include "
internal.h
"
33
34
enum
TwinVQCodec
{
35
TWINVQ_CODEC_VQF
,
36
TWINVQ_CODEC_METASOUND
,
37
};
38
39
enum
TwinVQFrameType
{
40
TWINVQ_FT_SHORT
= 0,
41
TWINVQ_FT_MEDIUM
,
42
TWINVQ_FT_LONG
,
43
TWINVQ_FT_PPC
,
44
};
45
46
#define TWINVQ_PPC_SHAPE_CB_SIZE 64
47
#define TWINVQ_PPC_SHAPE_LEN_MAX 60
48
#define TWINVQ_SUB_AMP_MAX 4500.0
49
#define TWINVQ_MULAW_MU 100.0
50
#define TWINVQ_GAIN_BITS 8
51
#define TWINVQ_AMP_MAX 13000.0
52
#define TWINVQ_SUB_GAIN_BITS 5
53
#define TWINVQ_WINDOW_TYPE_BITS 4
54
#define TWINVQ_PGAIN_MU 200
55
#define TWINVQ_LSP_COEFS_MAX 20
56
#define TWINVQ_LSP_SPLIT_MAX 4
57
#define TWINVQ_CHANNELS_MAX 2
58
#define TWINVQ_SUBBLOCKS_MAX 16
59
#define TWINVQ_BARK_N_COEF_MAX 4
60
61
#define TWINVQ_MAX_FRAMES_PER_PACKET 2
62
66
struct
TwinVQFrameMode
{
67
uint8_t
sub
;
68
const
uint16_t *
bark_tab
;
69
71
uint8_t
bark_env_size
;
72
73
const
int16_t *
bark_cb
;
74
uint8_t
bark_n_coef
;
75
uint8_t
bark_n_bit
;
76
78
79
const
int16_t *
cb0
;
80
const
int16_t *
cb1
;
82
83
uint8_t
cb_len_read
;
84
};
85
86
typedef
struct
TwinVQFrameData
{
87
int
window_type
;
88
enum
TwinVQFrameType
ftype
;
89
90
uint8_t
main_coeffs
[1024];
91
uint8_t
ppc_coeffs
[
TWINVQ_PPC_SHAPE_LEN_MAX
];
92
93
uint8_t
gain_bits
[
TWINVQ_CHANNELS_MAX
];
94
uint8_t
sub_gain_bits
[
TWINVQ_CHANNELS_MAX
*
TWINVQ_SUBBLOCKS_MAX
];
95
96
uint8_t
bark1
[
TWINVQ_CHANNELS_MAX
][
TWINVQ_SUBBLOCKS_MAX
][
TWINVQ_BARK_N_COEF_MAX
];
97
uint8_t
bark_use_hist
[
TWINVQ_CHANNELS_MAX
][
TWINVQ_SUBBLOCKS_MAX
];
98
99
uint8_t
lpc_idx1
[
TWINVQ_CHANNELS_MAX
];
100
uint8_t
lpc_idx2
[
TWINVQ_CHANNELS_MAX
][
TWINVQ_LSP_SPLIT_MAX
];
101
uint8_t
lpc_hist_idx
[
TWINVQ_CHANNELS_MAX
];
102
103
int
p_coef
[
TWINVQ_CHANNELS_MAX
];
104
int
g_coef
[
TWINVQ_CHANNELS_MAX
];
105
}
TwinVQFrameData
;
106
111
typedef
struct
TwinVQModeTab
{
112
struct
TwinVQFrameMode
fmode
[3];
113
114
uint16_t
size
;
115
uint8_t
n_lsp
;
116
const
float
*
lspcodebook
;
117
118
/* number of bits of the different LSP CB coefficients */
119
uint8_t
lsp_bit0
;
120
uint8_t
lsp_bit1
;
121
uint8_t
lsp_bit2
;
122
123
uint8_t
lsp_split
;
124
const
int16_t *
ppc_shape_cb
;
125
127
uint8_t
ppc_period_bit
;
128
129
uint8_t
ppc_shape_bit
;
130
uint8_t
ppc_shape_len
;
131
uint8_t
pgain_bit
;
132
134
uint16_t
peak_per2wid
;
135
}
TwinVQModeTab
;
136
137
typedef
struct
TwinVQContext
{
138
AVCodecContext
*
avctx
;
139
AVFloatDSPContext
fdsp
;
140
FFTContext
mdct_ctx
[3];
141
142
const
TwinVQModeTab
*
mtab
;
143
144
int
is_6kbps
;
145
146
// history
147
float
lsp_hist
[2][20];
148
float
bark_hist
[3][2][40];
149
150
// bitstream parameters
151
int16_t
permut
[4][4096];
152
uint8_t
length
[4][2];
153
uint8_t
length_change
[4];
154
uint8_t
bits_main_spec
[2][4][2];
155
int
bits_main_spec_change
[4];
156
int
n_div
[4];
157
158
float
*
spectrum
;
159
float
*
curr_frame
;
160
float
*
prev_frame
;
161
int
last_block_pos
[2];
162
int
discarded_packets
;
163
164
float
*
cos_tabs
[3];
165
166
// scratch buffers
167
float
*
tmp_buf
;
168
169
int
frame_size
,
frames_per_packet
,
cur_frame
;
170
TwinVQFrameData
bits
[
TWINVQ_MAX_FRAMES_PER_PACKET
];
171
172
enum
TwinVQCodec
codec
;
173
174
int (*
read_bitstream
)(
AVCodecContext
*
avctx
,
struct
TwinVQContext
*tctx,
175
const
uint8_t
*buf,
int
buf_size);
176
void
(*
dec_bark_env
)(
struct
TwinVQContext
*tctx,
const
uint8_t
*
in
,
177
int
use_hist,
int
ch,
float
*
out
,
float
gain,
178
enum
TwinVQFrameType
ftype);
179
void
(*
decode_ppc
)(
struct
TwinVQContext
*tctx,
int
period_coef,
int
g_coef,
180
const
float
*shape,
float
*speech);
181
}
TwinVQContext
;
182
183
extern
const
enum
TwinVQFrameType
ff_twinvq_wtype_to_ftype_table
[];
184
186
static
inline
void
twinvq_memset_float
(
float
*buf,
float
val,
int
size
)
187
{
188
while
(size--)
189
*buf++ = val;
190
}
191
192
static
inline
float
twinvq_mulawinv
(
float
y,
float
clip
,
float
mu)
193
{
194
y = av_clipf(y / clip, -1, 1);
195
return
clip *
FFSIGN
(y) * (exp(log(1 + mu) * fabs(y)) - 1) / mu;
196
}
197
198
int
ff_twinvq_decode_frame
(
AVCodecContext
*
avctx
,
void
*
data
,
199
int
*got_frame_ptr,
AVPacket
*avpkt);
200
av_cold
int
ff_twinvq_decode_close
(
AVCodecContext
*
avctx
);
201
av_cold
int
ff_twinvq_decode_init
(
AVCodecContext
*
avctx
);
202
203
#endif
/* AVCODEC_TWINVQ_DATA_H */
Generated on Tue Mar 1 2016 21:14:46 for Libav by
1.8.4