ed492b61 |
/*
* Spectral Band Replication definitions and structures
* Copyright (c) 2008-2009 Robert Swain ( rob opendot cl )
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/** |
ba87f080 |
* @file |
ed492b61 |
* Spectral Band Replication definitions and structures
* @author Robert Swain ( rob opendot cl )
*/
#ifndef AVCODEC_SBR_H
#define AVCODEC_SBR_H
#include <stdint.h>
#include "fft.h" |
fd6eb4a0 |
#include "aacps.h" |
aac46e08 |
#include "sbrdsp.h" |
ed492b61 |
|
8d2eb5fe |
typedef struct AACContext AACContext;
|
ed492b61 |
/**
* Spectral Band Replication header - spectrum parameters that invoke a reset if they differ from the previous header.
*/ |
e4cbf752 |
typedef struct SpectrumParameters { |
ed492b61 |
uint8_t bs_start_freq;
uint8_t bs_stop_freq;
uint8_t bs_xover_band;
/** |
21a19b79 |
* @name Variables associated with bs_header_extra_1 |
ed492b61 |
* @{
*/
uint8_t bs_freq_scale;
uint8_t bs_alter_scale;
uint8_t bs_noise_bands;
/** @} */
} SpectrumParameters;
#define SBR_SYNTHESIS_BUF_SIZE ((1280-128)*2)
/**
* Spectral Band Replication per channel data
*/ |
e4cbf752 |
typedef struct SBRData { |
ed492b61 |
/** |
21a19b79 |
* @name Main bitstream data variables |
ed492b61 |
* @{
*/
unsigned bs_frame_class;
unsigned bs_add_harmonic_flag; |
f85bc147 |
AAC_SIGNE bs_num_env; |
ed492b61 |
uint8_t bs_freq_res[7]; |
f85bc147 |
AAC_SIGNE bs_num_noise; |
ed492b61 |
uint8_t bs_df_env[5];
uint8_t bs_df_noise[2];
uint8_t bs_invf_mode[2][5];
uint8_t bs_add_harmonic[48];
unsigned bs_amp_res;
/** @} */
/** |
21a19b79 |
* @name State variables |
ed492b61 |
* @{
*/ |
f85bc147 |
DECLARE_ALIGNED(32, INTFLOAT, synthesis_filterbank_samples)[SBR_SYNTHESIS_BUF_SIZE];
DECLARE_ALIGNED(32, INTFLOAT, analysis_filterbank_samples) [1312]; |
ed492b61 |
int synthesis_filterbank_samples_offset;
///l_APrev and l_A
int e_a[2];
///Chirp factors |
f85bc147 |
INTFLOAT bw_array[5]; |
ed492b61 |
///QMF values of the original signal |
f85bc147 |
INTFLOAT W[2][32][32][2]; |
ed492b61 |
///QMF output of the HF adjustor |
cc412b71 |
int Ypos; |
f85bc147 |
DECLARE_ALIGNED(16, INTFLOAT, Y)[2][38][64][2];
DECLARE_ALIGNED(16, AAC_FLOAT, g_temp)[42][48];
AAC_FLOAT q_temp[42][48]; |
ed492b61 |
uint8_t s_indexmapped[8][48];
///Envelope scalefactors |
bfd0e02d |
uint8_t env_facs_q[6][48]; |
f85bc147 |
AAC_FLOAT env_facs[6][48]; |
ed492b61 |
///Noise scalefactors |
03a34ef7 |
uint8_t noise_facs_q[3][5]; |
f85bc147 |
AAC_FLOAT noise_facs[3][5]; |
ed492b61 |
///Envelope time borders
uint8_t t_env[8];
///Envelope time border of the last envelope of the previous frame
uint8_t t_env_num_env_old;
///Noise time borders
uint8_t t_q[3];
unsigned f_indexnoise;
unsigned f_indexsine;
/** @} */
} SBRData;
|
8d2eb5fe |
typedef struct SpectralBandReplication SpectralBandReplication;
/**
* aacsbr functions pointers
*/
typedef struct AACSBRContext {
int (*sbr_lf_gen)(AACContext *ac, SpectralBandReplication *sbr, |
f85bc147 |
INTFLOAT X_low[32][40][2], const INTFLOAT W[2][32][32][2], |
8d2eb5fe |
int buf_idx); |
f85bc147 |
void (*sbr_hf_assemble)(INTFLOAT Y1[38][64][2],
const INTFLOAT X_high[64][40][2], |
8d2eb5fe |
SpectralBandReplication *sbr, SBRData *ch_data,
const int e_a[2]); |
f85bc147 |
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); |
8d2eb5fe |
void (*sbr_hf_inverse_filter)(SBRDSPContext *dsp, |
f85bc147 |
INTFLOAT (*alpha0)[2], INTFLOAT (*alpha1)[2],
const INTFLOAT X_low[32][40][2], int k0); |
8d2eb5fe |
} AACSBRContext;
|
ed492b61 |
/**
* Spectral Band Replication
*/ |
8d2eb5fe |
struct SpectralBandReplication { |
ed492b61 |
int sample_rate;
int start; |
1c3e43a6 |
int ready_for_dequant; |
79a98294 |
int id_aac; |
ed492b61 |
int reset;
SpectrumParameters spectrum_params;
int bs_amp_res_header;
/** |
21a19b79 |
* @name Variables associated with bs_header_extra_2 |
ed492b61 |
* @{
*/
unsigned bs_limiter_bands;
unsigned bs_limiter_gains;
unsigned bs_interpol_freq;
unsigned bs_smoothing_mode;
/** @} */
unsigned bs_coupling; |
f85bc147 |
AAC_SIGNE k[5]; ///< k0, k1, k2 |
ed492b61 |
///kx', and kx respectively, kx is the first QMF subband where SBR is used.
///kx' is its value from the previous frame |
f85bc147 |
AAC_SIGNE kx[2]; |
ed492b61 |
///M' and M respectively, M is the number of QMF subbands that use SBR. |
f85bc147 |
AAC_SIGNE m[2]; |
0cb93dac |
unsigned kx_and_m_pushed; |
ed492b61 |
///The number of frequency bands in f_master |
f85bc147 |
AAC_SIGNE n_master; |
ed492b61 |
SBRData data[2]; |
a2063901 |
PSContext ps; |
ed492b61 |
///N_Low and N_High respectively, the number of frequency bands for low and high resolution |
f85bc147 |
AAC_SIGNE n[2]; |
ed492b61 |
///Number of noise floor bands |
f85bc147 |
AAC_SIGNE n_q; |
ed492b61 |
///Number of limiter bands |
f85bc147 |
AAC_SIGNE n_lim; |
ed492b61 |
///The master QMF frequency grouping
uint16_t f_master[49];
///Frequency borders for low resolution SBR
uint16_t f_tablelow[25];
///Frequency borders for high resolution SBR
uint16_t f_tablehigh[49];
///Frequency borders for noise floors
uint16_t f_tablenoise[6];
///Frequency borders for the limiter |
fdbb6164 |
uint16_t f_tablelim[30]; |
f85bc147 |
AAC_SIGNE num_patches; |
ed492b61 |
uint8_t patch_num_subbands[6];
uint8_t patch_start_subband[6];
///QMF low frequency input to the HF generator |
f85bc147 |
DECLARE_ALIGNED(16, INTFLOAT, X_low)[32][40][2]; |
ed492b61 |
///QMF output of the HF generator |
f85bc147 |
DECLARE_ALIGNED(16, INTFLOAT, X_high)[64][40][2]; |
ed492b61 |
///QMF values of the reconstructed signal |
f85bc147 |
DECLARE_ALIGNED(16, INTFLOAT, X)[2][2][38][64]; |
ed492b61 |
///Zeroth coefficient used to filter the subband signals |
f85bc147 |
DECLARE_ALIGNED(16, INTFLOAT, alpha0)[64][2]; |
ed492b61 |
///First coefficient used to filter the subband signals |
f85bc147 |
DECLARE_ALIGNED(16, INTFLOAT, alpha1)[64][2]; |
ed492b61 |
///Dequantized envelope scalefactors, remapped |
f85bc147 |
AAC_FLOAT e_origmapped[7][48]; |
ed492b61 |
///Dequantized noise scalefactors, remapped |
f85bc147 |
AAC_FLOAT q_mapped[7][48]; |
ed492b61 |
///Sinusoidal presence, remapped
uint8_t s_mapped[7][48];
///Estimated envelope |
f85bc147 |
AAC_FLOAT e_curr[7][48]; |
ed492b61 |
///Amplitude adjusted noise scalefactors |
f85bc147 |
AAC_FLOAT q_m[7][48]; |
ed492b61 |
///Sinusoidal levels |
f85bc147 |
AAC_FLOAT s_m[7][48];
AAC_FLOAT gain[7][48];
DECLARE_ALIGNED(32, INTFLOAT, qmf_filter_scratch)[5][64]; |
932963b8 |
FFTContext mdct_ana; |
ed492b61 |
FFTContext mdct; |
aac46e08 |
SBRDSPContext dsp; |
8d2eb5fe |
AACSBRContext c;
}; |
ed492b61 |
#endif /* AVCODEC_SBR_H */ |