annotate libfaad2/ic_predict.c @ 13707:3fff37ed4fe7

Fixed event handling for menubar and window close button.
author nplourde
date Wed, 20 Oct 2004 16:38:33 +0000
parents d81145997036
children 2ae5ab4331ca
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
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
10725
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 **
12625
d81145997036 More information about modifications to comply more closely with GPL 2a.
diego
parents: 12527
diff changeset
25 ** Initially modified for use with MPlayer by Arpad Gereöffy on 2003/08/30
d81145997036 More information about modifications to comply more closely with GPL 2a.
diego
parents: 12527
diff changeset
26 ** $Id: ic_predict.c,v 1.2 2004/06/02 22:59:03 diego Exp $
d81145997036 More information about modifications to comply more closely with GPL 2a.
diego
parents: 12527
diff changeset
27 ** detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
28 **/
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
29
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
30 #include "common.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
31 #include "structs.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
32
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
33 #ifdef MAIN_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
34
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
35 #include "syntax.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
36 #include "ic_predict.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
37 #include "pns.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
38
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
39
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
40 static void flt_round(float32_t *pf)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
41 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
42 int32_t flg;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
43 uint32_t tmp, tmp1, tmp2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
44
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
45 tmp = *(uint32_t*)pf;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
46 flg = tmp & (uint32_t)0x00008000;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
47 tmp &= (uint32_t)0xffff0000;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
48 tmp1 = tmp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
49 /* round 1/2 lsb toward infinity */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
50 if (flg)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
51 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
52 tmp &= (uint32_t)0xff800000; /* extract exponent and sign */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
53 tmp |= (uint32_t)0x00010000; /* insert 1 lsb */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
54 tmp2 = tmp; /* add 1 lsb and elided one */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
55 tmp &= (uint32_t)0xff800000; /* extract exponent and sign */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
56
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
57 *pf = *(float32_t*)&tmp1 + *(float32_t*)&tmp2 - *(float32_t*)&tmp;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
58 } else {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
59 *pf = *(float32_t*)&tmp;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
60 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
61 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
62
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
63 static int16_t quant_pred(float32_t x)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
64 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
65 int16_t q;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
66 uint32_t *tmp = (uint32_t*)&x;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
67
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
68 q = (int16_t)(*tmp>>16);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
69
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
70 return q;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
71 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
72
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
73 static float32_t inv_quant_pred(int16_t q)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
74 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
75 float32_t x;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
76 uint32_t *tmp = (uint32_t*)&x;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
77 *tmp = ((uint32_t)q)<<16;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
78
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
79 return x;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
80 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
81
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
82 static void ic_predict(pred_state *state, real_t input, real_t *output, uint8_t pred)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
83 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
84 uint16_t tmp;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
85 int16_t i, j;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
86 real_t dr1, predictedvalue;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87 real_t e0, e1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88 real_t k1, k2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
90 real_t r[2];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
91 real_t COR[2];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
92 real_t VAR[2];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
93
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
94 r[0] = inv_quant_pred(state->r[0]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
95 r[1] = inv_quant_pred(state->r[1]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
96 COR[0] = inv_quant_pred(state->COR[0]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
97 COR[1] = inv_quant_pred(state->COR[1]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
98 VAR[0] = inv_quant_pred(state->VAR[0]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
99 VAR[1] = inv_quant_pred(state->VAR[1]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
100
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
102 #if 1
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
103 tmp = state->VAR[0];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
104 j = (tmp >> 7);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
105 i = tmp & 0x7f;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
106 if (j >= 128)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
107 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
108 j -= 128;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
109 k1 = COR[0] * exp_table[j] * mnt_table[i];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
110 } else {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
111 k1 = REAL_CONST(0);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
112 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
113 #else
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
114
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
115 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
116 #define B 0.953125
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
117 real_t c = COR[0];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
118 real_t v = VAR[0];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
119 real_t tmp;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
120 if (c == 0 || v <= 1)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
121 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
122 k1 = 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
123 } else {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
124 tmp = B / v;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
125 flt_round(&tmp);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
126 k1 = c * tmp;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
127 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
128 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
129 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131 if (pred)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
132 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
133 #if 1
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
134 tmp = state->VAR[1];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
135 j = (tmp >> 7);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
136 i = tmp & 0x7f;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
137 if (j >= 128)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
138 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
139 j -= 128;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
140 k2 = COR[1] * exp_table[j] * mnt_table[i];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
141 } else {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
142 k2 = REAL_CONST(0);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
143 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
144 #else
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
146 #define B 0.953125
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
147 real_t c = COR[1];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
148 real_t v = VAR[1];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
149 real_t tmp;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
150 if (c == 0 || v <= 1)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
151 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
152 k2 = 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
153 } else {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
154 tmp = B / v;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
155 flt_round(&tmp);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
156 k2 = c * tmp;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
157 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
158 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
159
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
160 predictedvalue = k1*r[0] + k2*r[1];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
161 flt_round(&predictedvalue);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
162 *output = input + predictedvalue;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
163 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
165 /* calculate new state data */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
166 e0 = *output;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
167 e1 = e0 - k1*r[0];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
168 dr1 = k1*e0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
169
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
170 VAR[0] = ALPHA*VAR[0] + 0.5f * (r[0]*r[0] + e0*e0);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
171 COR[0] = ALPHA*COR[0] + r[0]*e0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
172 VAR[1] = ALPHA*VAR[1] + 0.5f * (r[1]*r[1] + e1*e1);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
173 COR[1] = ALPHA*COR[1] + r[1]*e1;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
174
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
175 r[1] = A * (r[0]-dr1);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
176 r[0] = A * e0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
177
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
178 state->r[0] = quant_pred(r[0]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
179 state->r[1] = quant_pred(r[1]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
180 state->COR[0] = quant_pred(COR[0]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
181 state->COR[1] = quant_pred(COR[1]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
182 state->VAR[0] = quant_pred(VAR[0]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
183 state->VAR[1] = quant_pred(VAR[1]);
10725
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 static void reset_pred_state(pred_state *state)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
187 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
188 state->r[0] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
189 state->r[1] = 0;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
190 state->COR[0] = 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
191 state->COR[1] = 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
192 state->VAR[0] = 0x3F80;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
193 state->VAR[1] = 0x3F80;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
194 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
195
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
196 void pns_reset_pred_state(ic_stream *ics, pred_state *state)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
197 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
198 uint8_t sfb, g, b;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
199 uint16_t i, offs, offs2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
200
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
201 /* prediction only for long blocks */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
202 if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
203 return;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
204
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
205 for (g = 0; g < ics->num_window_groups; g++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
206 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
207 for (b = 0; b < ics->window_group_length[g]; b++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
208 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
209 for (sfb = 0; sfb < ics->max_sfb; sfb++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
210 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
211 if (is_noise(ics, g, sfb))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
212 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
213 offs = ics->swb_offset[sfb];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
214 offs2 = ics->swb_offset[sfb+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
215
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
216 for (i = offs; i < offs2; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
217 reset_pred_state(&state[i]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
218 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
219 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
220 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
221 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
222 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
223
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
224 void reset_all_predictors(pred_state *state, uint16_t frame_len)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
225 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
226 uint16_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
227
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
228 for (i = 0; i < frame_len; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
229 reset_pred_state(&state[i]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
230 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
231
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
232 /* intra channel prediction */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
233 void ic_prediction(ic_stream *ics, real_t *spec, pred_state *state,
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
234 uint16_t frame_len, uint8_t sf_index)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
235 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
236 uint8_t sfb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
237 uint16_t bin;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
238
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
239 if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
240 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
241 reset_all_predictors(state, frame_len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
242 } else {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
243 for (sfb = 0; sfb < max_pred_sfb(sf_index); sfb++)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
244 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
245 uint16_t low = ics->swb_offset[sfb];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
246 uint16_t high = ics->swb_offset[sfb+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
247
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
248 for (bin = low; bin < high; bin++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
249 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
250 ic_predict(&state[bin], spec[bin], &spec[bin],
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10725
diff changeset
251 (ics->predictor_data_present && ics->pred.prediction_used[sfb]));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
252 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
253 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
254
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
255 if (ics->predictor_data_present)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
256 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
257 if (ics->pred.predictor_reset)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
258 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
259 for (bin = ics->pred.predictor_reset_group_number - 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
260 bin < frame_len; bin += 30)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
261 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
262 reset_pred_state(&state[bin]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
263 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
264 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
265 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
266 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
267 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
268
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
269 #endif