annotate aac.c @ 7523:a3f7ffdb676d libavcodec

Sync already committed code with that in SoC and commit more OKed hunks of code
author superdump
date Sat, 09 Aug 2008 10:46:27 +0000
parents d6012be599d3
children 4fca7939ad48
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
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
102 num_front = get_bits(gb, 4);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
103 num_side = get_bits(gb, 4);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
104 num_back = get_bits(gb, 4);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
105 num_lfe = get_bits(gb, 2);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
106 num_assoc_data = get_bits(gb, 3);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
107 num_cc = get_bits(gb, 4);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
108
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
109 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
110 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
111 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
112 skip_bits(gb, 4); // stereo_mixdown_tag
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
113
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
114 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
115 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
116
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
117 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
118 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
119 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
120 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
121
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
122 skip_bits_long(gb, 4 * num_assoc_data);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
123
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
124 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
125
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
126 align_get_bits(gb);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
127
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
128 /* comment field, first byte is length */
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
129 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
130 return 0;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
131 }
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
132
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
133 static av_cold int aac_decode_init(AVCodecContext * avccontext) {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
134 AACContext * ac = avccontext->priv_data;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
135 int i;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
136
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
137 ac->avccontext = avccontext;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
138
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
139 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
140 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
141 return -1;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
142
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
143 avccontext->sample_rate = ac->m4ac.sample_rate;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
144 avccontext->frame_size = 1024;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
145
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
146 AAC_INIT_VLC_STATIC( 0, 144);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
147 AAC_INIT_VLC_STATIC( 1, 114);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
148 AAC_INIT_VLC_STATIC( 2, 188);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
149 AAC_INIT_VLC_STATIC( 3, 180);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
150 AAC_INIT_VLC_STATIC( 4, 172);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
151 AAC_INIT_VLC_STATIC( 5, 140);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
152 AAC_INIT_VLC_STATIC( 6, 168);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
153 AAC_INIT_VLC_STATIC( 7, 114);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
154 AAC_INIT_VLC_STATIC( 8, 262);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
155 AAC_INIT_VLC_STATIC( 9, 248);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
156 AAC_INIT_VLC_STATIC(10, 384);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
157
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
158 dsputil_init(&ac->dsp, avccontext);
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 // -1024 - Compensate wrong IMDCT method.
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
161 // 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
162 // for float to int16 conversion.
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
163
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
164 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
165 ac->add_bias = 385.0f;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
166 ac->sf_scale = 1. / (-1024. * 32768.);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
167 ac->sf_offset = 0;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
168 } else {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
169 ac->add_bias = 0.0f;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
170 ac->sf_scale = 1. / -1024.;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
171 ac->sf_offset = 60;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
172 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
173
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
174 #ifndef CONFIG_HARDCODED_TABLES
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
175 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
176 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
177 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
178 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
179 #endif /* CONFIG_HARDCODED_TABLES */
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
180
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
181 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
182 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
183 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
184 352);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
185
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
186 ff_mdct_init(&ac->mdct, 11, 1);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
187 ff_mdct_init(&ac->mdct_small, 8, 1);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
188 return 0;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
189 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
190
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
191 int byte_align = get_bits1(gb);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
192 int count = get_bits(gb, 8);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
193 if (count == 255)
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
194 count += get_bits(gb, 8);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
195 if (byte_align)
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
196 align_get_bits(gb);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
197 skip_bits_long(gb, 8 * count);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
198 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
199
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
200 /**
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
201 * inverse quantization
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
202 *
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
203 * @param a quantized value to be dequantized
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
204 * @return Returns dequantized value.
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
205 */
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
206 static inline float ivquant(int a) {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
207 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
208 return ff_aac_ivquant_tab[a + IVQUANT_SIZE/2 - 1];
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
209 else
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
210 return cbrtf(fabsf(a)) * a;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
211 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
212
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
213 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
214 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
215 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
216 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
217 int k = 0;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
218 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
219 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
220 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
221 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
222 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
223 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
224 return -1;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
225 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
226 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
227 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
228 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
229 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
230 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
231 "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
232 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
233 return -1;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
234 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
235
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
236 *
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
237 * @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
238 * @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
239 * @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
240 * @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
241 * @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
242 *
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
243 * @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
244 */
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
245 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
246 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
247 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
248 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
249 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
250 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
251 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
252 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
253 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
254 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
255 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
256 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
257 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
258 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
259 sf[idx] = 0.;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
260 }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
261 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
262 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
263 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
264 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
265 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
266 "%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
267 return -1;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
268 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
269 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
270 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
271 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
272 }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
273 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
274 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
275 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
276 else
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
277 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
278 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
279 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
280 "%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
281 return -1;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
282 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
283 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
284 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
285 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
286 }else {
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
287 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
288 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
289 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
290 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
291 "%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
292 return -1;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
293 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
294 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
295 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
296 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
297 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
298 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
299 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
300 return 0;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
301 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
302
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
303 /**
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
304 * 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
305 */
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
306 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
307 int i;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
308 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
309 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
310 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
311 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
312 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
313 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
314 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
315
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
316 /**
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
317 * 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
318 *
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
319 * @param pulse pointer to pulse data struct
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
320 * @param icoef array of quantized spectral data
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
321 */
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
322 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
323 int i, off = ics->swb_offset[pulse->start];
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
324 for (i = 0; i < pulse->num_pulse; i++) {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
325 int ic;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
326 off += pulse->offset[i];
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
327 ic = (icoef[off] - 1)>>31;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
328 icoef[off] += (pulse->amp[i]^ic) - ic;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
329 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
330 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
331
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
332 /**
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
333 * Parse Spectral Band Replication extension data; reference: table 4.55.
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
334 *
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
335 * @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
336 * @param cnt length of TYPE_FIL syntactic element in bytes
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
337 * @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
338 */
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
339 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
340 // 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
341 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
342 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
343 return cnt;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
344 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
345
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
346 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
347 int res = cnt;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
348 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
349 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
350 crc_flag++;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
351 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
352 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
353 break;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
354 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
355 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
356 break;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
357 case EXT_FILL:
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
358 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
359 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
360 default:
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
361 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
362 break;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
363 };
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
364 return res;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
365 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
366
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
367 /**
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
368 * 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
369 *
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
370 * @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
371 */
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
372 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
373 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
374 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
375 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
376 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
377 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
378 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
379 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
380 "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
381 return;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
382 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
383 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
384 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
385 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
386 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
387 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
388 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
389 // XXX dsputil-ize
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
390 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
391 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
392 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
393 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
394 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
395 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
396 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
397 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
398 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
399
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
400 /**
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
401 * 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
402 *
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
403 * @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
404 */
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
405 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
406 int i;
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
407 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
408 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
409 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
410 }
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
411
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
412 static av_cold int aac_decode_close(AVCodecContext * avccontext) {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
413 AACContext * ac = avccontext->priv_data;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
414 int i, j;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
415
7523
a3f7ffdb676d Sync already committed code with that in SoC and commit more OKed hunks of code
superdump
parents: 7501
diff changeset
416 for (i = 0; i < MAX_ELEM_ID; i++) {
7501
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
417 for(j = 0; j < 4; j++)
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
418 av_freep(&ac->che[j][i]);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
419 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
420
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
421 ff_mdct_end(&ac->mdct);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
422 ff_mdct_end(&ac->mdct_small);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
423 return 0 ;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
424 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
425
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
426 AVCodec aac_decoder = {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
427 "aac",
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
428 CODEC_TYPE_AUDIO,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
429 CODEC_ID_AAC,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
430 sizeof(AACContext),
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
431 aac_decode_init,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
432 NULL,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
433 aac_decode_close,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
434 aac_decode_frame,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
435 .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
436 .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
437 };