FFmpeg
wma.h
Go to the documentation of this file.
1 /*
2  * WMA compatible codec
3  * Copyright (c) 2002-2007 The FFmpeg Project
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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 "libavutil/float_dsp.h"
26 #include "libavutil/mem_internal.h"
27 #include "libavutil/tx.h"
28 
29 #include "avcodec.h"
30 #include "get_bits.h"
31 #include "put_bits.h"
32 
33 /* size of blocks */
34 #define BLOCK_MIN_BITS 7
35 #define BLOCK_MAX_BITS 11
36 #define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS)
37 
38 #define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1)
39 
40 /* XXX: find exact max size */
41 #define HIGH_BAND_MAX_SIZE 16
42 
43 #define NB_LSP_COEFS 10
44 
45 /* XXX: is it a suitable value ? */
46 #define MAX_CODED_SUPERFRAME_SIZE 32768
47 
48 #define MAX_CHANNELS 2
49 
50 #define NOISE_TAB_SIZE 8192
51 
52 #define LSP_POW_BITS 7
53 
54 // FIXME should be in wmadec
55 #define VLCBITS 9
56 #define VLCMAX ((22 + VLCBITS - 1) / VLCBITS)
57 
58 typedef float WMACoef; ///< type for decoded coefficients, int16_t would be enough for wma 1/2
59 
60 typedef struct CoefVLCTable {
61  int n; ///< total number of codes
62  int max_level;
63  const uint32_t *huffcodes; ///< VLC bit values
64  const uint8_t *huffbits; ///< VLC bit size
65  const uint16_t *levels; ///< table to build run/level tables
66 } CoefVLCTable;
67 
68 typedef struct WMACodecContext {
72  int version; ///< 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2)
75  int use_exp_vlc; ///< exponent coding: 0 = lsp, 1 = vlc + delta
76  int use_noise_coding; ///< true if perceptual noise is added
81  int high_band_start[BLOCK_NB_SIZES]; ///< index of first coef in high band
82  int coefs_start; ///< first coded coef
83  int coefs_end[BLOCK_NB_SIZES]; ///< max number of coded coefficients
87 
88  /* coded values in high bands */
91 
92  /* there are two possible tables for spectral coefficients */
93 // FIXME the following 3 tables should be shared between decoders
95  uint16_t *run_table[2];
96  float *level_table[2];
97  uint16_t *int_table[2];
99  /* frame info */
100  int frame_len; ///< frame length in samples
101  int frame_len_bits; ///< frame_len = 1 << frame_len_bits
102  int nb_block_sizes; ///< number of block sizes
103  /* block info */
105  int block_len_bits; ///< log2 of current block length
106  int next_block_len_bits; ///< log2 of next block length
107  int prev_block_len_bits; ///< log2 of prev block length
108  int block_len; ///< block length in samples
109  int block_num; ///< block number in current frame
110  int block_pos; ///< current position in frame
111  uint8_t ms_stereo; ///< true if mid/side stereo mode
112  uint8_t channel_coded[MAX_CHANNELS]; ///< true if channel is coded
113  int exponents_bsize[MAX_CHANNELS]; ///< log2 ratio frame/exp. length
121  const float *windows[BLOCK_NB_SIZES];
122  /* output buffer for one frame and the last for IMDCT windowing */
124  /* last frame info */
131  float noise_mult; /* XXX: suppress that and integrate it in the noise array */
132  /* lsp_to_curve tables */
134  float lsp_pow_e_table[256];
138 
139  int eof_done; /* decode flag to output remaining samples after EOF */
140 
141 #ifdef TRACE
142  int frame_count;
143 #endif /* TRACE */
145 
146 extern const uint8_t ff_wma_hgain_hufftab[37][2];
147 extern const float ff_wma_lsp_codebook[NB_LSP_COEFS][16];
148 extern const uint32_t ff_aac_scalefactor_code[121];
149 extern const uint8_t ff_aac_scalefactor_bits[121];
150 
152 int ff_wma_init(AVCodecContext *avctx, int flags2);
153 
154 int ff_wma_total_gain_to_bits(int total_gain);
155 int ff_wma_end(AVCodecContext *avctx);
156 unsigned int ff_wma_get_large_val(GetBitContext *gb);
158  const VLCElem *vlc, const float *level_table,
159  const uint16_t *run_table, int version,
160  WMACoef *ptr, int offset, int num_coefs,
161  int block_len, int frame_len_bits,
162  int coef_nb_bits);
163 
164 #endif /* AVCODEC_WMA_H */
WMACodecContext::block_len_bits
int block_len_bits
log2 of current block length
Definition: wma.h:105
WMACodecContext::lsp_pow_m_table2
float lsp_pow_m_table2[(1<< LSP_POW_BITS)]
Definition: wma.h:136
ff_wma_run_level_decode
int ff_wma_run_level_decode(AVCodecContext *avctx, GetBitContext *gb, const VLCElem *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:427
ff_aac_scalefactor_code
const uint32_t ff_aac_scalefactor_code[121]
Definition: aactab.c:185
WMACodecContext::pb
PutBitContext pb
Definition: wma.h:71
mem_internal.h
WMACodecContext::gb
GetBitContext gb
Definition: wma.h:70
WMACodecContext::exponent_sizes
int exponent_sizes[BLOCK_NB_SIZES]
Definition: wma.h:79
AVTXContext
Definition: tx_priv.h:235
ff_wma_get_large_val
unsigned int ff_wma_get_large_val(GetBitContext *gb)
Decode an uncompressed coefficient.
Definition: wma.c:395
WMACodecContext::exponents
float exponents[MAX_CHANNELS][BLOCK_MAX_SIZE]
Definition: wma.h:114
ff_aac_scalefactor_bits
const uint8_t ff_aac_scalefactor_bits[121]
Definition: aactab.c:204
WMACodecContext::lsp_cos_table
float lsp_cos_table[BLOCK_MAX_SIZE]
Definition: wma.h:133
CoefVLCTable::n
int n
total number of codes
Definition: wma.h:61
MAX_CHANNELS
#define MAX_CHANNELS
Definition: wma.h:48
WMACodecContext::noise_mult
float noise_mult
Definition: wma.h:131
WMACodecContext::noise_table
float noise_table[NOISE_TAB_SIZE]
Definition: wma.h:129
WMACodecContext::high_band_start
int high_band_start[BLOCK_NB_SIZES]
index of first coef in high band
Definition: wma.h:81
CoefVLCTable::max_level
int max_level
Definition: wma.h:62
CoefVLCTable::huffbits
const uint8_t * huffbits
VLC bit size.
Definition: wma.h:64
ff_wma_hgain_hufftab
const uint8_t ff_wma_hgain_hufftab[37][2]
Definition: wmadata.h:54
WMACodecContext::block_pos
int block_pos
current position in frame
Definition: wma.h:110
WMACodecContext::exponents_initialized
int exponents_initialized[MAX_CHANNELS]
Definition: wma.h:128
HIGH_BAND_MAX_SIZE
#define HIGH_BAND_MAX_SIZE
Definition: wma.h:41
CoefVLCTable
Definition: wma.h:60
WMACoef
float WMACoef
type for decoded coefficients, int16_t would be enough for wma 1/2
Definition: wma.h:58
GetBitContext
Definition: get_bits.h:108
WMACodecContext::int_table
uint16_t * int_table[2]
Definition: wma.h:97
WMACodecContext
Definition: wma.h:68
ff_wma_end
int ff_wma_end(AVCodecContext *avctx)
Definition: wma.c:367
WMACodecContext::high_band_values
int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE]
Definition: wma.h:90
av_tx_fn
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
Definition: tx.h:151
WMACodecContext::mdct_ctx
AVTXContext * mdct_ctx[BLOCK_NB_SIZES]
Definition: wma.h:119
WMACodecContext::channel_coded
uint8_t channel_coded[MAX_CHANNELS]
true if channel is coded
Definition: wma.h:112
BLOCK_MAX_SIZE
#define BLOCK_MAX_SIZE
Definition: wma.h:36
WMACodecContext::run_table
uint16_t * run_table[2]
Definition: wma.h:95
get_bits.h
WMACodecContext::frame_len
int frame_len
frame length in samples
Definition: wma.h:100
PutBitContext
Definition: put_bits.h:50
CoefVLCTable::huffcodes
const uint32_t * huffcodes
VLC bit values.
Definition: wma.h:63
WMACodecContext::fdsp
AVFloatDSPContext * fdsp
Definition: wma.h:137
ff_wma_total_gain_to_bits
int ff_wma_total_gain_to_bits(int total_gain)
Definition: wma.c:353
WMACodecContext::last_bitoffset
int last_bitoffset
Definition: wma.h:126
WMACodecContext::mdct_fn
av_tx_fn mdct_fn[BLOCK_NB_SIZES]
Definition: wma.h:120
WMACodecContext::exponent_bands
uint16_t exponent_bands[BLOCK_NB_SIZES][25]
Definition: wma.h:80
WMACodecContext::lsp_pow_m_table1
float lsp_pow_m_table1[(1<< LSP_POW_BITS)]
Definition: wma.h:135
WMACodecContext::coef_vlc
VLC coef_vlc[2]
Definition: wma.h:94
WMACodecContext::avctx
AVCodecContext * avctx
Definition: wma.h:69
WMACodecContext::nb_block_sizes
int nb_block_sizes
number of block sizes
Definition: wma.h:102
WMACodecContext::reset_block_lengths
int reset_block_lengths
Definition: wma.h:104
WMACodecContext::output
float output[BLOCK_MAX_SIZE *2]
Definition: wma.h:118
MAX_CODED_SUPERFRAME_SIZE
#define MAX_CODED_SUPERFRAME_SIZE
Definition: wma.h:46
float_dsp.h
WMACodecContext::exponent_high_bands
int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE]
Definition: wma.h:85
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:109
WMACodecContext::ms_stereo
uint8_t ms_stereo
true if mid/side stereo mode
Definition: wma.h:111
WMACodecContext::last_superframe
uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE+AV_INPUT_BUFFER_PADDING_SIZE]
Definition: wma.h:125
BLOCK_NB_SIZES
#define BLOCK_NB_SIZES
Definition: wma.h:38
VLCElem
Definition: vlc.h:32
WMACodecContext::last_superframe_len
int last_superframe_len
Definition: wma.h:127
NOISE_TAB_SIZE
#define NOISE_TAB_SIZE
Definition: wma.h:50
WMACodecContext::exponent_high_sizes
int exponent_high_sizes[BLOCK_NB_SIZES]
Definition: wma.h:84
AVFloatDSPContext
Definition: float_dsp.h:24
WMACodecContext::noise_index
int noise_index
Definition: wma.h:130
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
WMACodecContext::block_num
int block_num
block number in current frame
Definition: wma.h:109
version
version
Definition: libkvazaar.c:321
WMACodecContext::lsp_pow_e_table
float lsp_pow_e_table[256]
Definition: wma.h:134
av_warn_unused_result
#define av_warn_unused_result
Definition: attributes.h:64
WMACodecContext::level_table
float * level_table[2]
Definition: wma.h:96
LSP_POW_BITS
#define LSP_POW_BITS
Definition: wma.h:52
WMACodecContext::use_bit_reservoir
int use_bit_reservoir
Definition: wma.h:73
WMACodecContext::frame_len_bits
int frame_len_bits
frame_len = 1 << frame_len_bits
Definition: wma.h:101
WMACodecContext::coefs
float coefs[MAX_CHANNELS][BLOCK_MAX_SIZE]
Definition: wma.h:117
WMACodecContext::version
int version
1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2)
Definition: wma.h:72
WMACodecContext::use_exp_vlc
int use_exp_vlc
exponent coding: 0 = lsp, 1 = vlc + delta
Definition: wma.h:75
WMACodecContext::prev_block_len_bits
int prev_block_len_bits
log2 of prev block length
Definition: wma.h:107
WMACodecContext::coefs1
WMACoef coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE]
Definition: wma.h:116
WMACodecContext::eof_done
int eof_done
Definition: wma.h:139
avcodec.h
WMACodecContext::hgain_vlc
VLC hgain_vlc
Definition: wma.h:86
WMACodecContext::coefs_start
int coefs_start
first coded coef
Definition: wma.h:82
WMACodecContext::use_variable_block_len
int use_variable_block_len
Definition: wma.h:74
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
AVCodecContext
main external API structure.
Definition: avcodec.h:451
WMACodecContext::high_band_coded
int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE]
Definition: wma.h:89
WMACodecContext::exp_vlc
VLC exp_vlc
Definition: wma.h:78
VLC
Definition: vlc.h:36
WMACodecContext::windows
const float * windows[BLOCK_NB_SIZES]
Definition: wma.h:121
WMACodecContext::frame_out
float frame_out[MAX_CHANNELS][BLOCK_MAX_SIZE *2]
Definition: wma.h:123
WMACodecContext::coefs_end
int coefs_end[BLOCK_NB_SIZES]
max number of coded coefficients
Definition: wma.h:83
ff_wma_init
av_warn_unused_result int ff_wma_init(AVCodecContext *avctx, int flags2)
Definition: wma.c:79
WMACodecContext::use_noise_coding
int use_noise_coding
true if perceptual noise is added
Definition: wma.h:76
ff_wma_lsp_codebook
const float ff_wma_lsp_codebook[NB_LSP_COEFS][16]
Definition: wmadata.h:64
WMACodecContext::byte_offset_bits
int byte_offset_bits
Definition: wma.h:77
WMACodecContext::exponents_bsize
int exponents_bsize[MAX_CHANNELS]
log2 ratio frame/exp. length
Definition: wma.h:113
WMACodecContext::coef_vlcs
const CoefVLCTable * coef_vlcs[2]
Definition: wma.h:98
NB_LSP_COEFS
#define NB_LSP_COEFS
Definition: wma.h:43
WMACodecContext::next_block_len_bits
int next_block_len_bits
log2 of next block length
Definition: wma.h:106
CoefVLCTable::levels
const uint16_t * levels
table to build run/level tables
Definition: wma.h:65
put_bits.h
WMACodecContext::block_len
int block_len
block length in samples
Definition: wma.h:108
WMACodecContext::max_exponent
float max_exponent[MAX_CHANNELS]
Definition: wma.h:115
tx.h