FFmpeg  4.0
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 #include "fft.h"
34 #include "aacps.h"
35 #include "sbrdsp.h"
36 
37 typedef struct AACContext AACContext;
38 
39 /**
40  * Spectral Band Replication header - spectrum parameters that invoke a reset if they differ from the previous header.
41  */
42 typedef struct SpectrumParameters {
46 
47  /**
48  * @name Variables associated with bs_header_extra_1
49  * @{
50  */
54  /** @} */
56 
57 #define SBR_SYNTHESIS_BUF_SIZE ((1280-128)*2)
58 
59 /**
60  * Spectral Band Replication per channel data
61  */
62 typedef struct SBRData {
63  /**
64  * @name Main bitstream data variables
65  * @{
66  */
67  unsigned bs_frame_class;
70  uint8_t bs_freq_res[7];
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  * @name State variables
81  * @{
82  */
83  DECLARE_ALIGNED(32, INTFLOAT, synthesis_filterbank_samples)[SBR_SYNTHESIS_BUF_SIZE];
84  DECLARE_ALIGNED(32, INTFLOAT, analysis_filterbank_samples) [1312];
86  ///l_APrev and l_A
87  int e_a[2];
88  ///Chirp factors
89  INTFLOAT bw_array[5];
90  ///QMF values of the original signal
91  INTFLOAT W[2][32][32][2];
92  ///QMF output of the HF adjustor
93  int Ypos;
94  DECLARE_ALIGNED(16, INTFLOAT, Y)[2][38][64][2];
95  DECLARE_ALIGNED(16, AAC_FLOAT, g_temp)[42][48];
96  AAC_FLOAT q_temp[42][48];
97  uint8_t s_indexmapped[8][48];
98  ///Envelope scalefactors
99  uint8_t env_facs_q[6][48];
100  AAC_FLOAT env_facs[6][48];
101  ///Noise scalefactors
102  uint8_t noise_facs_q[3][5];
103  AAC_FLOAT noise_facs[3][5];
104  ///Envelope time borders
105  uint8_t t_env[8];
106  ///Envelope time border of the last envelope of the previous frame
108  ///Noise time borders
109  uint8_t t_q[3];
110  unsigned f_indexnoise;
111  unsigned f_indexsine;
112  /** @} */
113 } SBRData;
114 
116 
117 /**
118  * aacsbr functions pointers
119  */
120 typedef struct AACSBRContext {
122  INTFLOAT X_low[32][40][2], const INTFLOAT W[2][32][32][2],
123  int buf_idx);
124  void (*sbr_hf_assemble)(INTFLOAT Y1[38][64][2],
125  const INTFLOAT X_high[64][40][2],
126  SpectralBandReplication *sbr, SBRData *ch_data,
127  const int e_a[2]);
129  const INTFLOAT Y0[38][64][2], const INTFLOAT Y1[38][64][2],
130  const INTFLOAT X_low[32][40][2], int ch);
132  INTFLOAT (*alpha0)[2], INTFLOAT (*alpha1)[2],
133  const INTFLOAT X_low[32][40][2], int k0);
134 } AACSBRContext;
135 
136 /**
137  * Spectral Band Replication
138  */
141  int start;
143  int id_aac;
144  int reset;
147  /**
148  * @name Variables associated with bs_header_extra_2
149  * @{
150  */
155  /** @} */
156  unsigned bs_coupling;
157  AAC_SIGNE k[5]; ///< k0, k1, k2
158  ///kx', and kx respectively, kx is the first QMF subband where SBR is used.
159  ///kx' is its value from the previous frame
160  AAC_SIGNE kx[2];
161  ///M' and M respectively, M is the number of QMF subbands that use SBR.
162  AAC_SIGNE m[2];
163  unsigned kx_and_m_pushed;
164  ///The number of frequency bands in f_master
168  ///N_Low and N_High respectively, the number of frequency bands for low and high resolution
170  ///Number of noise floor bands
172  ///Number of limiter bands
174  ///The master QMF frequency grouping
175  uint16_t f_master[49];
176  ///Frequency borders for low resolution SBR
177  uint16_t f_tablelow[25];
178  ///Frequency borders for high resolution SBR
179  uint16_t f_tablehigh[49];
180  ///Frequency borders for noise floors
181  uint16_t f_tablenoise[6];
182  ///Frequency borders for the limiter
183  uint16_t f_tablelim[30];
185  uint8_t patch_num_subbands[6];
186  uint8_t patch_start_subband[6];
187  ///QMF low frequency input to the HF generator
188  DECLARE_ALIGNED(16, INTFLOAT, X_low)[32][40][2];
189  ///QMF output of the HF generator
190  DECLARE_ALIGNED(16, INTFLOAT, X_high)[64][40][2];
191  ///QMF values of the reconstructed signal
192  DECLARE_ALIGNED(16, INTFLOAT, X)[2][2][38][64];
193  ///Zeroth coefficient used to filter the subband signals
194  DECLARE_ALIGNED(16, INTFLOAT, alpha0)[64][2];
195  ///First coefficient used to filter the subband signals
196  DECLARE_ALIGNED(16, INTFLOAT, alpha1)[64][2];
197  ///Dequantized envelope scalefactors, remapped
198  AAC_FLOAT e_origmapped[7][48];
199  ///Dequantized noise scalefactors, remapped
200  AAC_FLOAT q_mapped[7][48];
201  ///Sinusoidal presence, remapped
202  uint8_t s_mapped[7][48];
203  ///Estimated envelope
204  AAC_FLOAT e_curr[7][48];
205  ///Amplitude adjusted noise scalefactors
206  AAC_FLOAT q_m[7][48];
207  ///Sinusoidal levels
208  AAC_FLOAT s_m[7][48];
209  AAC_FLOAT gain[7][48];
210  DECLARE_ALIGNED(32, INTFLOAT, qmf_filter_scratch)[5][64];
215 };
216 
217 #endif /* AVCODEC_SBR_H */
unsigned bs_add_harmonic_flag
Definition: sbr.h:68
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)
Definition: aacsbr.c:276
unsigned bs_smoothing_mode
Definition: sbr.h:154
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPL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MT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&HAVE_MMX) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
FFTContext mdct
Definition: sbr.h:212
uint8_t bs_xover_band
Definition: sbr.h:45
SpectrumParameters spectrum_params
Definition: sbr.h:145
unsigned kx_and_m_pushed
Definition: sbr.h:163
float INTFLOAT
Definition: aac_defines.h:86
AAC_SIGNE num_patches
Definition: sbr.h:184
uint8_t
#define Y
Definition: vf_boxblur.c:76
AAC_SIGNE n_lim
Number of limiter bands.
Definition: sbr.h:173
const char data[16]
Definition: mxf.c:90
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
Definition: mem.h:112
AAC_SIGNE bs_num_noise
Definition: sbr.h:71
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: Thi...
Definition: aacsbr.c:140
Spectral Band Replication header - spectrum parameters that invoke a reset if they differ from the pr...
Definition: sbr.h:42
unsigned bs_interpol_freq
Definition: sbr.h:153
FFTContext mdct_ana
Definition: sbr.h:211
unsigned f_indexnoise
Definition: sbr.h:110
uint8_t t_env_num_env_old
Envelope time border of the last envelope of the previous frame.
Definition: sbr.h:107
Definition: fft.h:88
unsigned bs_amp_res
Definition: sbr.h:76
uint8_t bs_freq_scale
Definition: sbr.h:51
unsigned bs_limiter_gains
Definition: sbr.h:152
float AAC_FLOAT
Definition: aac_defines.h:90
int n
Definition: avisynth_c.h:684
static int sbr_lf_gen(AACContext *ac, SpectralBandReplication *sbr, INTFLOAT X_low[32][40][2], const INTFLOAT W[2][32][32][2], int buf_idx)
Generate the subband filtered lowband.
#define INTFLOAT
AAC_SIGNE bs_num_env
Definition: sbr.h:69
#define SBR_SYNTHESIS_BUF_SIZE
Definition: sbr.h:57
typedef void(RENAME(mix_any_func_type))
#define W(a, i, v)
Definition: jpegls.h:124
int synthesis_filterbank_samples_offset
Definition: sbr.h:85
uint8_t bs_noise_bands
Definition: sbr.h:53
main AAC context
Definition: aac.h:293
AAC_SIGNE n_master
The number of frequency bands in f_master.
Definition: sbr.h:165
AACSBRContext c
Definition: sbr.h:214
uint8_t bs_stop_freq
Definition: sbr.h:44
static 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)
Generate the subband filtered lowband.
int
unsigned f_indexsine
Definition: sbr.h:111
unsigned AAC_SIGNE
Definition: aac_defines.h:91
aacsbr functions pointers
Definition: sbr.h:120
Spectral Band Replication per channel data.
Definition: sbr.h:62
unsigned bs_limiter_bands
Definition: sbr.h:151
int Ypos
QMF output of the HF adjustor.
Definition: sbr.h:93
uint8_t bs_alter_scale
Definition: sbr.h:52
unsigned bs_frame_class
Definition: sbr.h:67
SBRDSPContext dsp
Definition: sbr.h:213
AAC_SIGNE n_q
Number of noise floor bands.
Definition: sbr.h:171
unsigned bs_coupling
Definition: sbr.h:156
Spectral Band Replication.
Definition: sbr.h:139
PSContext ps
Definition: sbr.h:167
uint8_t bs_start_freq
Definition: sbr.h:43