annotate sbr.h @ 11857:e1e986bb64d0 libavcodec

Improve the mp4toannexb BSF to convert the extradata.
author lucabe
date Wed, 09 Jun 2010 06:47:01 +0000
parents 67206bbbab10
children 2d81202be6e2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11401
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
1 /*
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
2 * Spectral Band Replication definitions and structures
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
3 * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl )
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
4 * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
5 *
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
6 * This file is part of FFmpeg.
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
7 *
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
12 *
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
16 * Lesser General Public License for more details.
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
17 *
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
21 */
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
22
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
23 /**
11644
7dd2a45249a9 Remove explicit filename from Doxygen @file commands.
diego
parents: 11446
diff changeset
24 * @file
11401
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
25 * Spectral Band Replication definitions and structures
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
26 * @author Robert Swain ( rob opendot cl )
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
27 */
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
28
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
29 #ifndef AVCODEC_SBR_H
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
30 #define AVCODEC_SBR_H
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
31
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
32 #include <stdint.h>
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
33 #include "fft.h"
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
34
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
35 /**
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
36 * Spectral Band Replication header - spectrum parameters that invoke a reset if they differ from the previous header.
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
37 */
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
38 typedef struct {
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
39 uint8_t bs_start_freq;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
40 uint8_t bs_stop_freq;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
41 uint8_t bs_xover_band;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
42
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
43 /**
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
44 * @defgroup bs_header_extra_1 Variables associated with bs_header_extra_1
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
45 * @{
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
46 */
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
47 uint8_t bs_freq_scale;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
48 uint8_t bs_alter_scale;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
49 uint8_t bs_noise_bands;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
50 /** @} */
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
51 } SpectrumParameters;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
52
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
53 #define SBR_SYNTHESIS_BUF_SIZE ((1280-128)*2)
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
54
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
55 /**
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
56 * Spectral Band Replication per channel data
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
57 */
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
58 typedef struct {
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
59 /**
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
60 * @defgroup bitstream Main bitstream data variables
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
61 * @{
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
62 */
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
63 unsigned bs_frame_class;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
64 unsigned bs_add_harmonic_flag;
11446
806dc446061d aacsbr: Make the previous value of bs_num_env local to read_sbr_data().
alexc
parents: 11437
diff changeset
65 unsigned bs_num_env;
11401
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
66 uint8_t bs_freq_res[7];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
67 unsigned bs_num_noise;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
68 uint8_t bs_df_env[5];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
69 uint8_t bs_df_noise[2];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
70 uint8_t bs_invf_mode[2][5];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
71 uint8_t bs_add_harmonic[48];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
72 unsigned bs_amp_res;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
73 /** @} */
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
74
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
75 /**
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
76 * @defgroup state State variables
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
77 * @{
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
78 */
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
79 DECLARE_ALIGNED(16, float, synthesis_filterbank_samples)[SBR_SYNTHESIS_BUF_SIZE];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
80 DECLARE_ALIGNED(16, float, analysis_filterbank_samples) [1312];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
81 int synthesis_filterbank_samples_offset;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
82 ///l_APrev and l_A
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
83 int e_a[2];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
84 ///Chirp factors
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
85 float bw_array[5];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
86 ///QMF values of the original signal
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
87 float W[2][32][32][2];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
88 ///QMF output of the HF adjustor
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
89 float Y[2][38][64][2];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
90 float g_temp[42][48];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
91 float q_temp[42][48];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
92 uint8_t s_indexmapped[8][48];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
93 ///Envelope scalefactors
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
94 float env_facs[6][48];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
95 ///Noise scalefactors
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
96 float noise_facs[3][5];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
97 ///Envelope time borders
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
98 uint8_t t_env[8];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
99 ///Envelope time border of the last envelope of the previous frame
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
100 uint8_t t_env_num_env_old;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
101 ///Noise time borders
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
102 uint8_t t_q[3];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
103 unsigned f_indexnoise;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
104 unsigned f_indexsine;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
105 /** @} */
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
106 } SBRData;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
107
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
108 /**
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
109 * Spectral Band Replication
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
110 */
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
111 typedef struct {
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
112 int sample_rate;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
113 int start;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
114 int reset;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
115 SpectrumParameters spectrum_params;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
116 int bs_amp_res_header;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
117 /**
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
118 * @defgroup bs_header_extra_2 variables associated with bs_header_extra_2
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
119 * @{
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
120 */
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
121 unsigned bs_limiter_bands;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
122 unsigned bs_limiter_gains;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
123 unsigned bs_interpol_freq;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
124 unsigned bs_smoothing_mode;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
125 /** @} */
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
126 unsigned bs_coupling;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
127 unsigned k[5]; ///< k0, k1, k2
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
128 ///kx', and kx respectively, kx is the first QMF subband where SBR is used.
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
129 ///kx' is its value from the previous frame
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
130 unsigned kx[2];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
131 ///M' and M respectively, M is the number of QMF subbands that use SBR.
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
132 unsigned m[2];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
133 ///The number of frequency bands in f_master
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
134 unsigned n_master;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
135 SBRData data[2];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
136 ///N_Low and N_High respectively, the number of frequency bands for low and high resolution
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
137 unsigned n[2];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
138 ///Number of noise floor bands
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
139 unsigned n_q;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
140 ///Number of limiter bands
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
141 unsigned n_lim;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
142 ///The master QMF frequency grouping
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
143 uint16_t f_master[49];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
144 ///Frequency borders for low resolution SBR
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
145 uint16_t f_tablelow[25];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
146 ///Frequency borders for high resolution SBR
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
147 uint16_t f_tablehigh[49];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
148 ///Frequency borders for noise floors
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
149 uint16_t f_tablenoise[6];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
150 ///Frequency borders for the limiter
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
151 uint16_t f_tablelim[29];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
152 unsigned num_patches;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
153 uint8_t patch_num_subbands[6];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
154 uint8_t patch_start_subband[6];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
155 ///QMF low frequency input to the HF generator
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
156 float X_low[32][40][2];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
157 ///QMF output of the HF generator
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
158 float X_high[64][40][2];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
159 ///QMF values of the reconstructed signal
11677
ed3d232c9d31 10l: The SBR refactor requires the use of 2 independent output X buffers.
alexc
parents: 11644
diff changeset
160 DECLARE_ALIGNED(16, float, X)[2][2][32][64];
11401
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
161 ///Zeroth coefficient used to filter the subband signals
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
162 float alpha0[64][2];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
163 ///First coefficient used to filter the subband signals
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
164 float alpha1[64][2];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
165 ///Dequantized envelope scalefactors, remapped
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
166 float e_origmapped[7][48];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
167 ///Dequantized noise scalefactors, remapped
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
168 float q_mapped[7][48];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
169 ///Sinusoidal presence, remapped
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
170 uint8_t s_mapped[7][48];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
171 ///Estimated envelope
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
172 float e_curr[7][48];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
173 ///Amplitude adjusted noise scalefactors
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
174 float q_m[7][48];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
175 ///Sinusoidal levels
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
176 float s_m[7][48];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
177 float gain[7][48];
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
178 DECLARE_ALIGNED(16, float, qmf_filter_scratch)[5][64];
11847
67206bbbab10 Rewrite the SBR decoder QMF analysis filter on top of the IMDCT instead of the RDFT.
alexc
parents: 11677
diff changeset
179 FFTContext mdct_ana;
11401
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
180 FFTContext mdct;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
181 } SpectralBandReplication;
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
182
e340262ba532 Add an HE-AAC v1 decoder.
alexc
parents:
diff changeset
183 #endif /* AVCODEC_SBR_H */