annotate libfaad2/output.c @ 12055:174ff71996aa

sync by danny <guru@digitalfantasy.it>
author diego
date Tue, 23 Mar 2004 04:24:52 +0000
parents 3185f64f6350
children 4a370c80fe5c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
4 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
5 ** This program is free software; you can redistribute it and/or modify
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
6 ** it under the terms of the GNU General Public License as published by
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
7 ** the Free Software Foundation; either version 2 of the License, or
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
8 ** (at your option) any later version.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
9 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
10 ** This program is distributed in the hope that it will be useful,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
13 ** GNU General Public License for more details.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
14 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
15 ** You should have received a copy of the GNU General Public License
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
16 ** along with this program; if not, write to the Free Software
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
18 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
19 ** Any non-GPL usage of this software or parts of this software is strictly
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
20 ** forbidden.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
21 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
22 ** Commercial non-GPL licensing of this software is possible.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
24 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
25 ** $Id$
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 "output.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
32 #include "decoder.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
33
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
34 #ifndef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
35
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
36 #include "dither.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
37
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
38
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
39 #define ftol(A,B) {tmp = *(int32_t*) & A - 0x4B7F8000; \
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
40 B = (int16_t)((tmp==(int16_t)tmp) ? tmp : (tmp>>31)^0x7FFF);}
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
41
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
42 #define ROUND(x) ((x >= 0) ? (int32_t)floor((x) + 0.5) : (int32_t)ceil((x) + 0.5))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
43
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
44 #define ROUND32(x) ROUND(x)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
45
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
46 #define ROUND64(x) (doubletmp = (x) + Dither.Add + (int64_t)0x001FFFFD80000000L, *(int64_t*)(&doubletmp) - (int64_t)0x433FFFFD80000000L)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
47
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
48 #define FLOAT_SCALE (1.0f/(1<<15))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
49
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
50 dither_t Dither;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
51 double doubletmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
52
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
53 #define DM_MUL ((real_t)1.0/((real_t)1.0+(real_t)sqrt(2.0)))
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
54
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
55 static INLINE real_t get_sample(real_t **input, uint8_t channel, uint16_t sample,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
56 uint8_t downMatrix, uint8_t *internal_channel)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
57 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
58 if (downMatrix)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
59 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
60 if (channel == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
61 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
62 return DM_MUL * (input[internal_channel[1]][sample] +
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
63 input[internal_channel[0]][sample]/(real_t)sqrt(2.) +
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
64 input[internal_channel[3]][sample]/(real_t)sqrt(2.));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
65 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
66 return DM_MUL * (input[internal_channel[2]][sample] +
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
67 input[internal_channel[0]][sample]/(real_t)sqrt(2.) +
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
68 input[internal_channel[4]][sample]/(real_t)sqrt(2.));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
69 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
70 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
71 return input[internal_channel[channel]][sample];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
72 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
73 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
74
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
75 void* output_to_PCM(faacDecHandle hDecoder,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
76 real_t **input, void *sample_buffer, uint8_t channels,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
77 uint16_t frame_len, uint8_t format)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
78 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
79 uint8_t ch;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
80 uint16_t i, j = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
81 uint8_t internal_channel;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
82
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
83 int16_t *short_sample_buffer = (int16_t*)sample_buffer;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
84 int32_t *int_sample_buffer = (int32_t*)sample_buffer;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
85 float32_t *float_sample_buffer = (float32_t*)sample_buffer;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
86 double *double_sample_buffer = (double*)sample_buffer;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88 /* Copy output to a standard PCM buffer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89 for (ch = 0; ch < channels; ch++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
90 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
91 internal_channel = hDecoder->internal_channel[ch];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
92
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
93 switch (format)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
94 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
95 case FAAD_FMT_16BIT:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
96 for(i = 0; i < frame_len; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
97 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
98 int32_t tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
99 real_t ftemp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 //real_t inp = input[internal_channel][i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
102
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 ftemp = inp + 0xff8000;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104 ftol(ftemp, short_sample_buffer[(i*channels)+ch]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
107 case FAAD_FMT_16BIT_DITHER:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
108 for(i = 0; i < frame_len; i++, j++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
110 //real_t inp = input[internal_channel][i];
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
111 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
112 double Sum = inp * 65535.f;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
113 int64_t val;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
114 if(j > 31)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
115 j = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116 val = dither_output(1, 0, j, Sum, ch) / 65536;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
117 if (val > (1<<15)-1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118 val = (1<<15)-1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 else if (val < -(1<<15))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120 val = -(1<<15);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121 short_sample_buffer[(i*channels)+ch] = (int16_t)val;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
124 case FAAD_FMT_16BIT_L_SHAPE:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125 case FAAD_FMT_16BIT_M_SHAPE:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
126 case FAAD_FMT_16BIT_H_SHAPE:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
127 for(i = 0; i < frame_len; i++, j++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
128 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
129 //real_t inp = input[internal_channel][i];
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
130 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131 double Sum = inp * 65535.f;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
132 int64_t val;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
133 if(j > 31)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
134 j = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135 val = dither_output(1, 1, j, Sum, ch) / 65536;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
136 if (val > (1<<15)-1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
137 val = (1<<15)-1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
138 else if (val < -(1<<15))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
139 val = -(1<<15);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
140 short_sample_buffer[(i*channels)+ch] = (int16_t)val;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
142 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
143 case FAAD_FMT_24BIT:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144 for(i = 0; i < frame_len; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
146 //real_t inp = input[internal_channel][i];
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
147 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
148 if (inp > (1<<15)-1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
149 inp = (1<<15)-1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
150 else if (inp < -(1<<15))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
151 inp = -(1<<15);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 int_sample_buffer[(i*channels)+ch] = ROUND(inp*(1<<8));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
153 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
154 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
155 case FAAD_FMT_32BIT:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
156 for(i = 0; i < frame_len; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
157 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
158 //real_t inp = input[internal_channel][i];
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
159 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160 if (inp > (1<<15)-1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
161 inp = (1<<15)-1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
162 else if (inp < -(1<<15))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
163 inp = -(1<<15);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164 int_sample_buffer[(i*channels)+ch] = ROUND32(inp*(1<<16));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
165 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
166 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
167 case FAAD_FMT_FLOAT:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
168 for(i = 0; i < frame_len; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
169 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
170 //real_t inp = input[internal_channel][i];
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
171 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
172 float_sample_buffer[(i*channels)+ch] = inp*FLOAT_SCALE;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
173 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
174 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
175 case FAAD_FMT_DOUBLE:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
176 for(i = 0; i < frame_len; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
177 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
178 //real_t inp = input[internal_channel][i];
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
179 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
180 double_sample_buffer[(i*channels)+ch] = (double)inp*FLOAT_SCALE;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
181 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
182 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
183 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
184 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
185
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
186 return sample_buffer;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
187 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
188
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
189
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
190 /* Dither output */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
191 static int64_t dither_output(uint8_t dithering, uint8_t shapingtype, uint16_t i, double Sum, uint8_t k)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
192 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
193 double Sum2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
194 int64_t val;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
195 if(dithering)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
196 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
197 if(!shapingtype)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
198 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
199 double tmp = Random_Equi(Dither.Dither);
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
200 Sum2 = tmp - (double)Dither.LastRandomNumber[k];
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
201 Dither.LastRandomNumber[k] = (int32_t)tmp;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
202 Sum2 = Sum += Sum2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
203 val = ROUND64(Sum2)&Dither.Mask;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
204 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
205 Sum2 = Random_Triangular(Dither.Dither) - scalar16(Dither.DitherHistory[k], Dither.FilterCoeff + i);
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
206 Sum += Dither.DitherHistory[k][(-1-i)&15] = (float32_t)Sum2;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
207 Sum2 = Sum + scalar16(Dither.ErrorHistory[k], Dither.FilterCoeff + i );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
208 val = ROUND64(Sum2)&Dither.Mask;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
209 Dither.ErrorHistory[k][(-1-i)&15] = (float)(Sum - val);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
210 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
211 return val;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
212 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
213 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
214 return ROUND64 (Sum);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
215 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
216
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
217 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
218
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
219 void* output_to_PCM(faacDecHandle hDecoder,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
220 real_t **input, void *sample_buffer, uint8_t channels,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
221 uint16_t frame_len, uint8_t format)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
222 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
223 uint8_t ch;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
224 uint16_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
225 int16_t *short_sample_buffer = (int16_t*)sample_buffer;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
226
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
227 /* Copy output to a standard PCM buffer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
228 for (ch = 0; ch < channels; ch++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
229 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
230 for(i = 0; i < frame_len; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
231 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
232 int32_t tmp = input[ch][i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
233 tmp += (1 << (REAL_BITS-1));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
234 tmp >>= REAL_BITS;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
235 if (tmp > 0x7fff) tmp = 0x7fff;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
236 else if (tmp <= -32768) tmp = -32768;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
237 short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
238 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
239 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
240
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
241 return sample_buffer;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
242 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
243
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
244 #endif