FFmpeg
aacdec_fixed_coupling.h
Go to the documentation of this file.
1 /*
2  * AAC decoder
3  * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
4  * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
5  * Copyright (c) 2008-2013 Alex Converse <alex.converse@gmail.com>
6  *
7  * AAC LATM decoder
8  * Copyright (c) 2008-2010 Paul Kendall <paul@kcbbs.gen.nz>
9  * Copyright (c) 2010 Janne Grunau <janne-libav@jannau.net>
10  *
11  * AAC decoder fixed-point implementation
12  * Copyright (c) 2013
13  * MIPS Technologies, Inc., California.
14  *
15  * This file is part of FFmpeg.
16  *
17  * FFmpeg is free software; you can redistribute it and/or
18  * modify it under the terms of the GNU Lesser General Public
19  * License as published by the Free Software Foundation; either
20  * version 2.1 of the License, or (at your option) any later version.
21  *
22  * FFmpeg is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25  * Lesser General Public License for more details.
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with FFmpeg; if not, write to the Free Software
29  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30  */
31 
32 #ifndef AVCODEC_AAC_AACDEC_FIXED_COUPLING_H
33 #define AVCODEC_AAC_AACDEC_FIXED_COUPLING_H
34 
35 #include "aacdec.h"
36 
37 /**
38  * Apply dependent channel coupling (applied before IMDCT).
39  *
40  * @param index index into coupling gain array
41  */
43  SingleChannelElement *target,
44  ChannelElement *cce, int index)
45 {
46  IndividualChannelStream *ics = &cce->ch[0].ics;
47  const uint16_t *offsets = ics->swb_offset;
48  int *dest = target->coeffs_fixed;
49  const int *src = cce->ch[0].coeffs_fixed;
50  int g, i, group, k, idx = 0;
51  if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP) {
52  av_log(ac->avctx, AV_LOG_ERROR,
53  "Dependent coupling is not supported together with LTP\n");
54  return;
55  }
56  for (g = 0; g < ics->num_window_groups; g++) {
57  for (i = 0; i < ics->max_sfb; i++, idx++) {
58  if (cce->ch[0].band_type[idx] != ZERO_BT) {
59  const int gain = cce->coup.gain[index][idx];
60  int shift, round, c, tmp;
61 
62  if (gain < 0) {
63  c = -cce_scale_fixed[-gain & 7];
64  shift = (-gain-1024) >> 3;
65  }
66  else {
67  c = cce_scale_fixed[gain & 7];
68  shift = (gain-1024) >> 3;
69  }
70 
71  if (shift < -31) {
72  // Nothing to do
73  } else if (shift < 0) {
74  shift = -shift;
75  round = 1 << (shift - 1);
76 
77  for (group = 0; group < ics->group_len[g]; group++) {
78  for (k = offsets[i]; k < offsets[i + 1]; k++) {
79  tmp = (int)(((int64_t)src[group * 128 + k] * c + \
80  (int64_t)0x1000000000) >> 37);
81  dest[group * 128 + k] += (tmp + (int64_t)round) >> shift;
82  }
83  }
84  }
85  else {
86  for (group = 0; group < ics->group_len[g]; group++) {
87  for (k = offsets[i]; k < offsets[i + 1]; k++) {
88  tmp = (int)(((int64_t)src[group * 128 + k] * c + \
89  (int64_t)0x1000000000) >> 37);
90  dest[group * 128 + k] += tmp * (1U << shift);
91  }
92  }
93  }
94  }
95  }
96  dest += ics->group_len[g] * 128;
97  src += ics->group_len[g] * 128;
98  }
99 }
100 
101 /**
102  * Apply independent channel coupling (applied after IMDCT).
103  *
104  * @param index index into coupling gain array
105  */
107  SingleChannelElement *target,
108  ChannelElement *cce, int index)
109 {
110  int i, c, shift, round, tmp;
111  const int gain = cce->coup.gain[index][0];
112  const int *src = cce->ch[0].output_fixed;
113  unsigned int *dest = target->output_fixed;
114  const int len = 1024 << (ac->oc[1].m4ac.sbr == 1);
115 
116  c = cce_scale_fixed[gain & 7];
117  shift = (gain-1024) >> 3;
118  if (shift < -31) {
119  return;
120  } else if (shift < 0) {
121  shift = -shift;
122  round = 1 << (shift - 1);
123 
124  for (i = 0; i < len; i++) {
125  tmp = (int)(((int64_t)src[i] * c + (int64_t)0x1000000000) >> 37);
126  dest[i] += (tmp + round) >> shift;
127  }
128  }
129  else {
130  for (i = 0; i < len; i++) {
131  tmp = (int)(((int64_t)src[i] * c + (int64_t)0x1000000000) >> 37);
132  dest[i] += tmp * (1U << shift);
133  }
134  }
135 }
136 
137 #endif /* AVCODEC_AAC_AACDEC_FIXED_COUPLING_H */
apply_independent_coupling
static void AAC_RENAME() apply_independent_coupling(AACDecContext *ac, SingleChannelElement *target, ChannelElement *cce, int index)
Apply independent channel coupling (applied after IMDCT).
Definition: aacdec_fixed_coupling.h:106
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
ZERO_BT
@ ZERO_BT
Scalefactors and spectral data are all zero.
Definition: aac.h:67
offsets
static const int offsets[]
Definition: hevc_pel.c:34
g
const char * g
Definition: vf_curves.c:128
IndividualChannelStream
Individual Channel Stream.
Definition: aacdec.h:162
IndividualChannelStream::num_window_groups
int num_window_groups
Definition: aacdec.h:166
index
int index
Definition: gxfenc.c:90
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
shift
static int shift(int a, int b)
Definition: bonk.c:261
cce_scale_fixed
static const int cce_scale_fixed[8]
Definition: aacdec_fixed.c:68
SingleChannelElement
Single Channel Element - used for both SCE and LFE elements.
Definition: aacdec.h:210
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
round
static av_always_inline av_const double round(double x)
Definition: libm.h:444
ChannelElement
channel element - generic struct for SCE/CPE/CCE/LFE
Definition: aacdec.h:260
IndividualChannelStream::swb_offset
const uint16_t * swb_offset
table of offsets to the lowest spectral coefficient of a scalefactor band, sfb, for a particular wind...
Definition: aacdec.h:170
AAC_RENAME
#define AAC_RENAME(x)
Definition: aac_defines.h:99
len
int len
Definition: vorbis_enc_data.h:426
U
#define U(x)
Definition: vpx_arith.h:37
aacdec.h
AACDecContext
main AAC decoding context
Definition: aacdec.h:449
apply_dependent_coupling
static void AAC_RENAME() apply_dependent_coupling(AACDecContext *ac, SingleChannelElement *target, ChannelElement *cce, int index)
Apply dependent channel coupling (applied before IMDCT).
Definition: aacdec_fixed_coupling.h:42
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
IndividualChannelStream::max_sfb
uint8_t max_sfb
number of scalefactor bands per group
Definition: aacdec.h:163
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
int
int
Definition: ffmpeg_filter.c:424
IndividualChannelStream::group_len
uint8_t group_len[8]
Definition: aacdec.h:168
AOT_AAC_LTP
@ AOT_AAC_LTP
Y Long Term Prediction.
Definition: mpeg4audio.h:76