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 **
|
|
25 ** $Id: lt_predict.c,v 1.11 2003/07/29 08:20:12 menno Exp $
|
|
26 **/
|
|
27
|
|
28 #include "common.h"
|
|
29 #include "structs.h"
|
|
30
|
|
31 #ifdef LTP_DEC
|
|
32
|
|
33 #include <stdlib.h>
|
|
34 #include "syntax.h"
|
|
35 #include "lt_predict.h"
|
|
36 #include "filtbank.h"
|
|
37 #include "tns.h"
|
|
38
|
|
39 static real_t codebook[8] =
|
|
40 {
|
|
41 COEF_CONST(0.570829),
|
|
42 COEF_CONST(0.696616),
|
|
43 COEF_CONST(0.813004),
|
|
44 COEF_CONST(0.911304),
|
|
45 COEF_CONST(0.984900),
|
|
46 COEF_CONST(1.067894),
|
|
47 COEF_CONST(1.194601),
|
|
48 COEF_CONST(1.369533)
|
|
49 };
|
|
50
|
|
51 void lt_prediction(ic_stream *ics, ltp_info *ltp, real_t *spec,
|
|
52 real_t *lt_pred_stat, fb_info *fb, uint8_t win_shape,
|
|
53 uint8_t win_shape_prev, uint8_t sr_index,
|
|
54 uint8_t object_type, uint16_t frame_len)
|
|
55 {
|
|
56 uint8_t sfb;
|
|
57 uint16_t bin, i, num_samples;
|
|
58 real_t *x_est;
|
|
59 real_t *X_est;
|
|
60
|
|
61 if (ics->window_sequence != EIGHT_SHORT_SEQUENCE)
|
|
62 {
|
|
63 if (ltp->data_present)
|
|
64 {
|
|
65 num_samples = frame_len << 1;
|
|
66
|
|
67 x_est = (real_t*)malloc(num_samples*sizeof(real_t));
|
|
68 X_est = (real_t*)malloc(num_samples*sizeof(real_t));
|
|
69
|
|
70 for(i = 0; i < num_samples; i++)
|
|
71 {
|
|
72 /* The extra lookback M (N/2 for LD, 0 for LTP) is handled
|
|
73 in the buffer updating */
|
|
74 x_est[i] = MUL_R_C(lt_pred_stat[num_samples + i - ltp->lag],
|
|
75 codebook[ltp->coef]);
|
|
76 }
|
|
77
|
|
78 filter_bank_ltp(fb, ics->window_sequence, win_shape, win_shape_prev,
|
|
79 x_est, X_est, object_type, frame_len);
|
|
80
|
|
81 tns_encode_frame(ics, &(ics->tns), sr_index, object_type, X_est,
|
|
82 frame_len);
|
|
83
|
|
84 for (sfb = 0; sfb < ltp->last_band; sfb++)
|
|
85 {
|
|
86 if (ltp->long_used[sfb])
|
|
87 {
|
|
88 uint16_t low = ics->swb_offset[sfb];
|
|
89 uint16_t high = ics->swb_offset[sfb+1];
|
|
90
|
|
91 for (bin = low; bin < high; bin++)
|
|
92 {
|
|
93 spec[bin] += X_est[bin];
|
|
94 }
|
|
95 }
|
|
96 }
|
|
97
|
|
98 free(x_est);
|
|
99 free(X_est);
|
|
100 }
|
|
101 }
|
|
102 }
|
|
103
|
|
104 void lt_update_state(real_t *lt_pred_stat, real_t *time, real_t *overlap,
|
|
105 uint16_t frame_len, uint8_t object_type)
|
|
106 {
|
|
107 uint16_t i;
|
|
108
|
|
109 /*
|
|
110 * The reference point for index i and the content of the buffer
|
|
111 * lt_pred_stat are arranged so that lt_pred_stat(0 ... N/2 - 1) contains the
|
|
112 * last aliased half window from the IMDCT, and lt_pred_stat(N/2 ... N-1)
|
|
113 * is always all zeros. The rest of lt_pred_stat (i<0) contains the previous
|
|
114 * fully reconstructed time domain samples, i.e., output of the decoder.
|
|
115 *
|
|
116 * These values are shifted up by N*2 to avoid (i<0)
|
|
117 *
|
|
118 * For the LD object type an extra 512 samples lookback is accomodated here.
|
|
119 */
|
|
120 #ifdef LD_DEC
|
|
121 if (object_type == LD)
|
|
122 {
|
|
123 for (i = 0; i < frame_len; i++)
|
|
124 {
|
|
125 lt_pred_stat[i] /* extra 512 */ = lt_pred_stat[i + frame_len];
|
|
126 lt_pred_stat[frame_len + i] = lt_pred_stat[i + (frame_len * 2)];
|
|
127 lt_pred_stat[(frame_len * 2) + i] = time[i];
|
|
128 lt_pred_stat[(frame_len * 3) + i] = overlap[i];
|
|
129 }
|
|
130 } else {
|
|
131 #endif
|
|
132 for (i = 0; i < frame_len; i++)
|
|
133 {
|
|
134 lt_pred_stat[i] = lt_pred_stat[i + frame_len];
|
|
135 lt_pred_stat[frame_len + i] = time[i];
|
|
136 lt_pred_stat[(frame_len * 2) + i] = overlap[i];
|
|
137 #if 0 /* set to zero once upon initialisation */
|
|
138 lt_pred_stat[(frame_len * 3) + i] = 0;
|
|
139 #endif
|
|
140 }
|
|
141 #ifdef LD_DEC
|
|
142 }
|
|
143 #endif
|
|
144 }
|
|
145
|
|
146 #endif
|