FFmpeg
sbr.h
Go to the documentation of this file.
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
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 
34 #include "libavutil/mem_internal.h"
35 #include "libavutil/tx.h"
36 
37 #include "aacps.h"
38 #include "sbrdsp.h"
39 
40 /**
41  * Spectral Band Replication header - spectrum parameters that invoke a reset if they differ from the previous header.
42  */
43 typedef struct SpectrumParameters {
44  uint8_t bs_start_freq;
45  uint8_t bs_stop_freq;
46  uint8_t bs_xover_band;
47 
48  /**
49  * @name Variables associated with bs_header_extra_1
50  * @{
51  */
52  uint8_t bs_freq_scale;
53  uint8_t bs_alter_scale;
54  uint8_t bs_noise_bands;
55  /** @} */
57 
58 #define SBR_SYNTHESIS_BUF_SIZE ((1280-128)*2)
59 
60 /**
61  * Spectral Band Replication per channel data
62  */
63 typedef struct SBRData {
64  /**
65  * @name Main bitstream data variables
66  * @{
67  */
68  unsigned bs_frame_class;
71  uint8_t bs_freq_res[9];
73  uint8_t bs_df_env[9];
74  uint8_t bs_df_noise[2];
75  uint8_t bs_invf_mode[2][5];
76  uint8_t bs_add_harmonic[48];
77  unsigned bs_amp_res;
78  /** @} */
79 
80  /**
81  * @name State variables
82  * @{
83  */
87  ///l_APrev and l_A
88  int e_a[2];
89  ///Chirp factors
91  ///QMF values of the original signal
92  INTFLOAT W[2][32][32][2];
93  ///QMF output of the HF adjustor
94  int Ypos;
95  DECLARE_ALIGNED(16, INTFLOAT, Y)[2][38][64][2];
97  AAC_FLOAT q_temp[42][48];
98  uint8_t s_indexmapped[9][48];
99  ///Envelope scalefactors
100  uint8_t env_facs_q[9][48];
102  ///Noise scalefactors
103  uint8_t noise_facs_q[3][5];
105  ///Envelope time borders
106  uint8_t t_env[9];
107  ///Envelope time border of the last envelope of the previous frame
109  ///Noise time borders
110  uint8_t t_q[3];
111  unsigned f_indexnoise;
112  unsigned f_indexsine;
113  //inter_tes (USAC)
114  uint8_t temp_shape[6];
115  uint8_t temp_shape_mode[6];
116  /** @} */
117 } SBRData;
118 
120 
121 /**
122  * aacsbr functions pointers
123  */
124 typedef struct AACSBRContext {
126  INTFLOAT X_low[32][40][2], const INTFLOAT W[2][32][32][2],
127  int buf_idx);
128  void (*sbr_hf_assemble)(INTFLOAT Y1[38][64][2],
129  const INTFLOAT X_high[64][40][2],
130  SpectralBandReplication *sbr, SBRData *ch_data,
131  const int e_a[2]);
132  int (*sbr_x_gen)(SpectralBandReplication *sbr, INTFLOAT X[2][38][64],
133  const INTFLOAT Y0[38][64][2], const INTFLOAT Y1[38][64][2],
134  const INTFLOAT X_low[32][40][2], int ch);
136  INTFLOAT (*alpha0)[2], INTFLOAT (*alpha1)[2],
137  const INTFLOAT X_low[32][40][2], int k0);
138 } AACSBRContext;
139 
140 /**
141  * Spectral Band Replication
142  */
145  int start;
147  int id_aac;
148  int usac;
149  int inter_tes; // USAC-only
150  int reset;
153  int bs_sbr_preprocessing; // USAC-only
154  /**
155  * @name Variables associated with bs_header_extra_2
156  * @{
157  */
162  /** @} */
163  unsigned bs_coupling;
164  AAC_SIGNE k[5]; ///< k0, k1, k2
165  ///kx', and kx respectively, kx is the first QMF subband where SBR is used.
166  ///kx' is its value from the previous frame
168  ///M' and M respectively, M is the number of QMF subbands that use SBR.
170  unsigned kx_and_m_pushed;
171  ///The number of frequency bands in f_master
175  ///N_Low and N_High respectively, the number of frequency bands for low and high resolution
177  ///Number of noise floor bands
179  ///Number of limiter bands
181  ///The master QMF frequency grouping
182  uint16_t f_master[49];
183  ///Frequency borders for low resolution SBR
184  uint16_t f_tablelow[25];
185  ///Frequency borders for high resolution SBR
186  uint16_t f_tablehigh[49];
187  ///Frequency borders for noise floors
188  uint16_t f_tablenoise[6];
189  ///Frequency borders for the limiter
190  uint16_t f_tablelim[30];
192  uint8_t patch_num_subbands[6];
194  ///QMF low frequency input to the HF generator
195  DECLARE_ALIGNED(16, INTFLOAT, X_low)[32][40][2];
196  ///QMF output of the HF generator
197  DECLARE_ALIGNED(16, INTFLOAT, X_high)[64][40][2];
198  ///QMF values of the reconstructed signal
199  DECLARE_ALIGNED(16, INTFLOAT, X)[2][2][38][64];
200  ///Zeroth coefficient used to filter the subband signals
202  ///First coefficient used to filter the subband signals
204  ///Dequantized envelope scalefactors, remapped
206  ///Dequantized noise scalefactors, remapped
208  ///Sinusoidal presence, remapped
209  uint8_t s_mapped[8][48];
210  ///Estimated envelope
212  ///Amplitude adjusted noise scalefactors
213  AAC_FLOAT q_m[8][48];
214  ///Sinusoidal levels
215  AAC_FLOAT s_m[8][48];
216  AAC_FLOAT gain[8][48];
224 };
225 
226 #endif /* AVCODEC_SBR_H */
SpectralBandReplication::bs_coupling
unsigned bs_coupling
Definition: sbr.h:163
SBRData::bs_freq_res
uint8_t bs_freq_res[9]
Definition: sbr.h:71
INTFLOAT
#define INTFLOAT
Definition: dct32_template.c:44
SpectralBandReplication::data
SBRData data[2]
Definition: sbr.h:173
SpectralBandReplication::bs_limiter_gains
unsigned bs_limiter_gains
Definition: sbr.h:159
mem_internal.h
SBRDSPContext
Definition: sbrdsp.h:27
AVTXContext
Definition: tx_priv.h:235
SpectralBandReplication::X
INTFLOAT X[2][2][38][64]
QMF values of the reconstructed signal.
Definition: sbr.h:199
AAC_SIGNE
unsigned AAC_SIGNE
Definition: aac_defines.h:106
SpectralBandReplication::m
AAC_SIGNE m[2]
M' and M respectively, M is the number of QMF subbands that use SBR.
Definition: sbr.h:169
SBRData::bs_df_env
uint8_t bs_df_env[9]
Definition: sbr.h:73
SBRData::t_env_num_env_old
uint8_t t_env_num_env_old
Envelope time border of the last envelope of the previous frame.
Definition: sbr.h:108
SpectrumParameters::bs_alter_scale
uint8_t bs_alter_scale
Definition: sbr.h:53
SBRData::env_facs_q
uint8_t env_facs_q[9][48]
Envelope scalefactors.
Definition: sbr.h:100
AACSBRContext::sbr_hf_assemble
void(* sbr_hf_assemble)(INTFLOAT Y1[38][64][2], const INTFLOAT X_high[64][40][2], SpectralBandReplication *sbr, SBRData *ch_data, const int e_a[2])
Definition: sbr.h:128
SpectrumParameters::bs_start_freq
uint8_t bs_start_freq
Definition: sbr.h:44
SpectralBandReplication::X_low
INTFLOAT X_low[32][40][2]
QMF low frequency input to the HF generator.
Definition: sbr.h:195
SBRData::temp_shape_mode
uint8_t temp_shape_mode[6]
Definition: sbr.h:115
SpectralBandReplication::s_mapped
uint8_t s_mapped[8][48]
Sinusoidal presence, remapped.
Definition: sbr.h:209
SpectralBandReplication::ready_for_dequant
int ready_for_dequant
Definition: sbr.h:146
SBRData::e_a
int e_a[2]
l_APrev and l_A
Definition: sbr.h:88
SBRData::analysis_filterbank_samples
INTFLOAT analysis_filterbank_samples[1312]
Definition: sbr.h:85
SBRData::t_env
uint8_t t_env[9]
Envelope time borders.
Definition: sbr.h:106
aacps.h
SpectralBandReplication::bs_interpol_freq
unsigned bs_interpol_freq
Definition: sbr.h:160
SpectralBandReplication::n_master
AAC_SIGNE n_master
The number of frequency bands in f_master.
Definition: sbr.h:172
SBRData::temp_shape
uint8_t temp_shape[6]
Definition: sbr.h:114
SpectralBandReplication::mdct_fn
av_tx_fn mdct_fn
Definition: sbr.h:221
SBRData::bs_add_harmonic_flag
unsigned bs_add_harmonic_flag
Definition: sbr.h:69
SpectralBandReplication::reset
int reset
Definition: sbr.h:150
SBRData::noise_facs
AAC_FLOAT noise_facs[3][5]
Definition: sbr.h:104
SpectrumParameters::bs_stop_freq
uint8_t bs_stop_freq
Definition: sbr.h:45
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
SpectralBandReplication::qmf_filter_scratch
INTFLOAT qmf_filter_scratch[5][64]
Definition: sbr.h:217
SBRData::bs_df_noise
uint8_t bs_df_noise[2]
Definition: sbr.h:74
SBRData::env_facs
AAC_FLOAT env_facs[9][48]
Definition: sbr.h:101
SBRData::bs_num_noise
AAC_SIGNE bs_num_noise
Definition: sbr.h:72
SpectrumParameters::bs_xover_band
uint8_t bs_xover_band
Definition: sbr.h:46
SpectralBandReplication::f_tablenoise
uint16_t f_tablenoise[6]
Frequency borders for noise floors.
Definition: sbr.h:188
SBRData::g_temp
AAC_FLOAT g_temp[42][48]
Definition: sbr.h:96
W
@ W
Definition: vf_addroi.c:27
SpectralBandReplication::e_origmapped
AAC_FLOAT e_origmapped[8][48]
Dequantized envelope scalefactors, remapped.
Definition: sbr.h:205
AACSBRContext::sbr_x_gen
int(* sbr_x_gen)(SpectralBandReplication *sbr, INTFLOAT X[2][38][64], const INTFLOAT Y0[38][64][2], const INTFLOAT Y1[38][64][2], const INTFLOAT X_low[32][40][2], int ch)
Definition: sbr.h:132
SpectralBandReplication::n_lim
AAC_SIGNE n_lim
Number of limiter bands.
Definition: sbr.h:180
SBRData::Ypos
int Ypos
QMF output of the HF adjustor.
Definition: sbr.h:94
SpectralBandReplication::f_tablelow
uint16_t f_tablelow[25]
Frequency borders for low resolution SBR.
Definition: sbr.h:184
SpectralBandReplication::mdct
AVTXContext * mdct
Definition: sbr.h:220
SBRData::f_indexnoise
unsigned f_indexnoise
Definition: sbr.h:111
SpectrumParameters::bs_freq_scale
uint8_t bs_freq_scale
Definition: sbr.h:52
SpectralBandReplication::f_tablelim
uint16_t f_tablelim[30]
Frequency borders for the limiter.
Definition: sbr.h:190
SBRData::bs_add_harmonic
uint8_t bs_add_harmonic[48]
Definition: sbr.h:76
AACSBRContext
aacsbr functions pointers
Definition: sbr.h:124
SBR_SYNTHESIS_BUF_SIZE
#define SBR_SYNTHESIS_BUF_SIZE
Definition: sbr.h:58
SpectralBandReplication::n
AAC_SIGNE n[2]
N_Low and N_High respectively, the number of frequency bands for low and high resolution.
Definition: sbr.h:176
SBRData::bs_num_env
AAC_SIGNE bs_num_env
Definition: sbr.h:70
SBRData::bs_amp_res
unsigned bs_amp_res
Definition: sbr.h:77
SpectralBandReplication::bs_smoothing_mode
unsigned bs_smoothing_mode
Definition: sbr.h:161
SpectralBandReplication::mdct_ana_fn
av_tx_fn mdct_ana_fn
Definition: sbr.h:219
SpectrumParameters
Spectral Band Replication header - spectrum parameters that invoke a reset if they differ from the pr...
Definition: sbr.h:43
SpectralBandReplication::f_master
uint16_t f_master[49]
The master QMF frequency grouping.
Definition: sbr.h:182
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:102
X
@ X
Definition: vf_addroi.c:27
SpectralBandReplication::q_m
AAC_FLOAT q_m[8][48]
Amplitude adjusted noise scalefactors.
Definition: sbr.h:213
SpectralBandReplication::sample_rate
int sample_rate
Definition: sbr.h:144
sbrdsp.h
SpectralBandReplication
Spectral Band Replication.
Definition: sbr.h:143
SpectralBandReplication::alpha0
INTFLOAT alpha0[64][2]
Zeroth coefficient used to filter the subband signals.
Definition: sbr.h:201
SpectralBandReplication::c
AACSBRContext c
Definition: sbr.h:223
SpectralBandReplication::bs_amp_res_header
int bs_amp_res_header
Definition: sbr.h:152
SBRData::bs_invf_mode
uint8_t bs_invf_mode[2][5]
Definition: sbr.h:75
SpectralBandReplication::alpha1
INTFLOAT alpha1[64][2]
First coefficient used to filter the subband signals.
Definition: sbr.h:203
SBRData::Y
INTFLOAT Y[2][38][64][2]
Definition: sbr.h:95
SpectralBandReplication::n_q
AAC_SIGNE n_q
Number of noise floor bands.
Definition: sbr.h:178
SpectralBandReplication::patch_start_subband
uint8_t patch_start_subband[6]
Definition: sbr.h:193
AACSBRContext::sbr_hf_inverse_filter
void(* sbr_hf_inverse_filter)(SBRDSPContext *dsp, INTFLOAT(*alpha0)[2], INTFLOAT(*alpha1)[2], const INTFLOAT X_low[32][40][2], int k0)
Definition: sbr.h:135
SpectralBandReplication::inter_tes
int inter_tes
Definition: sbr.h:149
SpectralBandReplication::id_aac
int id_aac
Definition: sbr.h:147
SpectralBandReplication::q_mapped
AAC_FLOAT q_mapped[8][48]
Dequantized noise scalefactors, remapped.
Definition: sbr.h:207
SBRData
Spectral Band Replication per channel data.
Definition: sbr.h:63
PSContext
Definition: aacps.h:71
SBRData::bw_array
INTFLOAT bw_array[5]
Chirp factors.
Definition: sbr.h:90
SpectralBandReplication::k
AAC_SIGNE k[5]
k0, k1, k2
Definition: sbr.h:164
SpectralBandReplication::X_high
INTFLOAT X_high[64][40][2]
QMF output of the HF generator.
Definition: sbr.h:197
SBRData::f_indexsine
unsigned f_indexsine
Definition: sbr.h:112
SBRData::bs_frame_class
unsigned bs_frame_class
Definition: sbr.h:68
SpectralBandReplication::kx_and_m_pushed
unsigned kx_and_m_pushed
Definition: sbr.h:170
SBRData::W
INTFLOAT W[2][32][32][2]
QMF values of the original signal.
Definition: sbr.h:92
SpectralBandReplication::usac
int usac
Definition: sbr.h:148
SBRData::q_temp
AAC_FLOAT q_temp[42][48]
Definition: sbr.h:97
SpectralBandReplication::gain
AAC_FLOAT gain[8][48]
Definition: sbr.h:216
SBRData::t_q
uint8_t t_q[3]
Noise time borders.
Definition: sbr.h:110
SpectralBandReplication::spectrum_params
SpectrumParameters spectrum_params
Definition: sbr.h:151
SpectralBandReplication::bs_sbr_preprocessing
int bs_sbr_preprocessing
Definition: sbr.h:153
SpectralBandReplication::f_tablehigh
uint16_t f_tablehigh[49]
Frequency borders for high resolution SBR.
Definition: sbr.h:186
SBRData::noise_facs_q
uint8_t noise_facs_q[3][5]
Noise scalefactors.
Definition: sbr.h:103
SBRData::synthesis_filterbank_samples
INTFLOAT synthesis_filterbank_samples[SBR_SYNTHESIS_BUF_SIZE]
Definition: sbr.h:84
SpectralBandReplication::bs_limiter_bands
unsigned bs_limiter_bands
Definition: sbr.h:158
SpectralBandReplication::patch_num_subbands
uint8_t patch_num_subbands[6]
Definition: sbr.h:192
SpectralBandReplication::start
int start
Definition: sbr.h:145
SpectralBandReplication::mdct_ana
AVTXContext * mdct_ana
Definition: sbr.h:218
AAC_FLOAT
float AAC_FLOAT
Definition: aac_defines.h:105
SpectralBandReplication::s_m
AAC_FLOAT s_m[8][48]
Sinusoidal levels.
Definition: sbr.h:215
SpectrumParameters::bs_noise_bands
uint8_t bs_noise_bands
Definition: sbr.h:54
AACSBRContext::sbr_lf_gen
int(* sbr_lf_gen)(SpectralBandReplication *sbr, INTFLOAT X_low[32][40][2], const INTFLOAT W[2][32][32][2], int buf_idx)
Definition: sbr.h:125
SBRData::synthesis_filterbank_samples_offset
int synthesis_filterbank_samples_offset
Definition: sbr.h:86
SBRData::s_indexmapped
uint8_t s_indexmapped[9][48]
Definition: sbr.h:98
SpectralBandReplication::kx
AAC_SIGNE kx[2]
kx', and kx respectively, kx is the first QMF subband where SBR is used.
Definition: sbr.h:167
INTFLOAT
float INTFLOAT
Definition: aac_defines.h:101
SpectralBandReplication::e_curr
AAC_FLOAT e_curr[8][48]
Estimated envelope.
Definition: sbr.h:211
tx.h
SpectralBandReplication::ps
PSContext ps
Definition: sbr.h:174
SpectralBandReplication::num_patches
AAC_SIGNE num_patches
Definition: sbr.h:191
SpectralBandReplication::dsp
SBRDSPContext dsp
Definition: sbr.h:222