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 #include "common.h"
00034 #include "structs.h"
00035
00036 #ifdef SSR_DEC
00037
00038 #include "syntax.h"
00039 #include "filtbank.h"
00040 #include "ssr.h"
00041 #include "ssr_fb.h"
00042
00043 void ssr_decode(ssr_info *ssr, fb_info *fb, uint8_t window_sequence,
00044 uint8_t window_shape, uint8_t window_shape_prev,
00045 real_t *freq_in, real_t *time_out, real_t *overlap,
00046 real_t ipqf_buffer[SSR_BANDS][96/4],
00047 real_t *prev_fmd, uint16_t frame_len)
00048 {
00049 uint8_t band;
00050 uint16_t ssr_frame_len = frame_len/SSR_BANDS;
00051 real_t time_tmp[2048] = {0};
00052 real_t output[1024] = {0};
00053
00054 for (band = 0; band < SSR_BANDS; band++)
00055 {
00056 int16_t j;
00057
00058
00059 if (band == 1 || band == 3)
00060 {
00061 for (j = 0; j < ssr_frame_len/2; j++)
00062 {
00063 real_t tmp;
00064 tmp = freq_in[j + ssr_frame_len*band];
00065 freq_in[j + ssr_frame_len*band] =
00066 freq_in[ssr_frame_len - j - 1 + ssr_frame_len*band];
00067 freq_in[ssr_frame_len - j - 1 + ssr_frame_len*band] = tmp;
00068 }
00069 }
00070
00071
00072 ssr_ifilter_bank(fb, window_sequence, window_shape, window_shape_prev,
00073 freq_in + band*ssr_frame_len, time_tmp + band*ssr_frame_len,
00074 ssr_frame_len);
00075
00076
00077 ssr_gain_control(ssr, time_tmp, output, overlap, prev_fmd,
00078 band, window_sequence, ssr_frame_len);
00079 }
00080
00081
00082 ssr_ipqf(ssr, output, time_out, ipqf_buffer, frame_len, SSR_BANDS);
00083 }
00084
00085 static void ssr_gain_control(ssr_info *ssr, real_t *data, real_t *output,
00086 real_t *overlap, real_t *prev_fmd, uint8_t band,
00087 uint8_t window_sequence, uint16_t frame_len)
00088 {
00089 uint16_t i;
00090 real_t gc_function[2*1024/SSR_BANDS];
00091
00092 if (window_sequence != EIGHT_SHORT_SEQUENCE)
00093 {
00094 ssr_gc_function(ssr, &prev_fmd[band * frame_len*2],
00095 gc_function, window_sequence, band, frame_len);
00096
00097 for (i = 0; i < frame_len*2; i++)
00098 data[band * frame_len*2 + i] *= gc_function[i];
00099 for (i = 0; i < frame_len; i++)
00100 {
00101 output[band*frame_len + i] = overlap[band*frame_len + i] +
00102 data[band*frame_len*2 + i];
00103 }
00104 for (i = 0; i < frame_len; i++)
00105 {
00106 overlap[band*frame_len + i] =
00107 data[band*frame_len*2 + frame_len + i];
00108 }
00109 } else {
00110 uint8_t w;
00111 for (w = 0; w < 8; w++)
00112 {
00113 uint16_t frame_len8 = frame_len/8;
00114 uint16_t frame_len16 = frame_len/16;
00115
00116 ssr_gc_function(ssr, &prev_fmd[band*frame_len*2 + w*frame_len*2/8],
00117 gc_function, window_sequence, frame_len);
00118
00119 for (i = 0; i < frame_len8*2; i++)
00120 data[band*frame_len*2 + w*frame_len8*2+i] *= gc_function[i];
00121 for (i = 0; i < frame_len8; i++)
00122 {
00123 overlap[band*frame_len + i + 7*frame_len16 + w*frame_len8] +=
00124 data[band*frame_len*2 + 2*w*frame_len8 + i];
00125 }
00126 for (i = 0; i < frame_len8; i++)
00127 {
00128 overlap[band*frame_len + i + 7*frame_len16 + (w+1)*frame_len8] =
00129 data[band*frame_len*2 + 2*w*frame_len8 + frame_len8 + i];
00130 }
00131 }
00132 for (i = 0; i < frame_len; i++)
00133 output[band*frame_len + i] = overlap[band*frame_len + i];
00134 for (i = 0; i < frame_len; i++)
00135 overlap[band*frame_len + i] = overlap[band*frame_len + i + frame_len];
00136 }
00137 }
00138
00139 static void ssr_gc_function(ssr_info *ssr, real_t *prev_fmd,
00140 real_t *gc_function, uint8_t window_sequence,
00141 uint8_t band, uint16_t frame_len)
00142 {
00143 uint16_t i;
00144 uint16_t len_area1, len_area2;
00145 int32_t aloc[10];
00146 real_t alev[10];
00147
00148 switch (window_sequence)
00149 {
00150 case ONLY_LONG_SEQUENCE:
00151 len_area1 = frame_len/SSR_BANDS;
00152 len_area2 = 0;
00153 break;
00154 case LONG_START_SEQUENCE:
00155 len_area1 = (frame_len/SSR_BANDS)*7/32;
00156 len_area2 = (frame_len/SSR_BANDS)/16;
00157 break;
00158 case EIGHT_SHORT_SEQUENCE:
00159 len_area1 = (frame_len/8)/SSR_BANDS;
00160 len_area2 = 0;
00161 break;
00162 case LONG_STOP_SEQUENCE:
00163 len_area1 = (frame_len/SSR_BANDS);
00164 len_area2 = 0;
00165 break;
00166 }
00167
00168
00169
00170
00171
00172
00173 for (i = 0; i < frame_len*2; i++)
00174 gc_function[i] = 1;
00175 }
00176
00177 #endif