comparison wma.h @ 4490:0efc832d9102 libavcodec

wma encoder
author michael
date Tue, 06 Feb 2007 20:19:04 +0000
parents
children 3975e734e07e
comparison
equal deleted inserted replaced
4489:27e74573b074 4490:0efc832d9102
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 WMA_H
23 #define WMA_H
24
25 #include "bitstream.h"
26 #include "dsputil.h"
27
28 /* size of blocks */
29 #define BLOCK_MIN_BITS 7
30 #define BLOCK_MAX_BITS 11
31 #define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS)
32
33 #define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1)
34
35 /* XXX: find exact max size */
36 #define HIGH_BAND_MAX_SIZE 16
37
38 #define NB_LSP_COEFS 10
39
40 /* XXX: is it a suitable value ? */
41 #define MAX_CODED_SUPERFRAME_SIZE 16384
42
43 #define MAX_CHANNELS 2
44
45 #define NOISE_TAB_SIZE 8192
46
47 #define LSP_POW_BITS 7
48
49 //FIXME should be in wmadec
50 #define VLCBITS 9
51 #define VLCMAX ((22+VLCBITS-1)/VLCBITS)
52
53 typedef struct CoefVLCTable {
54 int n; /* total number of codes */
55 int max_level;
56 const uint32_t *huffcodes; /* VLC bit values */
57 const uint8_t *huffbits; /* VLC bit size */
58 const uint16_t *levels; /* table to build run/level tables */
59 } CoefVLCTable;
60
61 typedef struct WMADecodeContext {
62 GetBitContext gb;
63 PutBitContext pb;
64 int sample_rate;
65 int nb_channels;
66 int bit_rate;
67 int version; /* 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2) */
68 int block_align;
69 int use_bit_reservoir;
70 int use_variable_block_len;
71 int use_exp_vlc; /* exponent coding: 0 = lsp, 1 = vlc + delta */
72 int use_noise_coding; /* true if perceptual noise is added */
73 int byte_offset_bits;
74 VLC exp_vlc;
75 int exponent_sizes[BLOCK_NB_SIZES];
76 uint16_t exponent_bands[BLOCK_NB_SIZES][25];
77 int high_band_start[BLOCK_NB_SIZES]; /* index of first coef in high band */
78 int coefs_start; /* first coded coef */
79 int coefs_end[BLOCK_NB_SIZES]; /* max number of coded coefficients */
80 int exponent_high_sizes[BLOCK_NB_SIZES];
81 int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE];
82 VLC hgain_vlc;
83
84 /* coded values in high bands */
85 int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
86 int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
87
88 /* there are two possible tables for spectral coefficients */
89 //FIXME the following 3 tables should be shared between decoders
90 VLC coef_vlc[2];
91 uint16_t *run_table[2];
92 uint16_t *level_table[2];
93 uint16_t *int_table[2];
94 CoefVLCTable *coef_vlcs[2];
95 /* frame info */
96 int frame_len; /* frame length in samples */
97 int frame_len_bits; /* frame_len = 1 << frame_len_bits */
98 int nb_block_sizes; /* number of block sizes */
99 /* block info */
100 int reset_block_lengths;
101 int block_len_bits; /* log2 of current block length */
102 int next_block_len_bits; /* log2 of next block length */
103 int prev_block_len_bits; /* log2 of prev block length */
104 int block_len; /* block length in samples */
105 int block_num; /* block number in current frame */
106 int block_pos; /* current position in frame */
107 uint8_t ms_stereo; /* true if mid/side stereo mode */
108 uint8_t channel_coded[MAX_CHANNELS]; /* true if channel is coded */
109 DECLARE_ALIGNED_16(float, exponents[MAX_CHANNELS][BLOCK_MAX_SIZE]);
110 float max_exponent[MAX_CHANNELS];
111 int16_t coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE];
112 DECLARE_ALIGNED_16(float, coefs[MAX_CHANNELS][BLOCK_MAX_SIZE]);
113 DECLARE_ALIGNED_16(FFTSample, output[BLOCK_MAX_SIZE * 2]);
114 DECLARE_ALIGNED_16(float, window[BLOCK_MAX_SIZE * 2]);
115 MDCTContext mdct_ctx[BLOCK_NB_SIZES];
116 float *windows[BLOCK_NB_SIZES];
117 DECLARE_ALIGNED_16(FFTSample, mdct_tmp[BLOCK_MAX_SIZE]); /* temporary storage for imdct */
118 /* output buffer for one frame and the last for IMDCT windowing */
119 DECLARE_ALIGNED_16(float, frame_out[MAX_CHANNELS][BLOCK_MAX_SIZE * 2]);
120 /* last frame info */
121 uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */
122 int last_bitoffset;
123 int last_superframe_len;
124 float noise_table[NOISE_TAB_SIZE];
125 int noise_index;
126 float noise_mult; /* XXX: suppress that and integrate it in the noise array */
127 /* lsp_to_curve tables */
128 float lsp_cos_table[BLOCK_MAX_SIZE];
129 float lsp_pow_e_table[256];
130 float lsp_pow_m_table1[(1 << LSP_POW_BITS)];
131 float lsp_pow_m_table2[(1 << LSP_POW_BITS)];
132 DSPContext dsp;
133
134 #ifdef TRACE
135 int frame_count;
136 #endif
137 } WMADecodeContext;
138
139 extern const uint16_t ff_wma_hgain_huffcodes[37];
140 extern const uint8_t ff_wma_hgain_huffbits[37];
141 extern const float ff_wma_lsp_codebook[NB_LSP_COEFS][16];
142 extern const uint32_t ff_wma_scale_huffcodes[121];
143 extern const uint8_t ff_wma_scale_huffbits[121];
144
145 int ff_wma_init(AVCodecContext * avctx, int flags2);
146 int ff_wma_total_gain_to_bits(int total_gain);
147 int ff_wma_end(AVCodecContext *avctx);
148
149 #endif