FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dca_lbr.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 foo86
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef AVCODEC_DCA_LBR_H
22 #define AVCODEC_DCA_LBR_H
23 
24 #include "libavutil/common.h"
25 #include "libavutil/float_dsp.h"
26 #include "libavutil/mem.h"
27 
28 #include "avcodec.h"
29 #include "internal.h"
30 #include "get_bits.h"
31 #include "dca.h"
32 #include "dca_exss.h"
33 #include "dcadsp.h"
34 #include "fft.h"
35 
36 #define DCA_LBR_CHANNELS 6
37 #define DCA_LBR_CHANNELS_TOTAL 32
38 #define DCA_LBR_SUBBANDS 32
39 #define DCA_LBR_TONES 512
40 
41 #define DCA_LBR_TIME_SAMPLES 128
42 #define DCA_LBR_TIME_HISTORY 8
43 
47 };
48 
49 typedef struct DCALbrTone {
50  uint8_t x_freq; ///< Spectral line offset
51  uint8_t f_delt; ///< Difference between original and center frequency
52  uint8_t ph_rot; ///< Phase rotation
53  uint8_t pad; ///< Padding field
54  uint8_t amp[DCA_LBR_CHANNELS]; ///< Per-channel amplitude
55  uint8_t phs[DCA_LBR_CHANNELS]; ///< Per-channel phase
56 } DCALbrTone;
57 
58 typedef struct DCALbrDecoder {
61 
62  int sample_rate; ///< Sample rate of LBR audio
63  int ch_mask; ///< LBR speaker mask
64  int flags; ///< Flags for LBR decoder initialization
65  int bit_rate_orig; ///< Original bit rate
66  int bit_rate_scaled; ///< Scaled bit rate
67 
68  int nchannels; ///< Number of fullband channels to decode
69  int nchannels_total; ///< Total number of fullband channels
70  int freq_range; ///< Frequency range of LBR audio
71  int band_limit; ///< Band limit factor
72  int limited_rate; ///< Band limited sample rate
73  int limited_range; ///< Band limited frequency range
74  int res_profile; ///< Resolution profile
75  int nsubbands; ///< Number of encoded subbands
76  int g3_avg_only_start_sb; ///< Subband index where grid 3 scale factors end
77  int min_mono_subband; ///< Subband index where mono encoding starts
78  int max_mono_subband; ///< Subband index where mono encoding ends
79 
80  int framenum; ///< Lower 5 bits of current frame number
81  int lbr_rand; ///< Seed for subband randomization
82  int warned; ///< Flags for warning suppression
83 
84  uint8_t quant_levels[DCA_LBR_CHANNELS / 2][DCA_LBR_SUBBANDS]; ///< Quantization levels
85  uint8_t sb_indices[DCA_LBR_SUBBANDS]; ///< Subband reordering indices
86 
87  uint8_t sec_ch_sbms[DCA_LBR_CHANNELS / 2][DCA_LBR_SUBBANDS]; ///< Right channel inversion or mid/side decoding flags
88  uint8_t sec_ch_lrms[DCA_LBR_CHANNELS / 2][DCA_LBR_SUBBANDS]; ///< Flags indicating if left/right channel are swapped
89  uint32_t ch_pres[DCA_LBR_CHANNELS]; ///< Subband allocation flags
90 
91  uint8_t grid_1_scf[DCA_LBR_CHANNELS][12][8]; ///< Grid 1 scale factors
92  uint8_t grid_2_scf[DCA_LBR_CHANNELS][3][64]; ///< Grid 2 scale factors
93 
94  int8_t grid_3_avg[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS - 4]; ///< Grid 3 average values
95  int8_t grid_3_scf[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS - 4][8]; ///< Grid 3 scale factors
96  uint32_t grid_3_pres[DCA_LBR_CHANNELS]; ///< Grid 3 scale factors presence flags
97 
98  uint8_t high_res_scf[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS][8]; ///< High-frequency resolution scale factors
99 
100  uint8_t part_stereo[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS / 4][5]; ///< Partial stereo coefficients
101  uint8_t part_stereo_pres; ///< Partial stereo coefficients presence flags
102 
103  float lpc_coeff[2][DCA_LBR_CHANNELS][3][2][8]; ///< Predictor coefficients
104 
105  float sb_scf[DCA_LBR_SUBBANDS]; ///< Subband randomization scale factors
106 
107  float *time_samples[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS]; ///< Time samples
108 
109  float *ts_buffer; ///< Time sample buffer base
110  unsigned int ts_size; ///< Time sample buffer size
111 
112  DECLARE_ALIGNED(32, float, history)[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS * 4]; ///< IMDCT history
113  DECLARE_ALIGNED(32, float, window)[DCA_LBR_SUBBANDS * 4]; ///< Long window for IMDCT
114 
115  DECLARE_ALIGNED(32, float, lfe_data)[64]; ///< Decimated LFE samples
116  DECLARE_ALIGNED(32, float, lfe_history)[5][2]; ///< LFE IIR filter history
117  float lfe_scale; ///< Scale factor of LFE samples before IIR filter
118 
119  uint8_t tonal_scf[6]; ///< Tonal scale factors
120  uint16_t tonal_bounds[5][32][2]; ///< Per-group per-subframe start/end positions of tones
121  DCALbrTone tones[DCA_LBR_TONES]; ///< Circular buffer of tones
122  int ntones; ///< Circular buffer head position
123 
127 } DCALbrDecoder;
128 
134 
135 #endif
int ntones
Circular buffer head position.
Definition: dca_lbr.h:122
float window[DCA_LBR_SUBBANDS *4]
Long window for IMDCT.
Definition: dca_lbr.h:113
const char * s
Definition: avisynth_c.h:768
This structure describes decoded (raw) audio or video data.
Definition: frame.h:201
int bit_rate_scaled
Scaled bit rate.
Definition: dca_lbr.h:66
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
uint8_t grid_2_scf[DCA_LBR_CHANNELS][3][64]
Grid 2 scale factors.
Definition: dca_lbr.h:92
uint32_t ch_pres[DCA_LBR_CHANNELS]
Subband allocation flags.
Definition: dca_lbr.h:89
Memory handling functions.
int max_mono_subband
Subband index where mono encoding ends.
Definition: dca_lbr.h:78
unsigned int ts_size
Time sample buffer size.
Definition: dca_lbr.h:110
int nchannels_total
Total number of fullband channels.
Definition: dca_lbr.h:69
int freq_range
Frequency range of LBR audio.
Definition: dca_lbr.h:70
uint8_t x_freq
Spectral line offset.
Definition: dca_lbr.h:50
av_cold int ff_dca_lbr_init(DCALbrDecoder *s)
Definition: dca_lbr.c:1794
int bit_rate_orig
Original bit rate.
Definition: dca_lbr.h:65
float * ts_buffer
Time sample buffer base.
Definition: dca_lbr.h:109
float sb_scf[DCA_LBR_SUBBANDS]
Subband randomization scale factors.
Definition: dca_lbr.h:105
float lfe_scale
Scale factor of LFE samples before IIR filter.
Definition: dca_lbr.h:117
uint8_t
#define av_cold
Definition: attributes.h:82
int ch_mask
LBR speaker mask.
Definition: dca_lbr.h:63
uint8_t part_stereo_pres
Partial stereo coefficients presence flags.
Definition: dca_lbr.h:101
int ff_dca_lbr_parse(DCALbrDecoder *s, uint8_t *data, DCAExssAsset *asset)
Definition: dca_lbr.c:1143
static AVFrame * frame
DCADSPContext * dcadsp
Definition: dca_lbr.h:126
uint8_t phs[DCA_LBR_CHANNELS]
Per-channel phase.
Definition: dca_lbr.h:55
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
Definition: mem.h:104
bitstream reader API header.
int nchannels
Number of fullband channels to decode.
Definition: dca_lbr.h:68
av_cold void ff_dca_lbr_flush(DCALbrDecoder *s)
Definition: dca_lbr.c:1770
av_cold void ff_dca_lbr_close(DCALbrDecoder *s)
Definition: dca_lbr.c:1805
int sample_rate
Sample rate of LBR audio.
Definition: dca_lbr.h:62
DCALbrTone tones[DCA_LBR_TONES]
Circular buffer of tones.
Definition: dca_lbr.h:121
uint8_t tonal_scf[6]
Tonal scale factors.
Definition: dca_lbr.h:119
uint8_t ph_rot
Phase rotation.
Definition: dca_lbr.h:52
int warned
Flags for warning suppression.
Definition: dca_lbr.h:82
float lfe_history[5][2]
LFE IIR filter history.
Definition: dca_lbr.h:116
uint8_t part_stereo[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS/4][5]
Partial stereo coefficients.
Definition: dca_lbr.h:100
uint8_t amp[DCA_LBR_CHANNELS]
Per-channel amplitude.
Definition: dca_lbr.h:54
uint16_t tonal_bounds[5][32][2]
Per-group per-subframe start/end positions of tones.
Definition: dca_lbr.h:120
#define DCA_LBR_CHANNELS
Definition: dca_lbr.h:36
Definition: fft.h:88
int lbr_rand
Seed for subband randomization.
Definition: dca_lbr.h:81
uint8_t sec_ch_sbms[DCA_LBR_CHANNELS/2][DCA_LBR_SUBBANDS]
Right channel inversion or mid/side decoding flags.
Definition: dca_lbr.h:87
int8_t grid_3_avg[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS-4]
Grid 3 average values.
Definition: dca_lbr.h:94
int nsubbands
Number of encoded subbands.
Definition: dca_lbr.h:75
GetBitContext gb
Definition: dca_lbr.h:60
#define DCA_LBR_TONES
Definition: dca_lbr.h:39
AVCodecContext * avctx
Definition: dca_lbr.h:59
uint8_t grid_1_scf[DCA_LBR_CHANNELS][12][8]
Grid 1 scale factors.
Definition: dca_lbr.h:91
float lpc_coeff[2][DCA_LBR_CHANNELS][3][2][8]
Predictor coefficients.
Definition: dca_lbr.h:103
float history[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS *4]
IMDCT history.
Definition: dca_lbr.h:112
Libavcodec external API header.
int8_t grid_3_scf[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS-4][8]
Grid 3 scale factors.
Definition: dca_lbr.h:95
int band_limit
Band limit factor.
Definition: dca_lbr.h:71
main external API structure.
Definition: avcodec.h:1761
FFTContext imdct
Definition: dca_lbr.h:124
int res_profile
Resolution profile.
Definition: dca_lbr.h:74
uint8_t sb_indices[DCA_LBR_SUBBANDS]
Subband reordering indices.
Definition: dca_lbr.h:85
int limited_range
Band limited frequency range.
Definition: dca_lbr.h:73
uint8_t f_delt
Difference between original and center frequency.
Definition: dca_lbr.h:51
int framenum
Lower 5 bits of current frame number.
Definition: dca_lbr.h:80
int limited_rate
Band limited sample rate.
Definition: dca_lbr.h:72
uint8_t sec_ch_lrms[DCA_LBR_CHANNELS/2][DCA_LBR_SUBBANDS]
Flags indicating if left/right channel are swapped.
Definition: dca_lbr.h:88
float lfe_data[64]
Decimated LFE samples.
Definition: dca_lbr.h:115
common internal api header.
common internal and external API header
uint32_t grid_3_pres[DCA_LBR_CHANNELS]
Grid 3 scale factors presence flags.
Definition: dca_lbr.h:96
int ff_dca_lbr_filter_frame(DCALbrDecoder *s, AVFrame *frame)
Definition: dca_lbr.c:1710
#define DCA_LBR_SUBBANDS
Definition: dca_lbr.h:38
float * time_samples[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS]
Time samples.
Definition: dca_lbr.h:107
AVFloatDSPContext * fdsp
Definition: dca_lbr.h:125
DCALBRHeader
Definition: dca_lbr.h:44
uint8_t pad
Padding field.
Definition: dca_lbr.h:53
int flags
Flags for LBR decoder initialization.
Definition: dca_lbr.h:64
uint8_t quant_levels[DCA_LBR_CHANNELS/2][DCA_LBR_SUBBANDS]
Quantization levels.
Definition: dca_lbr.h:84
int min_mono_subband
Subband index where mono encoding starts.
Definition: dca_lbr.h:77
int g3_avg_only_start_sb
Subband index where grid 3 scale factors end.
Definition: dca_lbr.h:76
uint8_t high_res_scf[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS][8]
High-frequency resolution scale factors.
Definition: dca_lbr.h:98