All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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
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  */
24 #include "libavutil/common.h"
25 #include "libavutil/float_dsp.h"
26 #include "libavutil/fixed_dsp.h"
27 #include "libavutil/mem.h"
29 #include "avcodec.h"
30 #include "internal.h"
31 #include "get_bits.h"
32 #include "dca.h"
33 #include "dca_exss.h"
34 #include "dcadsp.h"
35 #include "dcadct.h"
36 #include "dcahuff.h"
37 #include "fft.h"
38 #include "synth_filter.h"
40 #define DCA_CHANNELS 7
41 #define DCA_SUBBANDS 32
42 #define DCA_SUBBANDS_X96 64
43 #define DCA_SUBFRAMES 16
46 #define DCA_ADPCM_COEFFS 4
47 #define DCA_LFE_HISTORY 8
48 #define DCA_ABITS_MAX 26
54 #define DCA_EXSS_CHSETS_MAX 4
56 #define DCA_FILTER_MODE_X96 0x01
57 #define DCA_FILTER_MODE_FIXED 0x02
59 typedef struct DCADSPData {
60  union {
61  struct {
62  DECLARE_ALIGNED(32, float, hist1)[1024];
63  DECLARE_ALIGNED(32, float, hist2)[64];
64  } flt;
65  struct {
68  } fix;
69  } u;
70  int offset;
71 } DCADSPData;
73 typedef struct DCACoreDecoder {
77  // Bit stream header
78  int crc_present; ///< CRC present flag
79  int npcmblocks; ///< Number of PCM sample blocks
80  int frame_size; ///< Primary frame byte size
81  int audio_mode; ///< Audio channel arrangement
82  int sample_rate; ///< Core audio sampling frequency
83  int bit_rate; ///< Transmission bit rate
84  int drc_present; ///< Embedded dynamic range flag
85  int ts_present; ///< Embedded time stamp flag
86  int aux_present; ///< Auxiliary data flag
87  int ext_audio_type; ///< Extension audio descriptor flag
88  int ext_audio_present; ///< Extended coding flag
89  int sync_ssf; ///< Audio sync word insertion flag
90  int lfe_present; ///< Low frequency effects flag
91  int predictor_history; ///< Predictor history flag switch
92  int filter_perfect; ///< Multirate interpolator switch
93  int source_pcm_res; ///< Source PCM resolution
94  int es_format; ///< Extended surround (ES) mastering flag
95  int sumdiff_front; ///< Front sum/difference flag
96  int sumdiff_surround; ///< Surround sum/difference flag
98  // Primary audio coding header
99  int nsubframes; ///< Number of subframes
100  int nchannels; ///< Number of primary audio channels (incl. extension channels)
101  int ch_mask; ///< Speaker layout mask (incl. LFE and extension channels)
102  int8_t nsubbands[DCA_CHANNELS]; ///< Subband activity count
103  int8_t subband_vq_start[DCA_CHANNELS]; ///< High frequency VQ start subband
104  int8_t joint_intensity_index[DCA_CHANNELS]; ///< Joint intensity coding index
105  int8_t transition_mode_sel[DCA_CHANNELS]; ///< Transient mode code book
106  int8_t scale_factor_sel[DCA_CHANNELS]; ///< Scale factor code book
107  int8_t bit_allocation_sel[DCA_CHANNELS]; ///< Bit allocation quantizer select
108  int8_t quant_index_sel[DCA_CHANNELS][DCA_CODE_BOOKS]; ///< Quantization index codebook select
109  int32_t scale_factor_adj[DCA_CHANNELS][DCA_CODE_BOOKS]; ///< Scale factor adjustment
111  // Primary audio coding side information
112  int8_t nsubsubframes[DCA_SUBFRAMES]; ///< Subsubframe count for each subframe
113  int8_t prediction_mode[DCA_CHANNELS][DCA_SUBBANDS_X96]; ///< Prediction mode
114  int16_t prediction_vq_index[DCA_CHANNELS][DCA_SUBBANDS_X96]; ///< Prediction coefficients VQ address
115  int8_t bit_allocation[DCA_CHANNELS][DCA_SUBBANDS_X96]; ///< Bit allocation index
116  int8_t transition_mode[DCA_SUBFRAMES][DCA_CHANNELS][DCA_SUBBANDS]; ///< Transition mode
117  int32_t scale_factors[DCA_CHANNELS][DCA_SUBBANDS][2]; ///< Scale factors (2x for transients and X96)
118  int8_t joint_scale_sel[DCA_CHANNELS]; ///< Joint subband codebook select
119  int32_t joint_scale_factors[DCA_CHANNELS][DCA_SUBBANDS_X96]; ///< Scale factors for joint subband coding
121  // Auxiliary data
122  int prim_dmix_embedded; ///< Auxiliary dynamic downmix flag
123  int prim_dmix_type; ///< Auxiliary primary channel downmix type
124  int prim_dmix_coeff[DCA_DMIX_CHANNELS_MAX * DCA_CORE_CHANNELS_MAX]; ///< Dynamic downmix code coefficients
126  // Core extensions
127  int ext_audio_mask; ///< Bit mask of fully decoded core extensions
129  // XCH extension data
130  int xch_pos; ///< Bit position of XCH frame in core substream
132  // XXCH extension data
133  int xxch_crc_present; ///< CRC presence flag for XXCH channel set header
134  int xxch_mask_nbits; ///< Number of bits for loudspeaker mask
135  int xxch_core_mask; ///< Core loudspeaker activity mask
136  int xxch_spkr_mask; ///< Loudspeaker layout mask
137  int xxch_dmix_embedded; ///< Downmix already performed by encoder
138  int xxch_dmix_scale_inv; ///< Downmix scale factor
139  int xxch_dmix_mask[DCA_XXCH_CHANNELS_MAX]; ///< Downmix channel mapping mask
141  int xxch_pos; ///< Bit position of XXCH frame in core substream
143  // X96 extension data
144  int x96_rev_no; ///< X96 revision number
145  int x96_crc_present; ///< CRC presence flag for X96 channel set header
146  int x96_nchannels; ///< Number of primary channels in X96 extension
147  int x96_high_res; ///< X96 high resolution flag
148  int x96_subband_start; ///< First encoded subband in X96 extension
149  int x96_rand; ///< Random seed for generating samples for unallocated X96 subbands
150  int x96_pos; ///< Bit position of X96 frame in core substream
152  // Sample buffers
153  unsigned int x96_subband_size;
154  int32_t *x96_subband_buffer; ///< X96 subband sample buffer base
157  unsigned int subband_size;
158  int32_t *subband_buffer; ///< Subband sample buffer base
160  int32_t *lfe_samples; ///< Decimated LFE samples
162  // DSP contexts
163  DCADSPData dcadsp_data[DCA_CHANNELS]; ///< FIR history buffers
171  // PCM output data
172  unsigned int output_size;
173  void *output_buffer; ///< PCM output buffer base
174  int32_t *output_samples[DCA_SPEAKER_COUNT]; ///< PCM output for fixed point mode
175  int32_t output_history_lfe_fixed; ///< LFE PCM history for X96 filter
176  float output_history_lfe_float; ///< LFE PCM history for X96 filter
178  int ch_remap[DCA_SPEAKER_COUNT]; ///< Channel to speaker map
179  int request_mask; ///< Requested channel layout (for stereo downmix)
181  int npcmsamples; ///< Number of PCM samples per channel
182  int output_rate; ///< Output sample rate (1x or 2x header rate)
184  int filter_mode; ///< Previous filtering mode for detecting changes
187 static inline int ff_dca_core_map_spkr(DCACoreDecoder *core, int spkr)
188 {
189  if (core->ch_mask & (1U << spkr))
190  return spkr;
191  if (spkr == DCA_SPEAKER_Lss && (core->ch_mask & DCA_SPEAKER_MASK_Ls))
192  return DCA_SPEAKER_Ls;
193  if (spkr == DCA_SPEAKER_Rss && (core->ch_mask & DCA_SPEAKER_MASK_Rs))
194  return DCA_SPEAKER_Rs;
195  return -1;
196 }
200 int ff_dca_core_filter_fixed(DCACoreDecoder *s, int x96_synth);
206 #endif
int audio_mode
Audio channel arrangement.
Definition: dca_core.h:81
int16_t prediction_vq_index[DCA_CHANNELS][DCA_SUBBANDS_X96]
Prediction coefficients VQ address.
Definition: dca_core.h:114
int xxch_mask_nbits
Number of bits for loudspeaker mask.
Definition: dca_core.h:134
const char * s
Definition: avisynth_c.h:631
int offset
Definition: dca_core.h:70
Dynamic downmix code coefficients.
Definition: dca_core.h:124
This structure describes decoded (raw) audio or video data.
Definition: frame.h:184
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
memory handling functions
int xxch_dmix_embedded
Downmix already performed by encoder.
Definition: dca_core.h:137
int ext_audio_type
Extension audio descriptor flag.
Definition: dca_core.h:87
int frame_size
Primary frame byte size.
Definition: dca_core.h:80
unsigned int output_size
Definition: dca_core.h:172
int8_t joint_scale_sel[DCA_CHANNELS]
Joint subband codebook select.
Definition: dca_core.h:118
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:53
int8_t joint_intensity_index[DCA_CHANNELS]
Joint intensity coding index.
Definition: dca_core.h:104
union DCADSPData::@40 u
int filter_perfect
Multirate interpolator switch.
Definition: dca_core.h:92
float output_history_lfe_float
LFE PCM history for X96 filter.
Definition: dca_core.h:176
Definition: dca_core.h:50
Definition: dca_core.h:43
unsigned int x96_subband_size
Definition: dca_core.h:153
int nsubframes
Number of subframes.
Definition: dca_core.h:99
DCADSPData dcadsp_data[DCA_CHANNELS]
FIR history buffers.
Definition: dca_core.h:163
int32_t scale_factor_adj[DCA_CHANNELS][DCA_CODE_BOOKS]
Scale factor adjustment.
Definition: dca_core.h:109
int x96_rand
Random seed for generating samples for unallocated X96 subbands.
Definition: dca_core.h:149
int8_t prediction_mode[DCA_CHANNELS][DCA_SUBBANDS_X96]
Prediction mode.
Definition: dca_core.h:113
#define av_cold
Definition: attributes.h:82
int source_pcm_res
Source PCM resolution.
Definition: dca_core.h:93
int xxch_dmix_scale_inv
Downmix scale factor.
Definition: dca_core.h:138
int32_t * subband_samples[DCA_CHANNELS][DCA_SUBBANDS]
Subband samples.
Definition: dca_core.h:159
Definition: dca_core.h:51
int filter_mode
Previous filtering mode for detecting changes.
Definition: dca_core.h:184
static AVFrame * frame
void * output_buffer
PCM output buffer base.
Definition: dca_core.h:173
#define DCA_SUBBANDS_X96
Definition: dca_core.h:42
int prim_dmix_type
Auxiliary primary channel downmix type.
Definition: dca_core.h:123
bitstream reader API header.
int32_t * x96_subband_buffer
X96 subband sample buffer base.
Definition: dca_core.h:154
ptrdiff_t size
Definition: opengl_enc.c:101
int ff_dca_core_parse_exss(DCACoreDecoder *s, uint8_t *data, DCAExssAsset *asset)
Definition: dca_core.c:1936
av_cold void ff_dca_core_flush(DCACoreDecoder *s)
Definition: dca_core.c:2503
int sync_ssf
Audio sync word insertion flag.
Definition: dca_core.h:89
int32_t * subband_buffer
Subband sample buffer base.
Definition: dca_core.h:158
int npcmsamples
Number of PCM samples per channel.
Definition: dca_core.h:181
int8_t subband_vq_start[DCA_CHANNELS]
High frequency VQ start subband.
Definition: dca_core.h:103
#define U(x)
Definition: vp56_arith.h:37
int8_t nsubbands[DCA_CHANNELS]
Subband activity count.
Definition: dca_core.h:102
int sumdiff_front
Front sum/difference flag.
Definition: dca_core.h:95
int8_t nsubsubframes[DCA_SUBFRAMES]
Subsubframe count for each subframe.
Definition: dca_core.h:112
SynthFilterContext synth
Definition: dca_core.h:167
int8_t transition_mode_sel[DCA_CHANNELS]
Transient mode code book.
Definition: dca_core.h:105
int bit_rate
Transmission bit rate.
Definition: dca_core.h:83
int ff_dca_core_parse(DCACoreDecoder *s, uint8_t *data, int size)
Definition: dca_core.c:1903
int xxch_crc_present
CRC presence flag for XXCH channel set header.
Definition: dca_core.h:133
DCADCTContext dcadct
Definition: dca_core.h:165
AVFloatDSPContext * float_dsp
Definition: dca_core.h:168
int ff_dca_core_filter_fixed(DCACoreDecoder *s, int x96_synth)
Definition: dca_core.c:2063
int aux_present
Auxiliary data flag.
Definition: dca_core.h:86
int32_t * lfe_samples
Decimated LFE samples.
Definition: dca_core.h:160
int prim_dmix_embedded
Auxiliary dynamic downmix flag.
Definition: dca_core.h:122
int sample_rate
Core audio sampling frequency.
Definition: dca_core.h:82
int request_mask
Requested channel layout (for stereo downmix)
Definition: dca_core.h:179
Definition: fft.h:88
int output_rate
Output sample rate (1x or 2x header rate)
Definition: dca_core.h:182
int nchannels
Number of primary audio channels (incl. extension channels)
Definition: dca_core.h:100
static int ff_dca_core_map_spkr(DCACoreDecoder *core, int spkr)
Definition: dca_core.h:187
int xxch_pos
Bit position of XXCH frame in core substream.
Definition: dca_core.h:141
struct DCADSPData::@40::@42 fix
int sumdiff_surround
Surround sum/difference flag.
Definition: dca_core.h:96
struct DCADSPData::@40::@41 flt
AVCodecContext * avctx
Definition: dca_core.h:74
int x96_crc_present
CRC presence flag for X96 channel set header.
Definition: dca_core.h:145
float hist2[64]
Definition: dca_core.h:63
av_cold int ff_dca_core_init(DCACoreDecoder *s)
Definition: dca_core.c:2516
int xxch_core_mask
Core loudspeaker activity mask.
Definition: dca_core.h:135
Definition: dca_core.h:41
Libavcodec external API header.
int ts_present
Embedded time stamp flag.
Definition: dca_core.h:85
int xxch_spkr_mask
Loudspeaker layout mask.
Definition: dca_core.h:136
int crc_present
CRC present flag.
Definition: dca_core.h:78
Definition: dcahuff.h:31
main external API structure.
Definition: avcodec.h:1649
int8_t bit_allocation_sel[DCA_CHANNELS]
Bit allocation quantizer select.
Definition: dca_core.h:107
int ext_audio_present
Extended coding flag.
Definition: dca_core.h:88
int es_format
Extended surround (ES) mastering flag.
Definition: dca_core.h:94
int x96_subband_start
First encoded subband in X96 extension.
Definition: dca_core.h:148
Downmix coefficients.
Definition: dca_core.h:140
int x96_pos
Bit position of X96 frame in core substream.
Definition: dca_core.h:150
int xch_pos
Bit position of XCH frame in core substream.
Definition: dca_core.h:130
int xxch_dmix_mask[DCA_XXCH_CHANNELS_MAX]
Downmix channel mapping mask.
Definition: dca_core.h:139
int32_t * x96_subband_samples[DCA_CHANNELS][DCA_SUBBANDS_X96]
X96 subband samples.
Definition: dca_core.h:155
int8_t bit_allocation[DCA_CHANNELS][DCA_SUBBANDS_X96]
Bit allocation index.
Definition: dca_core.h:115
DCADSPContext * dcadsp
Definition: dca_core.h:164
int x96_rev_no
X96 revision number.
Definition: dca_core.h:144
Transition mode.
Definition: dca_core.h:116
int32_t * output_samples[DCA_SPEAKER_COUNT]
PCM output for fixed point mode.
Definition: dca_core.h:174
int x96_nchannels
Number of primary channels in X96 extension.
Definition: dca_core.h:146
float hist1[1024]
Definition: dca_core.h:62
int32_t joint_scale_factors[DCA_CHANNELS][DCA_SUBBANDS_X96]
Scale factors for joint subband coding.
Definition: dca_core.h:119
Definition: dca_core.h:40
unsigned int subband_size
Definition: dca_core.h:157
int lfe_present
Low frequency effects flag.
Definition: dca_core.h:90
int8_t scale_factor_sel[DCA_CHANNELS]
Scale factor code book.
Definition: dca_core.h:106
int32_t scale_factors[DCA_CHANNELS][DCA_SUBBANDS][2]
Scale factors (2x for transients and X96)
Definition: dca_core.h:117
int ch_remap[DCA_SPEAKER_COUNT]
Channel to speaker map.
Definition: dca_core.h:178
common internal api header.
Definition: dca_core.h:52
common internal and external API header
AVFixedDSPContext * fixed_dsp
Definition: dca_core.h:169
GetBitContext gb
Definition: dca_core.h:75
int ch_mask
Speaker layout mask (incl. LFE and extension channels)
Definition: dca_core.h:101
av_cold void ff_dca_core_close(DCACoreDecoder *s)
Definition: dca_core.c:2534
int drc_present
Embedded dynamic range flag.
Definition: dca_core.h:84
int ff_dca_core_filter_frame(DCACoreDecoder *s, AVFrame *frame)
Definition: dca_core.c:2449
int x96_high_res
X96 high resolution flag.
Definition: dca_core.h:147
int ext_audio_mask
Bit mask of fully decoded core extensions.
Definition: dca_core.h:127
int predictor_history
Predictor history flag switch.
Definition: dca_core.h:91
int32_t output_history_lfe_fixed
LFE PCM history for X96 filter.
Definition: dca_core.h:175
int8_t quant_index_sel[DCA_CHANNELS][DCA_CODE_BOOKS]
Quantization index codebook select.
Definition: dca_core.h:108
FFTContext imdct[2]
Definition: dca_core.h:166
int npcmblocks
Number of PCM sample blocks.
Definition: dca_core.h:79