wma.h
Go to the documentation of this file.
1 /*
2  * WMA compatible codec
3  * Copyright (c) 2002-2007 The Libav Project
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_WMA_H
23 #define AVCODEC_WMA_H
24 
25 #include "get_bits.h"
26 #include "put_bits.h"
27 #include "dsputil.h"
28 #include "fft.h"
29 #include "fmtconvert.h"
30 
31 /* size of blocks */
32 #define BLOCK_MIN_BITS 7
33 #define BLOCK_MAX_BITS 11
34 #define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS)
35 
36 #define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1)
37 
38 /* XXX: find exact max size */
39 #define HIGH_BAND_MAX_SIZE 16
40 
41 #define NB_LSP_COEFS 10
42 
43 /* XXX: is it a suitable value ? */
44 #define MAX_CODED_SUPERFRAME_SIZE 16384
45 
46 #define MAX_CHANNELS 2
47 
48 #define NOISE_TAB_SIZE 8192
49 
50 #define LSP_POW_BITS 7
51 
52 //FIXME should be in wmadec
53 #define VLCBITS 9
54 #define VLCMAX ((22+VLCBITS-1)/VLCBITS)
55 
56 typedef float WMACoef;
57 
58 typedef struct CoefVLCTable {
59  int n;
60  int max_level;
61  const uint32_t *huffcodes;
62  const uint8_t *huffbits;
63  const uint16_t *levels;
64 } CoefVLCTable;
65 
66 typedef struct WMACodecContext {
73  int bit_rate;
74  int version;
90 
91  /* coded values in high bands */
94 
95  /* there are two possible tables for spectral coefficients */
96 //FIXME the following 3 tables should be shared between decoders
98  uint16_t *run_table[2];
99  float *level_table[2];
100  uint16_t *int_table[2];
102  /* frame info */
103  int frame_len;
106  /* block info */
111  int block_len;
112  int block_num;
113  int block_pos;
114  uint8_t ms_stereo;
124  /* output buffer for one frame and the last for IMDCT windowing */
126  /* last frame info */
132  float noise_mult; /* XXX: suppress that and integrate it in the noise array */
133  /* lsp_to_curve tables */
135  float lsp_pow_e_table[256];
140 
141 #ifdef TRACE
142  int frame_count;
143 #endif
145 
146 extern const uint16_t ff_wma_critical_freqs[25];
147 extern const uint16_t ff_wma_hgain_huffcodes[37];
148 extern const uint8_t ff_wma_hgain_huffbits[37];
149 extern const float ff_wma_lsp_codebook[NB_LSP_COEFS][16];
150 extern const uint32_t ff_aac_scalefactor_code[121];
151 extern const uint8_t ff_aac_scalefactor_bits[121];
152 
153 int av_cold ff_wma_get_frame_len_bits(int sample_rate, int version,
154  unsigned int decode_flags);
155 int ff_wma_init(AVCodecContext * avctx, int flags2);
156 int ff_wma_total_gain_to_bits(int total_gain);
157 int ff_wma_end(AVCodecContext *avctx);
158 unsigned int ff_wma_get_large_val(GetBitContext* gb);
160  VLC *vlc,
161  const float *level_table, const uint16_t *run_table,
162  int version, WMACoef *ptr, int offset,
163  int num_coefs, int block_len, int frame_len_bits,
164  int coef_nb_bits);
165 
166 #endif /* AVCODEC_WMA_H */
int nb_channels
Definition: wma.h:72
uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE+FF_INPUT_BUFFER_PADDING_SIZE]
Definition: wma.h:127
Audio Video Frame.
Definition: avcodec.h:985
int sample_rate
Definition: wma.h:71
int block_align
Definition: wma.h:75
AVFrame frame
Definition: wma.h:68
int next_block_len_bits
log2 of next block length
Definition: wma.h:109
#define BLOCK_MAX_SIZE
Definition: wma.h:34
unsigned int ff_wma_get_large_val(GetBitContext *gb)
Decode an uncompressed coefficient.
Definition: wma.c:440
GetBitContext gb
Definition: wma.h:69
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:55
int block_len
block length in samples
Definition: wma.h:111
int ff_wma_run_level_decode(AVCodecContext *avctx, GetBitContext *gb, VLC *vlc, const float *level_table, const uint16_t *run_table, int version, WMACoef *ptr, int offset, int num_coefs, int block_len, int frame_len_bits, int coef_nb_bits)
Decode run level compressed coefficients.
Definition: wma.c:473
const uint8_t * huffbits
VLC bit size.
Definition: wma.h:62
const uint16_t ff_wma_critical_freqs[25]
Definition: wmadata.h:33
float exponents[MAX_CHANNELS][BLOCK_MAX_SIZE]
Definition: wma.h:117
int n
total number of codes
Definition: wma.h:59
#define NOISE_TAB_SIZE
Definition: wma.h:48
#define BLOCK_NB_SIZES
Definition: wma.h:36
float lsp_pow_m_table2[(1<< LSP_POW_BITS)]
Definition: wma.h:137
float lsp_cos_table[BLOCK_MAX_SIZE]
Definition: wma.h:134
int high_band_start[BLOCK_NB_SIZES]
index of first coef in high band
Definition: wma.h:84
int exponent_sizes[BLOCK_NB_SIZES]
Definition: wma.h:82
#define av_cold
Definition: attributes.h:71
float WMACoef
type for decoded coefficients, int16_t would be enough for wma 1/2
Definition: wma.h:56
int block_pos
current position in frame
Definition: wma.h:113
const uint32_t * huffcodes
VLC bit values.
Definition: wma.h:61
bitstream reader API header.
int max_level
Definition: wma.h:60
float lsp_pow_m_table1[(1<< LSP_POW_BITS)]
Definition: wma.h:136
int reset_block_lengths
Definition: wma.h:107
int nb_block_sizes
number of block sizes
Definition: wma.h:105
uint16_t * int_table[2]
Definition: wma.h:100
uint16_t exponent_bands[BLOCK_NB_SIZES][25]
Definition: wma.h:83
uint8_t channel_coded[MAX_CHANNELS]
true if channel is coded
Definition: wma.h:115
int last_superframe_len
Definition: wma.h:129
int ff_wma_total_gain_to_bits(int total_gain)
Definition: wma.c:402
FFTSample output[BLOCK_MAX_SIZE *2]
Definition: wma.h:121
const uint8_t ff_wma_hgain_huffbits[37]
Definition: wmadata.h:67
int noise_index
Definition: wma.h:131
Definition: get_bits.h:63
int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE]
Definition: wma.h:88
int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE]
Definition: wma.h:93
Definition: fft.h:62
int use_bit_reservoir
Definition: wma.h:76
float * windows[BLOCK_NB_SIZES]
Definition: wma.h:123
#define MAX_CODED_SUPERFRAME_SIZE
Definition: wma.h:44
uint16_t * run_table[2]
Definition: wma.h:98
const uint16_t ff_wma_hgain_huffcodes[37]
Definition: wmadata.h:59
int version
1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2)
Definition: wma.h:74
struct CoefVLCTable CoefVLCTable
static int frame_count
int frame_len
frame length in samples
Definition: wma.h:103
version
Definition: libspeexenc.c:304
#define MAX_CHANNELS
Definition: wma.h:46
int last_bitoffset
Definition: wma.h:128
int bit_rate
Definition: wma.h:73
int frame_len_bits
frame_len = 1 << frame_len_bits
Definition: wma.h:104
#define HIGH_BAND_MAX_SIZE
Definition: wma.h:39
int use_exp_vlc
exponent coding: 0 = lsp, 1 = vlc + delta
Definition: wma.h:78
VLC coef_vlc[2]
Definition: wma.h:97
#define NB_LSP_COEFS
Definition: wma.h:41
main external API structure.
Definition: avcodec.h:1329
AVCodecContext * avctx
Definition: wma.h:67
float frame_out[MAX_CHANNELS][BLOCK_MAX_SIZE *2]
Definition: wma.h:125
int exponent_high_sizes[BLOCK_NB_SIZES]
Definition: wma.h:87
int block_num
block number in current frame
Definition: wma.h:112
int use_noise_coding
true if perceptual noise is added
Definition: wma.h:79
int av_cold ff_wma_get_frame_len_bits(int sample_rate, int version, unsigned int decode_flags)
Get the samples per frame for this stream.
Definition: wma.c:77
float * level_table[2]
Definition: wma.h:99
#define LSP_POW_BITS
Definition: wma.h:50
int use_variable_block_len
Definition: wma.h:77
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:497
uint8_t ms_stereo
true if mid/side stereo mode
Definition: wma.h:114
FFTContext mdct_ctx[BLOCK_NB_SIZES]
Definition: wma.h:122
VLC exp_vlc
Definition: wma.h:81
int exponents_bsize[MAX_CHANNELS]
log2 ratio frame/exp. length
Definition: wma.h:116
float coefs[MAX_CHANNELS][BLOCK_MAX_SIZE]
Definition: wma.h:120
int prev_block_len_bits
log2 of prev block length
Definition: wma.h:110
int coefs_end[BLOCK_NB_SIZES]
max number of coded coefficients
Definition: wma.h:86
struct WMACodecContext WMACodecContext
float lsp_pow_e_table[256]
Definition: wma.h:135
const float ff_wma_lsp_codebook[NB_LSP_COEFS][16]
Definition: wmadata.h:75
FmtConvertContext fmt_conv
Definition: wma.h:139
DSP utils.
DSPContext dsp
Definition: wma.h:138
WMACoef coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE]
Definition: wma.h:119
int ff_wma_init(AVCodecContext *avctx, int flags2)
Definition: wma.c:110
const uint8_t ff_aac_scalefactor_bits[121]
Definition: aactab.c:70
float max_exponent[MAX_CHANNELS]
Definition: wma.h:118
const uint32_t ff_aac_scalefactor_code[121]
Definition: aactab.c:51
int ff_wma_end(AVCodecContext *avctx)
Definition: wma.c:411
VLC hgain_vlc
Definition: wma.h:89
int coefs_start
first coded coef
Definition: wma.h:85
int block_len_bits
log2 of current block length
Definition: wma.h:108
int byte_offset_bits
Definition: wma.h:80
int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE]
Definition: wma.h:92
const CoefVLCTable * coef_vlcs[2]
Definition: wma.h:101
PutBitContext pb
Definition: wma.h:70
DSPContext.
Definition: dsputil.h:226
float FFTSample
Definition: avfft.h:22
float noise_table[NOISE_TAB_SIZE]
Definition: wma.h:130
const uint16_t * levels
table to build run/level tables
Definition: wma.h:63
float noise_mult
Definition: wma.h:132
bitstream writer API