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