annotate libfaad2/decoder.c @ 11038:3bac281db5a1

SiS 650/651/740/etc driver by Jake Page <jake@CS.Stanford.EDU>
author alex
date Tue, 07 Oct 2003 23:12:16 +0000
parents 3185f64f6350
children 4a370c80fe5c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
4 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
5 ** This program is free software; you can redistribute it and/or modify
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
6 ** it under the terms of the GNU General Public License as published by
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
7 ** the Free Software Foundation; either version 2 of the License, or
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
8 ** (at your option) any later version.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
9 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
10 ** This program is distributed in the hope that it will be useful,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
13 ** GNU General Public License for more details.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
14 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
15 ** You should have received a copy of the GNU General Public License
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
16 ** along with this program; if not, write to the Free Software
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
18 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
19 ** Any non-GPL usage of this software or parts of this software is strictly
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
20 ** forbidden.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
21 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
22 ** Commercial non-GPL licensing of this software is possible.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
24 **
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
25 ** $Id: decoder.c,v 1.1 2003/08/30 22:30:21 arpi Exp $
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
26 **/
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
27
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
28 #include "common.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
29 #include "structs.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
30
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
31 #include <stdlib.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
32 #include <string.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
33
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
34 #include "decoder.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
35 #include "mp4.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
36 #include "syntax.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
37 #include "tns.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
38 #include "pns.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
39 #include "is.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
40 #include "ms.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
41 #include "ic_predict.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
42 #include "lt_predict.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
43 #include "drc.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
44 #include "error.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
45 #include "output.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
46 #include "dither.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
47 #ifdef SSR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
48 #include "ssr.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
49 #include "ssr_fb.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
50 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
51 #ifdef SBR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
52 #include "sbr_dec.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
53 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
54
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
55 #ifdef ANALYSIS
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
56 uint16_t dbg_count;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
57 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
58
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
59 int8_t* FAADAPI faacDecGetErrorMessage(uint8_t errcode)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
60 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
61 if (errcode >= NUM_ERROR_MESSAGES)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
62 return NULL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
63 return err_msg[errcode];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
64 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
65
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
66 uint32_t FAADAPI faacDecGetCapabilities()
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
67 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
68 uint32_t cap = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
69
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
70 /* can't do without it */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
71 cap += LC_DEC_CAP;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
72
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
73 #ifdef MAIN_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
74 cap += MAIN_DEC_CAP;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
75 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
76 #ifdef LTP_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
77 cap += LTP_DEC_CAP;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
78 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
79 #ifdef LD_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
80 cap += LD_DEC_CAP;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
81 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
82 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
83 cap += ERROR_RESILIENCE_CAP;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
84 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
85 #ifdef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
86 cap += FIXED_POINT_CAP;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89 return cap;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
90 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
91
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
92 faacDecHandle FAADAPI faacDecOpen()
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
93 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
94 uint8_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
95 faacDecHandle hDecoder = NULL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
96
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
97 if ((hDecoder = (faacDecHandle)malloc(sizeof(faacDecStruct))) == NULL)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
98 return NULL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
99
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 memset(hDecoder, 0, sizeof(faacDecStruct));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
102 hDecoder->config.outputFormat = FAAD_FMT_16BIT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 hDecoder->config.defObjectType = MAIN;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104 hDecoder->config.defSampleRate = 44100; /* Default: 44.1kHz */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105 hDecoder->adts_header_present = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106 hDecoder->adif_header_present = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
107 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
108 hDecoder->aacSectionDataResilienceFlag = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109 hDecoder->aacScalefactorDataResilienceFlag = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
110 hDecoder->aacSpectralDataResilienceFlag = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
111 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
112 hDecoder->frameLength = 1024;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
113
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
114 hDecoder->frame = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
115 hDecoder->sample_buffer = NULL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
117 for (i = 0; i < MAX_CHANNELS; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 hDecoder->window_shape_prev[i] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120 hDecoder->time_out[i] = NULL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121 #ifdef SBR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 hDecoder->time_out2[i] = NULL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
124 #ifdef SSR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125 hDecoder->ssr_overlap[i] = NULL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
126 hDecoder->prev_fmd[i] = NULL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
127 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
128 #ifdef MAIN_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
129 hDecoder->pred_stat[i] = NULL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131 #ifdef LTP_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
132 hDecoder->ltp_lag[i] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
133 hDecoder->lt_pred_stat[i] = NULL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
134 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
136
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
137 #ifdef SBR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
138 for (i = 0; i < 32; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
139 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
140 hDecoder->sbr[i] = NULL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
142 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
143
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144 hDecoder->drc = drc_init(REAL_CONST(1.0), REAL_CONST(1.0));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146 #if POW_TABLE_SIZE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147 hDecoder->pow2_table = (real_t*)malloc(POW_TABLE_SIZE*sizeof(real_t));
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
148 if (!hDecoder->pow2_table)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
149 {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
150 free(hDecoder);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
151 hDecoder = NULL;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
152 return hDecoder;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
153 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
154 build_tables(hDecoder->pow2_table);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
155 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
156
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
157 return hDecoder;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
158 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
159
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160 faacDecConfigurationPtr FAADAPI faacDecGetCurrentConfiguration(faacDecHandle hDecoder)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
161 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
162 if (hDecoder)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
163 {
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164 faacDecConfigurationPtr config = &(hDecoder->config);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
165
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
166 return config;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
167 }
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
168
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
169 return NULL;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
170 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
171
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
172 uint8_t FAADAPI faacDecSetConfiguration(faacDecHandle hDecoder,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
173 faacDecConfigurationPtr config)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
174 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
175 if (hDecoder && config)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
176 {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
177 /* check if we can decode this object type */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
178 if (can_decode_ot(config->defObjectType) < 0)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
179 return 0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
180 hDecoder->config.defObjectType = config->defObjectType;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
181
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
182 /* samplerate: anything but 0 should be possible */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
183 if (config->defSampleRate == 0)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
184 return 0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
185 hDecoder->config.defSampleRate = config->defSampleRate;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
186
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
187 /* check output format */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
188 if ((config->outputFormat < 1) || (config->outputFormat > 9))
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
189 return 0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
190 hDecoder->config.outputFormat = config->outputFormat;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
191
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
192 if (config->downMatrix > 1)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
193 hDecoder->config.downMatrix = config->downMatrix;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
194
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
195 /* OK */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
196 return 1;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
197 }
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
198
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
199 return 0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
200 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
201
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
202 int32_t FAADAPI faacDecInit(faacDecHandle hDecoder, uint8_t *buffer,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
203 uint32_t buffer_size,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
204 uint32_t *samplerate, uint8_t *channels)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
205 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
206 uint32_t bits = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
207 bitfile ld;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
208 adif_header adif;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
209 adts_header adts;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
210
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
211 if ((hDecoder == NULL) || (samplerate == NULL) || (channels == NULL))
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
212 return -1;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
213
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
214 hDecoder->sf_index = get_sr_index(hDecoder->config.defSampleRate);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
215 hDecoder->object_type = hDecoder->config.defObjectType;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
216 *samplerate = get_sample_rate(hDecoder->sf_index);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
217 *channels = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
218
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
219 if (buffer != NULL)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
220 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
221 faad_initbits(&ld, buffer, buffer_size);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
222
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
223 /* Check if an ADIF header is present */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
224 if ((buffer[0] == 'A') && (buffer[1] == 'D') &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
225 (buffer[2] == 'I') && (buffer[3] == 'F'))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
226 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
227 hDecoder->adif_header_present = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
228
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
229 get_adif_header(&adif, &ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
230 faad_byte_align(&ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
231
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
232 hDecoder->sf_index = adif.pce[0].sf_index;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
233 hDecoder->object_type = adif.pce[0].object_type + 1;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
234
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
235 *samplerate = get_sample_rate(hDecoder->sf_index);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
236 *channels = adif.pce[0].channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
237
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
238 memcpy(&(hDecoder->pce), &(adif.pce[0]), sizeof(program_config));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
239 hDecoder->pce_set = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
240
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
241 bits = bit2byte(faad_get_processed_bits(&ld));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
242
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
243 /* Check if an ADTS header is present */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
244 } else if (faad_showbits(&ld, 12) == 0xfff) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
245 hDecoder->adts_header_present = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
246
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
247 adts.old_format = hDecoder->config.useOldADTSFormat;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
248 adts_frame(&adts, &ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
249
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
250 hDecoder->sf_index = adts.sf_index;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
251 hDecoder->object_type = adts.profile + 1;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
252
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
253 *samplerate = get_sample_rate(hDecoder->sf_index);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
254 *channels = (adts.channel_configuration > 6) ?
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
255 2 : adts.channel_configuration;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
256 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
257
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
258 if (ld.error)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
259 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
260 faad_endbits(&ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
261 return -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
262 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
263 faad_endbits(&ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
264 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
265 hDecoder->channelConfiguration = *channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
266
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
267 #ifdef SBR_DEC
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
268 /* implicit signalling */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
269 if (*samplerate <= 24000)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
270 {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
271 *samplerate *= 2;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
272 hDecoder->forceUpSampling = 1;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
273 }
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
274 #endif
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
275
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
276 /* must be done before frameLength is divided by 2 for LD */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
277 #ifdef SSR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
278 if (hDecoder->object_type == SSR)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
279 hDecoder->fb = ssr_filter_bank_init(hDecoder->frameLength/SSR_BANDS);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
280 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
281 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
282 hDecoder->fb = filter_bank_init(hDecoder->frameLength);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
283
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
284 #ifdef LD_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
285 if (hDecoder->object_type == LD)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
286 hDecoder->frameLength >>= 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
287 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
288
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
289 if (can_decode_ot(hDecoder->object_type) < 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
290 return -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
291
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
292 #ifndef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
293 if (hDecoder->config.outputFormat >= FAAD_FMT_DITHER_LOWEST)
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
294 Init_Dither(16, (uint8_t)(hDecoder->config.outputFormat - FAAD_FMT_DITHER_LOWEST));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
295 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
296
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
297 return bits;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
298 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
299
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
300 /* Init the library using a DecoderSpecificInfo */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
301 int8_t FAADAPI faacDecInit2(faacDecHandle hDecoder, uint8_t *pBuffer,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
302 uint32_t SizeOfDecoderSpecificInfo,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
303 uint32_t *samplerate, uint8_t *channels)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
304 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
305 int8_t rc;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
306 mp4AudioSpecificConfig mp4ASC;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
307
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
308 if((hDecoder == NULL)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
309 || (pBuffer == NULL)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
310 || (SizeOfDecoderSpecificInfo < 2)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
311 || (samplerate == NULL)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
312 || (channels == NULL))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
313 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
314 return -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
315 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
316
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
317 hDecoder->adif_header_present = 0;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
318 hDecoder->adts_header_present = 0;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
319
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
320 /* decode the audio specific config */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
321 rc = AudioSpecificConfig2(pBuffer, SizeOfDecoderSpecificInfo, &mp4ASC,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
322 &(hDecoder->pce));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
323
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
324 /* copy the relevant info to the decoder handle */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
325 *samplerate = mp4ASC.samplingFrequency;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
326 if (mp4ASC.channelsConfiguration)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
327 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
328 *channels = mp4ASC.channelsConfiguration;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
329 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
330 *channels = hDecoder->pce.channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
331 hDecoder->pce_set = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
332 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
333 hDecoder->sf_index = mp4ASC.samplingFrequencyIndex;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
334 hDecoder->object_type = mp4ASC.objectTypeIndex;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
335 #ifdef ERROR_RESILIENCE
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
336 hDecoder->aacSectionDataResilienceFlag = mp4ASC.aacSectionDataResilienceFlag;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
337 hDecoder->aacScalefactorDataResilienceFlag = mp4ASC.aacScalefactorDataResilienceFlag;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
338 hDecoder->aacSpectralDataResilienceFlag = mp4ASC.aacSpectralDataResilienceFlag;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
339 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
340 #ifdef SBR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
341 hDecoder->sbr_present_flag = mp4ASC.sbr_present_flag;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
342 hDecoder->forceUpSampling = mp4ASC.forceUpSampling;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
343
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
344 /* AAC core decoder samplerate is 2 times as low */
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
345 if (hDecoder->sbr_present_flag == 1 || hDecoder->forceUpSampling == 1)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
346 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
347 hDecoder->sf_index = get_sr_index(mp4ASC.samplingFrequency / 2);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
348 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
349 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
350
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
351 if (rc != 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
352 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
353 return rc;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
354 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
355 hDecoder->channelConfiguration = mp4ASC.channelsConfiguration;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
356 if (mp4ASC.frameLengthFlag)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
357 hDecoder->frameLength = 960;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
358
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
359 /* must be done before frameLength is divided by 2 for LD */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
360 #ifdef SSR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
361 if (hDecoder->object_type == SSR)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
362 hDecoder->fb = ssr_filter_bank_init(hDecoder->frameLength/SSR_BANDS);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
363 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
364 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
365 hDecoder->fb = filter_bank_init(hDecoder->frameLength);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
366
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
367 #ifdef LD_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
368 if (hDecoder->object_type == LD)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
369 hDecoder->frameLength >>= 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
370 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
371
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
372 #ifndef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
373 if (hDecoder->config.outputFormat >= FAAD_FMT_DITHER_LOWEST)
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
374 Init_Dither(16, (uint8_t)(hDecoder->config.outputFormat - FAAD_FMT_DITHER_LOWEST));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
375 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
376
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
377 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
378 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
379
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
380 int8_t FAADAPI faacDecInitDRM(faacDecHandle hDecoder, uint32_t samplerate,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
381 uint8_t channels)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
382 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
383 /* Special object type defined for DRM */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
384 hDecoder->config.defObjectType = DRM_ER_LC;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
385
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
386 hDecoder->config.defSampleRate = samplerate;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
387 #ifdef ERROR_RESILIENCE // This shoudl always be defined for DRM
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
388 hDecoder->aacSectionDataResilienceFlag = 1; /* VCB11 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
389 hDecoder->aacScalefactorDataResilienceFlag = 0; /* no RVLC */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
390 hDecoder->aacSpectralDataResilienceFlag = 1; /* HCR */
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
391 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
392 hDecoder->frameLength = 960;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
393 hDecoder->sf_index = get_sr_index(hDecoder->config.defSampleRate);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
394 hDecoder->object_type = hDecoder->config.defObjectType;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
395
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
396 if ((channels == DRMCH_STEREO) || (channels == DRMCH_SBR_STEREO))
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
397 hDecoder->channelConfiguration = 2;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
398 else
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
399 hDecoder->channelConfiguration = 1;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
400
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
401 #ifdef SBR_DEC
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
402 #ifdef DRM
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
403 if (channels == DRMCH_SBR_LC_STEREO)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
404 hDecoder->lcstereo_flag = 1;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
405 else
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
406 hDecoder->lcstereo_flag = 0;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
407
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
408 if ((channels == DRMCH_MONO) || (channels == DRMCH_STEREO))
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
409 hDecoder->sbr_present_flag = 0;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
410 else
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
411 hDecoder->sbr_present_flag = 1;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
412
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
413 /* Reset sbr for new initialization */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
414 sbrDecodeEnd(hDecoder->sbr[0]);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
415 hDecoder->sbr[0] = NULL;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
416 #endif
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
417 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
418
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
419 /* must be done before frameLength is divided by 2 for LD */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
420 hDecoder->fb = filter_bank_init(hDecoder->frameLength);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
421
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
422 #ifndef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
423 if (hDecoder->config.outputFormat >= FAAD_FMT_DITHER_LOWEST)
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
424 Init_Dither(16, (uint8_t)(hDecoder->config.outputFormat - FAAD_FMT_DITHER_LOWEST));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
425 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
426
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
427 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
428 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
429
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
430 void FAADAPI faacDecClose(faacDecHandle hDecoder)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
431 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
432 uint8_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
433
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
434 if (hDecoder == NULL)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
435 return;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
436
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
437 for (i = 0; i < MAX_CHANNELS; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
438 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
439 if (hDecoder->time_out[i]) free(hDecoder->time_out[i]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
440 #ifdef SBR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
441 if (hDecoder->time_out2[i]) free(hDecoder->time_out2[i]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
442 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
443 #ifdef SSR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
444 if (hDecoder->ssr_overlap[i]) free(hDecoder->ssr_overlap[i]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
445 if (hDecoder->prev_fmd[i]) free(hDecoder->prev_fmd[i]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
446 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
447 #ifdef MAIN_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
448 if (hDecoder->pred_stat[i]) free(hDecoder->pred_stat[i]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
449 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
450 #ifdef LTP_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
451 if (hDecoder->lt_pred_stat[i]) free(hDecoder->lt_pred_stat[i]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
452 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
453 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
454
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
455 #ifdef SSR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
456 if (hDecoder->object_type == SSR)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
457 ssr_filter_bank_end(hDecoder->fb);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
458 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
459 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
460 filter_bank_end(hDecoder->fb);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
461
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
462 drc_end(hDecoder->drc);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
463
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
464 #ifndef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
465 #if POW_TABLE_SIZE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
466 if (hDecoder->pow2_table) free(hDecoder->pow2_table);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
467 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
468 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
469
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
470 if (hDecoder->sample_buffer) free(hDecoder->sample_buffer);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
471
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
472 #ifdef SBR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
473 for (i = 0; i < 32; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
474 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
475 if (hDecoder->sbr[i])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
476 sbrDecodeEnd(hDecoder->sbr[i]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
477 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
478 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
479
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
480 if (hDecoder) free(hDecoder);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
481 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
482
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
483 void FAADAPI faacDecPostSeekReset(faacDecHandle hDecoder, int32_t frame)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
484 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
485 if (hDecoder)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
486 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
487 hDecoder->postSeekResetFlag = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
488
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
489 if (frame != -1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
490 hDecoder->frame = frame;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
491 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
492 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
493
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
494 static void create_channel_config(faacDecHandle hDecoder, faacDecFrameInfo *hInfo)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
495 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
496 hInfo->num_front_channels = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
497 hInfo->num_side_channels = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
498 hInfo->num_back_channels = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
499 hInfo->num_lfe_channels = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
500 memset(hInfo->channel_position, 0, MAX_CHANNELS*sizeof(uint8_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
501
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
502 if (hDecoder->downMatrix)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
503 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
504 hInfo->num_front_channels = 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
505 hInfo->channel_position[0] = FRONT_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
506 hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
507 return;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
508 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
509
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
510 /* check if there is a PCE */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
511 if (hDecoder->pce_set)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
512 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
513 uint8_t i, chpos = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
514 uint8_t chdir, back_center = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
515
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
516 hInfo->num_front_channels = hDecoder->pce.num_front_channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
517 hInfo->num_side_channels = hDecoder->pce.num_side_channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
518 hInfo->num_back_channels = hDecoder->pce.num_back_channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
519 hInfo->num_lfe_channels = hDecoder->pce.num_lfe_channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
520
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
521 chdir = hInfo->num_front_channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
522 if (chdir & 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
523 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
524 hInfo->channel_position[chpos++] = FRONT_CHANNEL_CENTER;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
525 chdir--;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
526 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
527 for (i = 0; i < chdir; i += 2)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
528 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
529 hInfo->channel_position[chpos++] = FRONT_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
530 hInfo->channel_position[chpos++] = FRONT_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
531 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
532
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
533 for (i = 0; i < hInfo->num_side_channels; i += 2)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
534 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
535 hInfo->channel_position[chpos++] = SIDE_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
536 hInfo->channel_position[chpos++] = SIDE_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
537 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
538
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
539 chdir = hInfo->num_back_channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
540 if (chdir & 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
541 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
542 back_center = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
543 chdir--;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
544 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
545 for (i = 0; i < chdir; i += 2)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
546 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
547 hInfo->channel_position[chpos++] = BACK_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
548 hInfo->channel_position[chpos++] = BACK_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
549 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
550 if (back_center)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
551 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
552 hInfo->channel_position[chpos++] = BACK_CHANNEL_CENTER;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
553 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
554
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
555 for (i = 0; i < hInfo->num_lfe_channels; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
556 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
557 hInfo->channel_position[chpos++] = LFE_CHANNEL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
558 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
559
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
560 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
561 switch (hDecoder->channelConfiguration)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
562 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
563 case 1:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
564 hInfo->num_front_channels = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
565 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
566 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
567 case 2:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
568 hInfo->num_front_channels = 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
569 hInfo->channel_position[0] = FRONT_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
570 hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
571 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
572 case 3:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
573 hInfo->num_front_channels = 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
574 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
575 hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
576 hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
577 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
578 case 4:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
579 hInfo->num_front_channels = 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
580 hInfo->num_back_channels = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
581 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
582 hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
583 hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
584 hInfo->channel_position[3] = BACK_CHANNEL_CENTER;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
585 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
586 case 5:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
587 hInfo->num_front_channels = 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
588 hInfo->num_back_channels = 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
589 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
590 hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
591 hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
592 hInfo->channel_position[3] = BACK_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
593 hInfo->channel_position[4] = BACK_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
594 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
595 case 6:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
596 hInfo->num_front_channels = 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
597 hInfo->num_back_channels = 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
598 hInfo->num_lfe_channels = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
599 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
600 hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
601 hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
602 hInfo->channel_position[3] = BACK_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
603 hInfo->channel_position[4] = BACK_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
604 hInfo->channel_position[5] = LFE_CHANNEL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
605 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
606 case 7:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
607 hInfo->num_front_channels = 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
608 hInfo->num_side_channels = 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
609 hInfo->num_back_channels = 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
610 hInfo->num_lfe_channels = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
611 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
612 hInfo->channel_position[1] = FRONT_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
613 hInfo->channel_position[2] = FRONT_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
614 hInfo->channel_position[3] = SIDE_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
615 hInfo->channel_position[4] = SIDE_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
616 hInfo->channel_position[5] = BACK_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
617 hInfo->channel_position[6] = BACK_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
618 hInfo->channel_position[7] = LFE_CHANNEL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
619 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
620 default: /* channelConfiguration == 0 || channelConfiguration > 7 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
621 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
622 uint8_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
623 uint8_t ch = hDecoder->fr_channels - hDecoder->has_lfe;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
624 if (ch & 1) /* there's either a center front or a center back channel */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
625 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
626 uint8_t ch1 = (ch-1)/2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
627 if (hDecoder->first_syn_ele == ID_SCE)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
628 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
629 hInfo->num_front_channels = ch1 + 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
630 hInfo->num_back_channels = ch1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
631 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
632 for (i = 1; i <= ch1; i+=2)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
633 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
634 hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
635 hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
636 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
637 for (i = ch1+1; i < ch; i+=2)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
638 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
639 hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
640 hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
641 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
642 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
643 hInfo->num_front_channels = ch1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
644 hInfo->num_back_channels = ch1 + 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
645 for (i = 0; i < ch1; i+=2)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
646 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
647 hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
648 hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
649 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
650 for (i = ch1; i < ch-1; i+=2)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
651 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
652 hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
653 hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
654 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
655 hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
656 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
657 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
658 uint8_t ch1 = (ch)/2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
659 hInfo->num_front_channels = ch1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
660 hInfo->num_back_channels = ch1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
661 if (ch1 & 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
662 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
663 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
664 for (i = 1; i <= ch1; i+=2)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
665 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
666 hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
667 hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
668 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
669 for (i = ch1+1; i < ch-1; i+=2)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
670 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
671 hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
672 hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
673 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
674 hInfo->channel_position[ch-1] = BACK_CHANNEL_CENTER;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
675 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
676 for (i = 0; i < ch1; i+=2)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
677 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
678 hInfo->channel_position[i] = FRONT_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
679 hInfo->channel_position[i+1] = FRONT_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
680 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
681 for (i = ch1; i < ch; i+=2)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
682 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
683 hInfo->channel_position[i] = BACK_CHANNEL_LEFT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
684 hInfo->channel_position[i+1] = BACK_CHANNEL_RIGHT;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
685 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
686 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
687 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
688 hInfo->num_lfe_channels = hDecoder->has_lfe;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
689 for (i = ch; i < hDecoder->fr_channels; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
690 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
691 hInfo->channel_position[i] = LFE_CHANNEL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
692 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
693 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
694 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
695 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
696 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
697 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
698
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
699 void* FAADAPI faacDecDecode(faacDecHandle hDecoder,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
700 faacDecFrameInfo *hInfo,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
701 uint8_t *buffer, uint32_t buffer_size)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
702 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
703 int32_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
704 uint8_t ch;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
705 adts_header adts;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
706 uint8_t channels = 0, ch_ele = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
707 uint8_t output_channels = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
708 bitfile *ld = (bitfile*)malloc(sizeof(bitfile));
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
709 uint32_t bitsconsumed;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
710 #ifdef DRM
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
711 uint8_t *revbuffer;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
712 uint8_t *prevbufstart;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
713 uint8_t *pbufend;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
714 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
715
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
716 /* local copy of globals */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
717 uint8_t sf_index, object_type, channelConfiguration, outputFormat;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
718 uint8_t *window_shape_prev;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
719 uint16_t frame_len;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
720 #ifdef MAIN_DEC
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
721 pred_state **pred_stat;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
722 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
723 #ifdef LTP_DEC
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
724 real_t **lt_pred_stat;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
725 #endif
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
726 real_t **time_out;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
727 #ifdef SBR_DEC
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
728 real_t **time_out2;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
729 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
730 #ifdef SSR_DEC
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
731 real_t **ssr_overlap, **prev_fmd;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
732 #endif
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
733 fb_info *fb;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
734 drc_info *drc;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
735 #ifdef LTP_DEC
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
736 uint16_t *ltp_lag;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
737 #endif
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
738 program_config *pce;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
739
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
740 void *sample_buffer;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
741 element *syntax_elements[MAX_SYNTAX_ELEMENTS];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
742 element **elements;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
743 real_t *spec_coef[MAX_CHANNELS];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
744
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
745 /* safety checks */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
746 if ((hDecoder == NULL) || (hInfo == NULL) || (buffer == NULL) || (ld == NULL))
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
747 {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
748 return NULL;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
749 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
750
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
751 sf_index = hDecoder->sf_index;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
752 object_type = hDecoder->object_type;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
753 channelConfiguration = hDecoder->channelConfiguration;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
754 #ifdef MAIN_DEC
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
755 pred_stat = hDecoder->pred_stat;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
756 #endif
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
757 #ifdef LTP_DEC
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
758 lt_pred_stat = hDecoder->lt_pred_stat;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
759 #endif
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
760 window_shape_prev = hDecoder->window_shape_prev;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
761 time_out = hDecoder->time_out;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
762 #ifdef SBR_DEC
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
763 time_out2 = hDecoder->time_out2;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
764 #endif
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
765 #ifdef SSR_DEC
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
766 ssr_overlap = hDecoder->ssr_overlap;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
767 prev_fmd = hDecoder->prev_fmd;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
768 #endif
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
769 fb = hDecoder->fb;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
770 drc = hDecoder->drc;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
771 outputFormat = hDecoder->config.outputFormat;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
772 #ifdef LTP_DEC
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
773 ltp_lag = hDecoder->ltp_lag;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
774 #endif
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
775 pce = &hDecoder->pce;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
776 frame_len = hDecoder->frameLength;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
777
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
778
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
779 memset(hInfo, 0, sizeof(faacDecFrameInfo));
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
780 memset(hDecoder->internal_channel, 0, MAX_CHANNELS*sizeof(hDecoder->internal_channel[0]));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
781
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
782 /* initialize the bitstream */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
783 faad_initbits(ld, buffer, buffer_size);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
784
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
785 #ifdef DRM
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
786 if (object_type == DRM_ER_LC)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
787 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
788 faad_getbits(ld, 8
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
789 DEBUGVAR(1,1,"faacDecDecode(): skip CRC"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
790 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
791 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
792
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
793 if (hDecoder->adts_header_present)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
794 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
795 adts.old_format = hDecoder->config.useOldADTSFormat;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
796 if ((hInfo->error = adts_frame(&adts, ld)) > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
797 goto error;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
798
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
799 /* MPEG2 does byte_alignment() here,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
800 * but ADTS header is always multiple of 8 bits in MPEG2
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
801 * so not needed to actually do it.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
802 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
803 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
804
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
805 #ifdef ANALYSIS
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
806 dbg_count = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
807 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
808
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
809 elements = syntax_elements;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
810
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
811 /* decode the complete bitstream */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
812 elements = raw_data_block(hDecoder, hInfo, ld, syntax_elements,
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
813 spec_coef, pce, drc);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
814
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
815 ch_ele = hDecoder->fr_ch_ele;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
816 channels = hDecoder->fr_channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
817
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
818 if (hInfo->error > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
819 goto error;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
820
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
821
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
822 /* no more bit reading after this */
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
823 bitsconsumed = faad_get_processed_bits(ld);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
824 hInfo->bytesconsumed = bit2byte(bitsconsumed);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
825 if (ld->error)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
826 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
827 hInfo->error = 14;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
828 goto error;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
829 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
830 faad_endbits(ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
831 if (ld) free(ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
832 ld = NULL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
833
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
834 #ifdef DRM
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
835 #ifdef SBR_DEC
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
836 if ((hDecoder->sbr_present_flag == 1) && (hDecoder->object_type == DRM_ER_LC))
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
837 {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
838 if (bitsconsumed + 8 > buffer_size*8)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
839 {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
840 hInfo->error = 14;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
841 goto error;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
842 }
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
843
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
844 hDecoder->sbr_used[0] = 1;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
845
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
846 if (!hDecoder->sbr[0])
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
847 hDecoder->sbr[0] = sbrDecodeInit(hDecoder->frameLength, 1);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
848
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
849 /* Reverse bit reading of SBR data in DRM audio frame */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
850 revbuffer = (uint8_t*)malloc(buffer_size*sizeof(uint8_t));
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
851 prevbufstart = revbuffer;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
852 pbufend = &buffer[buffer_size - 1];
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
853 for (i = 0; i < buffer_size; i++)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
854 *prevbufstart++ = tabFlipbits[*pbufend--];
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
855
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
856 /* Set SBR data */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
857 hDecoder->sbr[0]->data = revbuffer;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
858 /* consider 8 bits from AAC-CRC */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
859 hDecoder->sbr[0]->data_size_bits = buffer_size*8 - bitsconsumed - 8;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
860 hDecoder->sbr[0]->data_size =
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
861 bit2byte(hDecoder->sbr[0]->data_size_bits + 8);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
862
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
863 hDecoder->sbr[0]->lcstereo_flag = hDecoder->lcstereo_flag;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
864
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
865 hDecoder->sbr[0]->sample_rate = get_sample_rate(hDecoder->sf_index);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
866 hDecoder->sbr[0]->sample_rate *= 2;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
867 }
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
868 #endif
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
869 #endif
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
870
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
871 if (!hDecoder->adts_header_present && !hDecoder->adif_header_present)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
872 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
873 if (channels != hDecoder->channelConfiguration)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
874 hDecoder->channelConfiguration = channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
875
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
876 if (channels == 8) /* 7.1 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
877 hDecoder->channelConfiguration = 7;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
878 if (channels == 7) /* not a standard channelConfiguration */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
879 hDecoder->channelConfiguration = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
880 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
881
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
882 if ((channels == 5 || channels == 6) && hDecoder->config.downMatrix)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
883 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
884 hDecoder->downMatrix = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
885 output_channels = 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
886 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
887 output_channels = channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
888 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
889
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
890 /* Make a channel configuration based on either a PCE or a channelConfiguration */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
891 create_channel_config(hDecoder, hInfo);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
892
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
893 /* number of samples in this frame */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
894 hInfo->samples = frame_len*output_channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
895 /* number of channels in this frame */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
896 hInfo->channels = output_channels;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
897 /* samplerate */
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
898 hInfo->samplerate = get_sample_rate(hDecoder->sf_index);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
899 /* object type */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
900 hInfo->object_type = hDecoder->object_type;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
901 /* sbr */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
902 hInfo->sbr = NO_SBR;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
903 /* header type */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
904 hInfo->header_type = RAW;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
905 if (hDecoder->adif_header_present)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
906 hInfo->header_type = ADIF;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
907 if (hDecoder->adts_header_present)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
908 hInfo->header_type = ADTS;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
909
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
910 /* check if frame has channel elements */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
911 if (channels == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
912 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
913 hDecoder->frame++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
914 return NULL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
915 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
916
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
917 if (hDecoder->sample_buffer == NULL)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
918 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
919 #ifdef SBR_DEC
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
920 if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1))
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
921 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
922 if (hDecoder->config.outputFormat == FAAD_FMT_DOUBLE)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
923 hDecoder->sample_buffer = malloc(2*frame_len*channels*sizeof(double));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
924 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
925 hDecoder->sample_buffer = malloc(2*frame_len*channels*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
926 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
927 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
928 if (hDecoder->config.outputFormat == FAAD_FMT_DOUBLE)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
929 hDecoder->sample_buffer = malloc(frame_len*channels*sizeof(double));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
930 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
931 hDecoder->sample_buffer = malloc(frame_len*channels*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
932 #ifdef SBR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
933 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
934 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
935 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
936
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
937 sample_buffer = hDecoder->sample_buffer;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
938
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
939
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
940 /* Because for ms, is and pns both channels spectral coefficients are needed
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
941 we have to restart running through all channels here.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
942 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
943 for (ch = 0; ch < channels; ch++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
944 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
945 int16_t pch = -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
946 uint8_t right_channel;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
947 ic_stream *ics, *icsr;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
948 ltp_info *ltp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
949
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
950 /* find the syntax element to which this channel belongs */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
951 if (syntax_elements[hDecoder->channel_element[ch]]->channel == ch)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
952 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
953 ics = &(syntax_elements[hDecoder->channel_element[ch]]->ics1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
954 icsr = &(syntax_elements[hDecoder->channel_element[ch]]->ics2);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
955 ltp = &(ics->ltp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
956 pch = syntax_elements[hDecoder->channel_element[ch]]->paired_channel;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
957 right_channel = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
958 } else if (syntax_elements[hDecoder->channel_element[ch]]->paired_channel == ch) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
959 ics = &(syntax_elements[hDecoder->channel_element[ch]]->ics2);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
960 if (syntax_elements[hDecoder->channel_element[ch]]->common_window)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
961 ltp = &(ics->ltp2);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
962 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
963 ltp = &(ics->ltp);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
964 right_channel = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
965 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
966
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
967 /* pns decoding */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
968 if ((!right_channel) && (pch != -1) && (ics->ms_mask_present))
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
969 pns_decode(ics, icsr, spec_coef[ch], spec_coef[pch], frame_len, 1, object_type);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
970 else if ((pch == -1) || ((pch != -1) && (!ics->ms_mask_present)))
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
971 pns_decode(ics, NULL, spec_coef[ch], NULL, frame_len, 0, object_type);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
972
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
973 if (!right_channel && (pch != -1))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
974 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
975 /* mid/side decoding */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
976 ms_decode(ics, icsr, spec_coef[ch], spec_coef[pch], frame_len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
977
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
978 /* intensity stereo decoding */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
979 is_decode(ics, icsr, spec_coef[ch], spec_coef[pch], frame_len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
980 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
981
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
982 #ifdef MAIN_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
983 /* MAIN object type prediction */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
984 if (object_type == MAIN)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
985 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
986 /* allocate the state only when needed */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
987 if (pred_stat[ch] == NULL)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
988 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
989 pred_stat[ch] = (pred_state*)malloc(frame_len * sizeof(pred_state));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
990 reset_all_predictors(pred_stat[ch], frame_len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
991 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
992
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
993 /* intra channel prediction */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
994 ic_prediction(ics, spec_coef[ch], pred_stat[ch], frame_len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
995
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
996 /* In addition, for scalefactor bands coded by perceptual
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
997 noise substitution the predictors belonging to the
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
998 corresponding spectral coefficients are reset.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
999 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1000 pns_reset_pred_state(ics, pred_stat[ch]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1001 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1002 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1003 #ifdef LTP_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1004 if ((object_type == LTP)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1005 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1006 || (object_type == ER_LTP)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1007 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1008 #ifdef LD_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1009 || (object_type == LD)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1010 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1011 )
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1012 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1013 #ifdef LD_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1014 if (object_type == LD)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1015 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1016 if (ltp->data_present)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1017 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1018 if (ltp->lag_update)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1019 ltp_lag[ch] = ltp->lag;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1020 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1021 ltp->lag = ltp_lag[ch];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1022 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1023 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1024
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1025 /* allocate the state only when needed */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1026 if (lt_pred_stat[ch] == NULL)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1027 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1028 lt_pred_stat[ch] = (real_t*)malloc(frame_len*4 * sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1029 memset(lt_pred_stat[ch], 0, frame_len*4 * sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1030 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1031
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1032 /* long term prediction */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1033 lt_prediction(ics, ltp, spec_coef[ch], lt_pred_stat[ch], fb,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1034 ics->window_shape, window_shape_prev[ch],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1035 sf_index, object_type, frame_len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1036 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1037 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1038
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1039 /* tns decoding */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1040 tns_decode_frame(ics, &(ics->tns), sf_index, object_type,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1041 spec_coef[ch], frame_len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1042
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1043 /* drc decoding */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1044 if (drc->present)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1045 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1046 if (!drc->exclude_mask[ch] || !drc->excluded_chns_present)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1047 drc_decode(drc, spec_coef[ch]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1048 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1049
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1050 if (time_out[ch] == NULL)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1051 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1052 time_out[ch] = (real_t*)malloc(frame_len*2*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1053 memset(time_out[ch], 0, frame_len*2*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1054 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1055 #ifdef SBR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1056 if (time_out2[ch] == NULL)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1057 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1058 time_out2[ch] = (real_t*)malloc(frame_len*2*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1059 memset(time_out2[ch], 0, frame_len*2*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1060 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1061 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1062
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1063 /* filter bank */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1064 #ifdef SSR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1065 if (object_type != SSR)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1066 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1067 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1068 ifilter_bank(fb, ics->window_sequence, ics->window_shape,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1069 window_shape_prev[ch], spec_coef[ch],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1070 time_out[ch], object_type, frame_len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1071 #ifdef SSR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1072 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1073 if (ssr_overlap[ch] == NULL)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1074 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1075 ssr_overlap[ch] = (real_t*)malloc(2*frame_len*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1076 memset(ssr_overlap[ch], 0, 2*frame_len*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1077 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1078 if (prev_fmd[ch] == NULL)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1079 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1080 uint16_t k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1081 prev_fmd[ch] = (real_t*)malloc(2*frame_len*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1082 for (k = 0; k < 2*frame_len; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1083 prev_fmd[ch][k] = REAL_CONST(-1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1084 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1085
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1086 ssr_decode(&(ics->ssr), fb, ics->window_sequence, ics->window_shape,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1087 window_shape_prev[ch], spec_coef[ch], time_out[ch],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1088 ssr_overlap[ch], hDecoder->ipqf_buffer[ch], prev_fmd[ch], frame_len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1089 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1090 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1091 /* save window shape for next frame */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1092 window_shape_prev[ch] = ics->window_shape;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1093
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1094 #ifdef LTP_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1095 if ((object_type == LTP)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1096 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1097 || (object_type == ER_LTP)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1098 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1099 #ifdef LD_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1100 || (object_type == LD)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1101 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1102 )
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1103 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1104 lt_update_state(lt_pred_stat[ch], time_out[ch], time_out[ch]+frame_len,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1105 frame_len, object_type);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1106 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1107 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1108 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1109
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1110 #ifdef SBR_DEC
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1111 if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1))
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1112 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1113 for (i = 0; i < ch_ele; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1114 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1115 /* following case can happen when forceUpSampling == 1 */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1116 if (hDecoder->sbr[i] == NULL)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1117 {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1118 hDecoder->sbr[i] = sbrDecodeInit(hDecoder->frameLength
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1119 #ifdef DRM
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1120 , 0
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1121 #endif
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1122 );
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1123 hDecoder->sbr[i]->data = NULL;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1124 hDecoder->sbr[i]->data_size = 0;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1125 }
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1126
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1127 if (syntax_elements[i]->paired_channel != -1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1128 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1129 memcpy(time_out2[syntax_elements[i]->channel],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1130 time_out[syntax_elements[i]->channel], frame_len*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1131 memcpy(time_out2[syntax_elements[i]->paired_channel],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1132 time_out[syntax_elements[i]->paired_channel], frame_len*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1133 sbrDecodeFrame(hDecoder->sbr[i],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1134 time_out2[syntax_elements[i]->channel],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1135 time_out2[syntax_elements[i]->paired_channel], ID_CPE,
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1136 hDecoder->postSeekResetFlag, hDecoder->forceUpSampling);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1137 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1138 memcpy(time_out2[syntax_elements[i]->channel],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1139 time_out[syntax_elements[i]->channel], frame_len*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1140 sbrDecodeFrame(hDecoder->sbr[i],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1141 time_out2[syntax_elements[i]->channel],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1142 NULL, ID_SCE,
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1143 hDecoder->postSeekResetFlag, hDecoder->forceUpSampling);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1144 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1145 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1146 frame_len *= 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1147 hInfo->samples *= 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1148 hInfo->samplerate *= 2;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1149 /* sbr */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1150 if (hDecoder->sbr_present_flag == 1)
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1151 {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1152 hInfo->object_type = HE_AAC;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1153 hInfo->sbr = SBR_UPSAMPLED;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1154 } else {
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1155 hInfo->sbr = NO_SBR_UPSAMPLED;
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
1156 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1157
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1158 sample_buffer = output_to_PCM(hDecoder, time_out2, sample_buffer,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1159 output_channels, frame_len, outputFormat);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1160 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1161 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1162 sample_buffer = output_to_PCM(hDecoder, time_out, sample_buffer,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1163 output_channels, frame_len, outputFormat);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1164 #ifdef SBR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1165 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1166 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1167
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1168 hDecoder->postSeekResetFlag = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1169
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1170 hDecoder->frame++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1171 #ifdef LD_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1172 if (object_type != LD)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1173 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1174 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1175 if (hDecoder->frame <= 1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1176 hInfo->samples = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1177 #ifdef LD_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1178 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1179 /* LD encoders will give lower delay */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1180 if (hDecoder->frame <= 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1181 hInfo->samples = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1182 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1183 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1184
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1185 /* cleanup */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1186 for (ch = 0; ch < channels; ch++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1187 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1188 if (spec_coef[ch]) free(spec_coef[ch]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1189 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1190
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1191 for (i = 0; i < ch_ele; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1192 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1193 if (syntax_elements[i]) free(syntax_elements[i]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1194 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1195
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1196 #ifdef ANALYSIS
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1197 fflush(stdout);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1198 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1199
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1200 return sample_buffer;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1201
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1202 error:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1203 /* free all memory that could have been allocated */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1204 faad_endbits(ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1205 if (ld) free(ld);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1206
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1207 /* cleanup */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1208 for (ch = 0; ch < channels; ch++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1209 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1210 if (spec_coef[ch]) free(spec_coef[ch]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1211 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1212
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1213 for (i = 0; i < ch_ele; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1214 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1215 if (syntax_elements[i]) free(syntax_elements[i]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1216 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1217
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1218 #ifdef ANALYSIS
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1219 fflush(stdout);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1220 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1221
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1222 return NULL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1223 }