FFmpeg
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/float_dsp.h"
25 #include "libavutil/mem_internal.h"
26 #include "libavutil/tx.h"
27 
28 #include "avcodec.h"
29 #include "get_bits.h"
30 #include "dca.h"
31 #include "dca_exss.h"
32 #include "dcadsp.h"
33 
34 #define DCA_LBR_CHANNELS 6
35 #define DCA_LBR_CHANNELS_TOTAL 32
36 #define DCA_LBR_SUBBANDS 32
37 #define DCA_LBR_TONES 512
38 
39 #define DCA_LBR_TIME_SAMPLES 128
40 #define DCA_LBR_TIME_HISTORY 8
41 
45 };
46 
47 typedef struct DCALbrTone {
48  uint8_t x_freq; ///< Spectral line offset
49  uint8_t f_delt; ///< Difference between original and center frequency
50  uint8_t ph_rot; ///< Phase rotation
51  uint8_t pad; ///< Padding field
52  uint8_t amp[DCA_LBR_CHANNELS]; ///< Per-channel amplitude
53  uint8_t phs[DCA_LBR_CHANNELS]; ///< Per-channel phase
54 } DCALbrTone;
55 
56 typedef struct DCALbrDecoder {
59 
60  int sample_rate; ///< Sample rate of LBR audio
61  int ch_mask; ///< LBR speaker mask
62  int flags; ///< Flags for LBR decoder initialization
63  int bit_rate_orig; ///< Original bit rate
64  int bit_rate_scaled; ///< Scaled bit rate
65 
66  int nchannels; ///< Number of fullband channels to decode
67  int nchannels_total; ///< Total number of fullband channels
68  int freq_range; ///< Frequency range of LBR audio
69  int band_limit; ///< Band limit factor
70  int limited_rate; ///< Band limited sample rate
71  int limited_range; ///< Band limited frequency range
72  int res_profile; ///< Resolution profile
73  int nsubbands; ///< Number of encoded subbands
74  int g3_avg_only_start_sb; ///< Subband index where grid 3 scale factors end
75  int min_mono_subband; ///< Subband index where mono encoding starts
76  int max_mono_subband; ///< Subband index where mono encoding ends
77 
78  int framenum; ///< Lower 5 bits of current frame number
79  int lbr_rand; ///< Seed for subband randomization
80  int warned; ///< Flags for warning suppression
81 
82  uint8_t quant_levels[DCA_LBR_CHANNELS / 2][DCA_LBR_SUBBANDS]; ///< Quantization levels
83  uint8_t sb_indices[DCA_LBR_SUBBANDS]; ///< Subband reordering indices
84 
85  uint8_t sec_ch_sbms[DCA_LBR_CHANNELS / 2][DCA_LBR_SUBBANDS]; ///< Right channel inversion or mid/side decoding flags
86  uint8_t sec_ch_lrms[DCA_LBR_CHANNELS / 2][DCA_LBR_SUBBANDS]; ///< Flags indicating if left/right channel are swapped
87  uint32_t ch_pres[DCA_LBR_CHANNELS]; ///< Subband allocation flags
88 
89  uint8_t grid_1_scf[DCA_LBR_CHANNELS][12][8]; ///< Grid 1 scale factors
90  uint8_t grid_2_scf[DCA_LBR_CHANNELS][3][64]; ///< Grid 2 scale factors
91 
92  int8_t grid_3_avg[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS - 4]; ///< Grid 3 average values
93  int8_t grid_3_scf[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS - 4][8]; ///< Grid 3 scale factors
94  uint32_t grid_3_pres[DCA_LBR_CHANNELS]; ///< Grid 3 scale factors presence flags
95 
96  uint8_t high_res_scf[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS][8]; ///< High-frequency resolution scale factors
97 
98  uint8_t part_stereo[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS / 4][5]; ///< Partial stereo coefficients
99  uint8_t part_stereo_pres; ///< Partial stereo coefficients presence flags
100 
101  float lpc_coeff[2][DCA_LBR_CHANNELS][3][2][8]; ///< Predictor coefficients
102 
103  float sb_scf[DCA_LBR_SUBBANDS]; ///< Subband randomization scale factors
104 
105  float *time_samples[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS]; ///< Time samples
106 
107  float *ts_buffer; ///< Time sample buffer base
108  unsigned int ts_size; ///< Time sample buffer size
109 
110  DECLARE_ALIGNED(32, float, history)[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS * 4]; ///< IMDCT history
111  DECLARE_ALIGNED(32, float, window)[DCA_LBR_SUBBANDS * 4]; ///< Long window for IMDCT
112 
113  DECLARE_ALIGNED(32, float, lfe_data)[64]; ///< Decimated LFE samples
114  DECLARE_ALIGNED(32, float, lfe_history)[5][2]; ///< LFE IIR filter history
115  float lfe_scale; ///< Scale factor of LFE samples before IIR filter
116 
117  uint8_t tonal_scf[6]; ///< Tonal scale factors
118  uint16_t tonal_bounds[5][32][2]; ///< Per-group per-subframe start/end positions of tones
119  DCALbrTone tones[DCA_LBR_TONES]; ///< Circular buffer of tones
120  int ntones; ///< Circular buffer head position
121 
126 } DCALbrDecoder;
127 
128 int ff_dca_lbr_parse(DCALbrDecoder *s, const uint8_t *data, DCAExssAsset *asset);
134 
135 #endif
DCALbrDecoder::bit_rate_orig
int bit_rate_orig
Original bit rate.
Definition: dca_lbr.h:63
DCALbrDecoder::ts_buffer
float * ts_buffer
Time sample buffer base.
Definition: dca_lbr.h:107
DCALbrDecoder::min_mono_subband
int min_mono_subband
Subband index where mono encoding starts.
Definition: dca_lbr.h:75
DCALbrDecoder::ch_mask
int ch_mask
LBR speaker mask.
Definition: dca_lbr.h:61
mem_internal.h
dca.h
DCALbrDecoder::lfe_history
float lfe_history[5][2]
LFE IIR filter history.
Definition: dca_lbr.h:114
AVTXContext
Definition: tx_priv.h:235
DCALbrDecoder::imdct_fn
av_tx_fn imdct_fn
Definition: dca_lbr.h:123
ff_dca_lbr_init_tables
av_cold void ff_dca_lbr_init_tables(void)
Definition: dca_lbr.c:134
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
DCALbrDecoder::tones
DCALbrTone tones[DCA_LBR_TONES]
Circular buffer of tones.
Definition: dca_lbr.h:119
DCALbrDecoder::dcadsp
DCADSPContext * dcadsp
Definition: dca_lbr.h:125
data
const char data[16]
Definition: mxf.c:148
DCALbrTone::phs
uint8_t phs[DCA_LBR_CHANNELS]
Per-channel phase.
Definition: dca_lbr.h:53
DCALbrDecoder::imdct
AVTXContext * imdct
Definition: dca_lbr.h:122
DCALbrTone::x_freq
uint8_t x_freq
Spectral line offset.
Definition: dca_lbr.h:48
DCALbrDecoder::grid_2_scf
uint8_t grid_2_scf[DCA_LBR_CHANNELS][3][64]
Grid 2 scale factors.
Definition: dca_lbr.h:90
DCALbrDecoder::max_mono_subband
int max_mono_subband
Subband index where mono encoding ends.
Definition: dca_lbr.h:76
DCAExssAsset
Definition: dca_exss.h:29
GetBitContext
Definition: get_bits.h:108
DCALbrTone::amp
uint8_t amp[DCA_LBR_CHANNELS]
Per-channel amplitude.
Definition: dca_lbr.h:52
DCALbrDecoder::part_stereo
uint8_t part_stereo[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS/4][5]
Partial stereo coefficients.
Definition: dca_lbr.h:98
DCALbrDecoder::nchannels_total
int nchannels_total
Total number of fullband channels.
Definition: dca_lbr.h:67
DCALbrDecoder::gb
GetBitContext gb
Definition: dca_lbr.h:58
av_cold
#define av_cold
Definition: attributes.h:90
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
DCALbrDecoder::g3_avg_only_start_sb
int g3_avg_only_start_sb
Subband index where grid 3 scale factors end.
Definition: dca_lbr.h:74
s
#define s(width, name)
Definition: cbs_vp9.c:198
DCALbrDecoder::res_profile
int res_profile
Resolution profile.
Definition: dca_lbr.h:72
DCALbrDecoder::tonal_scf
uint8_t tonal_scf[6]
Tonal scale factors.
Definition: dca_lbr.h:117
DCALbrDecoder::window
float window[DCA_LBR_SUBBANDS *4]
Long window for IMDCT.
Definition: dca_lbr.h:111
DCALbrDecoder::grid_3_scf
int8_t grid_3_scf[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS - 4][8]
Grid 3 scale factors.
Definition: dca_lbr.h:93
DCALbrDecoder::freq_range
int freq_range
Frequency range of LBR audio.
Definition: dca_lbr.h:68
get_bits.h
DCALbrDecoder::nchannels
int nchannels
Number of fullband channels to decode.
Definition: dca_lbr.h:66
DCALbrDecoder::limited_range
int limited_range
Band limited frequency range.
Definition: dca_lbr.h:71
dca_exss.h
DCALbrDecoder::sec_ch_sbms
uint8_t sec_ch_sbms[DCA_LBR_CHANNELS/2][DCA_LBR_SUBBANDS]
Right channel inversion or mid/side decoding flags.
Definition: dca_lbr.h:85
DCALbrDecoder::tonal_bounds
uint16_t tonal_bounds[5][32][2]
Per-group per-subframe start/end positions of tones.
Definition: dca_lbr.h:118
frame
static AVFrame * frame
Definition: demux_decode.c:54
DCALbrDecoder
Definition: dca_lbr.h:56
DCALbrDecoder::lfe_scale
float lfe_scale
Scale factor of LFE samples before IIR filter.
Definition: dca_lbr.h:115
DCALbrTone
Definition: dca_lbr.h:47
DCALbrDecoder::part_stereo_pres
uint8_t part_stereo_pres
Partial stereo coefficients presence flags.
Definition: dca_lbr.h:99
DCADSPContext
Definition: dcadsp.h:30
float_dsp.h
DCALbrDecoder::warned
int warned
Flags for warning suppression.
Definition: dca_lbr.h:80
ff_dca_lbr_close
av_cold void ff_dca_lbr_close(DCALbrDecoder *s)
Definition: dca_lbr.c:1831
DCA_LBR_HEADER_SYNC_ONLY
@ DCA_LBR_HEADER_SYNC_ONLY
Definition: dca_lbr.h:43
DCALbrTone::ph_rot
uint8_t ph_rot
Phase rotation.
Definition: dca_lbr.h:50
DCALbrDecoder::lfe_data
float lfe_data[64]
Decimated LFE samples.
Definition: dca_lbr.h:113
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:87
DCALbrDecoder::sample_rate
int sample_rate
Sample rate of LBR audio.
Definition: dca_lbr.h:60
DCALbrDecoder::lbr_rand
int lbr_rand
Seed for subband randomization.
Definition: dca_lbr.h:79
AVFloatDSPContext
Definition: float_dsp.h:24
DCALbrDecoder::avctx
AVCodecContext * avctx
Definition: dca_lbr.h:57
DCALbrDecoder::sb_indices
uint8_t sb_indices[DCA_LBR_SUBBANDS]
Subband reordering indices.
Definition: dca_lbr.h:83
DCA_LBR_HEADER_DECODER_INIT
@ DCA_LBR_HEADER_DECODER_INIT
Definition: dca_lbr.h:44
DCALbrTone::f_delt
uint8_t f_delt
Difference between original and center frequency.
Definition: dca_lbr.h:49
dcadsp.h
ff_dca_lbr_filter_frame
int ff_dca_lbr_filter_frame(DCALbrDecoder *s, AVFrame *frame)
Definition: dca_lbr.c:1736
DCALbrDecoder::sec_ch_lrms
uint8_t sec_ch_lrms[DCA_LBR_CHANNELS/2][DCA_LBR_SUBBANDS]
Flags indicating if left/right channel are swapped.
Definition: dca_lbr.h:86
DCALbrDecoder::grid_3_pres
uint32_t grid_3_pres[DCA_LBR_CHANNELS]
Grid 3 scale factors presence flags.
Definition: dca_lbr.h:94
DCALbrDecoder::ch_pres
uint32_t ch_pres[DCA_LBR_CHANNELS]
Subband allocation flags.
Definition: dca_lbr.h:87
DCALBRHeader
DCALBRHeader
Definition: dca_lbr.h:42
DCALbrDecoder::band_limit
int band_limit
Band limit factor.
Definition: dca_lbr.h:69
avcodec.h
DCALbrDecoder::nsubbands
int nsubbands
Number of encoded subbands.
Definition: dca_lbr.h:73
DCA_LBR_TONES
#define DCA_LBR_TONES
Definition: dca_lbr.h:37
DCALbrDecoder::quant_levels
uint8_t quant_levels[DCA_LBR_CHANNELS/2][DCA_LBR_SUBBANDS]
Quantization levels.
Definition: dca_lbr.h:82
DCALbrDecoder::bit_rate_scaled
int bit_rate_scaled
Scaled bit rate.
Definition: dca_lbr.h:64
AVCodecContext
main external API structure.
Definition: avcodec.h:441
ff_dca_lbr_flush
av_cold void ff_dca_lbr_flush(DCALbrDecoder *s)
Definition: dca_lbr.c:1798
DCALbrDecoder::grid_3_avg
int8_t grid_3_avg[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS - 4]
Grid 3 average values.
Definition: dca_lbr.h:92
DCALbrDecoder::ts_size
unsigned int ts_size
Time sample buffer size.
Definition: dca_lbr.h:108
DCALbrDecoder::flags
int flags
Flags for LBR decoder initialization.
Definition: dca_lbr.h:62
DCALbrDecoder::limited_rate
int limited_rate
Band limited sample rate.
Definition: dca_lbr.h:70
DCALbrDecoder::lpc_coeff
float lpc_coeff[2][DCA_LBR_CHANNELS][3][2][8]
Predictor coefficients.
Definition: dca_lbr.h:101
DCA_LBR_CHANNELS
#define DCA_LBR_CHANNELS
Definition: dca_lbr.h:34
DCALbrDecoder::framenum
int framenum
Lower 5 bits of current frame number.
Definition: dca_lbr.h:78
DCALbrDecoder::high_res_scf
uint8_t high_res_scf[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS][8]
High-frequency resolution scale factors.
Definition: dca_lbr.h:96
DCALbrDecoder::grid_1_scf
uint8_t grid_1_scf[DCA_LBR_CHANNELS][12][8]
Grid 1 scale factors.
Definition: dca_lbr.h:89
DCALbrDecoder::ntones
int ntones
Circular buffer head position.
Definition: dca_lbr.h:120
ff_dca_lbr_init
av_cold int ff_dca_lbr_init(DCALbrDecoder *s)
Definition: dca_lbr.c:1822
DCALbrTone::pad
uint8_t pad
Padding field.
Definition: dca_lbr.h:51
DCALbrDecoder::time_samples
float * time_samples[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS]
Time samples.
Definition: dca_lbr.h:105
ff_dca_lbr_parse
int ff_dca_lbr_parse(DCALbrDecoder *s, const uint8_t *data, DCAExssAsset *asset)
Definition: dca_lbr.c:1169
DCA_LBR_SUBBANDS
#define DCA_LBR_SUBBANDS
Definition: dca_lbr.h:36
DCALbrDecoder::history
float history[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS *4]
IMDCT history.
Definition: dca_lbr.h:110
tx.h
DCALbrDecoder::sb_scf
float sb_scf[DCA_LBR_SUBBANDS]
Subband randomization scale factors.
Definition: dca_lbr.h:103
DCALbrDecoder::fdsp
AVFloatDSPContext * fdsp
Definition: dca_lbr.h:124