11401
|
1 /*
|
|
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>
|
|
5 *
|
|
6 * This file is part of FFmpeg.
|
|
7 *
|
|
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.
|
|
12 *
|
|
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.
|
|
17 *
|
|
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
|
|
21 */
|
|
22
|
|
23 /**
|
|
24 * @file libavcodec/sbr.h
|
|
25 * Spectral Band Replication definitions and structures
|
|
26 * @author Robert Swain ( rob opendot cl )
|
|
27 */
|
|
28
|
|
29 #ifndef AVCODEC_SBR_H
|
|
30 #define AVCODEC_SBR_H
|
|
31
|
|
32 #include <stdint.h>
|
|
33 #include "fft.h"
|
|
34
|
|
35 /**
|
|
36 * Spectral Band Replication header - spectrum parameters that invoke a reset if they differ from the previous header.
|
|
37 */
|
|
38 typedef struct {
|
|
39 uint8_t bs_start_freq;
|
|
40 uint8_t bs_stop_freq;
|
|
41 uint8_t bs_xover_band;
|
|
42
|
|
43 /**
|
|
44 * @defgroup bs_header_extra_1 Variables associated with bs_header_extra_1
|
|
45 * @{
|
|
46 */
|
|
47 uint8_t bs_freq_scale;
|
|
48 uint8_t bs_alter_scale;
|
|
49 uint8_t bs_noise_bands;
|
|
50 /** @} */
|
|
51 } SpectrumParameters;
|
|
52
|
|
53 #define SBR_SYNTHESIS_BUF_SIZE ((1280-128)*2)
|
|
54
|
|
55 /**
|
|
56 * Spectral Band Replication per channel data
|
|
57 */
|
|
58 typedef struct {
|
|
59 /**
|
|
60 * @defgroup bitstream Main bitstream data variables
|
|
61 * @{
|
|
62 */
|
|
63 unsigned bs_frame_class;
|
|
64 unsigned bs_add_harmonic_flag;
|
|
65 unsigned bs_num_env[2];
|
|
66 uint8_t bs_freq_res[7];
|
|
67 uint8_t bs_var_bord[2];
|
|
68 uint8_t bs_num_rel[2];
|
|
69 uint8_t bs_rel_bord[2][3];
|
|
70 unsigned bs_pointer;
|
|
71 unsigned bs_num_noise;
|
|
72 uint8_t bs_df_env[5];
|
|
73 uint8_t bs_df_noise[2];
|
|
74 uint8_t bs_invf_mode[2][5];
|
|
75 uint8_t bs_add_harmonic[48];
|
|
76 unsigned bs_amp_res;
|
|
77 /** @} */
|
|
78
|
|
79 /**
|
|
80 * @defgroup state State variables
|
|
81 * @{
|
|
82 */
|
|
83 DECLARE_ALIGNED(16, float, synthesis_filterbank_samples)[SBR_SYNTHESIS_BUF_SIZE];
|
|
84 DECLARE_ALIGNED(16, float, analysis_filterbank_samples) [1312];
|
|
85 int synthesis_filterbank_samples_offset;
|
|
86 ///l_APrev and l_A
|
|
87 int e_a[2];
|
|
88 ///Chirp factors
|
|
89 float bw_array[5];
|
|
90 ///QMF values of the original signal
|
|
91 float W[2][32][32][2];
|
|
92 ///QMF output of the HF adjustor
|
|
93 float Y[2][38][64][2];
|
|
94 float g_temp[42][48];
|
|
95 float q_temp[42][48];
|
|
96 uint8_t s_indexmapped[8][48];
|
|
97 ///Envelope scalefactors
|
|
98 float env_facs[6][48];
|
|
99 ///Noise scalefactors
|
|
100 float noise_facs[3][5];
|
|
101 ///Envelope time borders
|
|
102 uint8_t t_env[8];
|
|
103 ///Envelope time border of the last envelope of the previous frame
|
|
104 uint8_t t_env_num_env_old;
|
|
105 ///Noise time borders
|
|
106 uint8_t t_q[3];
|
|
107 unsigned f_indexnoise;
|
|
108 unsigned f_indexsine;
|
|
109 /** @} */
|
|
110 } SBRData;
|
|
111
|
|
112 /**
|
|
113 * Spectral Band Replication
|
|
114 */
|
|
115 typedef struct {
|
|
116 int sample_rate;
|
|
117 int start;
|
|
118 int reset;
|
|
119 SpectrumParameters spectrum_params;
|
|
120 int bs_amp_res_header;
|
|
121 /**
|
|
122 * @defgroup bs_header_extra_2 variables associated with bs_header_extra_2
|
|
123 * @{
|
|
124 */
|
|
125 unsigned bs_limiter_bands;
|
|
126 unsigned bs_limiter_gains;
|
|
127 unsigned bs_interpol_freq;
|
|
128 unsigned bs_smoothing_mode;
|
|
129 /** @} */
|
|
130 unsigned bs_coupling;
|
|
131 unsigned k[5]; ///< k0, k1, k2
|
|
132 ///kx', and kx respectively, kx is the first QMF subband where SBR is used.
|
|
133 ///kx' is its value from the previous frame
|
|
134 unsigned kx[2];
|
|
135 ///M' and M respectively, M is the number of QMF subbands that use SBR.
|
|
136 unsigned m[2];
|
|
137 ///The number of frequency bands in f_master
|
|
138 unsigned n_master;
|
|
139 SBRData data[2];
|
|
140 ///N_Low and N_High respectively, the number of frequency bands for low and high resolution
|
|
141 unsigned n[2];
|
|
142 ///Number of noise floor bands
|
|
143 unsigned n_q;
|
|
144 ///Number of limiter bands
|
|
145 unsigned n_lim;
|
|
146 ///The master QMF frequency grouping
|
|
147 uint16_t f_master[49];
|
|
148 ///Frequency borders for low resolution SBR
|
|
149 uint16_t f_tablelow[25];
|
|
150 ///Frequency borders for high resolution SBR
|
|
151 uint16_t f_tablehigh[49];
|
|
152 ///Frequency borders for noise floors
|
|
153 uint16_t f_tablenoise[6];
|
|
154 ///Frequency borders for the limiter
|
|
155 uint16_t f_tablelim[29];
|
|
156 unsigned num_patches;
|
|
157 uint8_t patch_num_subbands[6];
|
|
158 uint8_t patch_start_subband[6];
|
|
159 ///QMF low frequency input to the HF generator
|
|
160 float X_low[32][40][2];
|
|
161 ///QMF output of the HF generator
|
|
162 float X_high[64][40][2];
|
|
163 ///QMF values of the reconstructed signal
|
|
164 DECLARE_ALIGNED(16, float, X)[2][32][64];
|
|
165 ///Zeroth coefficient used to filter the subband signals
|
|
166 float alpha0[64][2];
|
|
167 ///First coefficient used to filter the subband signals
|
|
168 float alpha1[64][2];
|
|
169 ///Dequantized envelope scalefactors, remapped
|
|
170 float e_origmapped[7][48];
|
|
171 ///Dequantized noise scalefactors, remapped
|
|
172 float q_mapped[7][48];
|
|
173 ///Sinusoidal presence, remapped
|
|
174 uint8_t s_mapped[7][48];
|
|
175 ///Estimated envelope
|
|
176 float e_curr[7][48];
|
|
177 ///Amplitude adjusted noise scalefactors
|
|
178 float q_m[7][48];
|
|
179 ///Sinusoidal levels
|
|
180 float s_m[7][48];
|
|
181 float gain[7][48];
|
|
182 DECLARE_ALIGNED(16, float, qmf_filter_scratch)[5][64];
|
|
183 RDFTContext rdft;
|
|
184 FFTContext mdct;
|
|
185 } SpectralBandReplication;
|
|
186
|
|
187 #endif /* AVCODEC_SBR_H */
|