History

floatdsp: move scalarproduct_float from dsputil to avfloatdsp.

This makes the aac decoder and all voice codecs independent of dsputil.

Ronald S. Bultje committed 13 years ago

Commit d56668b1 parent 5959bfa23 files · +142 −141Browse files

Unified · Split

23 files
  1. libavcodec/aac.h +0 −1
  2. libavcodec/aacdec.c +1 −2
  3. libavcodec/acelp_pitch_delay.c +2 −2
  4. libavcodec/acelp_vectors.c +3 −3
  5. libavcodec/amrnbdec.c +10 −10
  6. libavcodec/amrwbdec.c +17 −16
  7. libavcodec/arm/dsputil_init_neon.c +0 −3
  8. libavcodec/arm/dsputil_neon.S +0 −13
  9. libavcodec/dsputil.c +0 −12
  10. libavcodec/dsputil.h +0 −18
  11. libavcodec/qcelpdec.c +8 −9
  12. libavcodec/ra288.c +2 −2
  13. libavcodec/sipr.c +8 −7
  14. libavcodec/sipr16k.c +4 −4
  15. libavcodec/wmavoice.c +9 −7
  16. libavcodec/x86/dsputil.asm +0 −26
  17. libavcodec/x86/dsputil_mmx.c +0 −6
  18. libavutil/arm/float_dsp_init_neon.c +3 −0
  19. libavutil/arm/float_dsp_neon.S +13 −0
  20. libavutil/float_dsp.c +12 −0
  21. libavutil/float_dsp.h +22 −0
  22. libavutil/x86/float_dsp.asm +25 −0
  23. libavutil/x86/float_dsp_init.c +3 −0
libavcodec/aac.h+0−1
@@ -291,7 +291,6 @@ typedef struct AACContext { · 290 unmodified lines
291 FFTContext mdct;291 FFTContext mdct;
292 FFTContext mdct_small;292 FFTContext mdct_small;
293 FFTContext mdct_ltp;293 FFTContext mdct_ltp;
294 DSPContext dsp;
295 FmtConvertContext fmt_conv;294 FmtConvertContext fmt_conv;
296 AVFloatDSPContext fdsp;295 AVFloatDSPContext fdsp;
297 int random_state;296 int random_state;
libavcodec/aacdec.c+1−2
@@ -895,7 +895,6 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) · 894 unmodified lines
895 895
896 ff_aac_sbr_init();896 ff_aac_sbr_init();
897 897
898 ff_dsputil_init(&ac->dsp, avctx);
899 ff_fmt_convert_init(&ac->fmt_conv, avctx);898 ff_fmt_convert_init(&ac->fmt_conv, avctx);
900 avpriv_float_dsp_init(&ac->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);899 avpriv_float_dsp_init(&ac->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);
901 900
@@ -1358,7 +1357,7 @@ static int decode_spectrum_and_dequant(AACContext *ac, float coef[1024], · 456 unmodified lines
1358 cfo[k] = ac->random_state;1357 cfo[k] = ac->random_state;
1359 }1358 }
1360 1359
1361 band_energy = ac->dsp.scalarproduct_float(cfo, cfo, off_len);1360 band_energy = ac->fdsp.scalarproduct_float(cfo, cfo, off_len);
1362 scale = sf[idx] / sqrtf(band_energy);1361 scale = sf[idx] / sqrtf(band_energy);
1363 ac->fdsp.vector_fmul_scalar(cfo, cfo, scale, off_len);1362 ac->fdsp.vector_fmul_scalar(cfo, cfo, scale, off_len);
1364 }1363 }
libavcodec/acelp_pitch_delay.c+2−2
@@ -21,9 +21,9 @@ · 20 unmodified lines
21 */21 */
22 22
23#include "libavutil/common.h"23#include "libavutil/common.h"
24#include "libavutil/float_dsp.h"
24#include "libavutil/mathematics.h"25#include "libavutil/mathematics.h"
25#include "avcodec.h"26#include "avcodec.h"
26#include "dsputil.h"
27#include "acelp_pitch_delay.h"27#include "acelp_pitch_delay.h"
28#include "celp_math.h"28#include "celp_math.h"
29 29
@@ -120,7 +120,7 @@ float ff_amr_set_fixed_gain(float fixed_gain_factor, float fixed_mean_energy, · 90 unmodified lines
120 // Note 10^(0.05 * -10log(average x2)) = 1/sqrt((average x2)).120 // Note 10^(0.05 * -10log(average x2)) = 1/sqrt((average x2)).
121 float val = fixed_gain_factor *121 float val = fixed_gain_factor *
122 exp2f(M_LOG2_10 * 0.05 *122 exp2f(M_LOG2_10 * 0.05 *
123 (ff_scalarproduct_float_c(pred_table, prediction_error, 4) +123 (avpriv_scalarproduct_float_c(pred_table, prediction_error, 4) +
124 energy_mean)) /124 energy_mean)) /
125 sqrtf(fixed_mean_energy);125 sqrtf(fixed_mean_energy);
126 126
libavcodec/acelp_vectors.c+3−3
@@ -23,8 +23,8 @@ · 22 unmodified lines
23#include <inttypes.h>23#include <inttypes.h>
24 24
25#include "libavutil/common.h"25#include "libavutil/common.h"
26#include "libavutil/float_dsp.h"
26#include "avcodec.h"27#include "avcodec.h"
27#include "dsputil.h"
28#include "acelp_vectors.h"28#include "acelp_vectors.h"
29 29
30const uint8_t ff_fc_2pulses_9bits_track1[16] =30const uint8_t ff_fc_2pulses_9bits_track1[16] =
@@ -183,7 +183,7 @@ void ff_adaptive_gain_control(float *out, const float *in, float speech_energ, · 152 unmodified lines
183 int size, float alpha, float *gain_mem)183 int size, float alpha, float *gain_mem)
184{184{
185 int i;185 int i;
186 float postfilter_energ = ff_scalarproduct_float_c(in, in, size);186 float postfilter_energ = avpriv_scalarproduct_float_c(in, in, size);
187 float gain_scale_factor = 1.0;187 float gain_scale_factor = 1.0;
188 float mem = *gain_mem;188 float mem = *gain_mem;
189 189
@@ -204,7 +204,7 @@ void ff_scale_vector_to_given_sum_of_squares(float *out, const float *in, · 14 unmodified lines
204 float sum_of_squares, const int n)204 float sum_of_squares, const int n)
205{205{
206 int i;206 int i;
207 float scalefactor = ff_scalarproduct_float_c(in, in, n);207 float scalefactor = avpriv_scalarproduct_float_c(in, in, n);
208 if (scalefactor)208 if (scalefactor)
209 scalefactor = sqrt(sum_of_squares / scalefactor);209 scalefactor = sqrt(sum_of_squares / scalefactor);
210 for (i = 0; i < n; i++)210 for (i = 0; i < n; i++)
libavcodec/amrnbdec.c+10−10
@@ -44,8 +44,8 @@ · 43 unmodified lines
44#include <math.h>44#include <math.h>
45 45
46#include "libavutil/channel_layout.h"46#include "libavutil/channel_layout.h"
47#include "libavutil/float_dsp.h"
47#include "avcodec.h"48#include "avcodec.h"
48#include "dsputil.h"
49#include "libavutil/common.h"49#include "libavutil/common.h"
50#include "celp_filters.h"50#include "celp_filters.h"
51#include "acelp_filters.h"51#include "acelp_filters.h"
@@ -794,8 +794,8 @@ static int synthesis(AMRContext *p, float *lpc, · 742 unmodified lines
794 794
795 // emphasize pitch vector contribution795 // emphasize pitch vector contribution
796 if (p->pitch_gain[4] > 0.5 && !overflow) {796 if (p->pitch_gain[4] > 0.5 && !overflow) {
797 float energy = ff_scalarproduct_float_c(excitation, excitation,797 float energy = avpriv_scalarproduct_float_c(excitation, excitation,
798 AMR_SUBFRAME_SIZE);798 AMR_SUBFRAME_SIZE);
799 float pitch_factor =799 float pitch_factor =
800 p->pitch_gain[4] *800 p->pitch_gain[4] *
801 (p->cur_frame_mode == MODE_12k2 ?801 (p->cur_frame_mode == MODE_12k2 ?
@@ -871,8 +871,8 @@ static float tilt_factor(float *lpc_n, float *lpc_d) · 69 unmodified lines
871 ff_celp_lp_synthesis_filterf(hf, lpc_d, hf, AMR_TILT_RESPONSE,871 ff_celp_lp_synthesis_filterf(hf, lpc_d, hf, AMR_TILT_RESPONSE,
872 LP_FILTER_ORDER);872 LP_FILTER_ORDER);
873 873
874 rh0 = ff_scalarproduct_float_c(hf, hf, AMR_TILT_RESPONSE);874 rh0 = avpriv_scalarproduct_float_c(hf, hf, AMR_TILT_RESPONSE);
875 rh1 = ff_scalarproduct_float_c(hf, hf + 1, AMR_TILT_RESPONSE - 1);875 rh1 = avpriv_scalarproduct_float_c(hf, hf + 1, AMR_TILT_RESPONSE - 1);
876 876
877 // The spec only specifies this check for 12.2 and 10.2 kbit/s877 // The spec only specifies this check for 12.2 and 10.2 kbit/s
878 // modes. But in the ref source the tilt is always non-negative.878 // modes. But in the ref source the tilt is always non-negative.
@@ -892,8 +892,8 @@ static void postfilter(AMRContext *p, float *lpc, float *buf_out) · 13 unmodified lines
892 int i;892 int i;
893 float *samples = p->samples_in + LP_FILTER_ORDER; // Start of input893 float *samples = p->samples_in + LP_FILTER_ORDER; // Start of input
894 894
895 float speech_gain = ff_scalarproduct_float_c(samples, samples,895 float speech_gain = avpriv_scalarproduct_float_c(samples, samples,
896 AMR_SUBFRAME_SIZE);896 AMR_SUBFRAME_SIZE);
897 897
898 float pole_out[AMR_SUBFRAME_SIZE + LP_FILTER_ORDER]; // Output of pole filter898 float pole_out[AMR_SUBFRAME_SIZE + LP_FILTER_ORDER]; // Output of pole filter
899 const float *gamma_n, *gamma_d; // Formant filter factor table899 const float *gamma_n, *gamma_d; // Formant filter factor table
@@ -998,9 +998,9 @@ static int amrnb_decode_frame(AVCodecContext *avctx, void *data, · 98 unmodified lines
998 998
999 p->fixed_gain[4] =999 p->fixed_gain[4] =
1000 ff_amr_set_fixed_gain(fixed_gain_factor,1000 ff_amr_set_fixed_gain(fixed_gain_factor,
1001 ff_scalarproduct_float_c(p->fixed_vector,1001 avpriv_scalarproduct_float_c(p->fixed_vector,
1002 p->fixed_vector,1002 p->fixed_vector,
1003 AMR_SUBFRAME_SIZE) /1003 AMR_SUBFRAME_SIZE) /
1004 AMR_SUBFRAME_SIZE,1004 AMR_SUBFRAME_SIZE,
1005 p->prediction_error,1005 p->prediction_error,
1006 energy_mean[p->cur_frame_mode], energy_pred_fac);1006 energy_mean[p->cur_frame_mode], energy_pred_fac);
libavcodec/amrwbdec.c+17−16
@@ -26,10 +26,10 @@ · 25 unmodified lines
26 26
27#include "libavutil/channel_layout.h"27#include "libavutil/channel_layout.h"
28#include "libavutil/common.h"28#include "libavutil/common.h"
29#include "libavutil/float_dsp.h"
29#include "libavutil/lfg.h"30#include "libavutil/lfg.h"
30 31
31#include "avcodec.h"32#include "avcodec.h"
32#include "dsputil.h"
33#include "lsp.h"33#include "lsp.h"
34#include "celp_filters.h"34#include "celp_filters.h"
35#include "acelp_filters.h"35#include "acelp_filters.h"
@@ -595,11 +595,11 @@ static void pitch_sharpening(AMRWBContext *ctx, float *fixed_vector) · 559 unmodified lines
595static float voice_factor(float *p_vector, float p_gain,595static float voice_factor(float *p_vector, float p_gain,
596 float *f_vector, float f_gain)596 float *f_vector, float f_gain)
597{597{
598 double p_ener = (double) ff_scalarproduct_float_c(p_vector, p_vector,598 double p_ener = (double) avpriv_scalarproduct_float_c(p_vector, p_vector,
599 AMRWB_SFR_SIZE) *599 AMRWB_SFR_SIZE) *
600 p_gain * p_gain;600 p_gain * p_gain;
601 double f_ener = (double) ff_scalarproduct_float_c(f_vector, f_vector,601 double f_ener = (double) avpriv_scalarproduct_float_c(f_vector, f_vector,
602 AMRWB_SFR_SIZE) *602 AMRWB_SFR_SIZE) *
603 f_gain * f_gain;603 f_gain * f_gain;
604 604
605 return (p_ener - f_ener) / (p_ener + f_ener);605 return (p_ener - f_ener) / (p_ener + f_ener);
@@ -768,8 +768,8 @@ static void synthesis(AMRWBContext *ctx, float *lpc, float *excitation, · 162 unmodified lines
768 /* emphasize pitch vector contribution in low bitrate modes */768 /* emphasize pitch vector contribution in low bitrate modes */
769 if (ctx->pitch_gain[0] > 0.5 && ctx->fr_cur_mode <= MODE_8k85) {769 if (ctx->pitch_gain[0] > 0.5 && ctx->fr_cur_mode <= MODE_8k85) {
770 int i;770 int i;
771 float energy = ff_scalarproduct_float_c(excitation, excitation,771 float energy = avpriv_scalarproduct_float_c(excitation, excitation,
772 AMRWB_SFR_SIZE);772 AMRWB_SFR_SIZE);
773 773
774 // XXX: Weird part in both ref code and spec. A unknown parameter774 // XXX: Weird part in both ref code and spec. A unknown parameter
775 // {beta} seems to be identical to the current pitch gain775 // {beta} seems to be identical to the current pitch gain
@@ -828,9 +828,9 @@ static void upsample_5_4(float *out, const float *in, int o_size) · 52 unmodified lines
828 i++;828 i++;
829 829
830 for (k = 1; k < 5; k++) {830 for (k = 1; k < 5; k++) {
831 out[i] = ff_scalarproduct_float_c(in0 + int_part,831 out[i] = avpriv_scalarproduct_float_c(in0 + int_part,
832 upsample_fir[4 - frac_part],832 upsample_fir[4 - frac_part],
833 UPS_MEM_SIZE);833 UPS_MEM_SIZE);
834 int_part++;834 int_part++;
835 frac_part--;835 frac_part--;
836 i++;836 i++;
@@ -856,8 +856,8 @@ static float find_hb_gain(AMRWBContext *ctx, const float *synth, · 19 unmodified lines
856 if (ctx->fr_cur_mode == MODE_23k85)856 if (ctx->fr_cur_mode == MODE_23k85)
857 return qua_hb_gain[hb_idx] * (1.0f / (1 << 14));857 return qua_hb_gain[hb_idx] * (1.0f / (1 << 14));
858 858
859 tilt = ff_scalarproduct_float_c(synth, synth + 1, AMRWB_SFR_SIZE - 1) /859 tilt = avpriv_scalarproduct_float_c(synth, synth + 1, AMRWB_SFR_SIZE - 1) /
860 ff_scalarproduct_float_c(synth, synth, AMRWB_SFR_SIZE);860 avpriv_scalarproduct_float_c(synth, synth, AMRWB_SFR_SIZE);
861 861
862 /* return gain bounded by [0.1, 1.0] */862 /* return gain bounded by [0.1, 1.0] */
863 return av_clipf((1.0 - FFMAX(0.0, tilt)) * (1.25 - 0.25 * wsp), 0.1, 1.0);863 return av_clipf((1.0 - FFMAX(0.0, tilt)) * (1.25 - 0.25 * wsp), 0.1, 1.0);
@@ -876,7 +876,8 @@ static void scaled_hb_excitation(AMRWBContext *ctx, float *hb_exc, · 12 unmodified lines
876 const float *synth_exc, float hb_gain)876 const float *synth_exc, float hb_gain)
877{877{
878 int i;878 int i;
879 float energy = ff_scalarproduct_float_c(synth_exc, synth_exc, AMRWB_SFR_SIZE);879 float energy = avpriv_scalarproduct_float_c(synth_exc, synth_exc,
880 AMRWB_SFR_SIZE);
880 881
881 /* Generate a white-noise excitation */882 /* Generate a white-noise excitation */
882 for (i = 0; i < AMRWB_SFR_SIZE_16k; i++)883 for (i = 0; i < AMRWB_SFR_SIZE_16k; i++)
@@ -1168,9 +1169,9 @@ static int amrwb_decode_frame(AVCodecContext *avctx, void *data, · 285 unmodified lines
1168 1169
1169 ctx->fixed_gain[0] =1170 ctx->fixed_gain[0] =
1170 ff_amr_set_fixed_gain(fixed_gain_factor,1171 ff_amr_set_fixed_gain(fixed_gain_factor,
1171 ff_scalarproduct_float_c(ctx->fixed_vector,1172 avpriv_scalarproduct_float_c(ctx->fixed_vector,
1172 ctx->fixed_vector,1173 ctx->fixed_vector,
1173 AMRWB_SFR_SIZE) /1174 AMRWB_SFR_SIZE) /
1174 AMRWB_SFR_SIZE,1175 AMRWB_SFR_SIZE,
1175 ctx->prediction_error,1176 ctx->prediction_error,
1176 ENERGY_MEAN, energy_pred_fac);1177 ENERGY_MEAN, energy_pred_fac);
libavcodec/arm/dsputil_init_neon.c+0−3
@@ -142,8 +142,6 @@ void ff_avg_h264_chroma_mc8_neon(uint8_t *, uint8_t *, int, int, int, int); · 141 unmodified lines
142void ff_avg_h264_chroma_mc4_neon(uint8_t *, uint8_t *, int, int, int, int);142void ff_avg_h264_chroma_mc4_neon(uint8_t *, uint8_t *, int, int, int, int);
143void ff_avg_h264_chroma_mc2_neon(uint8_t *, uint8_t *, int, int, int, int);143void ff_avg_h264_chroma_mc2_neon(uint8_t *, uint8_t *, int, int, int, int);
144 144
145float ff_scalarproduct_float_neon(const float *v1, const float *v2, int len);
146
147void ff_vector_clipf_neon(float *dst, const float *src, float min, float max,145void ff_vector_clipf_neon(float *dst, const float *src, float min, float max,
148 int len);146 int len);
149void ff_vector_clip_int32_neon(int32_t *dst, const int32_t *src, int32_t min,147void ff_vector_clip_int32_neon(int32_t *dst, const int32_t *src, int32_t min,
@@ -293,7 +291,6 @@ void ff_dsputil_init_neon(DSPContext *c, AVCodecContext *avctx) · 143 unmodified lines
293 c->avg_h264_qpel_pixels_tab[1][15] = ff_avg_h264_qpel8_mc33_neon;291 c->avg_h264_qpel_pixels_tab[1][15] = ff_avg_h264_qpel8_mc33_neon;
294 }292 }
295 293
296 c->scalarproduct_float = ff_scalarproduct_float_neon;
297 c->vector_clipf = ff_vector_clipf_neon;294 c->vector_clipf = ff_vector_clipf_neon;
298 c->vector_clip_int32 = ff_vector_clip_int32_neon;295 c->vector_clip_int32 = ff_vector_clip_int32_neon;
299 296
libavcodec/arm/dsputil_neon.S+0−13
@@ -531,19 +531,6 @@ function ff_add_pixels_clamped_neon, export=1 · 530 unmodified lines
531 bx lr531 bx lr
532endfunc532endfunc
533 533
534function ff_scalarproduct_float_neon, export=1
535 vmov.f32 q2, #0.0
5361: vld1.32 {q0},[r0,:128]!
537 vld1.32 {q1},[r1,:128]!
538 vmla.f32 q2, q0, q1
539 subs r2, r2, #4
540 bgt 1b
541 vadd.f32 d0, d4, d5
542 vpadd.f32 d0, d0, d0
543NOVFP vmov.32 r0, d0[0]
544 bx lr
545endfunc
546
547function ff_vector_clipf_neon, export=1534function ff_vector_clipf_neon, export=1
548VFP vdup.32 q1, d0[1]535VFP vdup.32 q1, d0[1]
549VFP vdup.32 q0, d0[0]536VFP vdup.32 q0, d0[0]
libavcodec/dsputil.c+0−12
@@ -2353,17 +2353,6 @@ WRAPPER8_16_SQ(quant_psnr8x8_c, quant_psnr16_c) · 2352 unmodified lines
2353WRAPPER8_16_SQ(rd8x8_c, rd16_c)2353WRAPPER8_16_SQ(rd8x8_c, rd16_c)
2354WRAPPER8_16_SQ(bit8x8_c, bit16_c)2354WRAPPER8_16_SQ(bit8x8_c, bit16_c)
2355 2355
2356float ff_scalarproduct_float_c(const float *v1, const float *v2, int len)
2357{
2358 float p = 0.0;
2359 int i;
2360
2361 for (i = 0; i < len; i++)
2362 p += v1[i] * v2[i];
2363
2364 return p;
2365}
2366
2367static inline uint32_t clipf_c_one(uint32_t a, uint32_t mini,2356static inline uint32_t clipf_c_one(uint32_t a, uint32_t mini,
2368 uint32_t maxi, uint32_t maxisign)2357 uint32_t maxi, uint32_t maxisign)
2369{2358{
@@ -2694,7 +2683,6 @@ av_cold void ff_dsputil_init(DSPContext* c, AVCodecContext *avctx) · 324 unmodified lines
2694 c->scalarproduct_and_madd_int16 = scalarproduct_and_madd_int16_c;2683 c->scalarproduct_and_madd_int16 = scalarproduct_and_madd_int16_c;
2695 c->apply_window_int16 = apply_window_int16_c;2684 c->apply_window_int16 = apply_window_int16_c;
2696 c->vector_clip_int32 = vector_clip_int32_c;2685 c->vector_clip_int32 = vector_clip_int32_c;
2697 c->scalarproduct_float = ff_scalarproduct_float_c;
2698 2686
2699 c->shrink[0]= av_image_copy_plane;2687 c->shrink[0]= av_image_copy_plane;
2700 c->shrink[1]= ff_shrink22;2688 c->shrink[1]= ff_shrink22;
libavcodec/dsputil.h+0−18
@@ -342,13 +342,6 @@ typedef struct DSPContext { · 341 unmodified lines
342 342
343 /* assume len is a multiple of 8, and arrays are 16-byte aligned */343 /* assume len is a multiple of 8, and arrays are 16-byte aligned */
344 void (*vector_clipf)(float *dst /* align 16 */, const float *src /* align 16 */, float min, float max, int len /* align 16 */);344 void (*vector_clipf)(float *dst /* align 16 */, const float *src /* align 16 */, float min, float max, int len /* align 16 */);
345 /**
346 * Calculate the scalar product of two vectors of floats.
347 * @param v1 first vector, 16-byte aligned
348 * @param v2 second vector, 16-byte aligned
349 * @param len length of vectors, multiple of 4
350 */
351 float (*scalarproduct_float)(const float *v1, const float *v2, int len);
352 345
353 /* (I)DCT */346 /* (I)DCT */
354 void (*fdct)(DCTELEM *block/* align 16*/);347 void (*fdct)(DCTELEM *block/* align 16*/);
@@ -454,17 +447,6 @@ void ff_dsputil_init(DSPContext* p, AVCodecContext *avctx); · 99 unmodified lines
454 447
455int ff_check_alignment(void);448int ff_check_alignment(void);
456 449
457/**
458 * Return the scalar product of two vectors.
459 *
460 * @param v1 first input vector
461 * @param v2 first input vector
462 * @param len number of elements
463 *
464 * @return sum of elementwise products
465 */
466float ff_scalarproduct_float_c(const float *v1, const float *v2, int len);
467
468/**450/**
469 * permute block according to permuatation.451 * permute block according to permuatation.
470 * @param last last non zero element in scantable order452 * @param last last non zero element in scantable order
libavcodec/qcelpdec.c+8−9
@@ -30,10 +30,10 @@ · 29 unmodified lines
30#include <stddef.h>30#include <stddef.h>
31 31
32#include "libavutil/channel_layout.h"32#include "libavutil/channel_layout.h"
33#include "libavutil/float_dsp.h"
33#include "avcodec.h"34#include "avcodec.h"
34#include "internal.h"35#include "internal.h"
35#include "get_bits.h"36#include "get_bits.h"
36#include "dsputil.h"
37#include "qcelpdata.h"37#include "qcelpdata.h"
38#include "celp_filters.h"38#include "celp_filters.h"
39#include "acelp_filters.h"39#include "acelp_filters.h"
@@ -400,12 +400,10 @@ static void apply_gain_ctrl(float *v_out, const float *v_ref, const float *v_in) · 360 unmodified lines
400{400{
401 int i;401 int i;
402 402
403 for (i = 0; i < 160; i += 40)403 for (i = 0; i < 160; i += 40) {
404 ff_scale_vector_to_given_sum_of_squares(v_out + i, v_in + i,404 float res = avpriv_scalarproduct_float_c(v_ref + i, v_ref + i, 40);
405 ff_scalarproduct_float_c(v_ref + i,405 ff_scale_vector_to_given_sum_of_squares(v_out + i, v_in + i, res, 40);
406 v_ref + i,406 }
407 40),
408 40);
409}407}
410 408
411/**409/**
@@ -680,8 +678,9 @@ static void postfilter(QCELPContext *q, float *samples, float *lpc) · 268 unmodified lines
680 ff_tilt_compensation(&q->postfilter_tilt_mem, 0.3, pole_out + 10, 160);678 ff_tilt_compensation(&q->postfilter_tilt_mem, 0.3, pole_out + 10, 160);
681 679
682 ff_adaptive_gain_control(samples, pole_out + 10,680 ff_adaptive_gain_control(samples, pole_out + 10,
683 ff_scalarproduct_float_c(q->formant_mem + 10,681 avpriv_scalarproduct_float_c(q->formant_mem + 10,
684 q->formant_mem + 10, 160),682 q->formant_mem + 10,
683 160),
685 160, 0.9375, &q->postfilter_agc_mem);684 160, 0.9375, &q->postfilter_agc_mem);
686}685}
687 686
libavcodec/ra288.c+2−2
@@ -79,7 +79,7 @@ static av_cold int ra288_decode_init(AVCodecContext *avctx) · 78 unmodified lines
79static void convolve(float *tgt, const float *src, int len, int n)79static void convolve(float *tgt, const float *src, int len, int n)
80{80{
81 for (; n >= 0; n--)81 for (; n >= 0; n--)
82 tgt[n] = ff_scalarproduct_float_c(src, src - n, len);82 tgt[n] = avpriv_scalarproduct_float_c(src, src - n, len);
83 83
84}84}
85 85
@@ -108,7 +108,7 @@ static void decode(RA288Context *ractx, float gain, int cb_coef) · 22 unmodified lines
108 for (i=0; i < 5; i++)108 for (i=0; i < 5; i++)
109 buffer[i] = codetable[cb_coef][i] * sumsum;109 buffer[i] = codetable[cb_coef][i] * sumsum;
110 110
111 sum = ff_scalarproduct_float_c(buffer, buffer, 5) * ((1 << 24) / 5.);111 sum = avpriv_scalarproduct_float_c(buffer, buffer, 5) * ((1 << 24) / 5.);
112 112
113 sum = FFMAX(sum, 1);113 sum = FFMAX(sum, 1);
114 114
libavcodec/sipr.c+8−7
@@ -26,11 +26,11 @@ · 25 unmodified lines
26#include <string.h>26#include <string.h>
27 27
28#include "libavutil/channel_layout.h"28#include "libavutil/channel_layout.h"
29#include "libavutil/float_dsp.h"
29#include "libavutil/mathematics.h"30#include "libavutil/mathematics.h"
30#include "avcodec.h"31#include "avcodec.h"
31#define BITSTREAM_READER_LE32#define BITSTREAM_READER_LE
32#include "get_bits.h"33#include "get_bits.h"
33#include "dsputil.h"
34#include "internal.h"34#include "internal.h"
35 35
36#include "lsp.h"36#include "lsp.h"
@@ -411,9 +411,10 @@ static void decode_frame(SiprContext *ctx, SiprParameters *params, · 374 unmodified lines
411 convolute_with_sparse(fixed_vector, &fixed_cb, impulse_response,411 convolute_with_sparse(fixed_vector, &fixed_cb, impulse_response,
412 SUBFR_SIZE);412 SUBFR_SIZE);
413 413
414 avg_energy =414 avg_energy = (0.01 + avpriv_scalarproduct_float_c(fixed_vector,
415 (0.01 + ff_scalarproduct_float_c(fixed_vector, fixed_vector, SUBFR_SIZE)) /415 fixed_vector,
416 SUBFR_SIZE;416 SUBFR_SIZE)) /
417 SUBFR_SIZE;
417 418
418 ctx->past_pitch_gain = pitch_gain = gain_cb[params->gc_index[i]][0];419 ctx->past_pitch_gain = pitch_gain = gain_cb[params->gc_index[i]][0];
419 420
@@ -454,9 +455,9 @@ static void decode_frame(SiprContext *ctx, SiprParameters *params, · 34 unmodified lines
454 455
455 if (ctx->mode == MODE_5k0) {456 if (ctx->mode == MODE_5k0) {
456 for (i = 0; i < subframe_count; i++) {457 for (i = 0; i < subframe_count; i++) {
457 float energy = ff_scalarproduct_float_c(ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i * SUBFR_SIZE,458 float energy = avpriv_scalarproduct_float_c(ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i * SUBFR_SIZE,
458 ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i * SUBFR_SIZE,459 ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i * SUBFR_SIZE,
459 SUBFR_SIZE);460 SUBFR_SIZE);
460 ff_adaptive_gain_control(&synth[i * SUBFR_SIZE],461 ff_adaptive_gain_control(&synth[i * SUBFR_SIZE],
461 &synth[i * SUBFR_SIZE], energy,462 &synth[i * SUBFR_SIZE], energy,
462 SUBFR_SIZE, 0.9, &ctx->postfilter_agc);463 SUBFR_SIZE, 0.9, &ctx->postfilter_agc);
libavcodec/sipr16k.c+4−4
@@ -25,8 +25,8 @@ · 24 unmodified lines
25 25
26#include "sipr.h"26#include "sipr.h"
27#include "libavutil/common.h"27#include "libavutil/common.h"
28#include "libavutil/float_dsp.h"
28#include "libavutil/mathematics.h"29#include "libavutil/mathematics.h"
29#include "dsputil.h"
30#include "lsp.h"30#include "lsp.h"
31#include "celp_filters.h"31#include "celp_filters.h"
32#include "acelp_vectors.h"32#include "acelp_vectors.h"
@@ -163,11 +163,11 @@ static float acelp_decode_gain_codef(float gain_corr_factor, const float *fc_v, · 130 unmodified lines
163 const float *ma_prediction_coeff,163 const float *ma_prediction_coeff,
164 int subframe_size, int ma_pred_order)164 int subframe_size, int ma_pred_order)
165{165{
166 mr_energy +=166 mr_energy += avpriv_scalarproduct_float_c(quant_energy, ma_prediction_coeff,
167 ff_scalarproduct_float_c(quant_energy, ma_prediction_coeff, ma_pred_order);167 ma_pred_order);
168 168
169 mr_energy = gain_corr_factor * exp(M_LN10 / 20. * mr_energy) /169 mr_energy = gain_corr_factor * exp(M_LN10 / 20. * mr_energy) /
170 sqrt((0.01 + ff_scalarproduct_float_c(fc_v, fc_v, subframe_size)));170 sqrt((0.01 + avpriv_scalarproduct_float_c(fc_v, fc_v, subframe_size)));
171 return mr_energy;171 return mr_energy;
172}172}
173 173
libavcodec/wmavoice.c+9−7
@@ -30,8 +30,8 @@ · 29 unmodified lines
30#include <math.h>30#include <math.h>
31 31
32#include "libavutil/channel_layout.h"32#include "libavutil/channel_layout.h"
33#include "libavutil/float_dsp.h"
33#include "libavutil/mem.h"34#include "libavutil/mem.h"
34#include "dsputil.h"
35#include "avcodec.h"35#include "avcodec.h"
36#include "internal.h"36#include "internal.h"
37#include "get_bits.h"37#include "get_bits.h"
@@ -523,7 +523,7 @@ static int kalman_smoothen(WMAVoiceContext *s, int pitch, · 485 unmodified lines
523 523
524 /* find best fitting point in history */524 /* find best fitting point in history */
525 do {525 do {
526 dot = ff_scalarproduct_float_c(in, ptr, size);526 dot = avpriv_scalarproduct_float_c(in, ptr, size);
527 if (dot > optimal_gain) {527 if (dot > optimal_gain) {
528 optimal_gain = dot;528 optimal_gain = dot;
529 best_hist_ptr = ptr;529 best_hist_ptr = ptr;
@@ -532,7 +532,7 @@ static int kalman_smoothen(WMAVoiceContext *s, int pitch, · 2 unmodified lines
532 532
533 if (optimal_gain <= 0)533 if (optimal_gain <= 0)
534 return -1;534 return -1;
535 dot = ff_scalarproduct_float_c(best_hist_ptr, best_hist_ptr, size);535 dot = avpriv_scalarproduct_float_c(best_hist_ptr, best_hist_ptr, size);
536 if (dot <= 0) // would be 1.0536 if (dot <= 0) // would be 1.0
537 return -1;537 return -1;
538 538
@@ -562,8 +562,8 @@ static float tilt_factor(const float *lpcs, int n_lpcs) · 23 unmodified lines
562{562{
563 float rh0, rh1;563 float rh0, rh1;
564 564
565 rh0 = 1.0 + ff_scalarproduct_float_c(lpcs, lpcs, n_lpcs);565 rh0 = 1.0 + avpriv_scalarproduct_float_c(lpcs, lpcs, n_lpcs);
566 rh1 = lpcs[0] + ff_scalarproduct_float_c(lpcs, &lpcs[1], n_lpcs - 1);566 rh1 = lpcs[0] + avpriv_scalarproduct_float_c(lpcs, &lpcs[1], n_lpcs - 1);
567 567
568 return rh1 / rh0;568 return rh1 / rh0;
569}569}
@@ -656,7 +656,8 @@ static void calc_input_response(WMAVoiceContext *s, float *lpcs, · 86 unmodified lines
656 -1.8 * tilt_factor(coeffs, remainder - 1),656 -1.8 * tilt_factor(coeffs, remainder - 1),
657 coeffs, remainder);657 coeffs, remainder);
658 }658 }
659 sq = (1.0 / 64.0) * sqrtf(1 / ff_scalarproduct_float_c(coeffs, coeffs, remainder));659 sq = (1.0 / 64.0) * sqrtf(1 / avpriv_scalarproduct_float_c(coeffs, coeffs,
660 remainder));
660 for (n = 0; n < remainder; n++)661 for (n = 0; n < remainder; n++)
661 coeffs[n] *= sq;662 coeffs[n] *= sq;
662}663}
@@ -1320,7 +1321,8 @@ static void synth_block_fcb_acb(WMAVoiceContext *s, GetBitContext *gb, · 657 unmodified lines
1320 /* Calculate gain for adaptive & fixed codebook signal.1321 /* Calculate gain for adaptive & fixed codebook signal.
1321 * see ff_amr_set_fixed_gain(). */1322 * see ff_amr_set_fixed_gain(). */
1322 idx = get_bits(gb, 7);1323 idx = get_bits(gb, 7);
1323 fcb_gain = expf(ff_scalarproduct_float_c(s->gain_pred_err, gain_coeff, 6) -1324 fcb_gain = expf(avpriv_scalarproduct_float_c(s->gain_pred_err,
1325 gain_coeff, 6) -
1324 5.2409161640 + wmavoice_gain_codebook_fcb[idx]);1326 5.2409161640 + wmavoice_gain_codebook_fcb[idx]);
1325 acb_gain = wmavoice_gain_codebook_acb[idx];1327 acb_gain = wmavoice_gain_codebook_acb[idx];
1326 pred_err = av_clipf(wmavoice_gain_codebook_fcb[idx],1328 pred_err = av_clipf(wmavoice_gain_codebook_fcb[idx],
libavcodec/x86/dsputil.asm+0−26
@@ -463,32 +463,6 @@ cglobal add_hfyu_left_prediction, 3,3,7, dst, src, w, left · 462 unmodified lines
463.src_unaligned:463.src_unaligned:
464 ADD_HFYU_LEFT_LOOP 0, 0464 ADD_HFYU_LEFT_LOOP 0, 0
465 465
466
467; float scalarproduct_float_sse(const float *v1, const float *v2, int len)
468INIT_XMM sse
469cglobal scalarproduct_float, 3,3,2, v1, v2, offset
470 neg offsetq
471 shl offsetq, 2
472 sub v1q, offsetq
473 sub v2q, offsetq
474 xorps xmm0, xmm0
475 .loop:
476 movaps xmm1, [v1q+offsetq]
477 mulps xmm1, [v2q+offsetq]
478 addps xmm0, xmm1
479 add offsetq, 16
480 js .loop
481 movhlps xmm1, xmm0
482 addps xmm0, xmm1
483 movss xmm1, xmm0
484 shufps xmm0, xmm0, 1
485 addss xmm0, xmm1
486%if ARCH_X86_64 == 0
487 movss r0m, xmm0
488 fld dword r0m
489%endif
490 RET
491
492;-----------------------------------------------------------------------------466;-----------------------------------------------------------------------------
493; void ff_vector_clip_int32(int32_t *dst, const int32_t *src, int32_t min,467; void ff_vector_clip_int32(int32_t *dst, const int32_t *src, int32_t min,
494; int32_t max, unsigned int len)468; int32_t max, unsigned int len)
libavcodec/x86/dsputil_mmx.c+0−6
@@ -1846,8 +1846,6 @@ int ff_add_hfyu_left_prediction_ssse3(uint8_t *dst, const uint8_t *src, · 1845 unmodified lines
1846int ff_add_hfyu_left_prediction_sse4(uint8_t *dst, const uint8_t *src,1846int ff_add_hfyu_left_prediction_sse4(uint8_t *dst, const uint8_t *src,
1847 int w, int left);1847 int w, int left);
1848 1848
1849float ff_scalarproduct_float_sse(const float *v1, const float *v2, int order);
1850
1851void ff_vector_clip_int32_mmx (int32_t *dst, const int32_t *src,1849void ff_vector_clip_int32_mmx (int32_t *dst, const int32_t *src,
1852 int32_t min, int32_t max, unsigned int len);1850 int32_t min, int32_t max, unsigned int len);
1853void ff_vector_clip_int32_sse2 (int32_t *dst, const int32_t *src,1851void ff_vector_clip_int32_sse2 (int32_t *dst, const int32_t *src,
@@ -2128,10 +2126,6 @@ static void dsputil_init_sse(DSPContext *c, AVCodecContext *avctx, int mm_flags) · 274 unmodified lines
2128 2126
2129 c->vector_clipf = vector_clipf_sse;2127 c->vector_clipf = vector_clipf_sse;
2130#endif /* HAVE_INLINE_ASM */2128#endif /* HAVE_INLINE_ASM */
2131
2132#if HAVE_YASM
2133 c->scalarproduct_float = ff_scalarproduct_float_sse;
2134#endif /* HAVE_YASM */
2135}2129}
2136 2130
2137static void dsputil_init_sse2(DSPContext *c, AVCodecContext *avctx,2131static void dsputil_init_sse2(DSPContext *c, AVCodecContext *avctx,
libavutil/arm/float_dsp_init_neon.c+3−0
@@ -43,6 +43,8 @@ void ff_vector_fmul_reverse_neon(float *dst, const float *src0, · 42 unmodified lines
43 43
44void ff_butterflies_float_neon(float *v1, float *v2, int len);44void ff_butterflies_float_neon(float *v1, float *v2, int len);
45 45
46float ff_scalarproduct_float_neon(const float *v1, const float *v2, int len);
47
46void ff_float_dsp_init_neon(AVFloatDSPContext *fdsp)48void ff_float_dsp_init_neon(AVFloatDSPContext *fdsp)
47{49{
48 fdsp->vector_fmul = ff_vector_fmul_neon;50 fdsp->vector_fmul = ff_vector_fmul_neon;
@@ -52,4 +54,5 @@ void ff_float_dsp_init_neon(AVFloatDSPContext *fdsp) · 3 unmodified lines
52 fdsp->vector_fmul_add = ff_vector_fmul_add_neon;54 fdsp->vector_fmul_add = ff_vector_fmul_add_neon;
53 fdsp->vector_fmul_reverse = ff_vector_fmul_reverse_neon;55 fdsp->vector_fmul_reverse = ff_vector_fmul_reverse_neon;
54 fdsp->butterflies_float = ff_butterflies_float_neon;56 fdsp->butterflies_float = ff_butterflies_float_neon;
57 fdsp->scalarproduct_float = ff_scalarproduct_float_neon;
55}58}
libavutil/arm/float_dsp_neon.S+13−0
@@ -256,3 +256,16 @@ function ff_butterflies_float_neon, export=1 · 255 unmodified lines
256 bgt 1b256 bgt 1b
257 bx lr257 bx lr
258endfunc258endfunc
259
260function ff_scalarproduct_float_neon, export=1
261 vmov.f32 q2, #0.0
2621: vld1.32 {q0},[r0,:128]!
263 vld1.32 {q1},[r1,:128]!
264 vmla.f32 q2, q0, q1
265 subs r2, r2, #4
266 bgt 1b
267 vadd.f32 d0, d4, d5
268 vpadd.f32 d0, d0, d0
269NOVFP vmov.32 r0, d0[0]
270 bx lr
271endfunc
libavutil/float_dsp.c+12−0
@@ -101,6 +101,17 @@ static void butterflies_float_c(float *restrict v1, float *restrict v2, · 100 unmodified lines
101 }101 }
102}102}
103 103
104float avpriv_scalarproduct_float_c(const float *v1, const float *v2, int len)
105{
106 float p = 0.0;
107 int i;
108
109 for (i = 0; i < len; i++)
110 p += v1[i] * v2[i];
111
112 return p;
113}
114
104void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact)115void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact)
105{116{
106 fdsp->vector_fmul = vector_fmul_c;117 fdsp->vector_fmul = vector_fmul_c;
@@ -111,6 +122,7 @@ void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact) · 4 unmodified lines
111 fdsp->vector_fmul_add = vector_fmul_add_c;122 fdsp->vector_fmul_add = vector_fmul_add_c;
112 fdsp->vector_fmul_reverse = vector_fmul_reverse_c;123 fdsp->vector_fmul_reverse = vector_fmul_reverse_c;
113 fdsp->butterflies_float = butterflies_float_c;124 fdsp->butterflies_float = butterflies_float_c;
125 fdsp->scalarproduct_float = avpriv_scalarproduct_float_c;
114 126
115#if ARCH_ARM127#if ARCH_ARM
116 ff_float_dsp_init_arm(fdsp);128 ff_float_dsp_init_arm(fdsp);
libavutil/float_dsp.h+22−0
@@ -146,8 +146,30 @@ typedef struct AVFloatDSPContext { · 145 unmodified lines
146 * @param len length of vectors, multiple of 4146 * @param len length of vectors, multiple of 4
147 */147 */
148 void (*butterflies_float)(float *restrict v1, float *restrict v2, int len);148 void (*butterflies_float)(float *restrict v1, float *restrict v2, int len);
149
150 /**
151 * Calculate the scalar product of two vectors of floats.
152 *
153 * @param v1 first vector, 16-byte aligned
154 * @param v2 second vector, 16-byte aligned
155 * @param len length of vectors, multiple of 4
156 *
157 * @return sum of elementwise products
158 */
159 float (*scalarproduct_float)(const float *v1, const float *v2, int len);
149} AVFloatDSPContext;160} AVFloatDSPContext;
150 161
162/**
163 * Return the scalar product of two vectors.
164 *
165 * @param v1 first input vector
166 * @param v2 first input vector
167 * @param len number of elements
168 *
169 * @return sum of elementwise products
170 */
171float avpriv_scalarproduct_float_c(const float *v1, const float *v2, int len);
172
151/**173/**
152 * Initialize a float DSP context.174 * Initialize a float DSP context.
153 *175 *
libavutil/x86/float_dsp.asm+25−0
@@ -227,3 +227,28 @@ INIT_XMM sse · 226 unmodified lines
227VECTOR_FMUL_REVERSE227VECTOR_FMUL_REVERSE
228INIT_YMM avx228INIT_YMM avx
229VECTOR_FMUL_REVERSE229VECTOR_FMUL_REVERSE
230
231; float scalarproduct_float_sse(const float *v1, const float *v2, int len)
232INIT_XMM sse
233cglobal scalarproduct_float, 3,3,2, v1, v2, offset
234 neg offsetq
235 shl offsetq, 2
236 sub v1q, offsetq
237 sub v2q, offsetq
238 xorps xmm0, xmm0
239.loop:
240 movaps xmm1, [v1q+offsetq]
241 mulps xmm1, [v2q+offsetq]
242 addps xmm0, xmm1
243 add offsetq, 16
244 js .loop
245 movhlps xmm1, xmm0
246 addps xmm0, xmm1
247 movss xmm1, xmm0
248 shufps xmm0, xmm0, 1
249 addss xmm0, xmm1
250%if ARCH_X86_64 == 0
251 movss r0m, xmm0
252 fld dword r0m
253%endif
254 RET
libavutil/x86/float_dsp_init.c+3−0
@@ -51,6 +51,8 @@ void ff_vector_fmul_reverse_sse(float *dst, const float *src0, · 50 unmodified lines
51void ff_vector_fmul_reverse_avx(float *dst, const float *src0,51void ff_vector_fmul_reverse_avx(float *dst, const float *src0,
52 const float *src1, int len);52 const float *src1, int len);
53 53
54float ff_scalarproduct_float_sse(const float *v1, const float *v2, int order);
55
54#if HAVE_6REGS && HAVE_INLINE_ASM56#if HAVE_6REGS && HAVE_INLINE_ASM
55static void vector_fmul_window_3dnowext(float *dst, const float *src0,57static void vector_fmul_window_3dnowext(float *dst, const float *src0,
56 const float *src1, const float *win,58 const float *src1, const float *win,
@@ -135,6 +137,7 @@ void ff_float_dsp_init_x86(AVFloatDSPContext *fdsp) · 78 unmodified lines
135 fdsp->vector_fmul_scalar = ff_vector_fmul_scalar_sse;137 fdsp->vector_fmul_scalar = ff_vector_fmul_scalar_sse;
136 fdsp->vector_fmul_add = ff_vector_fmul_add_sse;138 fdsp->vector_fmul_add = ff_vector_fmul_add_sse;
137 fdsp->vector_fmul_reverse = ff_vector_fmul_reverse_sse;139 fdsp->vector_fmul_reverse = ff_vector_fmul_reverse_sse;
140 fdsp->scalarproduct_float = ff_scalarproduct_float_sse;
138 }141 }
139 if (EXTERNAL_SSE2(mm_flags)) {142 if (EXTERNAL_SSE2(mm_flags)) {
140 fdsp->vector_dmul_scalar = ff_vector_dmul_scalar_sse2;143 fdsp->vector_dmul_scalar = ff_vector_dmul_scalar_sse2;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t