annotate Input/aac/libfaad2/output.c @ 22:696f87ed66e2 trunk

[svn] More GCC retardation
author nenolod
date Mon, 24 Oct 2005 20:25:00 -0700
parents 6efb9e514224
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
1 /*
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
4 **
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
5 ** This program is free software; you can redistribute it and/or modify
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
6 ** it under the terms of the GNU General Public License as published by
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
7 ** the Free Software Foundation; either version 2 of the License, or
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
8 ** (at your option) any later version.
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
9 **
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
10 ** This program is distributed in the hope that it will be useful,
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
13 ** GNU General Public License for more details.
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
14 **
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
15 ** You should have received a copy of the GNU General Public License
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
16 ** along with this program; if not, write to the Free Software
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
18 **
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
19 ** Any non-GPL usage of this software or parts of this software is strictly
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
20 ** forbidden.
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
21 **
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
22 ** Commercial non-GPL licensing of this software is possible.
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
24 **
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
25 ** $Id: output.c,v 1.29 2003/11/12 20:47:58 menno Exp $
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
26 **/
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
27
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
28 #include "common.h"
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
29 #include "structs.h"
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
30
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
31 #include "output.h"
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
32 #include "decoder.h"
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
33
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
34 #ifndef FIXED_POINT
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
35
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
36
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
37 #define FLOAT_SCALE (1.0f/(1<<15))
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
38
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
39 #define DM_MUL ((real_t)1.0/((real_t)1.0+(real_t)sqrt(2.0)))
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
40
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
41
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
42 static INLINE real_t get_sample(real_t **input, uint8_t channel, uint16_t sample,
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
43 uint8_t downMatrix, uint8_t *internal_channel)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
44 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
45 if (!downMatrix)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
46 return input[internal_channel[channel]][sample];
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
47
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
48 if (channel == 0)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
49 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
50 return DM_MUL * (input[internal_channel[1]][sample] +
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
51 input[internal_channel[0]][sample]/(real_t)sqrt(2.) +
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
52 input[internal_channel[3]][sample]/(real_t)sqrt(2.));
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
53 } else {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
54 return DM_MUL * (input[internal_channel[2]][sample] +
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
55 input[internal_channel[0]][sample]/(real_t)sqrt(2.) +
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
56 input[internal_channel[4]][sample]/(real_t)sqrt(2.));
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
57 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
58 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
59
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
60 void* output_to_PCM(faacDecHandle hDecoder,
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
61 real_t **input, void *sample_buffer, uint8_t channels,
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
62 uint16_t frame_len, uint8_t format)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
63 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
64 uint8_t ch;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
65 uint16_t i, j = 0;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
66 uint8_t internal_channel;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
67
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
68 int16_t *short_sample_buffer = (int16_t*)sample_buffer;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
69 int32_t *int_sample_buffer = (int32_t*)sample_buffer;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
70 float32_t *float_sample_buffer = (float32_t*)sample_buffer;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
71 double *double_sample_buffer = (double*)sample_buffer;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
72
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
73 /* Copy output to a standard PCM buffer */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
74 for (ch = 0; ch < channels; ch++)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
75 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
76 internal_channel = hDecoder->internal_channel[ch];
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
77
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
78 switch (format)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
79 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
80 case FAAD_FMT_16BIT:
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
81 for(i = 0; i < frame_len; i++)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
82 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
83 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
84 if (inp >= 0.0f)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
85 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
86 #ifndef HAS_LRINTF
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
87 inp += 0.5f;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
88 #endif
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
89 if (inp >= 32768.0f)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
90 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
91 inp = 32767.0f;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
92 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
93 } else {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
94 #ifndef HAS_LRINTF
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
95 inp += -0.5f;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
96 #endif
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
97 if (inp <= -32769.0f)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
98 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
99 inp = -32768.0f;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
100 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
101 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
102 short_sample_buffer[(i*channels)+ch] = (int16_t)lrintf(inp);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
103 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
104 break;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
105 case FAAD_FMT_24BIT:
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
106 for(i = 0; i < frame_len; i++)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
107 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
108 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
109 inp *= 256.0f;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
110 if (inp >= 0.0f)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
111 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
112 #ifndef HAS_LRINTF
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
113 inp += 0.5f;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
114 #endif
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
115 if (inp >= 8388608.0f)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
116 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
117 inp = 8388607.0f;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
118 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
119 } else {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
120 #ifndef HAS_LRINTF
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
121 inp += -0.5f;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
122 #endif
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
123 if (inp <= -8388609.0f)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
124 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
125 inp = -8388608.0f;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
126 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
127 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
128 int_sample_buffer[(i*channels)+ch] = lrintf(inp);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
129 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
130 break;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
131 case FAAD_FMT_32BIT:
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
132 for(i = 0; i < frame_len; i++)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
133 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
134 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
135 inp *= 65536.0f;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
136 if (inp >= 0.0f)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
137 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
138 #ifndef HAS_LRINTF
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
139 inp += 0.5f;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
140 #endif
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
141 if (inp >= 2147483648.0f)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
142 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
143 inp = 2147483647.0f;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
144 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
145 } else {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
146 #ifndef HAS_LRINTF
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
147 inp += -0.5f;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
148 #endif
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
149 if (inp <= -2147483649.0f)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
150 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
151 inp = -2147483648.0f;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
152 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
153 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
154 int_sample_buffer[(i*channels)+ch] = lrintf(inp);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
155 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
156 break;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
157 case FAAD_FMT_FLOAT:
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
158 for(i = 0; i < frame_len; i++)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
159 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
160 //real_t inp = input[internal_channel][i];
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
161 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
162 float_sample_buffer[(i*channels)+ch] = inp*FLOAT_SCALE;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
163 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
164 break;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
165 case FAAD_FMT_DOUBLE:
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
166 for(i = 0; i < frame_len; i++)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
167 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
168 //real_t inp = input[internal_channel][i];
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
169 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
170 double_sample_buffer[(i*channels)+ch] = (double)inp*FLOAT_SCALE;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
171 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
172 break;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
173 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
174 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
175
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
176 return sample_buffer;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
177 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
178
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
179 #else
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
180
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
181 void* output_to_PCM(faacDecHandle hDecoder,
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
182 real_t **input, void *sample_buffer, uint8_t channels,
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
183 uint16_t frame_len, uint8_t format)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
184 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
185 uint8_t ch;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
186 uint16_t i;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
187 int16_t *short_sample_buffer = (int16_t*)sample_buffer;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
188 int32_t *int_sample_buffer = (int32_t*)sample_buffer;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
189
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
190 /* Copy output to a standard PCM buffer */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
191 for (ch = 0; ch < channels; ch++)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
192 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
193 switch (format)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
194 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
195 case FAAD_FMT_16BIT:
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
196 for(i = 0; i < frame_len; i++)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
197 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
198 int32_t tmp = input[ch][i];
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
199 if (tmp >= 0)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
200 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
201 tmp += (1 << (REAL_BITS-1));
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
202 if (tmp >= REAL_CONST(32768))
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
203 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
204 tmp = REAL_CONST(32767);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
205 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
206 } else {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
207 tmp += -(1 << (REAL_BITS-1));
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
208 if (tmp <= REAL_CONST(-32769))
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
209 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
210 tmp = REAL_CONST(-32768);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
211 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
212 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
213 tmp >>= REAL_BITS;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
214 short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
215 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
216 break;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
217 case FAAD_FMT_24BIT:
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
218 for(i = 0; i < frame_len; i++)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
219 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
220 int32_t tmp = input[ch][i];
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
221 if (tmp >= 0)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
222 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
223 tmp += (1 << (REAL_BITS-9));
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
224 tmp >>= (REAL_BITS-8);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
225 if (tmp >= 8388608)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
226 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
227 tmp = 8388607;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
228 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
229 } else {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
230 tmp += -(1 << (REAL_BITS-9));
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
231 tmp >>= (REAL_BITS-8);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
232 if (tmp <= -8388609)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
233 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
234 tmp = -8388608;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
235 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
236 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
237 int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
238 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
239 break;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
240 case FAAD_FMT_32BIT:
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
241 for(i = 0; i < frame_len; i++)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
242 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
243 int32_t tmp = input[ch][i];
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
244 if (tmp >= 0)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
245 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
246 tmp += (1 << (16-REAL_BITS-1));
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
247 tmp <<= (16-REAL_BITS);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
248 } else {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
249 tmp += -(1 << (16-REAL_BITS-1));
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
250 tmp <<= (16-REAL_BITS);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
251 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
252 int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
253 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
254 break;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
255 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
256 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
257
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
258 return sample_buffer;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
259 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
260
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
261 #endif