annotate aac.c @ 7578:a05954c505ab libavcodec

More OKed sections of AAC decoder code
author superdump
date Fri, 15 Aug 2008 00:05:09 +0000
parents 5298e05f931d
children c49ab52db74c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1 /*
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
2 * AAC decoder
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
3 * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
4 * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
5 *
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
6 * This file is part of FFmpeg.
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
7 *
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
12 *
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
16 * Lesser General Public License for more details.
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
17 *
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
21 */
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
22
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
23 /**
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
24 * @file aac.c
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
25 * AAC decoder
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
26 * @author Oded Shimon ( ods15 ods15 dyndns org )
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
27 * @author Maxim Gavrilov ( maxim.gavrilov gmail com )
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
28 */
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
29
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
30 /*
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
31 * supported tools
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
32 *
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
33 * Support? Name
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
34 * N (code in SoC repo) gain control
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
35 * Y block switching
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
36 * Y window shapes - standard
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
37 * N window shapes - Low Delay
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
38 * Y filterbank - standard
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
39 * N (code in SoC repo) filterbank - Scalable Sample Rate
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
40 * Y Temporal Noise Shaping
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
41 * N (code in SoC repo) Long Term Prediction
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
42 * Y intensity stereo
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
43 * Y channel coupling
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
44 * N frequency domain prediction
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
45 * Y Perceptual Noise Substitution
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
46 * Y Mid/Side stereo
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
47 * N Scalable Inverse AAC Quantization
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
48 * N Frequency Selective Switch
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
49 * N upsampling filter
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
50 * Y quantization & coding - AAC
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
51 * N quantization & coding - TwinVQ
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
52 * N quantization & coding - BSAC
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
53 * N AAC Error Resilience tools
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
54 * N Error Resilience payload syntax
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
55 * N Error Protection tool
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
56 * N CELP
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
57 * N Silence Compression
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
58 * N HVXC
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
59 * N HVXC 4kbits/s VR
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
60 * N Structured Audio tools
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
61 * N Structured Audio Sample Bank Format
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
62 * N MIDI
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
63 * N Harmonic and Individual Lines plus Noise
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
64 * N Text-To-Speech Interface
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
65 * N (in progress) Spectral Band Replication
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
66 * Y (not in this code) Layer-1
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
67 * Y (not in this code) Layer-2
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
68 * Y (not in this code) Layer-3
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
69 * N SinuSoidal Coding (Transient, Sinusoid, Noise)
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
70 * N (planned) Parametric Stereo
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
71 * N Direct Stream Transfer
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
72 *
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
73 * Note: - HE AAC v1 comprises LC AAC with Spectral Band Replication.
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
74 * - HE AAC v2 comprises LC AAC with Spectral Band Replication and
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
75 Parametric Stereo.
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
76 */
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
77
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
78
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
79 #include "avcodec.h"
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
80 #include "bitstream.h"
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
81 #include "dsputil.h"
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
82
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
83 #include "aac.h"
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
84 #include "aactab.h"
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
85 #include "aacdectab.h"
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
86 #include "mpeg4audio.h"
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
87
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
88 #include <assert.h>
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
89 #include <errno.h>
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
90 #include <math.h>
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
91 #include <string.h>
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
92
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
93 #ifndef CONFIG_HARDCODED_TABLES
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
94 static float ff_aac_ivquant_tab[IVQUANT_SIZE];
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
95 static float ff_aac_pow2sf_tab[316];
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
96 #endif /* CONFIG_HARDCODED_TABLES */
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
97
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
98 static VLC vlc_scalefactors;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
99 static VLC vlc_spectral[11];
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
100
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
101
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
102 /**
7578
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
103 * Configure output channel order based on the current program configuration element.
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
104 *
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
105 * @param che_pos current channel position configuration
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
106 * @param new_che_pos New channel position configuration - we only do something if it differs from the current one.
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
107 *
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
108 * @return Returns error status. 0 - OK, !0 - error
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
109 */
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
110 static int output_configure(AACContext *ac, enum ChannelPosition che_pos[4][MAX_ELEM_ID],
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
111 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
112 AVCodecContext *avctx = ac->avccontext;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
113 int i, type, channels = 0;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
114
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
115 if(!memcmp(che_pos, new_che_pos, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])))
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
116 return 0; /* no change */
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
117
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
118 memcpy(che_pos, new_che_pos, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
119
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
120 /* Allocate or free elements depending on if they are in the
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
121 * current program configuration.
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
122 *
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
123 * Set up default 1:1 output mapping.
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
124 *
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
125 * For a 5.1 stream the output order will be:
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
126 * [ Front Left ] [ Front Right ] [ Center ] [ LFE ] [ Surround Left ] [ Surround Right ]
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
127 */
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
128
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
129 for(i = 0; i < MAX_ELEM_ID; i++) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
130 for(type = 0; type < 4; type++) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
131 if(che_pos[type][i]) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
132 if(!ac->che[type][i] && !(ac->che[type][i] = av_mallocz(sizeof(ChannelElement))))
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
133 return AVERROR(ENOMEM);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
134 if(type != TYPE_CCE) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
135 ac->output_data[channels++] = ac->che[type][i]->ch[0].ret;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
136 if(type == TYPE_CPE) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
137 ac->output_data[channels++] = ac->che[type][i]->ch[1].ret;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
138 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
139 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
140 } else
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
141 av_freep(&ac->che[type][i]);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
142 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
143 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
144
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
145 avctx->channels = channels;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
146 return 0;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
147 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
148
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
149 /**
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
150 * Decode an array of 4 bit element IDs, optionally interleaved with a stereo/mono switching bit.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
151 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
152 * @param cpe_map Stereo (Channel Pair Element) map, NULL if stereo bit is not present.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
153 * @param sce_map mono (Single Channel Element) map
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
154 * @param type speaker type/position for these channels
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
155 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
156 static void decode_channel_map(enum ChannelPosition *cpe_map,
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
157 enum ChannelPosition *sce_map, enum ChannelPosition type, GetBitContext * gb, int n) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
158 while(n--) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
159 enum ChannelPosition *map = cpe_map && get_bits1(gb) ? cpe_map : sce_map; // stereo or mono map
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
160 map[get_bits(gb, 4)] = type;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
161 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
162 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
163
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
164 /**
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
165 * Decode program configuration element; reference: table 4.2.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
166 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
167 * @param new_che_pos New channel position configuration - we only do something if it differs from the current one.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
168 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
169 * @return Returns error status. 0 - OK, !0 - error
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
170 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
171 static int decode_pce(AACContext * ac, enum ChannelPosition new_che_pos[4][MAX_ELEM_ID],
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
172 GetBitContext * gb) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
173 int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
174
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
175 skip_bits(gb, 2); // object_type
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
176
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
177 ac->m4ac.sampling_index = get_bits(gb, 4);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
178 if(ac->m4ac.sampling_index > 11) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
179 av_log(ac->avccontext, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->m4ac.sampling_index);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
180 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
181 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
182 ac->m4ac.sample_rate = ff_mpeg4audio_sample_rates[ac->m4ac.sampling_index];
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
183 num_front = get_bits(gb, 4);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
184 num_side = get_bits(gb, 4);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
185 num_back = get_bits(gb, 4);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
186 num_lfe = get_bits(gb, 2);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
187 num_assoc_data = get_bits(gb, 3);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
188 num_cc = get_bits(gb, 4);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
189
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
190 if (get_bits1(gb))
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
191 skip_bits(gb, 4); // mono_mixdown_tag
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
192 if (get_bits1(gb))
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
193 skip_bits(gb, 4); // stereo_mixdown_tag
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
194
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
195 if (get_bits1(gb))
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
196 skip_bits(gb, 3); // mixdown_coeff_index and pseudo_surround
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
197
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
198 decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_FRONT, gb, num_front);
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
199 decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_SIDE, gb, num_side );
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
200 decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_BACK, gb, num_back );
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
201 decode_channel_map(NULL, new_che_pos[TYPE_LFE], AAC_CHANNEL_LFE, gb, num_lfe );
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
202
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
203 skip_bits_long(gb, 4 * num_assoc_data);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
204
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
205 decode_channel_map(new_che_pos[TYPE_CCE], new_che_pos[TYPE_CCE], AAC_CHANNEL_CC, gb, num_cc );
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
206
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
207 align_get_bits(gb);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
208
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
209 /* comment field, first byte is length */
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
210 skip_bits_long(gb, 8 * get_bits(gb, 8));
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
211 return 0;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
212 }
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
213
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
214 /**
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
215 * Set up channel positions based on a default channel configuration
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
216 * as specified in table 1.17.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
217 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
218 * @param new_che_pos New channel position configuration - we only do something if it differs from the current one.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
219 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
220 * @return Returns error status. 0 - OK, !0 - error
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
221 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
222 static int set_default_channel_config(AACContext *ac, enum ChannelPosition new_che_pos[4][MAX_ELEM_ID],
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
223 int channel_config)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
224 {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
225 if(channel_config < 1 || channel_config > 7) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
226 av_log(ac->avccontext, AV_LOG_ERROR, "invalid default channel configuration (%d)\n",
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
227 channel_config);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
228 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
229 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
230
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
231 /* default channel configurations:
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
232 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
233 * 1ch : front center (mono)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
234 * 2ch : L + R (stereo)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
235 * 3ch : front center + L + R
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
236 * 4ch : front center + L + R + back center
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
237 * 5ch : front center + L + R + back stereo
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
238 * 6ch : front center + L + R + back stereo + LFE
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
239 * 7ch : front center + L + R + outer front left + outer front right + back stereo + LFE
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
240 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
241
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
242 if(channel_config != 2)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
243 new_che_pos[TYPE_SCE][0] = AAC_CHANNEL_FRONT; // front center (or mono)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
244 if(channel_config > 1)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
245 new_che_pos[TYPE_CPE][0] = AAC_CHANNEL_FRONT; // L + R (or stereo)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
246 if(channel_config == 4)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
247 new_che_pos[TYPE_SCE][1] = AAC_CHANNEL_BACK; // back center
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
248 if(channel_config > 4)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
249 new_che_pos[TYPE_CPE][(channel_config == 7) + 1]
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
250 = AAC_CHANNEL_BACK; // back stereo
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
251 if(channel_config > 5)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
252 new_che_pos[TYPE_LFE][0] = AAC_CHANNEL_LFE; // LFE
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
253 if(channel_config == 7)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
254 new_che_pos[TYPE_CPE][1] = AAC_CHANNEL_FRONT; // outer front left + outer front right
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
255
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
256 return 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
257 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
258
7578
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
259 /**
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
260 * Decode GA "General Audio" specific configuration; reference: table 4.1.
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
261 *
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
262 * @return Returns error status. 0 - OK, !0 - error
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
263 */
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
264 static int decode_ga_specific_config(AACContext * ac, GetBitContext * gb, int channel_config) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
265 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID];
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
266 int extension_flag, ret;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
267
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
268 if(get_bits1(gb)) { // frameLengthFlag
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
269 av_log_missing_feature(ac->avccontext, "960/120 MDCT window is", 1);
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
270 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
271 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
272
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
273 if (get_bits1(gb)) // dependsOnCoreCoder
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
274 skip_bits(gb, 14); // coreCoderDelay
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
275 extension_flag = get_bits1(gb);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
276
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
277 if(ac->m4ac.object_type == AOT_AAC_SCALABLE ||
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
278 ac->m4ac.object_type == AOT_ER_AAC_SCALABLE)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
279 skip_bits(gb, 3); // layerNr
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
280
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
281 memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
282 if (channel_config == 0) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
283 skip_bits(gb, 4); // element_instance_tag
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
284 if((ret = decode_pce(ac, new_che_pos, gb)))
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
285 return ret;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
286 } else {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
287 if((ret = set_default_channel_config(ac, new_che_pos, channel_config)))
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
288 return ret;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
289 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
290 if((ret = output_configure(ac, ac->che_pos, new_che_pos)))
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
291 return ret;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
292
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
293 if (extension_flag) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
294 switch (ac->m4ac.object_type) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
295 case AOT_ER_BSAC:
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
296 skip_bits(gb, 5); // numOfSubFrame
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
297 skip_bits(gb, 11); // layer_length
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
298 break;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
299 case AOT_ER_AAC_LC:
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
300 case AOT_ER_AAC_LTP:
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
301 case AOT_ER_AAC_SCALABLE:
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
302 case AOT_ER_AAC_LD:
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
303 skip_bits(gb, 3); /* aacSectionDataResilienceFlag
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
304 * aacScalefactorDataResilienceFlag
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
305 * aacSpectralDataResilienceFlag
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
306 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
307 break;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
308 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
309 skip_bits1(gb); // extensionFlag3 (TBD in version 3)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
310 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
311 return 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
312 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
313
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
314 /**
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
315 * Decode audio specific configuration; reference: table 1.13.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
316 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
317 * @param data pointer to AVCodecContext extradata
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
318 * @param data_size size of AVCCodecContext extradata
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
319 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
320 * @return Returns error status. 0 - OK, !0 - error
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
321 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
322 static int decode_audio_specific_config(AACContext * ac, void *data, int data_size) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
323 GetBitContext gb;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
324 int i;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
325
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
326 init_get_bits(&gb, data, data_size * 8);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
327
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
328 if((i = ff_mpeg4audio_get_config(&ac->m4ac, data, data_size)) < 0)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
329 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
330 if(ac->m4ac.sampling_index > 11) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
331 av_log(ac->avccontext, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->m4ac.sampling_index);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
332 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
333 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
334
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
335 skip_bits_long(&gb, i);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
336
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
337 switch (ac->m4ac.object_type) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
338 case AOT_AAC_LC:
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
339 if (decode_ga_specific_config(ac, &gb, ac->m4ac.chan_config))
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
340 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
341 break;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
342 default:
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
343 av_log(ac->avccontext, AV_LOG_ERROR, "Audio object type %s%d is not supported.\n",
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
344 ac->m4ac.sbr == 1? "SBR+" : "", ac->m4ac.object_type);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
345 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
346 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
347 return 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
348 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
349
7578
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
350 /**
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
351 * linear congruential pseudorandom number generator
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
352 *
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
353 * @param previous_val pointer to the current state of the generator
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
354 *
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
355 * @return Returns a 32-bit pseudorandom integer
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
356 */
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
357 static av_always_inline int lcg_random(int previous_val) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
358 return previous_val * 1664525 + 1013904223;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
359 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
360
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
361 static av_cold int aac_decode_init(AVCodecContext * avccontext) {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
362 AACContext * ac = avccontext->priv_data;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
363 int i;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
364
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
365 ac->avccontext = avccontext;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
366
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
367 if (avccontext->extradata_size <= 0 ||
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
368 decode_audio_specific_config(ac, avccontext->extradata, avccontext->extradata_size))
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
369 return -1;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
370
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
371 avccontext->sample_fmt = SAMPLE_FMT_S16;
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
372 avccontext->sample_rate = ac->m4ac.sample_rate;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
373 avccontext->frame_size = 1024;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
374
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
375 AAC_INIT_VLC_STATIC( 0, 144);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
376 AAC_INIT_VLC_STATIC( 1, 114);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
377 AAC_INIT_VLC_STATIC( 2, 188);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
378 AAC_INIT_VLC_STATIC( 3, 180);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
379 AAC_INIT_VLC_STATIC( 4, 172);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
380 AAC_INIT_VLC_STATIC( 5, 140);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
381 AAC_INIT_VLC_STATIC( 6, 168);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
382 AAC_INIT_VLC_STATIC( 7, 114);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
383 AAC_INIT_VLC_STATIC( 8, 262);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
384 AAC_INIT_VLC_STATIC( 9, 248);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
385 AAC_INIT_VLC_STATIC(10, 384);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
386
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
387 dsputil_init(&ac->dsp, avccontext);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
388
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
389 ac->random_state = 0x1f2e3d4c;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
390
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
391 // -1024 - Compensate wrong IMDCT method.
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
392 // 32768 - Required to scale values to the correct range for the bias method
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
393 // for float to int16 conversion.
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
394
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
395 if(ac->dsp.float_to_int16 == ff_float_to_int16_c) {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
396 ac->add_bias = 385.0f;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
397 ac->sf_scale = 1. / (-1024. * 32768.);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
398 ac->sf_offset = 0;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
399 } else {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
400 ac->add_bias = 0.0f;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
401 ac->sf_scale = 1. / -1024.;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
402 ac->sf_offset = 60;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
403 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
404
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
405 #ifndef CONFIG_HARDCODED_TABLES
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
406 for (i = 1 - IVQUANT_SIZE/2; i < IVQUANT_SIZE/2; i++)
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
407 ff_aac_ivquant_tab[i + IVQUANT_SIZE/2 - 1] = cbrt(fabs(i)) * i;
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
408 for (i = 0; i < 316; i++)
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
409 ff_aac_pow2sf_tab[i] = pow(2, (i - 200)/4.);
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
410 #endif /* CONFIG_HARDCODED_TABLES */
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
411
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
412 INIT_VLC_STATIC(&vlc_scalefactors, 7, sizeof(ff_aac_scalefactor_code)/sizeof(ff_aac_scalefactor_code[0]),
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
413 ff_aac_scalefactor_bits, sizeof(ff_aac_scalefactor_bits[0]), sizeof(ff_aac_scalefactor_bits[0]),
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
414 ff_aac_scalefactor_code, sizeof(ff_aac_scalefactor_code[0]), sizeof(ff_aac_scalefactor_code[0]),
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
415 352);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
416
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
417 ff_mdct_init(&ac->mdct, 11, 1);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
418 ff_mdct_init(&ac->mdct_small, 8, 1);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
419 return 0;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
420 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
421
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
422 /**
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
423 * Skip data_stream_element; reference: table 4.10.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
424 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
425 static void skip_data_stream_element(GetBitContext * gb) {
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
426 int byte_align = get_bits1(gb);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
427 int count = get_bits(gb, 8);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
428 if (count == 255)
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
429 count += get_bits(gb, 8);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
430 if (byte_align)
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
431 align_get_bits(gb);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
432 skip_bits_long(gb, 8 * count);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
433 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
434
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
435 /**
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
436 * Decode Individual Channel Stream info; reference: table 4.6.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
437 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
438 * @param common_window Channels have independent [0], or shared [1], Individual Channel Stream information.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
439 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
440 static int decode_ics_info(AACContext * ac, IndividualChannelStream * ics, GetBitContext * gb, int common_window) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
441 if (get_bits1(gb)) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
442 av_log(ac->avccontext, AV_LOG_ERROR, "Reserved bit set.\n");
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
443 memset(ics, 0, sizeof(IndividualChannelStream));
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
444 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
445 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
446 ics->window_sequence[1] = ics->window_sequence[0];
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
447 ics->window_sequence[0] = get_bits(gb, 2);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
448 ics->use_kb_window[1] = ics->use_kb_window[0];
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
449 ics->use_kb_window[0] = get_bits1(gb);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
450 ics->num_window_groups = 1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
451 ics->group_len[0] = 1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
452
7578
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
453 if (get_bits1(gb)) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
454 av_log_missing_feature(ac->avccontext, "Predictor bit set but LTP is", 1);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
455 memset(ics, 0, sizeof(IndividualChannelStream));
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
456 return -1;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
457 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
458 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
459
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
460 if(ics->max_sfb > ics->num_swb) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
461 av_log(ac->avccontext, AV_LOG_ERROR,
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
462 "Number of scalefactor bands in group (%d) exceeds limit (%d).\n",
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
463 ics->max_sfb, ics->num_swb);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
464 memset(ics, 0, sizeof(IndividualChannelStream));
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
465 return -1;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
466 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
467
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
468 return 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
469 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
470
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
471 /**
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
472 * inverse quantization
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
473 *
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
474 * @param a quantized value to be dequantized
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
475 * @return Returns dequantized value.
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
476 */
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
477 static inline float ivquant(int a) {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
478 if (a + (unsigned int)IVQUANT_SIZE/2 - 1 < (unsigned int)IVQUANT_SIZE - 1)
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
479 return ff_aac_ivquant_tab[a + IVQUANT_SIZE/2 - 1];
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
480 else
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
481 return cbrtf(fabsf(a)) * a;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
482 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
483
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
484 /**
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
485 * Decode band types (section_data payload); reference: table 4.46.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
486 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
487 * @param band_type array of the used band type
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
488 * @param band_type_run_end array of the last scalefactor band of a band type run
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
489 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
490 * @return Returns error status. 0 - OK, !0 - error
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
491 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
492 static int decode_band_types(AACContext * ac, enum BandType band_type[120],
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
493 int band_type_run_end[120], GetBitContext * gb, IndividualChannelStream * ics) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
494 int g, idx = 0;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
495 const int bits = (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) ? 3 : 5;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
496 for (g = 0; g < ics->num_window_groups; g++) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
497 int k = 0;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
498 while (k < ics->max_sfb) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
499 uint8_t sect_len = k;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
500 int sect_len_incr;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
501 int sect_band_type = get_bits(gb, 4);
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
502 if (sect_band_type == 12) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
503 av_log(ac->avccontext, AV_LOG_ERROR, "invalid band type\n");
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
504 return -1;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
505 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
506 while ((sect_len_incr = get_bits(gb, bits)) == (1 << bits)-1)
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
507 sect_len += sect_len_incr;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
508 sect_len += sect_len_incr;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
509 if (sect_len > ics->max_sfb) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
510 av_log(ac->avccontext, AV_LOG_ERROR,
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
511 "Number of bands (%d) exceeds limit (%d).\n",
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
512 sect_len, ics->max_sfb);
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
513 return -1;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
514 }
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
515 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
516 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
517 return 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
518 }
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
519
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
520 /**
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
521 * Decode scalefactors; reference: table 4.47.
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
522 *
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
523 * @param global_gain first scalefactor value as scalefactors are differentially coded
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
524 * @param band_type array of the used band type
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
525 * @param band_type_run_end array of the last scalefactor band of a band type run
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
526 * @param sf array of scalefactors or intensity stereo positions
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
527 *
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
528 * @return Returns error status. 0 - OK, !0 - error
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
529 */
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
530 static int decode_scalefactors(AACContext * ac, float sf[120], GetBitContext * gb,
7540
5298e05f931d Synchronise code with AAC decoder in SoC
superdump
parents: 7539
diff changeset
531 unsigned int global_gain, IndividualChannelStream * ics,
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
532 enum BandType band_type[120], int band_type_run_end[120]) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
533 const int sf_offset = ac->sf_offset + (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE ? 12 : 0);
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
534 int g, i, idx = 0;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
535 int offset[3] = { global_gain, global_gain - 90, 100 };
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
536 int noise_flag = 1;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
537 static const char *sf_str[3] = { "Global gain", "Noise gain", "Intensity stereo position" };
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
538 ics->intensity_present = 0;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
539 for (g = 0; g < ics->num_window_groups; g++) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
540 for (i = 0; i < ics->max_sfb;) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
541 int run_end = band_type_run_end[idx];
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
542 if (band_type[idx] == ZERO_BT) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
543 for(; i < run_end; i++, idx++)
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
544 sf[idx] = 0.;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
545 }else if((band_type[idx] == INTENSITY_BT) || (band_type[idx] == INTENSITY_BT2)) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
546 ics->intensity_present = 1;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
547 for(; i < run_end; i++, idx++) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
548 offset[2] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
549 if(offset[2] > 255U) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
550 av_log(ac->avccontext, AV_LOG_ERROR,
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
551 "%s (%d) out of range.\n", sf_str[2], offset[2]);
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
552 return -1;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
553 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
554 sf[idx] = ff_aac_pow2sf_tab[-offset[2] + 300];
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
555 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
556 }else if(band_type[idx] == NOISE_BT) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
557 for(; i < run_end; i++, idx++) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
558 if(noise_flag-- > 0)
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
559 offset[1] += get_bits(gb, 9) - 256;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
560 else
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
561 offset[1] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
562 if(offset[1] > 255U) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
563 av_log(ac->avccontext, AV_LOG_ERROR,
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
564 "%s (%d) out of range.\n", sf_str[1], offset[1]);
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
565 return -1;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
566 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
567 sf[idx] = -ff_aac_pow2sf_tab[ offset[1] + sf_offset];
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
568 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
569 }else {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
570 for(; i < run_end; i++, idx++) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
571 offset[0] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
572 if(offset[0] > 255U) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
573 av_log(ac->avccontext, AV_LOG_ERROR,
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
574 "%s (%d) out of range.\n", sf_str[0], offset[0]);
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
575 return -1;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
576 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
577 sf[idx] = -ff_aac_pow2sf_tab[ offset[0] + sf_offset];
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
578 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
579 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
580 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
581 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
582 return 0;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
583 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
584
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
585 /**
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
586 * Decode pulse data; reference: table 4.7.
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
587 */
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
588 static void decode_pulses(Pulse * pulse, GetBitContext * gb) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
589 int i;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
590 pulse->num_pulse = get_bits(gb, 2) + 1;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
591 pulse->start = get_bits(gb, 6);
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
592 for (i = 0; i < pulse->num_pulse; i++) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
593 pulse->offset[i] = get_bits(gb, 5);
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
594 pulse->amp [i] = get_bits(gb, 4);
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
595 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
596 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
597
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
598 /**
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
599 * Decode Mid/Side data; reference: table 4.54.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
600 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
601 * @param ms_present Indicates mid/side stereo presence. [0] mask is all 0s;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
602 * [1] mask is decoded from bitstream; [2] mask is all 1s;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
603 * [3] reserved for scalable AAC
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
604 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
605 static void decode_mid_side_stereo(ChannelElement * cpe, GetBitContext * gb,
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
606 int ms_present) {
7578
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
607 int idx;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
608 if (ms_present == 1) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
609 for (idx = 0; idx < cpe->ch[0].ics.num_window_groups * cpe->ch[0].ics.max_sfb; idx++)
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
610 cpe->ms_mask[idx] = get_bits1(gb);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
611 } else if (ms_present == 2) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
612 memset(cpe->ms_mask, 1, cpe->ch[0].ics.num_window_groups * cpe->ch[0].ics.max_sfb * sizeof(cpe->ms_mask[0]));
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
613 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
614 }
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
615
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
616 /**
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
617 * Add pulses with particular amplitudes to the quantized spectral data; reference: 4.6.3.3.
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
618 *
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
619 * @param pulse pointer to pulse data struct
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
620 * @param icoef array of quantized spectral data
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
621 */
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
622 static void add_pulses(int icoef[1024], const Pulse * pulse, const IndividualChannelStream * ics) {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
623 int i, off = ics->swb_offset[pulse->start];
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
624 for (i = 0; i < pulse->num_pulse; i++) {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
625 int ic;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
626 off += pulse->offset[i];
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
627 ic = (icoef[off] - 1)>>31;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
628 icoef[off] += (pulse->amp[i]^ic) - ic;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
629 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
630 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
631
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
632 /**
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
633 * Decode an individual_channel_stream payload; reference: table 4.44.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
634 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
635 * @param common_window Channels have independent [0], or shared [1], Individual Channel Stream information.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
636 * @param scale_flag scalable [1] or non-scalable [0] AAC (Unused until scalable AAC is implemented.)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
637 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
638 * @return Returns error status. 0 - OK, !0 - error
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
639 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
640 static int decode_ics(AACContext * ac, SingleChannelElement * sce, GetBitContext * gb, int common_window, int scale_flag) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
641 int icoeffs[1024];
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
642 Pulse pulse;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
643 TemporalNoiseShaping * tns = &sce->tns;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
644 IndividualChannelStream * ics = &sce->ics;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
645 float * out = sce->coeffs;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
646 int global_gain, pulse_present = 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
647
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
648 /* These two assignments are to silence some GCC warnings about the
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
649 * variables being used uninitialised when in fact they always are.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
650 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
651 pulse.num_pulse = 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
652 pulse.start = 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
653
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
654 global_gain = get_bits(gb, 8);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
655
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
656 if (!common_window && !scale_flag) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
657 if (decode_ics_info(ac, ics, gb, 0) < 0)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
658 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
659 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
660
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
661 if (decode_band_types(ac, sce->band_type, sce->band_type_run_end, gb, ics) < 0)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
662 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
663 if (decode_scalefactors(ac, sce->sf, gb, global_gain, ics, sce->band_type, sce->band_type_run_end) < 0)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
664 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
665
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
666 pulse_present = 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
667 if (!scale_flag) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
668 if ((pulse_present = get_bits1(gb))) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
669 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
670 av_log(ac->avccontext, AV_LOG_ERROR, "Pulse tool not allowed in eight short sequence.\n");
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
671 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
672 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
673 decode_pulses(&pulse, gb);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
674 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
675 if ((tns->present = get_bits1(gb)) && decode_tns(ac, tns, gb, ics))
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
676 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
677 if (get_bits1(gb)) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
678 av_log_missing_feature(ac->avccontext, "SSR", 1);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
679 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
680 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
681 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
682
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
683 if (decode_spectrum(ac, icoeffs, gb, ics, sce->band_type) < 0)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
684 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
685 if (pulse_present)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
686 add_pulses(icoeffs, &pulse, ics);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
687 dequant(ac, out, icoeffs, sce->sf, ics, sce->band_type);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
688 return 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
689 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
690
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
691 /**
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
692 * Decode a channel_pair_element; reference: table 4.4.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
693 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
694 * @param elem_id Identifies the instance of a syntax element.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
695 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
696 * @return Returns error status. 0 - OK, !0 - error
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
697 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
698 static int decode_cpe(AACContext * ac, GetBitContext * gb, int elem_id) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
699 int i, ret, common_window, ms_present = 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
700 ChannelElement * cpe;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
701
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
702 cpe = ac->che[TYPE_CPE][elem_id];
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
703 common_window = get_bits1(gb);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
704 if (common_window) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
705 if (decode_ics_info(ac, &cpe->ch[0].ics, gb, 1))
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
706 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
707 i = cpe->ch[1].ics.use_kb_window[0];
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
708 cpe->ch[1].ics = cpe->ch[0].ics;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
709 cpe->ch[1].ics.use_kb_window[1] = i;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
710 ms_present = get_bits(gb, 2);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
711 if(ms_present == 3) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
712 av_log(ac->avccontext, AV_LOG_ERROR, "ms_present = 3 is reserved.\n");
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
713 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
714 } else if(ms_present)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
715 decode_mid_side_stereo(cpe, gb, ms_present);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
716 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
717 if ((ret = decode_ics(ac, &cpe->ch[0], gb, common_window, 0)))
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
718 return ret;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
719 if ((ret = decode_ics(ac, &cpe->ch[1], gb, common_window, 0)))
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
720 return ret;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
721
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
722 if (common_window && ms_present)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
723 apply_mid_side_stereo(cpe);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
724
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
725 if (cpe->ch[1].ics.intensity_present)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
726 apply_intensity_stereo(cpe, ms_present);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
727 return 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
728 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
729
7578
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
730 coup->coupling_point = 2*get_bits1(gb);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
731 coup->num_coupled = get_bits(gb, 3);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
732 for (c = 0; c <= coup->num_coupled; c++) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
733 num_gain++;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
734 coup->type[c] = get_bits1(gb) ? TYPE_CPE : TYPE_SCE;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
735 coup->id_select[c] = get_bits(gb, 4);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
736 if (coup->type[c] == TYPE_CPE) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
737 coup->ch_select[c] = get_bits(gb, 2);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
738 if (coup->ch_select[c] == 3)
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
739 num_gain++;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
740 } else
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
741 coup->ch_select[c] = 1;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
742 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
743 coup->coupling_point += get_bits1(gb);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
744
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
745 if (coup->coupling_point == 2) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
746 av_log(ac->avccontext, AV_LOG_ERROR,
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
747 "Independently switched CCE with 'invalid' domain signalled.\n");
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
748 memset(coup, 0, sizeof(ChannelCoupling));
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
749 return -1;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
750 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
751
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
752 sign = get_bits(gb, 1);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
753 scale = pow(2., pow(2., get_bits(gb, 2) - 3));
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
754
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
755 if ((ret = decode_ics(ac, sce, gb, 0, 0)))
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
756 return ret;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
757
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
758 for (c = 0; c < num_gain; c++) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
759 int cge = 1;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
760 int gain = 0;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
761 float gain_cache = 1.;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
762 if (c) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
763 cge = coup->coupling_point == AFTER_IMDCT ? 1 : get_bits1(gb);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
764 gain = cge ? get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60: 0;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
765 gain_cache = pow(scale, gain);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
766 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
767 for (g = 0; g < sce->ics.num_window_groups; g++)
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
768 for (sfb = 0; sfb < sce->ics.max_sfb; sfb++, idx++)
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
769 if (sce->band_type[idx] != ZERO_BT) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
770 if (!cge) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
771 int t = get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
772 if (t) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
773 int s = 1;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
774 if (sign) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
775 s -= 2 * (t & 0x1);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
776 t >>= 1;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
777 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
778 gain += t;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
779 gain_cache = pow(scale, gain) * s;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
780 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
781 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
782 coup->gain[c][idx] = gain_cache;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
783 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
784 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
785 return 0;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
786 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
787
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
788 /**
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
789 * Decode Spectral Band Replication extension data; reference: table 4.55.
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
790 *
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
791 * @param crc flag indicating the presence of CRC checksum
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
792 * @param cnt length of TYPE_FIL syntactic element in bytes
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
793 *
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
794 * @return Returns number of bytes consumed from the TYPE_FIL element.
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
795 */
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
796 static int decode_sbr_extension(AACContext * ac, GetBitContext * gb, int crc, int cnt) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
797 // TODO : sbr_extension implementation
7540
5298e05f931d Synchronise code with AAC decoder in SoC
superdump
parents: 7539
diff changeset
798 av_log_missing_feature(ac->avccontext, "SBR", 0);
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
799 skip_bits_long(gb, 8*cnt - 4); // -4 due to reading extension type
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
800 return cnt;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
801 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
802
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
803 /**
7578
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
804 * Parse whether channels are to be excluded from Dynamic Range Compression; reference: table 4.53.
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
805 *
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
806 * @return Returns number of bytes consumed.
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
807 */
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
808 static int decode_drc_channel_exclusions(DynamicRangeControl *che_drc, GetBitContext * gb) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
809 int i;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
810 int num_excl_chan = 0;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
811
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
812 do {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
813 for (i = 0; i < 7; i++)
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
814 che_drc->exclude_mask[num_excl_chan++] = get_bits1(gb);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
815 } while (num_excl_chan < MAX_CHANNELS - 7 && get_bits1(gb));
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
816
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
817 return num_excl_chan / 7;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
818 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
819
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
820 /**
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
821 * Decode dynamic range information; reference: table 4.52.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
822 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
823 * @param cnt length of TYPE_FIL syntactic element in bytes
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
824 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
825 * @return Returns number of bytes consumed.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
826 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
827 static int decode_dynamic_range(DynamicRangeControl *che_drc, GetBitContext * gb, int cnt) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
828 int n = 1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
829 int drc_num_bands = 1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
830 int i;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
831
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
832 /* pce_tag_present? */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
833 if(get_bits1(gb)) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
834 che_drc->pce_instance_tag = get_bits(gb, 4);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
835 skip_bits(gb, 4); // tag_reserved_bits
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
836 n++;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
837 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
838
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
839 /* excluded_chns_present? */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
840 if(get_bits1(gb)) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
841 n += decode_drc_channel_exclusions(che_drc, gb);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
842 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
843
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
844 /* drc_bands_present? */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
845 if (get_bits1(gb)) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
846 che_drc->band_incr = get_bits(gb, 4);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
847 che_drc->interpolation_scheme = get_bits(gb, 4);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
848 n++;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
849 drc_num_bands += che_drc->band_incr;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
850 for (i = 0; i < drc_num_bands; i++) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
851 che_drc->band_top[i] = get_bits(gb, 8);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
852 n++;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
853 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
854 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
855
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
856 /* prog_ref_level_present? */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
857 if (get_bits1(gb)) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
858 che_drc->prog_ref_level = get_bits(gb, 7);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
859 skip_bits1(gb); // prog_ref_level_reserved_bits
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
860 n++;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
861 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
862
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
863 for (i = 0; i < drc_num_bands; i++) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
864 che_drc->dyn_rng_sgn[i] = get_bits1(gb);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
865 che_drc->dyn_rng_ctl[i] = get_bits(gb, 7);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
866 n++;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
867 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
868
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
869 return n;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
870 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
871
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
872 /**
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
873 * Decode extension data (incomplete); reference: table 4.51.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
874 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
875 * @param cnt length of TYPE_FIL syntactic element in bytes
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
876 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
877 * @return Returns number of bytes consumed
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
878 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
879 static int decode_extension_payload(AACContext * ac, GetBitContext * gb, int cnt) {
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
880 int crc_flag = 0;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
881 int res = cnt;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
882 switch (get_bits(gb, 4)) { // extension type
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
883 case EXT_SBR_DATA_CRC:
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
884 crc_flag++;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
885 case EXT_SBR_DATA:
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
886 res = decode_sbr_extension(ac, gb, crc_flag, cnt);
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
887 break;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
888 case EXT_DYNAMIC_RANGE:
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
889 res = decode_dynamic_range(&ac->che_drc, gb, cnt);
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
890 break;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
891 case EXT_FILL:
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
892 case EXT_FILL_DATA:
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
893 case EXT_DATA_ELEMENT:
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
894 default:
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
895 skip_bits_long(gb, 8*cnt - 4);
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
896 break;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
897 };
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
898 return res;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
899 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
900
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
901 /**
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
902 * Conduct IMDCT and windowing.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
903 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
904 static void imdct_and_windowing(AACContext * ac, SingleChannelElement * sce) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
905 IndividualChannelStream * ics = &sce->ics;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
906 float * in = sce->coeffs;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
907 float * out = sce->ret;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
908 float * saved = sce->saved;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
909 const float * lwindow = ics->use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_aac_sine_long_1024;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
910 const float * swindow = ics->use_kb_window[0] ? ff_aac_kbd_short_128 : ff_aac_sine_short_128;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
911 const float * lwindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_long_1024 : ff_aac_sine_long_1024;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
912 const float * swindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_short_128 : ff_aac_sine_short_128;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
913 float * buf = ac->buf_mdct;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
914 int i;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
915
7578
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
916 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
917 if (ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE)
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
918 av_log(ac->avccontext, AV_LOG_WARNING,
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
919 "Transition from an ONLY_LONG or LONG_STOP to an EIGHT_SHORT sequence detected. "
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
920 "If you heard an audible artifact, please submit the sample to the FFmpeg developers.\n");
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
921 for (i = 0; i < 2048; i += 256) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
922 ff_imdct_calc(&ac->mdct_small, buf + i, in + i/2);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
923 ac->dsp.vector_fmul_reverse(ac->revers + i/2, buf + i + 128, swindow, 128);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
924 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
925 for (i = 0; i < 448; i++) out[i] = saved[i] + ac->add_bias;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
926
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
927 ac->dsp.vector_fmul_add_add(out + 448 + 0*128, buf + 0*128, swindow_prev, saved + 448 , ac->add_bias, 128, 1);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
928 ac->dsp.vector_fmul_add_add(out + 448 + 1*128, buf + 2*128, swindow, ac->revers + 0*128, ac->add_bias, 128, 1);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
929 ac->dsp.vector_fmul_add_add(out + 448 + 2*128, buf + 4*128, swindow, ac->revers + 1*128, ac->add_bias, 128, 1);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
930 ac->dsp.vector_fmul_add_add(out + 448 + 3*128, buf + 6*128, swindow, ac->revers + 2*128, ac->add_bias, 128, 1);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
931 ac->dsp.vector_fmul_add_add(out + 448 + 4*128, buf + 8*128, swindow, ac->revers + 3*128, ac->add_bias, 64, 1);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
932
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
933 #if 0
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
934 vector_fmul_add_add_add(&ac->dsp, out + 448 + 1*128, buf + 2*128, swindow, saved + 448 + 1*128, ac->revers + 0*128, ac->add_bias, 128);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
935 vector_fmul_add_add_add(&ac->dsp, out + 448 + 2*128, buf + 4*128, swindow, saved + 448 + 2*128, ac->revers + 1*128, ac->add_bias, 128);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
936 vector_fmul_add_add_add(&ac->dsp, out + 448 + 3*128, buf + 6*128, swindow, saved + 448 + 3*128, ac->revers + 2*128, ac->add_bias, 128);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
937 vector_fmul_add_add_add(&ac->dsp, out + 448 + 4*128, buf + 8*128, swindow, saved + 448 + 4*128, ac->revers + 3*128, ac->add_bias, 64);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
938 #endif
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
939
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
940 ac->dsp.vector_fmul_add_add(saved, buf + 1024 + 64, swindow + 64, ac->revers + 3*128+64, 0, 64, 1);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
941 ac->dsp.vector_fmul_add_add(saved + 64, buf + 1024 + 2*128, swindow, ac->revers + 4*128, 0, 128, 1);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
942 ac->dsp.vector_fmul_add_add(saved + 192, buf + 1024 + 4*128, swindow, ac->revers + 5*128, 0, 128, 1);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
943 ac->dsp.vector_fmul_add_add(saved + 320, buf + 1024 + 6*128, swindow, ac->revers + 6*128, 0, 128, 1);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
944 memcpy( saved + 448, ac->revers + 7*128, 128 * sizeof(float));
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
945 memset( saved + 576, 0, 448 * sizeof(float));
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
946 } else {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
947 ff_imdct_calc(&ac->mdct, buf, in);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
948 if (ics->window_sequence[0] == LONG_STOP_SEQUENCE) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
949 for (i = 0; i < 448; i++) out[i] = saved[i] + ac->add_bias;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
950 ac->dsp.vector_fmul_add_add(out + 448, buf + 448, swindow_prev, saved + 448, ac->add_bias, 128, 1);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
951 for (i = 576; i < 1024; i++) out[i] = buf[i] + saved[i] + ac->add_bias;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
952 } else {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
953 ac->dsp.vector_fmul_add_add(out, buf, lwindow_prev, saved, ac->add_bias, 1024, 1);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
954 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
955 if (ics->window_sequence[0] == LONG_START_SEQUENCE) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
956 memcpy(saved, buf + 1024, 448 * sizeof(float));
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
957 ac->dsp.vector_fmul_reverse(saved + 448, buf + 1024 + 448, swindow, 128);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
958 memset(saved + 576, 0, 448 * sizeof(float));
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
959 } else {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
960 ac->dsp.vector_fmul_reverse(saved, buf + 1024, lwindow, 1024);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
961 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
962 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
963 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
964
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
965 /**
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
966 * Apply dependent channel coupling (applied before IMDCT).
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
967 *
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
968 * @param index index into coupling gain array
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
969 */
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
970 static void apply_dependent_coupling(AACContext * ac, SingleChannelElement * sce, ChannelElement * cc, int index) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
971 IndividualChannelStream * ics = &cc->ch[0].ics;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
972 const uint16_t * offsets = ics->swb_offset;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
973 float * dest = sce->coeffs;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
974 const float * src = cc->ch[0].coeffs;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
975 int g, i, group, k, idx = 0;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
976 if(ac->m4ac.object_type == AOT_AAC_LTP) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
977 av_log(ac->avccontext, AV_LOG_ERROR,
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
978 "Dependent coupling is not supported together with LTP\n");
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
979 return;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
980 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
981 for (g = 0; g < ics->num_window_groups; g++) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
982 for (i = 0; i < ics->max_sfb; i++, idx++) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
983 if (cc->ch[0].band_type[idx] != ZERO_BT) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
984 for (group = 0; group < ics->group_len[g]; group++) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
985 for (k = offsets[i]; k < offsets[i+1]; k++) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
986 // XXX dsputil-ize
7540
5298e05f931d Synchronise code with AAC decoder in SoC
superdump
parents: 7539
diff changeset
987 dest[group*128+k] += cc->coup.gain[index][idx] * src[group*128+k];
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
988 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
989 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
990 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
991 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
992 dest += ics->group_len[g]*128;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
993 src += ics->group_len[g]*128;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
994 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
995 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
996
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
997 /**
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
998 * Apply independent channel coupling (applied after IMDCT).
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
999 *
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
1000 * @param index index into coupling gain array
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
1001 */
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
1002 static void apply_independent_coupling(AACContext * ac, SingleChannelElement * sce, ChannelElement * cc, int index) {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
1003 int i;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
1004 for (i = 0; i < 1024; i++)
7540
5298e05f931d Synchronise code with AAC decoder in SoC
superdump
parents: 7539
diff changeset
1005 sce->ret[i] += cc->coup.gain[index][0] * (cc->ch[0].ret[i] - ac->add_bias);
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
1006 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
1007
7578
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1008 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1009 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1010 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1011 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1012
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1013 static int aac_decode_frame(AVCodecContext * avccontext, void * data, int * data_size, const uint8_t * buf, int buf_size) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1014 AACContext * ac = avccontext->priv_data;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1015 GetBitContext gb;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1016 enum RawDataBlockType elem_type;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1017 int err, elem_id, data_size_tmp;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1018
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1019 init_get_bits(&gb, buf, buf_size*8);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1020
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1021 // parse
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1022 while ((elem_type = get_bits(&gb, 3)) != TYPE_END) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1023 elem_id = get_bits(&gb, 4);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1024 err = -1;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1025
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1026 if(elem_type == TYPE_SCE && elem_id == 1 &&
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1027 !ac->che[TYPE_SCE][elem_id] && ac->che[TYPE_LFE][0]) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1028 /* Some streams incorrectly code 5.1 audio as SCE[0] CPE[0] CPE[1] SCE[1]
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1029 instead of SCE[0] CPE[0] CPE[0] LFE[0]. If we seem to have
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1030 encountered such a stream, transfer the LFE[0] element to SCE[1] */
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1031 ac->che[TYPE_SCE][elem_id] = ac->che[TYPE_LFE][0];
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1032 ac->che[TYPE_LFE][0] = NULL;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1033 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1034 if(elem_type && elem_type < TYPE_DSE) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1035 if(!ac->che[elem_type][elem_id])
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1036 return -1;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1037 if(elem_type != TYPE_CCE)
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1038 ac->che[elem_type][elem_id]->coup.coupling_point = 4;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1039 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1040
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1041 switch (elem_type) {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1042
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1043 case TYPE_SCE:
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1044 err = decode_ics(ac, &ac->che[TYPE_SCE][elem_id]->ch[0], &gb, 0, 0);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1045 break;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1046
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1047 case TYPE_CPE:
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1048 err = decode_cpe(ac, &gb, elem_id);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1049 break;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1050
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1051 case TYPE_CCE:
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1052 err = decode_cce(ac, &gb, ac->che[TYPE_SCE][elem_id]);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1053 break;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1054
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1055 case TYPE_LFE:
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1056 err = decode_ics(ac, &ac->che[TYPE_LFE][elem_id]->ch[0], &gb, 0, 0);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1057 break;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1058
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1059 case TYPE_DSE:
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1060 skip_data_stream_element(&gb);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1061 err = 0;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1062 break;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1063
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1064 case TYPE_PCE:
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1065 {
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1066 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID];
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1067 memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1068 if((err = decode_pce(ac, new_che_pos, &gb)))
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1069 break;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1070 err = output_configure(ac, ac->che_pos, new_che_pos);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1071 break;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1072 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1073
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1074 case TYPE_FIL:
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1075 if (elem_id == 15)
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1076 elem_id += get_bits(&gb, 8) - 1;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1077 while (elem_id > 0)
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1078 elem_id -= decode_extension_payload(ac, &gb, elem_id);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1079 err = 0; /* FIXME */
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1080 break;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1081
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1082 default:
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1083 err = -1; /* should not happen, but keeps compiler happy */
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1084 break;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1085 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1086
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1087 if(err)
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1088 return err;
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1089 }
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1090
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1091 spectral_to_sample(ac);
a05954c505ab More OKed sections of AAC decoder code
superdump
parents: 7540
diff changeset
1092
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
1093 if (!ac->is_saved) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
1094 ac->is_saved = 1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
1095 *data_size = 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
1096 return 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
1097 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
1098
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
1099 data_size_tmp = 1024 * avccontext->channels * sizeof(int16_t);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
1100 if(*data_size < data_size_tmp) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
1101 av_log(avccontext, AV_LOG_ERROR,
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
1102 "Output buffer too small (%d) or trying to output too many samples (%d) for this frame.\n",
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
1103 *data_size, data_size_tmp);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
1104 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
1105 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
1106 *data_size = data_size_tmp;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
1107
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
1108 ac->dsp.float_to_int16_interleave(data, (const float **)ac->output_data, 1024, avccontext->channels);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
1109
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
1110 return buf_size;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
1111 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
1112
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1113 static av_cold int aac_decode_close(AVCodecContext * avccontext) {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1114 AACContext * ac = avccontext->priv_data;
7540
5298e05f931d Synchronise code with AAC decoder in SoC
superdump
parents: 7539
diff changeset
1115 int i, type;
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1116
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
1117 for (i = 0; i < MAX_ELEM_ID; i++) {
7540
5298e05f931d Synchronise code with AAC decoder in SoC
superdump
parents: 7539
diff changeset
1118 for(type = 0; type < 4; type++)
5298e05f931d Synchronise code with AAC decoder in SoC
superdump
parents: 7539
diff changeset
1119 av_freep(&ac->che[type][i]);
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1120 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1121
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1122 ff_mdct_end(&ac->mdct);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1123 ff_mdct_end(&ac->mdct_small);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1124 return 0 ;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1125 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1126
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1127 AVCodec aac_decoder = {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1128 "aac",
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1129 CODEC_TYPE_AUDIO,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1130 CODEC_ID_AAC,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1131 sizeof(AACContext),
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1132 aac_decode_init,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1133 NULL,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1134 aac_decode_close,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1135 aac_decode_frame,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1136 .long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"),
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
1137 .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
1138 };