| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * AAC Spectral Band Replication decoding functions | ||
| 3 | * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl ) | ||
| 4 | * Copyright (c) 2009-2010 Alex Converse <alex.converse@gmail.com> | ||
| 5 | * | ||
| 6 | * This file is part of FFmpeg. | ||
| 7 | * | ||
| 8 | * FFmpeg is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU Lesser General Public | ||
| 10 | * License as published by the Free Software Foundation; either | ||
| 11 | * version 2.1 of the License, or (at your option) any later version. | ||
| 12 | * | ||
| 13 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * Lesser General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU Lesser General Public | ||
| 19 | * License along with FFmpeg; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 21 | */ | ||
| 22 | |||
| 23 | #define USE_FIXED 0 | ||
| 24 | |||
| 25 | #include "aac.h" | ||
| 26 | #include "libavutil/attributes.h" | ||
| 27 | #include "libavutil/intfloat.h" | ||
| 28 | #include "sbrdsp.h" | ||
| 29 | |||
| 30 | 251188 | static float sbr_sum_square_c(float (*x)[2], int n) | |
| 31 | { | ||
| 32 | 251188 | float sum0 = 0.0f, sum1 = 0.0f; | |
| 33 | int i; | ||
| 34 | |||
| 35 |
2/2✓ Branch 0 taken 2752464 times.
✓ Branch 1 taken 251188 times.
|
3003652 | for (i = 0; i < n; i += 2) |
| 36 | { | ||
| 37 | 2752464 | sum0 += x[i + 0][0] * x[i + 0][0]; | |
| 38 | 2752464 | sum1 += x[i + 0][1] * x[i + 0][1]; | |
| 39 | 2752464 | sum0 += x[i + 1][0] * x[i + 1][0]; | |
| 40 | 2752464 | sum1 += x[i + 1][1] * x[i + 1][1]; | |
| 41 | } | ||
| 42 | |||
| 43 | 251188 | return sum0 + sum1; | |
| 44 | } | ||
| 45 | |||
| 46 | 355459 | static void sbr_neg_odd_64_c(float *x) | |
| 47 | { | ||
| 48 | 355459 | union av_intfloat32 *xi = (union av_intfloat32*) x; | |
| 49 | int i; | ||
| 50 |
2/2✓ Branch 0 taken 5687344 times.
✓ Branch 1 taken 355459 times.
|
6042803 | for (i = 1; i < 64; i += 4) { |
| 51 | 5687344 | xi[i + 0].i ^= 1U << 31; | |
| 52 | 5687344 | xi[i + 2].i ^= 1U << 31; | |
| 53 | } | ||
| 54 | 355459 | } | |
| 55 | |||
| 56 | 365091 | static void sbr_qmf_pre_shuffle_c(float *z) | |
| 57 | { | ||
| 58 | 365091 | union av_intfloat32 *zi = (union av_intfloat32*) z; | |
| 59 | int k; | ||
| 60 | 365091 | zi[64].i = zi[0].i; | |
| 61 | 365091 | zi[65].i = zi[1].i; | |
| 62 |
2/2✓ Branch 0 taken 5476365 times.
✓ Branch 1 taken 365091 times.
|
5841456 | for (k = 1; k < 31; k += 2) { |
| 63 | 5476365 | zi[64 + 2 * k + 0].i = zi[64 - k].i ^ (1U << 31); | |
| 64 | 5476365 | zi[64 + 2 * k + 1].i = zi[ k + 1].i; | |
| 65 | 5476365 | zi[64 + 2 * k + 2].i = zi[63 - k].i ^ (1U << 31); | |
| 66 | 5476365 | zi[64 + 2 * k + 3].i = zi[ k + 2].i; | |
| 67 | } | ||
| 68 | |||
| 69 | 365091 | zi[64 + 2 * 31 + 0].i = zi[64 - 31].i ^ (1U << 31); | |
| 70 | 365091 | zi[64 + 2 * 31 + 1].i = zi[31 + 1].i; | |
| 71 | 365091 | } | |
| 72 | |||
| 73 | 365091 | static void sbr_qmf_post_shuffle_c(float W[32][2], const float *z) | |
| 74 | { | ||
| 75 | 365091 | const union av_intfloat32 *zi = (const union av_intfloat32*) z; | |
| 76 | 365091 | union av_intfloat32 *Wi = (union av_intfloat32*) W; | |
| 77 | int k; | ||
| 78 |
2/2✓ Branch 0 taken 5841456 times.
✓ Branch 1 taken 365091 times.
|
6206547 | for (k = 0; k < 32; k += 2) { |
| 79 | 5841456 | Wi[2 * k + 0].i = zi[63 - k].i ^ (1U << 31); | |
| 80 | 5841456 | Wi[2 * k + 1].i = zi[ k + 0].i; | |
| 81 | 5841456 | Wi[2 * k + 2].i = zi[62 - k].i ^ (1U << 31); | |
| 82 | 5841456 | Wi[2 * k + 3].i = zi[ k + 1].i; | |
| 83 | } | ||
| 84 | 365091 | } | |
| 85 | |||
| 86 | 73603 | static void sbr_qmf_deint_neg_c(float *v, const float *src) | |
| 87 | { | ||
| 88 | 73603 | const union av_intfloat32 *si = (const union av_intfloat32*)src; | |
| 89 | 73603 | union av_intfloat32 *vi = (union av_intfloat32*)v; | |
| 90 | int i; | ||
| 91 |
2/2✓ Branch 0 taken 2355296 times.
✓ Branch 1 taken 73603 times.
|
2428899 | for (i = 0; i < 32; i++) { |
| 92 | 2355296 | vi[ i].i = si[63 - 2 * i ].i; | |
| 93 | 2355296 | vi[63 - i].i = si[63 - 2 * i - 1].i ^ (1U << 31); | |
| 94 | } | ||
| 95 | 73603 | } | |
| 96 | |||
| 97 | #if 0 | ||
| 98 | /* This code is slower because it multiplies memory accesses. | ||
| 99 | * It is left for educational purposes and because it may offer | ||
| 100 | * a better reference for writing arch-specific DSP functions. */ | ||
| 101 | static av_always_inline void autocorrelate(const float x[40][2], | ||
| 102 | float phi[3][2][2], int lag) | ||
| 103 | { | ||
| 104 | int i; | ||
| 105 | float real_sum = 0.0f; | ||
| 106 | float imag_sum = 0.0f; | ||
| 107 | if (lag) { | ||
| 108 | for (i = 1; i < 38; i++) { | ||
| 109 | real_sum += x[i][0] * x[i+lag][0] + x[i][1] * x[i+lag][1]; | ||
| 110 | imag_sum += x[i][0] * x[i+lag][1] - x[i][1] * x[i+lag][0]; | ||
| 111 | } | ||
| 112 | phi[2-lag][1][0] = real_sum + x[ 0][0] * x[lag][0] + x[ 0][1] * x[lag][1]; | ||
| 113 | phi[2-lag][1][1] = imag_sum + x[ 0][0] * x[lag][1] - x[ 0][1] * x[lag][0]; | ||
| 114 | if (lag == 1) { | ||
| 115 | phi[0][0][0] = real_sum + x[38][0] * x[39][0] + x[38][1] * x[39][1]; | ||
| 116 | phi[0][0][1] = imag_sum + x[38][0] * x[39][1] - x[38][1] * x[39][0]; | ||
| 117 | } | ||
| 118 | } else { | ||
| 119 | for (i = 1; i < 38; i++) { | ||
| 120 | real_sum += x[i][0] * x[i][0] + x[i][1] * x[i][1]; | ||
| 121 | } | ||
| 122 | phi[2][1][0] = real_sum + x[ 0][0] * x[ 0][0] + x[ 0][1] * x[ 0][1]; | ||
| 123 | phi[1][0][0] = real_sum + x[38][0] * x[38][0] + x[38][1] * x[38][1]; | ||
| 124 | } | ||
| 125 | } | ||
| 126 | |||
| 127 | static void sbr_autocorrelate_c(const float x[40][2], float phi[3][2][2]) | ||
| 128 | { | ||
| 129 | autocorrelate(x, phi, 0); | ||
| 130 | autocorrelate(x, phi, 1); | ||
| 131 | autocorrelate(x, phi, 2); | ||
| 132 | } | ||
| 133 | #else | ||
| 134 | 124327 | static void sbr_autocorrelate_c(const float x[40][2], float phi[3][2][2]) | |
| 135 | { | ||
| 136 | 124327 | float real_sum2 = x[0][0] * x[2][0] + x[0][1] * x[2][1]; | |
| 137 | 124327 | float imag_sum2 = x[0][0] * x[2][1] - x[0][1] * x[2][0]; | |
| 138 | 124327 | float real_sum1 = 0.0f, imag_sum1 = 0.0f, real_sum0 = 0.0f; | |
| 139 | int i; | ||
| 140 |
2/2✓ Branch 0 taken 4600099 times.
✓ Branch 1 taken 124327 times.
|
4724426 | for (i = 1; i < 38; i++) { |
| 141 | 4600099 | real_sum0 += x[i][0] * x[i ][0] + x[i][1] * x[i ][1]; | |
| 142 | 4600099 | real_sum1 += x[i][0] * x[i + 1][0] + x[i][1] * x[i + 1][1]; | |
| 143 | 4600099 | imag_sum1 += x[i][0] * x[i + 1][1] - x[i][1] * x[i + 1][0]; | |
| 144 | 4600099 | real_sum2 += x[i][0] * x[i + 2][0] + x[i][1] * x[i + 2][1]; | |
| 145 | 4600099 | imag_sum2 += x[i][0] * x[i + 2][1] - x[i][1] * x[i + 2][0]; | |
| 146 | } | ||
| 147 | 124327 | phi[2 - 2][1][0] = real_sum2; | |
| 148 | 124327 | phi[2 - 2][1][1] = imag_sum2; | |
| 149 | 124327 | phi[2 ][1][0] = real_sum0 + x[ 0][0] * x[ 0][0] + x[ 0][1] * x[ 0][1]; | |
| 150 | 124327 | phi[1 ][0][0] = real_sum0 + x[38][0] * x[38][0] + x[38][1] * x[38][1]; | |
| 151 | 124327 | phi[2 - 1][1][0] = real_sum1 + x[ 0][0] * x[ 1][0] + x[ 0][1] * x[ 1][1]; | |
| 152 | 124327 | phi[2 - 1][1][1] = imag_sum1 + x[ 0][0] * x[ 1][1] - x[ 0][1] * x[ 1][0]; | |
| 153 | 124327 | phi[0 ][0][0] = real_sum1 + x[38][0] * x[39][0] + x[38][1] * x[39][1]; | |
| 154 | 124327 | phi[0 ][0][1] = imag_sum1 + x[38][0] * x[39][1] - x[38][1] * x[39][0]; | |
| 155 | 124327 | } | |
| 156 | #endif | ||
| 157 | |||
| 158 | 172098 | static void sbr_hf_gen_c(float (*X_high)[2], const float (*X_low)[2], | |
| 159 | const float alpha0[2], const float alpha1[2], | ||
| 160 | float bw, int start, int end) | ||
| 161 | { | ||
| 162 | float alpha[4]; | ||
| 163 | int i; | ||
| 164 | |||
| 165 | 172098 | alpha[0] = alpha1[0] * bw * bw; | |
| 166 | 172098 | alpha[1] = alpha1[1] * bw * bw; | |
| 167 | 172098 | alpha[2] = alpha0[0] * bw; | |
| 168 | 172098 | alpha[3] = alpha0[1] * bw; | |
| 169 | |||
| 170 |
2/2✓ Branch 0 taken 5513088 times.
✓ Branch 1 taken 172098 times.
|
5685186 | for (i = start; i < end; i++) { |
| 171 | 5513088 | X_high[i][0] = | |
| 172 | 5513088 | X_low[i - 2][0] * alpha[0] - | |
| 173 | 5513088 | X_low[i - 2][1] * alpha[1] + | |
| 174 | 5513088 | X_low[i - 1][0] * alpha[2] - | |
| 175 | 5513088 | X_low[i - 1][1] * alpha[3] + | |
| 176 | 5513088 | X_low[i][0]; | |
| 177 | 5513088 | X_high[i][1] = | |
| 178 | 5513088 | X_low[i - 2][1] * alpha[0] + | |
| 179 | 5513088 | X_low[i - 2][0] * alpha[1] + | |
| 180 | 5513088 | X_low[i - 1][1] * alpha[2] + | |
| 181 | 5513088 | X_low[i - 1][0] * alpha[3] + | |
| 182 | 5513088 | X_low[i][1]; | |
| 183 | } | ||
| 184 | 172098 | } | |
| 185 | |||
| 186 | 212195 | static void sbr_hf_g_filt_c(float (*Y)[2], const float (*X_high)[40][2], | |
| 187 | const float *g_filt, int m_max, intptr_t ixh) | ||
| 188 | { | ||
| 189 | int m; | ||
| 190 | |||
| 191 |
2/2✓ Branch 0 taken 5504544 times.
✓ Branch 1 taken 212195 times.
|
5716739 | for (m = 0; m < m_max; m++) { |
| 192 | 5504544 | Y[m][0] = X_high[m][ixh][0] * g_filt[m]; | |
| 193 | 5504544 | Y[m][1] = X_high[m][ixh][1] * g_filt[m]; | |
| 194 | } | ||
| 195 | 212195 | } | |
| 196 | |||
| 197 | 209994 | static av_always_inline void sbr_hf_apply_noise(float (*Y)[2], | |
| 198 | const float *s_m, | ||
| 199 | const float *q_filt, | ||
| 200 | int noise, | ||
| 201 | float phi_sign0, | ||
| 202 | float phi_sign1, | ||
| 203 | int m_max) | ||
| 204 | { | ||
| 205 | int m; | ||
| 206 | |||
| 207 |
2/2✓ Branch 0 taken 5449888 times.
✓ Branch 1 taken 209994 times.
|
5659882 | for (m = 0; m < m_max; m++) { |
| 208 | 5449888 | float y0 = Y[m][0]; | |
| 209 | 5449888 | float y1 = Y[m][1]; | |
| 210 | 5449888 | noise = (noise + 1) & 0x1ff; | |
| 211 |
2/2✓ Branch 0 taken 37910 times.
✓ Branch 1 taken 5411978 times.
|
5449888 | if (s_m[m]) { |
| 212 | 37910 | y0 += s_m[m] * phi_sign0; | |
| 213 | 37910 | y1 += s_m[m] * phi_sign1; | |
| 214 | } else { | ||
| 215 | 5411978 | y0 += q_filt[m] * ff_sbr_noise_table[noise][0]; | |
| 216 | 5411978 | y1 += q_filt[m] * ff_sbr_noise_table[noise][1]; | |
| 217 | } | ||
| 218 | 5449888 | Y[m][0] = y0; | |
| 219 | 5449888 | Y[m][1] = y1; | |
| 220 | 5449888 | phi_sign1 = -phi_sign1; | |
| 221 | } | ||
| 222 | 209994 | } | |
| 223 | |||
| 224 | #include "sbrdsp_template.c" | ||
| 225 |