blob: e6ca8057e9d0739fcf74b69c91828cf5ff472d34
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 | |
44 | typedef struct DCALbrTone { |
45 | uint8_t x_freq; ///< Spectral line offset |
46 | uint8_t f_delt; ///< Difference between original and center frequency |
47 | uint8_t ph_rot; ///< Phase rotation |
48 | uint8_t pad; ///< Padding field |
49 | uint8_t amp[DCA_LBR_CHANNELS]; ///< Per-channel amplitude |
50 | uint8_t phs[DCA_LBR_CHANNELS]; ///< Per-channel phase |
51 | } DCALbrTone; |
52 | |
53 | typedef struct DCALbrDecoder { |
54 | AVCodecContext *avctx; |
55 | GetBitContext gb; |
56 | |
57 | int sample_rate; ///< Sample rate of LBR audio |
58 | int ch_mask; ///< LBR speaker mask |
59 | int flags; ///< Flags for LBR decoder initialization |
60 | int bit_rate_orig; ///< Original bit rate |
61 | int bit_rate_scaled; ///< Scaled bit rate |
62 | |
63 | int nchannels; ///< Number of fullband channels to decode |
64 | int nchannels_total; ///< Total number of fullband channels |
65 | int freq_range; ///< Frequency range of LBR audio |
66 | int band_limit; ///< Band limit factor |
67 | int limited_rate; ///< Band limited sample rate |
68 | int limited_range; ///< Band limited frequency range |
69 | int res_profile; ///< Resolution profile |
70 | int nsubbands; ///< Number of encoded subbands |
71 | int g3_avg_only_start_sb; ///< Subband index where grid 3 scale factors end |
72 | int min_mono_subband; ///< Subband index where mono encoding starts |
73 | int max_mono_subband; ///< Subband index where mono encoding ends |
74 | |
75 | int framenum; ///< Lower 5 bits of current frame number |
76 | int lbr_rand; ///< Seed for subband randomization |
77 | int warned; ///< Flags for warning suppression |
78 | |
79 | uint8_t quant_levels[DCA_LBR_CHANNELS / 2][DCA_LBR_SUBBANDS]; ///< Quantization levels |
80 | uint8_t sb_indices[DCA_LBR_SUBBANDS]; ///< Subband reordering indices |
81 | |
82 | uint8_t sec_ch_sbms[DCA_LBR_CHANNELS / 2][DCA_LBR_SUBBANDS]; ///< Right channel inversion or mid/side decoding flags |
83 | uint8_t sec_ch_lrms[DCA_LBR_CHANNELS / 2][DCA_LBR_SUBBANDS]; ///< Flags indicating if left/right channel are swapped |
84 | uint32_t ch_pres[DCA_LBR_CHANNELS]; ///< Subband allocation flags |
85 | |
86 | uint8_t grid_1_scf[DCA_LBR_CHANNELS][12][8]; ///< Grid 1 scale factors |
87 | uint8_t grid_2_scf[DCA_LBR_CHANNELS][3][64]; ///< Grid 2 scale factors |
88 | |
89 | int8_t grid_3_avg[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS - 4]; ///< Grid 3 average values |
90 | int8_t grid_3_scf[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS - 4][8]; ///< Grid 3 scale factors |
91 | uint32_t grid_3_pres[DCA_LBR_CHANNELS]; ///< Grid 3 scale factors presence flags |
92 | |
93 | uint8_t high_res_scf[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS][8]; ///< High-frequency resolution scale factors |
94 | |
95 | uint8_t part_stereo[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS / 4][5]; ///< Partial stereo coefficients |
96 | uint8_t part_stereo_pres; ///< Partial stereo coefficients presence flags |
97 | |
98 | float lpc_coeff[2][DCA_LBR_CHANNELS][3][2][8]; ///< Predictor coefficients |
99 | |
100 | float sb_scf[DCA_LBR_SUBBANDS]; ///< Subband randomization scale factors |
101 | |
102 | float *time_samples[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS]; ///< Time samples |
103 | |
104 | float *ts_buffer; ///< Time sample buffer base |
105 | unsigned int ts_size; ///< Time sample buffer size |
106 | |
107 | DECLARE_ALIGNED(32, float, history)[DCA_LBR_CHANNELS][DCA_LBR_SUBBANDS * 4]; ///< IMDCT history |
108 | DECLARE_ALIGNED(32, float, window)[DCA_LBR_SUBBANDS * 4]; ///< Long window for IMDCT |
109 | |
110 | DECLARE_ALIGNED(32, float, lfe_data)[64]; ///< Decimated LFE samples |
111 | DECLARE_ALIGNED(32, float, lfe_history)[5][2]; ///< LFE IIR filter history |
112 | float lfe_scale; ///< Scale factor of LFE samples before IIR filter |
113 | |
114 | uint8_t tonal_scf[6]; ///< Tonal scale factors |
115 | uint16_t tonal_bounds[5][32][2]; ///< Per-group per-subframe start/end positions of tones |
116 | DCALbrTone tones[DCA_LBR_TONES]; ///< Circular buffer of tones |
117 | int ntones; ///< Circular buffer head position |
118 | |
119 | FFTContext imdct; |
120 | AVFloatDSPContext *fdsp; |
121 | DCADSPContext *dcadsp; |
122 | } DCALbrDecoder; |
123 | |
124 | int ff_dca_lbr_parse(DCALbrDecoder *s, uint8_t *data, DCAExssAsset *asset); |
125 | int ff_dca_lbr_filter_frame(DCALbrDecoder *s, AVFrame *frame); |
126 | av_cold void ff_dca_lbr_flush(DCALbrDecoder *s); |
127 | av_cold int ff_dca_lbr_init(DCALbrDecoder *s); |
128 | av_cold void ff_dca_lbr_close(DCALbrDecoder *s); |
129 | |
130 | #endif |
131 |