annotate libfaad2/lt_predict.c @ 12125:f4fc74a88e65

full screen flipping synchronization corrections (by Adam Tla/lka)
author rathann
date Mon, 05 Apr 2004 21:35:30 +0000
parents 3185f64f6350
children 4a370c80fe5c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
4 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
5 ** This program is free software; you can redistribute it and/or modify
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
6 ** it under the terms of the GNU General Public License as published by
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
7 ** the Free Software Foundation; either version 2 of the License, or
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
8 ** (at your option) any later version.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
9 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
10 ** This program is distributed in the hope that it will be useful,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
13 ** GNU General Public License for more details.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
14 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
15 ** You should have received a copy of the GNU General Public License
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
16 ** along with this program; if not, write to the Free Software
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
18 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
19 ** Any non-GPL usage of this software or parts of this software is strictly
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
20 ** forbidden.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
21 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
22 ** Commercial non-GPL licensing of this software is possible.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
24 **
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
25 ** $Id: lt_predict.c,v 1.12 2003/09/09 18:09:52 menno Exp $
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
26 **/
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
27
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
28
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
29 #include "common.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
30 #include "structs.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
31
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
32 #ifdef LTP_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
33
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
34 #include <stdlib.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
35 #include "syntax.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
36 #include "lt_predict.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
37 #include "filtbank.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
38 #include "tns.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
39
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
40 static real_t codebook[8] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
41 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
42 COEF_CONST(0.570829),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
43 COEF_CONST(0.696616),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
44 COEF_CONST(0.813004),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
45 COEF_CONST(0.911304),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
46 COEF_CONST(0.984900),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
47 COEF_CONST(1.067894),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
48 COEF_CONST(1.194601),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
49 COEF_CONST(1.369533)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
50 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
51
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
52 void lt_prediction(ic_stream *ics, ltp_info *ltp, real_t *spec,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
53 real_t *lt_pred_stat, fb_info *fb, uint8_t win_shape,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
54 uint8_t win_shape_prev, uint8_t sr_index,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
55 uint8_t object_type, uint16_t frame_len)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
56 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
57 uint8_t sfb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
58 uint16_t bin, i, num_samples;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
59 real_t *x_est;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
60 real_t *X_est;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
61
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
62 if (ics->window_sequence != EIGHT_SHORT_SEQUENCE)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
63 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
64 if (ltp->data_present)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
65 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
66 num_samples = frame_len << 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
67
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
68 x_est = (real_t*)malloc(num_samples*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
69 X_est = (real_t*)malloc(num_samples*sizeof(real_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
70
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
71 for(i = 0; i < num_samples; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
72 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
73 /* The extra lookback M (N/2 for LD, 0 for LTP) is handled
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
74 in the buffer updating */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
75 x_est[i] = MUL_R_C(lt_pred_stat[num_samples + i - ltp->lag],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
76 codebook[ltp->coef]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
77 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
78
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
79 filter_bank_ltp(fb, ics->window_sequence, win_shape, win_shape_prev,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
80 x_est, X_est, object_type, frame_len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
81
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
82 tns_encode_frame(ics, &(ics->tns), sr_index, object_type, X_est,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
83 frame_len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
84
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
85 for (sfb = 0; sfb < ltp->last_band; sfb++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
86 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87 if (ltp->long_used[sfb])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89 uint16_t low = ics->swb_offset[sfb];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
90 uint16_t high = ics->swb_offset[sfb+1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
91
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
92 for (bin = low; bin < high; bin++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
93 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
94 spec[bin] += X_est[bin];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
95 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
96 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
97 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
98
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
99 free(x_est);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 free(X_est);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
102 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105 void lt_update_state(real_t *lt_pred_stat, real_t *time, real_t *overlap,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106 uint16_t frame_len, uint8_t object_type)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
107 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
108 uint16_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
110 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
111 * The reference point for index i and the content of the buffer
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
112 * lt_pred_stat are arranged so that lt_pred_stat(0 ... N/2 - 1) contains the
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
113 * last aliased half window from the IMDCT, and lt_pred_stat(N/2 ... N-1)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
114 * is always all zeros. The rest of lt_pred_stat (i<0) contains the previous
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
115 * fully reconstructed time domain samples, i.e., output of the decoder.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116 *
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
117 * These values are shifted up by N*2 to avoid (i<0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118 *
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 * For the LD object type an extra 512 samples lookback is accomodated here.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121 #ifdef LD_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 if (object_type == LD)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
124 for (i = 0; i < frame_len; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
126 lt_pred_stat[i] /* extra 512 */ = lt_pred_stat[i + frame_len];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
127 lt_pred_stat[frame_len + i] = lt_pred_stat[i + (frame_len * 2)];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
128 lt_pred_stat[(frame_len * 2) + i] = time[i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
129 lt_pred_stat[(frame_len * 3) + i] = overlap[i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
132 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
133 for (i = 0; i < frame_len; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
134 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135 lt_pred_stat[i] = lt_pred_stat[i + frame_len];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
136 lt_pred_stat[frame_len + i] = time[i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
137 lt_pred_stat[(frame_len * 2) + i] = overlap[i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
138 #if 0 /* set to zero once upon initialisation */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
139 lt_pred_stat[(frame_len * 3) + i] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
140 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
142 #ifdef LD_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
143 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147 #endif