annotate libfaad2/decoder.c @ 10847:98dc548dbf2d

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