annotate aac.c @ 7501:d6012be599d3 libavcodec

OKed sections of code from the SoC AAC decoder
author superdump
date Tue, 05 Aug 2008 19:32:01 +0000
parents
children a3f7ffdb676d
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"
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
85 #include "mpeg4audio.h"
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
86
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
87 #include <assert.h>
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
88 #include <errno.h>
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
89 #include <math.h>
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
90 #include <string.h>
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
91
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
92 #ifndef CONFIG_HARDCODED_TABLES
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
93 static float ff_aac_ivquant_tab[IVQUANT_SIZE];
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
94 #endif /* CONFIG_HARDCODED_TABLES */
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
95
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
96 static VLC vlc_scalefactors;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
97 static VLC vlc_spectral[11];
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
98
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
99
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
100 num_front = get_bits(gb, 4);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
101 num_side = get_bits(gb, 4);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
102 num_back = get_bits(gb, 4);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
103 num_lfe = get_bits(gb, 2);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
104 num_assoc_data = get_bits(gb, 3);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
105 num_cc = get_bits(gb, 4);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
106
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
107 newpcs->mono_mixdown_tag = get_bits1(gb) ? get_bits(gb, 4) : -1;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
108 newpcs->stereo_mixdown_tag = get_bits1(gb) ? get_bits(gb, 4) : -1;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
109
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
110 if (get_bits1(gb)) {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
111 newpcs->mixdown_coeff_index = get_bits(gb, 2);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
112 newpcs->pseudo_surround = get_bits1(gb);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
113 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
114
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
115 program_config_element_parse_tags(newpcs->che_type[ID_CPE], newpcs->che_type[ID_SCE], AAC_CHANNEL_FRONT, gb, num_front);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
116 program_config_element_parse_tags(newpcs->che_type[ID_CPE], newpcs->che_type[ID_SCE], AAC_CHANNEL_SIDE, gb, num_side );
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
117 program_config_element_parse_tags(newpcs->che_type[ID_CPE], newpcs->che_type[ID_SCE], AAC_CHANNEL_BACK, gb, num_back );
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
118 program_config_element_parse_tags(NULL, newpcs->che_type[ID_LFE], AAC_CHANNEL_LFE, gb, num_lfe );
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
119
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
120 skip_bits_long(gb, 4 * num_assoc_data);
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 program_config_element_parse_tags(newpcs->che_type[ID_CCE], newpcs->che_type[ID_CCE], AAC_CHANNEL_CC, gb, num_cc );
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
123
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
124 align_get_bits(gb);
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 /* comment field, first byte is length */
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
127 skip_bits_long(gb, 8 * get_bits(gb, 8));
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
128
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
129 static av_cold int aac_decode_init(AVCodecContext * avccontext) {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
130 AACContext * ac = avccontext->priv_data;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
131 int i;
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 ac->avccontext = avccontext;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
134
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
135 avccontext->sample_rate = ac->m4ac.sample_rate;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
136 avccontext->frame_size = 1024;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
137
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
138 AAC_INIT_VLC_STATIC( 0, 144);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
139 AAC_INIT_VLC_STATIC( 1, 114);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
140 AAC_INIT_VLC_STATIC( 2, 188);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
141 AAC_INIT_VLC_STATIC( 3, 180);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
142 AAC_INIT_VLC_STATIC( 4, 172);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
143 AAC_INIT_VLC_STATIC( 5, 140);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
144 AAC_INIT_VLC_STATIC( 6, 168);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
145 AAC_INIT_VLC_STATIC( 7, 114);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
146 AAC_INIT_VLC_STATIC( 8, 262);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
147 AAC_INIT_VLC_STATIC( 9, 248);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
148 AAC_INIT_VLC_STATIC(10, 384);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
149
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
150 dsputil_init(&ac->dsp, avccontext);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
151
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
152 // -1024 - Compensate wrong IMDCT method.
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
153 // 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
154 // for float to int16 conversion.
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 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
157 ac->add_bias = 385.0f;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
158 ac->sf_scale = 1. / (-1024. * 32768.);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
159 ac->sf_offset = 0;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
160 } else {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
161 ac->add_bias = 0.0f;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
162 ac->sf_scale = 1. / -1024.;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
163 ac->sf_offset = 60;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
164 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
165
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
166 #ifndef CONFIG_HARDCODED_TABLES
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
167 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
168 ff_aac_ivquant_tab[i + IVQUANT_SIZE/2 - 1] = cbrt(fabs(i)) * i;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
169 #endif /* CONFIG_HARDCODED_TABLES */
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
170
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
171 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
172 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
173 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
174 352);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
175
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
176 ff_mdct_init(&ac->mdct, 11, 1);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
177 ff_mdct_init(&ac->mdct_small, 8, 1);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
178 return 0;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
179 }
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 int byte_align = get_bits1(gb);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
182 int count = get_bits(gb, 8);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
183 if (count == 255)
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
184 count += get_bits(gb, 8);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
185 if (byte_align)
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
186 align_get_bits(gb);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
187 skip_bits_long(gb, 8 * count);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
188 }
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 * inverse quantization
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
192 *
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
193 * @param a quantized value to be dequantized
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
194 * @return Returns dequantized value.
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
195 */
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
196 static inline float ivquant(int a) {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
197 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
198 return ff_aac_ivquant_tab[a + IVQUANT_SIZE/2 - 1];
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
199 else
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
200 return cbrtf(fabsf(a)) * a;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
201 }
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 pulse pointer to pulse data struct
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
204 * @param icoef array of quantized spectral data
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 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
207 int i, off = ics->swb_offset[pulse->start];
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
208 for (i = 0; i < pulse->num_pulse; i++) {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
209 int ic;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
210 off += pulse->offset[i];
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
211 ic = (icoef[off] - 1)>>31;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
212 icoef[off] += (pulse->amp[i]^ic) - ic;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
213 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
214 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
215
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
216 static av_cold int aac_decode_close(AVCodecContext * avccontext) {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
217 AACContext * ac = avccontext->priv_data;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
218 int i, j;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
219
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
220 for (i = 0; i < MAX_TAGID; i++) {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
221 for(j = 0; j < 4; j++)
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
222 av_freep(&ac->che[j][i]);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
223 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
224
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
225 ff_mdct_end(&ac->mdct);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
226 ff_mdct_end(&ac->mdct_small);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
227 av_freep(&ac->interleaved_output);
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
228 return 0 ;
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
229 }
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
230
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
231 AVCodec aac_decoder = {
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
232 "aac",
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
233 CODEC_TYPE_AUDIO,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
234 CODEC_ID_AAC,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
235 sizeof(AACContext),
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
236 aac_decode_init,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
237 NULL,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
238 aac_decode_close,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
239 aac_decode_frame,
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
240 .long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"),
d6012be599d3 OKed sections of code from the SoC AAC decoder
superdump
parents:
diff changeset
241 };