annotate aac.c @ 7539:4fca7939ad48 libavcodec

More OKed hunks of the AAC decoder from SoC
author superdump
date Mon, 11 Aug 2008 11:16:06 +0000
parents a3f7ffdb676d
children 5298e05f931d
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 /**
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
103 * 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
104 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
105 * @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
106 * @param sce_map mono (Single Channel Element) map
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
107 * @param type speaker type/position for these channels
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
108 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
109 static void decode_channel_map(enum ChannelPosition *cpe_map,
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
110 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
111 while(n--) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
112 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
113 map[get_bits(gb, 4)] = type;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
114 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
115 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
116
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
117 /**
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
118 * Decode program configuration element; reference: table 4.2.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
119 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
120 * @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
121 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
122 * @return Returns error status. 0 - OK, !0 - error
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
123 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
124 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
125 GetBitContext * gb) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
126 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
127
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
128 skip_bits(gb, 2); // object_type
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
129
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
130 ac->m4ac.sampling_index = get_bits(gb, 4);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
131 if(ac->m4ac.sampling_index > 11) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
132 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
133 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
134 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
135 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
136 num_front = get_bits(gb, 4);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
137 num_side = get_bits(gb, 4);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
138 num_back = get_bits(gb, 4);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
139 num_lfe = get_bits(gb, 2);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
140 num_assoc_data = get_bits(gb, 3);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
141 num_cc = get_bits(gb, 4);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
142
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
143 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
144 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
145 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
146 skip_bits(gb, 4); // stereo_mixdown_tag
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
147
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
148 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
149 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
150
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
151 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
152 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
153 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
154 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
155
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
156 skip_bits_long(gb, 4 * num_assoc_data);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
157
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
158 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
159
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
160 align_get_bits(gb);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
161
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
162 /* comment field, first byte is length */
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
163 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
164 return 0;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
165 }
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
166
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
167 /**
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
168 * 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
169 * as specified in table 1.17.
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 * @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
172 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
173 * @return Returns error status. 0 - OK, !0 - error
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 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
176 int channel_config)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
177 {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
178 if(channel_config < 1 || channel_config > 7) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
179 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
180 channel_config);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
181 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
182 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
183
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
184 /* default channel configurations:
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
185 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
186 * 1ch : front center (mono)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
187 * 2ch : L + R (stereo)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
188 * 3ch : front center + L + R
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
189 * 4ch : front center + L + R + back center
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
190 * 5ch : front center + L + R + back stereo
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
191 * 6ch : front center + L + R + back stereo + LFE
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
192 * 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
193 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
194
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
195 if(channel_config != 2)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
196 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
197 if(channel_config > 1)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
198 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
199 if(channel_config == 4)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
200 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
201 if(channel_config > 4)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
202 new_che_pos[TYPE_CPE][(channel_config == 7) + 1]
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
203 = AAC_CHANNEL_BACK; // back stereo
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
204 if(channel_config > 5)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
205 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
206 if(channel_config == 7)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
207 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
208
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
209 return 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
210 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
211
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
212 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
213 }
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 if (get_bits1(gb)) // dependsOnCoreCoder
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
216 skip_bits(gb, 14); // coreCoderDelay
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
217 extension_flag = get_bits1(gb);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
218
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
219 if(ac->m4ac.object_type == AOT_AAC_SCALABLE ||
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
220 ac->m4ac.object_type == AOT_ER_AAC_SCALABLE)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
221 skip_bits(gb, 3); // layerNr
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
222
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
223 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
224 if (channel_config == 0) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
225 skip_bits(gb, 4); // element_instance_tag
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
226 if((ret = decode_pce(ac, new_che_pos, gb)))
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
227 return ret;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
228 } else {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
229 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
230 return ret;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
231 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
232 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
233 return ret;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
234
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
235 if (extension_flag) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
236 switch (ac->m4ac.object_type) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
237 case AOT_ER_BSAC:
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
238 skip_bits(gb, 5); // numOfSubFrame
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
239 skip_bits(gb, 11); // layer_length
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
240 break;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
241 case AOT_ER_AAC_LC:
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
242 case AOT_ER_AAC_LTP:
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
243 case AOT_ER_AAC_SCALABLE:
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
244 case AOT_ER_AAC_LD:
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
245 skip_bits(gb, 3); /* aacSectionDataResilienceFlag
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
246 * aacScalefactorDataResilienceFlag
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
247 * aacSpectralDataResilienceFlag
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
248 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
249 break;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
250 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
251 skip_bits1(gb); // extensionFlag3 (TBD in version 3)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
252 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
253 return 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
254 }
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 /**
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
257 * Decode audio specific configuration; reference: table 1.13.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
258 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
259 * @param data pointer to AVCodecContext extradata
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
260 * @param data_size size of AVCCodecContext extradata
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
261 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
262 * @return Returns error status. 0 - OK, !0 - error
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
263 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
264 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
265 GetBitContext gb;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
266 int i;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
267
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
268 init_get_bits(&gb, data, data_size * 8);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
269
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
270 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
271 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
272 if(ac->m4ac.sampling_index > 11) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
273 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
274 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
275 }
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 skip_bits_long(&gb, i);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
278
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
279 switch (ac->m4ac.object_type) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
280 case AOT_AAC_LC:
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
281 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
282 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
283 break;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
284 default:
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
285 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
286 ac->m4ac.sbr == 1? "SBR+" : "", ac->m4ac.object_type);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
287 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
288 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
289 return 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
290 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
291
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
292 static av_cold int aac_decode_init(AVCodecContext * avccontext) {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
293 AACContext * ac = avccontext->priv_data;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
294 int i;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
295
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
296 ac->avccontext = avccontext;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
297
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
298 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
299 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
300 return -1;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
301
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
302 avccontext->sample_fmt = SAMPLE_FMT_S16;
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
303 avccontext->sample_rate = ac->m4ac.sample_rate;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
304 avccontext->frame_size = 1024;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
305
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
306 AAC_INIT_VLC_STATIC( 0, 144);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
307 AAC_INIT_VLC_STATIC( 1, 114);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
308 AAC_INIT_VLC_STATIC( 2, 188);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
309 AAC_INIT_VLC_STATIC( 3, 180);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
310 AAC_INIT_VLC_STATIC( 4, 172);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
311 AAC_INIT_VLC_STATIC( 5, 140);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
312 AAC_INIT_VLC_STATIC( 6, 168);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
313 AAC_INIT_VLC_STATIC( 7, 114);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
314 AAC_INIT_VLC_STATIC( 8, 262);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
315 AAC_INIT_VLC_STATIC( 9, 248);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
316 AAC_INIT_VLC_STATIC(10, 384);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
317
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
318 dsputil_init(&ac->dsp, avccontext);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
319
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
320 ac->random_state = 0x1f2e3d4c;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
321
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
322 // -1024 - Compensate wrong IMDCT method.
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
323 // 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
324 // for float to int16 conversion.
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
325
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
326 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
327 ac->add_bias = 385.0f;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
328 ac->sf_scale = 1. / (-1024. * 32768.);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
329 ac->sf_offset = 0;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
330 } else {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
331 ac->add_bias = 0.0f;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
332 ac->sf_scale = 1. / -1024.;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
333 ac->sf_offset = 60;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
334 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
335
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
336 #ifndef CONFIG_HARDCODED_TABLES
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
337 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
338 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
339 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
340 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
341 #endif /* CONFIG_HARDCODED_TABLES */
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
342
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
343 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
344 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
345 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
346 352);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
347
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
348 ff_mdct_init(&ac->mdct, 11, 1);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
349 ff_mdct_init(&ac->mdct_small, 8, 1);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
350 return 0;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
351 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
352
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
353 /**
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
354 * Skip data_stream_element; reference: table 4.10.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
355 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
356 static void skip_data_stream_element(GetBitContext * gb) {
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
357 int byte_align = get_bits1(gb);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
358 int count = get_bits(gb, 8);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
359 if (count == 255)
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
360 count += get_bits(gb, 8);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
361 if (byte_align)
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
362 align_get_bits(gb);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
363 skip_bits_long(gb, 8 * count);
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
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
366 /**
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
367 * Decode Individual Channel Stream info; reference: table 4.6.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
368 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
369 * @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
370 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
371 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
372 if (get_bits1(gb)) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
373 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
374 memset(ics, 0, sizeof(IndividualChannelStream));
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
375 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
376 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
377 ics->window_sequence[1] = ics->window_sequence[0];
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
378 ics->window_sequence[0] = get_bits(gb, 2);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
379 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
380 ics->use_kb_window[0] = get_bits1(gb);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
381 ics->num_window_groups = 1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
382 ics->group_len[0] = 1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
383
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
384 return 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
385 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
386
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
387 /**
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
388 * inverse quantization
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
389 *
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
390 * @param a quantized value to be dequantized
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
391 * @return Returns dequantized value.
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
392 */
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
393 static inline float ivquant(int a) {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
394 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
395 return ff_aac_ivquant_tab[a + IVQUANT_SIZE/2 - 1];
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
396 else
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
397 return cbrtf(fabsf(a)) * a;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
398 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
399
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
400 /**
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
401 * 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
402 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
403 * @param band_type array of the used band type
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
404 * @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
405 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
406 * @return Returns error status. 0 - OK, !0 - error
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
407 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
408 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
409 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
410 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
411 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
412 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
413 int k = 0;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
414 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
415 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
416 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
417 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
418 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
419 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
420 return -1;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
421 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
422 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
423 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
424 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
425 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
426 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
427 "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
428 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
429 return -1;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
430 }
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
431 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
432 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
433 return 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
434 }
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
435
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
436 /**
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
437 * 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
438 *
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
439 * @param mix_gain channel gain (Not used by AAC bitstream.)
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
440 * @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
441 * @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
442 * @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
443 * @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
444 *
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
445 * @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
446 */
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
447 static int decode_scalefactors(AACContext * ac, float sf[120], GetBitContext * gb,
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
448 float mix_gain, unsigned int global_gain, IndividualChannelStream * ics,
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
449 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
450 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
451 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
452 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
453 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
454 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
455 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
456 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
457 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
458 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
459 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
460 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
461 sf[idx] = 0.;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
462 }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
463 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
464 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
465 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
466 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
467 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
468 "%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
469 return -1;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
470 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
471 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
472 sf[idx] *= mix_gain;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
473 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
474 }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
475 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
476 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
477 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
478 else
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
479 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
480 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
481 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
482 "%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
483 return -1;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
484 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
485 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
486 sf[idx] *= mix_gain;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
487 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
488 }else {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
489 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
490 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
491 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
492 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
493 "%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
494 return -1;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
495 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
496 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
497 sf[idx] *= mix_gain;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
498 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
499 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
500 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
501 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
502 return 0;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
503 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
504
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 * 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
507 */
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
508 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
509 int i;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
510 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
511 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
512 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
513 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
514 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
515 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
516 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
517
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
518 /**
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
519 * Decode Mid/Side data; reference: table 4.54.
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 * @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
522 * [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
523 * [3] reserved for scalable AAC
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
524 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
525 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
526 int ms_present) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
527
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
528 /**
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
529 * 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
530 *
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
531 * @param pulse pointer to pulse data struct
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
532 * @param icoef array of quantized spectral data
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
533 */
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
534 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
535 int i, off = ics->swb_offset[pulse->start];
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
536 for (i = 0; i < pulse->num_pulse; i++) {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
537 int ic;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
538 off += pulse->offset[i];
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
539 ic = (icoef[off] - 1)>>31;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
540 icoef[off] += (pulse->amp[i]^ic) - ic;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
541 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
542 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
543
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
544 /**
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
545 * 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
546 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
547 * @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
548 * @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
549 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
550 * @return Returns error status. 0 - OK, !0 - error
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
551 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
552 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
553 int icoeffs[1024];
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
554 Pulse pulse;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
555 TemporalNoiseShaping * tns = &sce->tns;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
556 IndividualChannelStream * ics = &sce->ics;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
557 float * out = sce->coeffs;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
558 int global_gain, pulse_present = 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
559
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
560 /* 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
561 * 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
562 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
563 pulse.num_pulse = 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
564 pulse.start = 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
565
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
566 global_gain = get_bits(gb, 8);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
567
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
568 if (!common_window && !scale_flag) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
569 if (decode_ics_info(ac, ics, gb, 0) < 0)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
570 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
571 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
572
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
573 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
574 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
575 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
576 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
577
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
578 pulse_present = 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
579 if (!scale_flag) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
580 if ((pulse_present = get_bits1(gb))) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
581 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
582 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
583 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
584 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
585 decode_pulses(&pulse, gb);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
586 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
587 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
588 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
589 if (get_bits1(gb)) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
590 av_log_missing_feature(ac->avccontext, "SSR", 1);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
591 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
592 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
593 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
594
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
595 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
596 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
597 if (pulse_present)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
598 add_pulses(icoeffs, &pulse, ics);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
599 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
600 return 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
601 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
602
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
603 /**
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
604 * Decode a channel_pair_element; reference: table 4.4.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
605 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
606 * @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
607 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
608 * @return Returns error status. 0 - OK, !0 - error
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
609 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
610 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
611 int i, ret, common_window, ms_present = 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
612 ChannelElement * cpe;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
613
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
614 cpe = ac->che[TYPE_CPE][elem_id];
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
615 common_window = get_bits1(gb);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
616 if (common_window) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
617 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
618 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
619 i = cpe->ch[1].ics.use_kb_window[0];
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
620 cpe->ch[1].ics = cpe->ch[0].ics;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
621 cpe->ch[1].ics.use_kb_window[1] = i;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
622 ms_present = get_bits(gb, 2);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
623 if(ms_present == 3) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
624 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
625 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
626 } else if(ms_present)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
627 decode_mid_side_stereo(cpe, gb, ms_present);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
628 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
629 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
630 return ret;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
631 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
632 return ret;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
633
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
634 if (common_window && ms_present)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
635 apply_mid_side_stereo(cpe);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
636
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
637 if (cpe->ch[1].ics.intensity_present)
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
638 apply_intensity_stereo(cpe, ms_present);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
639 return 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
640 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
641
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
642 /**
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
643 * 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
644 *
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
645 * @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
646 * @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
647 *
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
648 * @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
649 */
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
650 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
651 // TODO : sbr_extension implementation
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
652 av_log(ac->avccontext, AV_LOG_DEBUG, "aac: SBR not yet supported.\n");
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
653 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
654 return cnt;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
655 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
656
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
657 /**
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
658 * Decode dynamic range information; reference: table 4.52.
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 * @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
661 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
662 * @return Returns number of bytes consumed.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
663 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
664 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
665 int n = 1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
666 int drc_num_bands = 1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
667 int i;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
668
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
669 /* pce_tag_present? */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
670 if(get_bits1(gb)) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
671 che_drc->pce_instance_tag = get_bits(gb, 4);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
672 skip_bits(gb, 4); // tag_reserved_bits
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
673 n++;
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
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
676 /* excluded_chns_present? */
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 n += decode_drc_channel_exclusions(che_drc, gb);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
679 }
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 /* drc_bands_present? */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
682 if (get_bits1(gb)) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
683 che_drc->band_incr = get_bits(gb, 4);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
684 che_drc->interpolation_scheme = get_bits(gb, 4);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
685 n++;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
686 drc_num_bands += che_drc->band_incr;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
687 for (i = 0; i < drc_num_bands; i++) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
688 che_drc->band_top[i] = get_bits(gb, 8);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
689 n++;
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
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
693 /* prog_ref_level_present? */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
694 if (get_bits1(gb)) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
695 che_drc->prog_ref_level = get_bits(gb, 7);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
696 skip_bits1(gb); // prog_ref_level_reserved_bits
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
697 n++;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
698 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
699
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
700 for (i = 0; i < drc_num_bands; i++) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
701 che_drc->dyn_rng_sgn[i] = get_bits1(gb);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
702 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
703 n++;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
704 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
705
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
706 return n;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
707 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
708
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
709 /**
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
710 * Decode extension data (incomplete); reference: table 4.51.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
711 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
712 * @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
713 *
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
714 * @return Returns number of bytes consumed
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
715 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
716 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
717 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
718 int res = cnt;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
719 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
720 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
721 crc_flag++;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
722 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
723 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
724 break;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
725 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
726 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
727 break;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
728 case EXT_FILL:
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
729 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
730 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
731 default:
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
732 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
733 break;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
734 };
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
735 return res;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
736 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
737
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
738 /**
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
739 * Conduct IMDCT and windowing.
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
740 */
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
741 static void imdct_and_windowing(AACContext * ac, SingleChannelElement * sce) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
742 IndividualChannelStream * ics = &sce->ics;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
743 float * in = sce->coeffs;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
744 float * out = sce->ret;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
745 float * saved = sce->saved;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
746 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
747 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
748 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
749 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
750 float * buf = ac->buf_mdct;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
751 int i;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
752
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
753 /**
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
754 * 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
755 *
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
756 * @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
757 */
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
758 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
759 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
760 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
761 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
762 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
763 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
764 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
765 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
766 "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
767 return;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
768 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
769 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
770 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
771 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
772 float gain = cc->coup.gain[index][idx] * sce->mixing_gain;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
773 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
774 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
775 // XXX dsputil-ize
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
776 dest[group*128+k] += gain * src[group*128+k];
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
777 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
778 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
779 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
780 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
781 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
782 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
783 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
784 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
785
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
786 /**
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
787 * 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
788 *
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
789 * @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
790 */
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
791 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
792 int i;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
793 float gain = cc->coup.gain[index][0] * sce->mixing_gain;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
794 for (i = 0; i < 1024; i++)
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
795 sce->ret[i] += gain * (cc->ch[0].ret[i] - ac->add_bias);
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
796 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
797
7539
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
798 if (!ac->is_saved) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
799 ac->is_saved = 1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
800 *data_size = 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
801 return 0;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
802 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
803
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
804 data_size_tmp = 1024 * avccontext->channels * sizeof(int16_t);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
805 if(*data_size < data_size_tmp) {
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
806 av_log(avccontext, AV_LOG_ERROR,
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
807 "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
808 *data_size, data_size_tmp);
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
809 return -1;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
810 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
811 *data_size = data_size_tmp;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
812
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
813 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
814
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
815 return buf_size;
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
816 }
4fca7939ad48 More OKed hunks of the AAC decoder from SoC
superdump
parents: 7523
diff changeset
817
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
818 static av_cold int aac_decode_close(AVCodecContext * avccontext) {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
819 AACContext * ac = avccontext->priv_data;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
820 int i, j;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
821
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
822 for (i = 0; i < MAX_ELEM_ID; i++) {
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
823 for(j = 0; j < 4; j++)
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
824 av_freep(&ac->che[j][i]);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
825 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
826
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
827 ff_mdct_end(&ac->mdct);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
828 ff_mdct_end(&ac->mdct_small);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
829 return 0 ;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
830 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
831
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
832 AVCodec aac_decoder = {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
833 "aac",
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
834 CODEC_TYPE_AUDIO,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
835 CODEC_ID_AAC,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
836 sizeof(AACContext),
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
837 aac_decode_init,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
838 NULL,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
839 aac_decode_close,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
840 aac_decode_frame,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
841 .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
842 .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
843 };