FFmpeg
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Enumerations | Functions | Variables
aacsbr.c File Reference

AAC Spectral Band Replication decoding functions. More...

#include "aac.h"
#include "sbr.h"
#include "aacsbr.h"
#include "aacsbrdata.h"
#include "fft.h"
#include "aacps.h"
#include "sbrdsp.h"
#include "libavutil/internal.h"
#include "libavutil/libm.h"
#include "libavutil/avassert.h"
#include <stdint.h>
#include <float.h>
#include <math.h>

Go to the source code of this file.

Macros

#define ENVELOPE_ADJUSTMENT_OFFSET   2
 
#define NOISE_FLOOR_OFFSET   6.0f
 
#define SBR_INIT_VLC_STATIC(num, size)
 
#define SBR_VLC_ROW(name)   { name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) }
 

Enumerations

enum  {
  T_HUFFMAN_ENV_1_5DB, F_HUFFMAN_ENV_1_5DB, T_HUFFMAN_ENV_BAL_1_5DB, F_HUFFMAN_ENV_BAL_1_5DB,
  T_HUFFMAN_ENV_3_0DB, F_HUFFMAN_ENV_3_0DB, T_HUFFMAN_ENV_BAL_3_0DB, F_HUFFMAN_ENV_BAL_3_0DB,
  T_HUFFMAN_NOISE_3_0DB, T_HUFFMAN_NOISE_BAL_3_0DB
}
 SBR VLC tables. More...
 
enum  { FIXFIX, FIXVAR, VARFIX, VARVAR }
 bs_frame_class - frame class of current SBR frame (14496-3 sp04 p98) More...
 
enum  { EXTENSION_ID_PS = 2 }
 

Functions

static void aacsbr_func_ptr_init (AACSBRContext *c)
 
av_cold void ff_aac_sbr_init (void)
 Initialize SBR.
 
static void sbr_turnoff (SpectralBandReplication *sbr)
 Places SBR in pure upsampling mode.
 
av_cold void ff_aac_sbr_ctx_init (AACContext *ac, SpectralBandReplication *sbr)
 Initialize one SBR context.
 
av_cold void ff_aac_sbr_ctx_close (SpectralBandReplication *sbr)
 Close one SBR context.
 
static int qsort_comparison_function_int16 (const void *a, const void *b)
 
static int in_table_int16 (const int16_t *table, int last_el, int16_t needle)
 
static void sbr_make_f_tablelim (SpectralBandReplication *sbr)
 Limiter Frequency Band Table (14496-3 sp04 p198)
 
static unsigned int read_sbr_header (SpectralBandReplication *sbr, GetBitContext *gb)
 
static int array_min_int16 (const int16_t *array, int nel)
 
static void make_bands (int16_t *bands, int start, int stop, int num_bands)
 
static int check_n_master (AVCodecContext *avctx, int n_master, int bs_xover_band)
 
static int sbr_make_f_master (AACContext *ac, SpectralBandReplication *sbr, SpectrumParameters *spectrum)
 Master Frequency Band Table (14496-3 sp04 p194)
 
static int sbr_hf_calc_npatches (AACContext *ac, SpectralBandReplication *sbr)
 High Frequency Generation - Patch Construction (14496-3 sp04 p216 fig. 4.46)
 
static int sbr_make_f_derived (AACContext *ac, SpectralBandReplication *sbr)
 Derived Frequency Band Tables (14496-3 sp04 p197)
 
static av_always_inline void get_bits1_vector (GetBitContext *gb, uint8_t *vec, int elements)
 
static int read_sbr_grid (AACContext *ac, SpectralBandReplication *sbr, GetBitContext *gb, SBRData *ch_data)
 
static void copy_sbr_grid (SBRData *dst, const SBRData *src)
 
static void read_sbr_dtdf (SpectralBandReplication *sbr, GetBitContext *gb, SBRData *ch_data)
 Read how the envelope and noise floor data is delta coded.
 
static void read_sbr_invf (SpectralBandReplication *sbr, GetBitContext *gb, SBRData *ch_data)
 Read inverse filtering data.
 
static void read_sbr_envelope (SpectralBandReplication *sbr, GetBitContext *gb, SBRData *ch_data, int ch)
 
static void read_sbr_noise (SpectralBandReplication *sbr, GetBitContext *gb, SBRData *ch_data, int ch)
 
static void read_sbr_extension (AACContext *ac, SpectralBandReplication *sbr, GetBitContext *gb, int bs_extension_id, int *num_bits_left)
 
static int read_sbr_single_channel_element (AACContext *ac, SpectralBandReplication *sbr, GetBitContext *gb)
 
static int read_sbr_channel_pair_element (AACContext *ac, SpectralBandReplication *sbr, GetBitContext *gb)
 
static unsigned int read_sbr_data (AACContext *ac, SpectralBandReplication *sbr, GetBitContext *gb, int id_aac)
 
static void sbr_reset (AACContext *ac, SpectralBandReplication *sbr)
 
int ff_decode_sbr_extension (AACContext *ac, SpectralBandReplication *sbr, GetBitContext *gb_host, int crc, int cnt, int id_aac)
 Decode Spectral Band Replication extension data; reference: table 4.55.
 
static void sbr_dequant (SpectralBandReplication *sbr, int id_aac)
 Dequantization and stereo decoding (14496-3 sp04 p203)
 
static void sbr_qmf_analysis (AVFloatDSPContext *dsp, FFTContext *mdct, SBRDSPContext *sbrdsp, const float *in, float *x, float z[320], float W[2][32][32][2], int buf_idx)
 Analysis QMF Bank (14496-3 sp04 p206)
 
static void sbr_qmf_synthesis (FFTContext *mdct, SBRDSPContext *sbrdsp, AVFloatDSPContext *dsp, float *out, float X[2][38][64], float mdct_buf[2][64], float *v0, int *v_off, const unsigned int div)
 Synthesis QMF Bank (14496-3 sp04 p206) and Downsampled Synthesis QMF Bank (14496-3 sp04 p206)
 
static void sbr_hf_inverse_filter (SBRDSPContext *dsp, float(*alpha0)[2], float(*alpha1)[2], const float X_low[32][40][2], int k0)
 High Frequency Generation (14496-3 sp04 p214+) and Inverse Filtering (14496-3 sp04 p214) Warning: This routine does not seem numerically stable.
 
static void sbr_chirp (SpectralBandReplication *sbr, SBRData *ch_data)
 Chirp Factors (14496-3 sp04 p214)
 
static int sbr_lf_gen (AACContext *ac, SpectralBandReplication *sbr, float X_low[32][40][2], const float W[2][32][32][2], int buf_idx)
 Generate the subband filtered lowband.
 
static int sbr_hf_gen (AACContext *ac, SpectralBandReplication *sbr, float X_high[64][40][2], const float X_low[32][40][2], const float(*alpha0)[2], const float(*alpha1)[2], const float bw_array[5], const uint8_t *t_env, int bs_num_env)
 High Frequency Generator (14496-3 sp04 p215)
 
static int sbr_x_gen (SpectralBandReplication *sbr, float X[2][38][64], const float Y0[38][64][2], const float Y1[38][64][2], const float X_low[32][40][2], int ch)
 Generate the subband filtered lowband.
 
static int sbr_mapping (AACContext *ac, SpectralBandReplication *sbr, SBRData *ch_data, int e_a[2])
 High Frequency Adjustment (14496-3 sp04 p217) and Mapping (14496-3 sp04 p217)
 
static void sbr_env_estimate (float(*e_curr)[48], float X_high[64][40][2], SpectralBandReplication *sbr, SBRData *ch_data)
 Estimation of current envelope (14496-3 sp04 p218)
 
static void sbr_gain_calc (AACContext *ac, SpectralBandReplication *sbr, SBRData *ch_data, const int e_a[2])
 Calculation of levels of additional HF signal components (14496-3 sp04 p219) and Calculation of gain (14496-3 sp04 p219)
 
static void sbr_hf_assemble (float Y1[38][64][2], const float X_high[64][40][2], SpectralBandReplication *sbr, SBRData *ch_data, const int e_a[2])
 Assembling HF Signals (14496-3 sp04 p220)
 
void ff_sbr_apply (AACContext *ac, SpectralBandReplication *sbr, int id_aac, float *L, float *R)
 Apply one SBR element to one AAC element.
 

Variables

static VLC vlc_sbr [10]
 
static const int8_t vlc_sbr_lav [10]
 
static const int8_t ceil_log2 []
 ceil(log2(index+1))
 

Detailed Description

AAC Spectral Band Replication decoding functions.

Author
Robert Swain ( rob opendot cl )

Definition in file aacsbr.c.

Macro Definition Documentation

#define ENVELOPE_ADJUSTMENT_OFFSET   2

Definition at line 44 of file aacsbr.c.

Referenced by sbr_env_estimate(), sbr_hf_assemble(), sbr_hf_gen(), and sbr_x_gen().

#define NOISE_FLOOR_OFFSET   6.0f

Definition at line 45 of file aacsbr.c.

Referenced by sbr_dequant().

#define SBR_INIT_VLC_STATIC (   num,
  size 
)
Value:
INIT_VLC_STATIC(&vlc_sbr[num], 9, sbr_tmp[num].table_size / sbr_tmp[num].elem_size, \
sbr_tmp[num].sbr_bits , 1, 1, \
sbr_tmp[num].sbr_codes, sbr_tmp[num].elem_size, sbr_tmp[num].elem_size, \

Definition at line 85 of file aacsbr.c.

Referenced by ff_aac_sbr_init().

#define SBR_VLC_ROW (   name)    { name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) }

Definition at line 91 of file aacsbr.c.

Referenced by ff_aac_sbr_init().

Enumeration Type Documentation

anonymous enum

SBR VLC tables.

Enumerator:
T_HUFFMAN_ENV_1_5DB 
F_HUFFMAN_ENV_1_5DB 
T_HUFFMAN_ENV_BAL_1_5DB 
F_HUFFMAN_ENV_BAL_1_5DB 
T_HUFFMAN_ENV_3_0DB 
F_HUFFMAN_ENV_3_0DB 
T_HUFFMAN_ENV_BAL_3_0DB 
F_HUFFMAN_ENV_BAL_3_0DB 
T_HUFFMAN_NOISE_3_0DB 
T_HUFFMAN_NOISE_BAL_3_0DB 

Definition at line 54 of file aacsbr.c.

anonymous enum

bs_frame_class - frame class of current SBR frame (14496-3 sp04 p98)

Enumerator:
FIXFIX 
FIXVAR 
VARFIX 
VARVAR 

Definition at line 70 of file aacsbr.c.

anonymous enum
Enumerator:
EXTENSION_ID_PS 

Definition at line 77 of file aacsbr.c.

Function Documentation

static void aacsbr_func_ptr_init ( AACSBRContext c)
static

Definition at line 1753 of file aacsbr.c.

Referenced by ff_aac_sbr_ctx_init().

av_cold void ff_aac_sbr_init ( void  )

Initialize SBR.

Definition at line 96 of file aacsbr.c.

Referenced by aac_decode_init().

static void sbr_turnoff ( SpectralBandReplication sbr)
static

Places SBR in pure upsampling mode.

Definition at line 139 of file aacsbr.c.

Referenced by ff_aac_sbr_ctx_init(), read_sbr_data(), sbr_mapping(), and sbr_reset().

av_cold void ff_aac_sbr_ctx_init ( AACContext ac,
SpectralBandReplication sbr 
)

Initialize one SBR context.

Definition at line 149 of file aacsbr.c.

Referenced by che_configure().

av_cold void ff_aac_sbr_ctx_close ( SpectralBandReplication sbr)

Close one SBR context.

Definition at line 167 of file aacsbr.c.

Referenced by aac_decode_close(), and che_configure().

static int qsort_comparison_function_int16 ( const void a,
const void b 
)
static

Definition at line 173 of file aacsbr.c.

Referenced by sbr_make_f_master(), and sbr_make_f_tablelim().

static int in_table_int16 ( const int16_t *  table,
int  last_el,
int16_t  needle 
)
inlinestatic

Definition at line 178 of file aacsbr.c.

Referenced by sbr_make_f_tablelim().

static void sbr_make_f_tablelim ( SpectralBandReplication sbr)
static

Limiter Frequency Band Table (14496-3 sp04 p198)

Definition at line 188 of file aacsbr.c.

Referenced by read_sbr_header(), and sbr_make_f_derived().

static unsigned int read_sbr_header ( SpectralBandReplication sbr,
GetBitContext gb 
)
static

Definition at line 235 of file aacsbr.c.

Referenced by ff_decode_sbr_extension().

static int array_min_int16 ( const int16_t *  array,
int  nel 
)
static

Definition at line 289 of file aacsbr.c.

Referenced by sbr_make_f_master().

static void make_bands ( int16_t *  bands,
int  start,
int  stop,
int  num_bands 
)
static

Definition at line 297 of file aacsbr.c.

Referenced by sbr_make_f_master().

static int check_n_master ( AVCodecContext avctx,
int  n_master,
int  bs_xover_band 
)
static

Definition at line 315 of file aacsbr.c.

Referenced by sbr_make_f_master().

static int sbr_make_f_master ( AACContext ac,
SpectralBandReplication sbr,
SpectrumParameters spectrum 
)
static

Master Frequency Band Table (14496-3 sp04 p194)

Definition at line 332 of file aacsbr.c.

Referenced by sbr_reset().

static int sbr_hf_calc_npatches ( AACContext ac,
SpectralBandReplication sbr 
)
static

High Frequency Generation - Patch Construction (14496-3 sp04 p216 fig. 4.46)

Definition at line 521 of file aacsbr.c.

Referenced by sbr_make_f_derived().

static int sbr_make_f_derived ( AACContext ac,
SpectralBandReplication sbr 
)
static

Derived Frequency Band Tables (14496-3 sp04 p197)

Definition at line 572 of file aacsbr.c.

Referenced by sbr_reset().

static av_always_inline void get_bits1_vector ( GetBitContext gb,
uint8_t vec,
int  elements 
)
static
static int read_sbr_grid ( AACContext ac,
SpectralBandReplication sbr,
GetBitContext gb,
SBRData ch_data 
)
static

Definition at line 639 of file aacsbr.c.

Referenced by read_sbr_channel_pair_element(), and read_sbr_single_channel_element().

static void copy_sbr_grid ( SBRData dst,
const SBRData src 
)
static

Definition at line 781 of file aacsbr.c.

Referenced by read_sbr_channel_pair_element().

static void read_sbr_dtdf ( SpectralBandReplication sbr,
GetBitContext gb,
SBRData ch_data 
)
static

Read how the envelope and noise floor data is delta coded.

Definition at line 799 of file aacsbr.c.

Referenced by read_sbr_channel_pair_element(), and read_sbr_single_channel_element().

static void read_sbr_invf ( SpectralBandReplication sbr,
GetBitContext gb,
SBRData ch_data 
)
static

Read inverse filtering data.

Definition at line 807 of file aacsbr.c.

Referenced by read_sbr_channel_pair_element(), and read_sbr_single_channel_element().

static void read_sbr_envelope ( SpectralBandReplication sbr,
GetBitContext gb,
SBRData ch_data,
int  ch 
)
static

Definition at line 817 of file aacsbr.c.

Referenced by read_sbr_channel_pair_element(), and read_sbr_single_channel_element().

static void read_sbr_noise ( SpectralBandReplication sbr,
GetBitContext gb,
SBRData ch_data,
int  ch 
)
static

Definition at line 886 of file aacsbr.c.

Referenced by read_sbr_channel_pair_element(), and read_sbr_single_channel_element().

static void read_sbr_extension ( AACContext ac,
SpectralBandReplication sbr,
GetBitContext gb,
int  bs_extension_id,
int *  num_bits_left 
)
static

Definition at line 922 of file aacsbr.c.

Referenced by read_sbr_data().

static int read_sbr_single_channel_element ( AACContext ac,
SpectralBandReplication sbr,
GetBitContext gb 
)
static

Definition at line 952 of file aacsbr.c.

Referenced by read_sbr_data().

static int read_sbr_channel_pair_element ( AACContext ac,
SpectralBandReplication sbr,
GetBitContext gb 
)
static

Definition at line 972 of file aacsbr.c.

Referenced by read_sbr_data().

static unsigned int read_sbr_data ( AACContext ac,
SpectralBandReplication sbr,
GetBitContext gb,
int  id_aac 
)
static

Definition at line 1014 of file aacsbr.c.

Referenced by ff_decode_sbr_extension().

static void sbr_reset ( AACContext ac,
SpectralBandReplication sbr 
)
static

Definition at line 1055 of file aacsbr.c.

Referenced by ff_decode_sbr_extension().

int ff_decode_sbr_extension ( AACContext ac,
SpectralBandReplication sbr,
GetBitContext gb_host,
int  crc,
int  cnt,
int  id_aac 
)

Decode Spectral Band Replication extension data; reference: table 4.55.

Decode one SBR element.

Parameters
crcflag indicating the presence of CRC checksum
cntlength of TYPE_FIL syntactic element in bytes
Returns
Returns number of bytes consumed from the TYPE_FIL element.

Definition at line 1076 of file aacsbr.c.

Referenced by decode_extension_payload().

static void sbr_dequant ( SpectralBandReplication sbr,
int  id_aac 
)
static

Dequantization and stereo decoding (14496-3 sp04 p203)

Definition at line 1122 of file aacsbr.c.

Referenced by ff_sbr_apply().

static void sbr_qmf_analysis ( AVFloatDSPContext dsp,
FFTContext mdct,
SBRDSPContext sbrdsp,
const float *  in,
float *  x,
float  z[320],
float  W[2][32][32][2],
int  buf_idx 
)
static

Analysis QMF Bank (14496-3 sp04 p206)

Parameters
xpointer to the beginning of the first sample window
Warray of complex-valued samples split into subbands

Definition at line 1186 of file aacsbr.c.

Referenced by ff_sbr_apply().

static void sbr_qmf_synthesis ( FFTContext mdct,
SBRDSPContext sbrdsp,
AVFloatDSPContext dsp,
float *  out,
float  X[2][38][64],
float  mdct_buf[2][64],
float *  v0,
int *  v_off,
const unsigned int  div 
)
static

Synthesis QMF Bank (14496-3 sp04 p206) and Downsampled Synthesis QMF Bank (14496-3 sp04 p206)

Definition at line 1210 of file aacsbr.c.

Referenced by ff_sbr_apply().

static void sbr_hf_inverse_filter ( SBRDSPContext dsp,
float(*)  alpha0[2],
float(*)  alpha1[2],
const float  X_low[32][40][2],
int  k0 
)
static

High Frequency Generation (14496-3 sp04 p214+) and Inverse Filtering (14496-3 sp04 p214) Warning: This routine does not seem numerically stable.

Definition at line 1261 of file aacsbr.c.

Referenced by aacsbr_func_ptr_init().

static void sbr_chirp ( SpectralBandReplication sbr,
SBRData ch_data 
)
static

Chirp Factors (14496-3 sp04 p214)

Definition at line 1316 of file aacsbr.c.

Referenced by ff_sbr_apply().

static int sbr_lf_gen ( AACContext ac,
SpectralBandReplication sbr,
float  X_low[32][40][2],
const float  W[2][32][32][2],
int  buf_idx 
)
static

Generate the subband filtered lowband.

Definition at line 1337 of file aacsbr.c.

Referenced by aacsbr_func_ptr_init().

static int sbr_hf_gen ( AACContext ac,
SpectralBandReplication sbr,
float  X_high[64][40][2],
const float  X_low[32][40][2],
const float(*)  alpha0[2],
const float(*)  alpha1[2],
const float  bw_array[5],
const uint8_t t_env,
int  bs_num_env 
)
static

High Frequency Generator (14496-3 sp04 p215)

Definition at line 1362 of file aacsbr.c.

Referenced by ff_sbr_apply().

static int sbr_x_gen ( SpectralBandReplication sbr,
float  X[2][38][64],
const float  Y0[38][64][2],
const float  Y1[38][64][2],
const float  X_low[32][40][2],
int  ch 
)
static

Generate the subband filtered lowband.

Definition at line 1397 of file aacsbr.c.

Referenced by aacsbr_func_ptr_init().

static int sbr_mapping ( AACContext ac,
SpectralBandReplication sbr,
SBRData ch_data,
int  e_a[2] 
)
static

High Frequency Adjustment (14496-3 sp04 p217) and Mapping (14496-3 sp04 p217)

Definition at line 1436 of file aacsbr.c.

Referenced by ff_sbr_apply().

static void sbr_env_estimate ( float(*)  e_curr[48],
float  X_high[64][40][2],
SpectralBandReplication sbr,
SBRData ch_data 
)
static

Estimation of current envelope (14496-3 sp04 p218)

Definition at line 1491 of file aacsbr.c.

Referenced by ff_sbr_apply().

static void sbr_gain_calc ( AACContext ac,
SpectralBandReplication sbr,
SBRData ch_data,
const int  e_a[2] 
)
static

Calculation of levels of additional HF signal components (14496-3 sp04 p219) and Calculation of gain (14496-3 sp04 p219)

Definition at line 1537 of file aacsbr.c.

Referenced by ff_sbr_apply().

static void sbr_hf_assemble ( float  Y1[38][64][2],
const float  X_high[64][40][2],
SpectralBandReplication sbr,
SBRData ch_data,
const int  e_a[2] 
)
static

Assembling HF Signals (14496-3 sp04 p220)

Definition at line 1593 of file aacsbr.c.

Referenced by aacsbr_func_ptr_init().

void ff_sbr_apply ( AACContext ac,
SpectralBandReplication sbr,
int  id_aac,
float *  L,
float *  R 
)

Apply one SBR element to one AAC element.

Definition at line 1681 of file aacsbr.c.

Referenced by spectral_to_sample().

Variable Documentation

VLC vlc_sbr[10]
static

Definition at line 81 of file aacsbr.c.

const int8_t vlc_sbr_lav[10]
static
Initial value:
=
{ 60, 60, 24, 24, 31, 31, 12, 12, 31, 12 }

Definition at line 82 of file aacsbr.c.

Referenced by read_sbr_envelope(), and read_sbr_noise().

const int8_t ceil_log2[]
static
Initial value:
= {
0, 1, 2, 2, 3, 3,
}

ceil(log2(index+1))

Definition at line 635 of file aacsbr.c.

Referenced by read_sbr_grid().