2 * Spectral Band Replication definitions and structures
3 * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl )
4 * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 * Spectral Band Replication definitions and structures
26 * @author Robert Swain ( rob opendot cl )
34 #include "libavutil/mem_internal.h"
40 typedef struct AACContext AACContext;
43 * Spectral Band Replication header - spectrum parameters that invoke a reset if they differ from the previous header.
45 typedef struct SpectrumParameters {
46 uint8_t bs_start_freq;
48 uint8_t bs_xover_band;
51 * @name Variables associated with bs_header_extra_1
54 uint8_t bs_freq_scale;
55 uint8_t bs_alter_scale;
56 uint8_t bs_noise_bands;
60 #define SBR_SYNTHESIS_BUF_SIZE ((1280-128)*2)
63 * Spectral Band Replication per channel data
65 typedef struct SBRData {
67 * @name Main bitstream data variables
70 unsigned bs_frame_class;
71 unsigned bs_add_harmonic_flag;
73 uint8_t bs_freq_res[7];
74 AAC_SIGNE bs_num_noise;
76 uint8_t bs_df_noise[2];
77 uint8_t bs_invf_mode[2][5];
78 uint8_t bs_add_harmonic[48];
83 * @name State variables
86 DECLARE_ALIGNED(32, INTFLOAT, synthesis_filterbank_samples)[SBR_SYNTHESIS_BUF_SIZE];
87 DECLARE_ALIGNED(32, INTFLOAT, analysis_filterbank_samples) [1312];
88 int synthesis_filterbank_samples_offset;
93 ///QMF values of the original signal
94 INTFLOAT W[2][32][32][2];
95 ///QMF output of the HF adjustor
97 DECLARE_ALIGNED(16, INTFLOAT, Y)[2][38][64][2];
98 DECLARE_ALIGNED(16, AAC_FLOAT, g_temp)[42][48];
99 AAC_FLOAT q_temp[42][48];
100 uint8_t s_indexmapped[8][48];
101 ///Envelope scalefactors
102 uint8_t env_facs_q[6][48];
103 AAC_FLOAT env_facs[6][48];
104 ///Noise scalefactors
105 uint8_t noise_facs_q[3][5];
106 AAC_FLOAT noise_facs[3][5];
107 ///Envelope time borders
109 ///Envelope time border of the last envelope of the previous frame
110 uint8_t t_env_num_env_old;
111 ///Noise time borders
113 unsigned f_indexnoise;
114 unsigned f_indexsine;
118 typedef struct SpectralBandReplication SpectralBandReplication;
121 * aacsbr functions pointers
123 typedef struct AACSBRContext {
124 int (*sbr_lf_gen)(AACContext *ac, SpectralBandReplication *sbr,
125 INTFLOAT X_low[32][40][2], const INTFLOAT W[2][32][32][2],
127 void (*sbr_hf_assemble)(INTFLOAT Y1[38][64][2],
128 const INTFLOAT X_high[64][40][2],
129 SpectralBandReplication *sbr, SBRData *ch_data,
131 int (*sbr_x_gen)(SpectralBandReplication *sbr, INTFLOAT X[2][38][64],
132 const INTFLOAT Y0[38][64][2], const INTFLOAT Y1[38][64][2],
133 const INTFLOAT X_low[32][40][2], int ch);
134 void (*sbr_hf_inverse_filter)(SBRDSPContext *dsp,
135 INTFLOAT (*alpha0)[2], INTFLOAT (*alpha1)[2],
136 const INTFLOAT X_low[32][40][2], int k0);
140 * Spectral Band Replication
142 struct SpectralBandReplication {
145 int ready_for_dequant;
148 SpectrumParameters spectrum_params;
149 int bs_amp_res_header;
151 * @name Variables associated with bs_header_extra_2
154 unsigned bs_limiter_bands;
155 unsigned bs_limiter_gains;
156 unsigned bs_interpol_freq;
157 unsigned bs_smoothing_mode;
159 unsigned bs_coupling;
160 AAC_SIGNE k[5]; ///< k0, k1, k2
161 ///kx', and kx respectively, kx is the first QMF subband where SBR is used.
162 ///kx' is its value from the previous frame
164 ///M' and M respectively, M is the number of QMF subbands that use SBR.
166 unsigned kx_and_m_pushed;
167 ///The number of frequency bands in f_master
171 ///N_Low and N_High respectively, the number of frequency bands for low and high resolution
173 ///Number of noise floor bands
175 ///Number of limiter bands
177 ///The master QMF frequency grouping
178 uint16_t f_master[49];
179 ///Frequency borders for low resolution SBR
180 uint16_t f_tablelow[25];
181 ///Frequency borders for high resolution SBR
182 uint16_t f_tablehigh[49];
183 ///Frequency borders for noise floors
184 uint16_t f_tablenoise[6];
185 ///Frequency borders for the limiter
186 uint16_t f_tablelim[30];
187 AAC_SIGNE num_patches;
188 uint8_t patch_num_subbands[6];
189 uint8_t patch_start_subband[6];
190 ///QMF low frequency input to the HF generator
191 DECLARE_ALIGNED(16, INTFLOAT, X_low)[32][40][2];
192 ///QMF output of the HF generator
193 DECLARE_ALIGNED(16, INTFLOAT, X_high)[64][40][2];
194 ///QMF values of the reconstructed signal
195 DECLARE_ALIGNED(16, INTFLOAT, X)[2][2][38][64];
196 ///Zeroth coefficient used to filter the subband signals
197 DECLARE_ALIGNED(16, INTFLOAT, alpha0)[64][2];
198 ///First coefficient used to filter the subband signals
199 DECLARE_ALIGNED(16, INTFLOAT, alpha1)[64][2];
200 ///Dequantized envelope scalefactors, remapped
201 AAC_FLOAT e_origmapped[7][48];
202 ///Dequantized noise scalefactors, remapped
203 AAC_FLOAT q_mapped[7][48];
204 ///Sinusoidal presence, remapped
205 uint8_t s_mapped[7][48];
206 ///Estimated envelope
207 AAC_FLOAT e_curr[7][48];
208 ///Amplitude adjusted noise scalefactors
209 AAC_FLOAT q_m[7][48];
211 AAC_FLOAT s_m[7][48];
212 AAC_FLOAT gain[7][48];
213 DECLARE_ALIGNED(32, INTFLOAT, qmf_filter_scratch)[5][64];
220 #endif /* AVCODEC_SBR_H */