00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "config.h"
00024 #include "libavutil/attributes.h"
00025 #include "sbrdsp.h"
00026
00027 static void sbr_sum64x5_c(float *z)
00028 {
00029 int k;
00030 for (k = 0; k < 64; k++) {
00031 float f = z[k] + z[k + 64] + z[k + 128] + z[k + 192] + z[k + 256];
00032 z[k] = f;
00033 }
00034 }
00035
00036 static float sbr_sum_square_c(float (*x)[2], int n)
00037 {
00038 float sum0 = 0.0f, sum1 = 0.0f;
00039 int i;
00040
00041 for (i = 0; i < n; i += 2)
00042 {
00043 sum0 += x[i + 0][0] * x[i + 0][0];
00044 sum1 += x[i + 0][1] * x[i + 0][1];
00045 sum0 += x[i + 1][0] * x[i + 1][0];
00046 sum1 += x[i + 1][1] * x[i + 1][1];
00047 }
00048
00049 return sum0 + sum1;
00050 }
00051
00052 static void sbr_neg_odd_64_c(float *x)
00053 {
00054 int i;
00055 for (i = 1; i < 64; i += 2)
00056 x[i] = -x[i];
00057 }
00058
00059 static void sbr_qmf_pre_shuffle_c(float *z)
00060 {
00061 int k;
00062 z[64] = z[0];
00063 z[65] = z[1];
00064 for (k = 1; k < 32; k++) {
00065 z[64+2*k ] = -z[64 - k];
00066 z[64+2*k+1] = z[ k + 1];
00067 }
00068 }
00069
00070 static void sbr_qmf_post_shuffle_c(float W[32][2], const float *z)
00071 {
00072 int k;
00073 for (k = 0; k < 32; k++) {
00074 W[k][0] = -z[63-k];
00075 W[k][1] = z[k];
00076 }
00077 }
00078
00079 static void sbr_qmf_deint_neg_c(float *v, const float *src)
00080 {
00081 int i;
00082 for (i = 0; i < 32; i++) {
00083 v[ i] = src[63 - 2*i ];
00084 v[63 - i] = -src[63 - 2*i - 1];
00085 }
00086 }
00087
00088 static void sbr_qmf_deint_bfly_c(float *v, const float *src0, const float *src1)
00089 {
00090 int i;
00091 for (i = 0; i < 64; i++) {
00092 v[ i] = src0[i] - src1[63 - i];
00093 v[127 - i] = src0[i] + src1[63 - i];
00094 }
00095 }
00096
00097 static av_always_inline void autocorrelate(const float x[40][2],
00098 float phi[3][2][2], int lag)
00099 {
00100 int i;
00101 float real_sum = 0.0f;
00102 float imag_sum = 0.0f;
00103 if (lag) {
00104 for (i = 1; i < 38; i++) {
00105 real_sum += x[i][0] * x[i+lag][0] + x[i][1] * x[i+lag][1];
00106 imag_sum += x[i][0] * x[i+lag][1] - x[i][1] * x[i+lag][0];
00107 }
00108 phi[2-lag][1][0] = real_sum + x[ 0][0] * x[lag][0] + x[ 0][1] * x[lag][1];
00109 phi[2-lag][1][1] = imag_sum + x[ 0][0] * x[lag][1] - x[ 0][1] * x[lag][0];
00110 if (lag == 1) {
00111 phi[0][0][0] = real_sum + x[38][0] * x[39][0] + x[38][1] * x[39][1];
00112 phi[0][0][1] = imag_sum + x[38][0] * x[39][1] - x[38][1] * x[39][0];
00113 }
00114 } else {
00115 for (i = 1; i < 38; i++) {
00116 real_sum += x[i][0] * x[i][0] + x[i][1] * x[i][1];
00117 }
00118 phi[2][1][0] = real_sum + x[ 0][0] * x[ 0][0] + x[ 0][1] * x[ 0][1];
00119 phi[1][0][0] = real_sum + x[38][0] * x[38][0] + x[38][1] * x[38][1];
00120 }
00121 }
00122
00123 static void sbr_autocorrelate_c(const float x[40][2], float phi[3][2][2])
00124 {
00125 autocorrelate(x, phi, 0);
00126 autocorrelate(x, phi, 1);
00127 autocorrelate(x, phi, 2);
00128 }
00129
00130 static void sbr_hf_gen_c(float (*X_high)[2], const float (*X_low)[2],
00131 const float alpha0[2], const float alpha1[2],
00132 float bw, int start, int end)
00133 {
00134 float alpha[4];
00135 int i;
00136
00137 alpha[0] = alpha1[0] * bw * bw;
00138 alpha[1] = alpha1[1] * bw * bw;
00139 alpha[2] = alpha0[0] * bw;
00140 alpha[3] = alpha0[1] * bw;
00141
00142 for (i = start; i < end; i++) {
00143 X_high[i][0] =
00144 X_low[i - 2][0] * alpha[0] -
00145 X_low[i - 2][1] * alpha[1] +
00146 X_low[i - 1][0] * alpha[2] -
00147 X_low[i - 1][1] * alpha[3] +
00148 X_low[i][0];
00149 X_high[i][1] =
00150 X_low[i - 2][1] * alpha[0] +
00151 X_low[i - 2][0] * alpha[1] +
00152 X_low[i - 1][1] * alpha[2] +
00153 X_low[i - 1][0] * alpha[3] +
00154 X_low[i][1];
00155 }
00156 }
00157
00158 static void sbr_hf_g_filt_c(float (*Y)[2], const float (*X_high)[40][2],
00159 const float *g_filt, int m_max, intptr_t ixh)
00160 {
00161 int m;
00162
00163 for (m = 0; m < m_max; m++) {
00164 Y[m][0] = X_high[m][ixh][0] * g_filt[m];
00165 Y[m][1] = X_high[m][ixh][1] * g_filt[m];
00166 }
00167 }
00168
00169 static av_always_inline void sbr_hf_apply_noise(float (*Y)[2],
00170 const float *s_m,
00171 const float *q_filt,
00172 int noise,
00173 float phi_sign0,
00174 float phi_sign1,
00175 int m_max)
00176 {
00177 int m;
00178
00179 for (m = 0; m < m_max; m++) {
00180 float y0 = Y[m][0];
00181 float y1 = Y[m][1];
00182 noise = (noise + 1) & 0x1ff;
00183 if (s_m[m]) {
00184 y0 += s_m[m] * phi_sign0;
00185 y1 += s_m[m] * phi_sign1;
00186 } else {
00187 y0 += q_filt[m] * ff_sbr_noise_table[noise][0];
00188 y1 += q_filt[m] * ff_sbr_noise_table[noise][1];
00189 }
00190 Y[m][0] = y0;
00191 Y[m][1] = y1;
00192 phi_sign1 = -phi_sign1;
00193 }
00194 }
00195
00196 static void sbr_hf_apply_noise_0(float (*Y)[2], const float *s_m,
00197 const float *q_filt, int noise,
00198 int kx, int m_max)
00199 {
00200 sbr_hf_apply_noise(Y, s_m, q_filt, noise, 1.0, 0.0, m_max);
00201 }
00202
00203 static void sbr_hf_apply_noise_1(float (*Y)[2], const float *s_m,
00204 const float *q_filt, int noise,
00205 int kx, int m_max)
00206 {
00207 float phi_sign = 1 - 2 * (kx & 1);
00208 sbr_hf_apply_noise(Y, s_m, q_filt, noise, 0.0, phi_sign, m_max);
00209 }
00210
00211 static void sbr_hf_apply_noise_2(float (*Y)[2], const float *s_m,
00212 const float *q_filt, int noise,
00213 int kx, int m_max)
00214 {
00215 sbr_hf_apply_noise(Y, s_m, q_filt, noise, -1.0, 0.0, m_max);
00216 }
00217
00218 static void sbr_hf_apply_noise_3(float (*Y)[2], const float *s_m,
00219 const float *q_filt, int noise,
00220 int kx, int m_max)
00221 {
00222 float phi_sign = 1 - 2 * (kx & 1);
00223 sbr_hf_apply_noise(Y, s_m, q_filt, noise, 0.0, -phi_sign, m_max);
00224 }
00225
00226 av_cold void ff_sbrdsp_init(SBRDSPContext *s)
00227 {
00228 s->sum64x5 = sbr_sum64x5_c;
00229 s->sum_square = sbr_sum_square_c;
00230 s->neg_odd_64 = sbr_neg_odd_64_c;
00231 s->qmf_pre_shuffle = sbr_qmf_pre_shuffle_c;
00232 s->qmf_post_shuffle = sbr_qmf_post_shuffle_c;
00233 s->qmf_deint_neg = sbr_qmf_deint_neg_c;
00234 s->qmf_deint_bfly = sbr_qmf_deint_bfly_c;
00235 s->autocorrelate = sbr_autocorrelate_c;
00236 s->hf_gen = sbr_hf_gen_c;
00237 s->hf_g_filt = sbr_hf_g_filt_c;
00238
00239 s->hf_apply_noise[0] = sbr_hf_apply_noise_0;
00240 s->hf_apply_noise[1] = sbr_hf_apply_noise_1;
00241 s->hf_apply_noise[2] = sbr_hf_apply_noise_2;
00242 s->hf_apply_noise[3] = sbr_hf_apply_noise_3;
00243
00244 if (ARCH_ARM)
00245 ff_sbrdsp_init_arm(s);
00246 if (HAVE_MMX)
00247 ff_sbrdsp_init_x86(s);
00248 }