00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "common.h"
00035 #include "structs.h"
00036
00037 #ifdef LTP_DEC
00038
00039 #include <stdlib.h>
00040 #include "syntax.h"
00041 #include "lt_predict.h"
00042 #include "filtbank.h"
00043 #include "tns.h"
00044
00045
00046
00047 static int16_t real_to_int16(real_t sig_in);
00048
00049
00050
00051 uint8_t is_ltp_ot(uint8_t object_type)
00052 {
00053 #ifdef LTP_DEC
00054 if ((object_type == LTP)
00055 #ifdef ERROR_RESILIENCE
00056 || (object_type == ER_LTP)
00057 #endif
00058 #ifdef LD_DEC
00059 || (object_type == LD)
00060 #endif
00061 )
00062 {
00063 return 1;
00064 }
00065 #endif
00066
00067 return 0;
00068 }
00069
00070 ALIGN static const real_t codebook[8] =
00071 {
00072 REAL_CONST(0.570829),
00073 REAL_CONST(0.696616),
00074 REAL_CONST(0.813004),
00075 REAL_CONST(0.911304),
00076 REAL_CONST(0.984900),
00077 REAL_CONST(1.067894),
00078 REAL_CONST(1.194601),
00079 REAL_CONST(1.369533)
00080 };
00081
00082 void lt_prediction(ic_stream *ics, ltp_info *ltp, real_t *spec,
00083 int16_t *lt_pred_stat, fb_info *fb, uint8_t win_shape,
00084 uint8_t win_shape_prev, uint8_t sr_index,
00085 uint8_t object_type, uint16_t frame_len)
00086 {
00087 uint8_t sfb;
00088 uint16_t bin, i, num_samples;
00089 ALIGN real_t x_est[2048];
00090 ALIGN real_t X_est[2048];
00091
00092 if (ics->window_sequence != EIGHT_SHORT_SEQUENCE)
00093 {
00094 if (ltp->data_present)
00095 {
00096 num_samples = frame_len << 1;
00097
00098 for(i = 0; i < num_samples; i++)
00099 {
00100
00101
00102
00103 #if 0
00104 x_est[i] = MUL_R_C(lt_pred_stat[num_samples + i - ltp->lag],
00105 codebook[ltp->coef]);
00106 #else
00107
00108
00109
00110 x_est[i] = (real_t)lt_pred_stat[num_samples + i - ltp->lag] * codebook[ltp->coef];
00111 #endif
00112 }
00113
00114 filter_bank_ltp(fb, ics->window_sequence, win_shape, win_shape_prev,
00115 x_est, X_est, object_type, frame_len);
00116
00117 tns_encode_frame(ics, &(ics->tns), sr_index, object_type, X_est,
00118 frame_len);
00119
00120 for (sfb = 0; sfb < ltp->last_band; sfb++)
00121 {
00122 if (ltp->long_used[sfb])
00123 {
00124 uint16_t low = ics->swb_offset[sfb];
00125 uint16_t high = ics->swb_offset[sfb+1];
00126
00127 for (bin = low; bin < high; bin++)
00128 {
00129 spec[bin] += X_est[bin];
00130 }
00131 }
00132 }
00133 }
00134 }
00135 }
00136
00137 #ifdef FIXED_POINT
00138 static INLINE int16_t real_to_int16(real_t sig_in)
00139 {
00140 if (sig_in >= 0)
00141 {
00142 sig_in += (1 << (REAL_BITS-1));
00143 if (sig_in >= REAL_CONST(32768))
00144 return 32767;
00145 } else {
00146 sig_in += -(1 << (REAL_BITS-1));
00147 if (sig_in <= REAL_CONST(-32768))
00148 return -32768;
00149 }
00150
00151 return (sig_in >> REAL_BITS);
00152 }
00153 #else
00154 static INLINE int16_t real_to_int16(real_t sig_in)
00155 {
00156 if (sig_in >= 0)
00157 {
00158 #ifndef HAS_LRINTF
00159 sig_in += 0.5f;
00160 #endif
00161 if (sig_in >= 32768.0f)
00162 return 32767;
00163 } else {
00164 #ifndef HAS_LRINTF
00165 sig_in += -0.5f;
00166 #endif
00167 if (sig_in <= -32768.0f)
00168 return -32768;
00169 }
00170
00171 return lrintf(sig_in);
00172 }
00173 #endif
00174
00175 void lt_update_state(int16_t *lt_pred_stat, real_t *time, real_t *overlap,
00176 uint16_t frame_len, uint8_t object_type)
00177 {
00178 uint16_t i;
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 #ifdef LD_DEC
00192 if (object_type == LD)
00193 {
00194 for (i = 0; i < frame_len; i++)
00195 {
00196 lt_pred_stat[i] = lt_pred_stat[i + frame_len];
00197 lt_pred_stat[frame_len + i] = lt_pred_stat[i + (frame_len * 2)];
00198 lt_pred_stat[(frame_len * 2) + i] = real_to_int16(time[i]);
00199 lt_pred_stat[(frame_len * 3) + i] = real_to_int16(overlap[i]);
00200 }
00201 } else {
00202 #endif
00203 for (i = 0; i < frame_len; i++)
00204 {
00205 lt_pred_stat[i] = lt_pred_stat[i + frame_len];
00206 lt_pred_stat[frame_len + i] = real_to_int16(time[i]);
00207 lt_pred_stat[(frame_len * 2) + i] = real_to_int16(overlap[i]);
00208 #if 0
00209 lt_pred_stat[(frame_len * 3) + i] = 0;
00210 #endif
00211 }
00212 #ifdef LD_DEC
00213 }
00214 #endif
00215 }
00216
00217 #endif