Signed-off-by: Mans Rullgard <mans@mansr.com>
(cherry picked from commit 56f8952b252f85281317ecd3e0b04c4cae93fd72)
... | ... |
@@ -51,11 +51,11 @@ typedef struct RiceContext { |
51 | 51 |
int rice_modifier; |
52 | 52 |
} RiceContext; |
53 | 53 |
|
54 |
-typedef struct LPCContext { |
|
54 |
+typedef struct AlacLPCContext { |
|
55 | 55 |
int lpc_order; |
56 | 56 |
int lpc_coeff[ALAC_MAX_LPC_ORDER+1]; |
57 | 57 |
int lpc_quant; |
58 |
-} LPCContext; |
|
58 |
+} AlacLPCContext; |
|
59 | 59 |
|
60 | 60 |
typedef struct AlacEncodeContext { |
61 | 61 |
int compression_level; |
... | ... |
@@ -69,8 +69,8 @@ typedef struct AlacEncodeContext { |
69 | 69 |
int interlacing_leftweight; |
70 | 70 |
PutBitContext pbctx; |
71 | 71 |
RiceContext rc; |
72 |
- LPCContext lpc[MAX_CHANNELS]; |
|
73 |
- DSPContext dspctx; |
|
72 |
+ AlacLPCContext lpc[MAX_CHANNELS]; |
|
73 |
+ LPCContext lpc_ctx; |
|
74 | 74 |
AVCodecContext *avctx; |
75 | 75 |
} AlacEncodeContext; |
76 | 76 |
|
... | ... |
@@ -141,7 +141,7 @@ static void calc_predictor_params(AlacEncodeContext *s, int ch) |
141 | 141 |
s->lpc[ch].lpc_coeff[4] = 80; |
142 | 142 |
s->lpc[ch].lpc_coeff[5] = -25; |
143 | 143 |
} else { |
144 |
- opt_order = ff_lpc_calc_coefs(&s->dspctx, s->sample_buf[ch], |
|
144 |
+ opt_order = ff_lpc_calc_coefs(&s->lpc_ctx, s->sample_buf[ch], |
|
145 | 145 |
s->avctx->frame_size, |
146 | 146 |
s->min_prediction_order, |
147 | 147 |
s->max_prediction_order, |
... | ... |
@@ -237,7 +237,7 @@ static void alac_stereo_decorrelation(AlacEncodeContext *s) |
237 | 237 |
static void alac_linear_predictor(AlacEncodeContext *s, int ch) |
238 | 238 |
{ |
239 | 239 |
int i; |
240 |
- LPCContext lpc = s->lpc[ch]; |
|
240 |
+ AlacLPCContext lpc = s->lpc[ch]; |
|
241 | 241 |
|
242 | 242 |
if(lpc.lpc_order == 31) { |
243 | 243 |
s->predictor_buf[0] = s->sample_buf[ch][0]; |
... | ... |
@@ -455,7 +455,7 @@ static av_cold int alac_encode_init(AVCodecContext *avctx) |
455 | 455 |
avctx->coded_frame->key_frame = 1; |
456 | 456 |
|
457 | 457 |
s->avctx = avctx; |
458 |
- dsputil_init(&s->dspctx, avctx); |
|
458 |
+ ff_lpc_init(&s->lpc_ctx); |
|
459 | 459 |
|
460 | 460 |
return 0; |
461 | 461 |
} |
... | ... |
@@ -33,16 +33,16 @@ |
33 | 33 |
#define Y_DC_SCALE 0xab4 |
34 | 34 |
#define C_DC_SCALE 0xab8 |
35 | 35 |
#define AC_PRED 0xae0 |
36 |
-#define BLOCK_LAST_INDEX 0x21c0 |
|
37 |
-#define INTER_SCANTAB_RASTER_END 0x23c0 |
|
38 |
-#define H263_AIC 0x2670 |
|
36 |
+#define BLOCK_LAST_INDEX 0x21bc |
|
37 |
+#define INTER_SCANTAB_RASTER_END 0x23bc |
|
38 |
+#define H263_AIC 0x2668 |
|
39 | 39 |
#elif defined(__APPLE__) |
40 | 40 |
#define Y_DC_SCALE 0xa70 |
41 | 41 |
#define C_DC_SCALE 0xa74 |
42 | 42 |
#define AC_PRED 0xa9c |
43 |
-#define BLOCK_LAST_INDEX 0x217c |
|
44 |
-#define INTER_SCANTAB_RASTER_END 0x237c |
|
45 |
-#define H263_AIC 0x2620 |
|
43 |
+#define BLOCK_LAST_INDEX 0x2178 |
|
44 |
+#define INTER_SCANTAB_RASTER_END 0x2378 |
|
45 |
+#define H263_AIC 0x261c |
|
46 | 46 |
#endif |
47 | 47 |
|
48 | 48 |
#endif |
... | ... |
@@ -36,7 +36,6 @@ |
36 | 36 |
#include "mathops.h" |
37 | 37 |
#include "mpegvideo.h" |
38 | 38 |
#include "config.h" |
39 |
-#include "lpc.h" |
|
40 | 39 |
#include "ac3dec.h" |
41 | 40 |
#include "vorbis.h" |
42 | 41 |
#include "png.h" |
... | ... |
@@ -4431,9 +4430,6 @@ av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx) |
4431 | 4431 |
#if CONFIG_AC3_DECODER |
4432 | 4432 |
c->ac3_downmix = ff_ac3_downmix_c; |
4433 | 4433 |
#endif |
4434 |
-#if CONFIG_LPC |
|
4435 |
- c->lpc_compute_autocorr = ff_lpc_compute_autocorr; |
|
4436 |
-#endif |
|
4437 | 4434 |
c->vector_fmul = vector_fmul_c; |
4438 | 4435 |
c->vector_fmul_reverse = vector_fmul_reverse_c; |
4439 | 4436 |
c->vector_fmul_add = vector_fmul_add_c; |
... | ... |
@@ -374,8 +374,6 @@ typedef struct DSPContext { |
374 | 374 |
/* assume len is a multiple of 4, and arrays are 16-byte aligned */ |
375 | 375 |
void (*vorbis_inverse_coupling)(float *mag, float *ang, int blocksize); |
376 | 376 |
void (*ac3_downmix)(float (*samples)[256], float (*matrix)[2], int out_ch, int in_ch, int len); |
377 |
- /* no alignment needed */ |
|
378 |
- void (*lpc_compute_autocorr)(const int32_t *data, int len, int lag, double *autoc); |
|
379 | 377 |
/* assume len is a multiple of 8, and arrays are 16-byte aligned */ |
380 | 378 |
void (*vector_fmul)(float *dst, const float *src, int len); |
381 | 379 |
void (*vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len); |
... | ... |
@@ -23,7 +23,6 @@ |
23 | 23 |
#include "libavutil/md5.h" |
24 | 24 |
#include "avcodec.h" |
25 | 25 |
#include "get_bits.h" |
26 |
-#include "dsputil.h" |
|
27 | 26 |
#include "golomb.h" |
28 | 27 |
#include "lpc.h" |
29 | 28 |
#include "flac.h" |
... | ... |
@@ -95,7 +94,7 @@ typedef struct FlacEncodeContext { |
95 | 95 |
FlacFrame frame; |
96 | 96 |
CompressionOptions options; |
97 | 97 |
AVCodecContext *avctx; |
98 |
- DSPContext dsp; |
|
98 |
+ LPCContext lpc_ctx; |
|
99 | 99 |
struct AVMD5 *md5ctx; |
100 | 100 |
} FlacEncodeContext; |
101 | 101 |
|
... | ... |
@@ -217,7 +216,7 @@ static av_cold int flac_encode_init(AVCodecContext *avctx) |
217 | 217 |
|
218 | 218 |
s->avctx = avctx; |
219 | 219 |
|
220 |
- dsputil_init(&s->dsp, avctx); |
|
220 |
+ ff_lpc_init(&s->lpc_ctx); |
|
221 | 221 |
|
222 | 222 |
if (avctx->sample_fmt != AV_SAMPLE_FMT_S16) |
223 | 223 |
return -1; |
... | ... |
@@ -902,7 +901,7 @@ static int encode_residual_ch(FlacEncodeContext *s, int ch) |
902 | 902 |
|
903 | 903 |
/* LPC */ |
904 | 904 |
sub->type = FLAC_SUBFRAME_LPC; |
905 |
- opt_order = ff_lpc_calc_coefs(&s->dsp, smp, n, min_order, max_order, |
|
905 |
+ opt_order = ff_lpc_calc_coefs(&s->lpc_ctx, smp, n, min_order, max_order, |
|
906 | 906 |
s->options.lpc_coeff_precision, coefs, shift, s->options.lpc_type, |
907 | 907 |
s->options.lpc_passes, omethod, |
908 | 908 |
MAX_LPC_SHIFT, 0); |
... | ... |
@@ -20,7 +20,6 @@ |
20 | 20 |
*/ |
21 | 21 |
|
22 | 22 |
#include "libavutil/lls.h" |
23 |
-#include "dsputil.h" |
|
24 | 23 |
|
25 | 24 |
#define LPC_USE_DOUBLE |
26 | 25 |
#include "lpc.h" |
... | ... |
@@ -55,7 +54,7 @@ static void apply_welch_window(const int32_t *data, int len, double *w_data) |
55 | 55 |
* Calculate autocorrelation data from audio samples |
56 | 56 |
* A Welch window function is applied before calculation. |
57 | 57 |
*/ |
58 |
-void ff_lpc_compute_autocorr(const int32_t *data, int len, int lag, |
|
58 |
+static void lpc_compute_autocorr_c(const int32_t *data, int len, int lag, |
|
59 | 59 |
double *autoc) |
60 | 60 |
{ |
61 | 61 |
int i, j; |
... | ... |
@@ -162,7 +161,7 @@ static int estimate_best_order(double *ref, int min_order, int max_order) |
162 | 162 |
* 1 = LPC with coeffs determined by Levinson-Durbin recursion |
163 | 163 |
* 2+ = LPC with coeffs determined by Cholesky factorization using (use_lpc-1) passes. |
164 | 164 |
*/ |
165 |
-int ff_lpc_calc_coefs(DSPContext *s, |
|
165 |
+int ff_lpc_calc_coefs(LPCContext *s, |
|
166 | 166 |
const int32_t *samples, int blocksize, int min_order, |
167 | 167 |
int max_order, int precision, |
168 | 168 |
int32_t coefs[][MAX_LPC_ORDER], int *shift, |
... | ... |
@@ -236,3 +235,11 @@ int ff_lpc_calc_coefs(DSPContext *s, |
236 | 236 |
|
237 | 237 |
return opt_order; |
238 | 238 |
} |
239 |
+ |
|
240 |
+av_cold void ff_lpc_init(LPCContext *s) |
|
241 |
+{ |
|
242 |
+ s->lpc_compute_autocorr = lpc_compute_autocorr_c; |
|
243 |
+ |
|
244 |
+ if (HAVE_MMX) |
|
245 |
+ ff_lpc_init_x86(s); |
|
246 |
+} |
... | ... |
@@ -36,18 +36,36 @@ |
36 | 36 |
#define MAX_LPC_ORDER 32 |
37 | 37 |
|
38 | 38 |
|
39 |
+typedef struct LPCContext { |
|
40 |
+ /** |
|
41 |
+ * Perform autocorrelation on input samples with delay of 0 to lag. |
|
42 |
+ * @param data input samples. |
|
43 |
+ * no alignment needed. |
|
44 |
+ * @param len number of input samples to process |
|
45 |
+ * @param lag maximum delay to calculate |
|
46 |
+ * @param autoc output autocorrelation coefficients. |
|
47 |
+ * constraints: array size must be at least lag+1. |
|
48 |
+ */ |
|
49 |
+ void (*lpc_compute_autocorr)(const int32_t *data, int len, int lag, |
|
50 |
+ double *autoc); |
|
51 |
+} LPCContext; |
|
52 |
+ |
|
53 |
+ |
|
39 | 54 |
/** |
40 | 55 |
* Calculate LPC coefficients for multiple orders |
41 | 56 |
*/ |
42 |
-int ff_lpc_calc_coefs(DSPContext *s, |
|
57 |
+int ff_lpc_calc_coefs(LPCContext *s, |
|
43 | 58 |
const int32_t *samples, int blocksize, int min_order, |
44 | 59 |
int max_order, int precision, |
45 | 60 |
int32_t coefs[][MAX_LPC_ORDER], int *shift, |
46 | 61 |
enum AVLPCType lpc_type, int lpc_passes, |
47 | 62 |
int omethod, int max_shift, int zero_shift); |
48 | 63 |
|
49 |
-void ff_lpc_compute_autocorr(const int32_t *data, int len, int lag, |
|
50 |
- double *autoc); |
|
64 |
+/** |
|
65 |
+ * Initialize LPCContext. |
|
66 |
+ */ |
|
67 |
+void ff_lpc_init(LPCContext *s); |
|
68 |
+void ff_lpc_init_x86(LPCContext *s); |
|
51 | 69 |
|
52 | 70 |
#ifdef LPC_USE_DOUBLE |
53 | 71 |
#define LPC_TYPE double |
... | ... |
@@ -23,7 +23,7 @@ |
23 | 23 |
#define AVCODEC_RA144_H |
24 | 24 |
|
25 | 25 |
#include <stdint.h> |
26 |
-#include "dsputil.h" |
|
26 |
+#include "lpc.h" |
|
27 | 27 |
|
28 | 28 |
#define NBLOCKS 4 ///< number of subblocks within a block |
29 | 29 |
#define BLOCKSIZE 40 ///< subblock size in 16-bit words |
... | ... |
@@ -34,7 +34,7 @@ |
34 | 34 |
|
35 | 35 |
typedef struct { |
36 | 36 |
AVCodecContext *avctx; |
37 |
- DSPContext dsp; |
|
37 |
+ LPCContext lpc_ctx; |
|
38 | 38 |
|
39 | 39 |
unsigned int old_energy; ///< previous frame energy |
40 | 40 |
|
... | ... |
@@ -29,7 +29,6 @@ |
29 | 29 |
|
30 | 30 |
#include "avcodec.h" |
31 | 31 |
#include "put_bits.h" |
32 |
-#include "lpc.h" |
|
33 | 32 |
#include "celp_filters.h" |
34 | 33 |
#include "ra144.h" |
35 | 34 |
|
... | ... |
@@ -53,7 +52,7 @@ static av_cold int ra144_encode_init(AVCodecContext * avctx) |
53 | 53 |
ractx->lpc_coef[0] = ractx->lpc_tables[0]; |
54 | 54 |
ractx->lpc_coef[1] = ractx->lpc_tables[1]; |
55 | 55 |
ractx->avctx = avctx; |
56 |
- dsputil_init(&ractx->dsp, avctx); |
|
56 |
+ ff_lpc_init(&ractx->lpc_ctx); |
|
57 | 57 |
return 0; |
58 | 58 |
} |
59 | 59 |
|
... | ... |
@@ -451,7 +450,7 @@ static int ra144_encode_frame(AVCodecContext *avctx, uint8_t *frame, |
451 | 451 |
energy = ff_energy_tab[quantize(ff_t_sqrt(energy >> 5) >> 10, ff_energy_tab, |
452 | 452 |
32)]; |
453 | 453 |
|
454 |
- ff_lpc_calc_coefs(&ractx->dsp, lpc_data, NBLOCKS * BLOCKSIZE, LPC_ORDER, |
|
454 |
+ ff_lpc_calc_coefs(&ractx->lpc_ctx, lpc_data, NBLOCKS * BLOCKSIZE, LPC_ORDER, |
|
455 | 455 |
LPC_ORDER, 16, lpc_coefs, shift, AV_LPC_TYPE_LEVINSON, |
456 | 456 |
0, ORDER_METHOD_EST, 12, 0); |
457 | 457 |
for (i = 0; i < LPC_ORDER; i++) |
... | ... |
@@ -200,9 +200,6 @@ void ff_vc1dsp_init_mmx(DSPContext* dsp, AVCodecContext *avctx); |
200 | 200 |
void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd); |
201 | 201 |
void ff_avg_vc1_mspel_mc00_mmx2(uint8_t *dst, const uint8_t *src, int stride, int rnd); |
202 | 202 |
|
203 |
-void ff_lpc_compute_autocorr_sse2(const int32_t *data, int len, int lag, |
|
204 |
- double *autoc); |
|
205 |
- |
|
206 | 203 |
void ff_mmx_idct(DCTELEM *block); |
207 | 204 |
void ff_mmxext_idct(DCTELEM *block); |
208 | 205 |
|
... | ... |
@@ -1166,10 +1166,6 @@ void dsputilenc_init_mmx(DSPContext* c, AVCodecContext *avctx) |
1166 | 1166 |
#endif |
1167 | 1167 |
} |
1168 | 1168 |
|
1169 |
- if (CONFIG_LPC && mm_flags & (AV_CPU_FLAG_SSE2|AV_CPU_FLAG_SSE2SLOW)) { |
|
1170 |
- c->lpc_compute_autocorr = ff_lpc_compute_autocorr_sse2; |
|
1171 |
- } |
|
1172 |
- |
|
1173 | 1169 |
#if HAVE_SSSE3 |
1174 | 1170 |
if(mm_flags & AV_CPU_FLAG_SSSE3){ |
1175 | 1171 |
if(!(avctx->flags & CODEC_FLAG_BITEXACT)){ |
... | ... |
@@ -20,7 +20,8 @@ |
20 | 20 |
*/ |
21 | 21 |
|
22 | 22 |
#include "libavutil/x86_cpu.h" |
23 |
-#include "dsputil_mmx.h" |
|
23 |
+#include "libavutil/cpu.h" |
|
24 |
+#include "libavcodec/lpc.h" |
|
24 | 25 |
|
25 | 26 |
static void apply_welch_window_sse2(const int32_t *data, int len, double *w_data) |
26 | 27 |
{ |
... | ... |
@@ -68,7 +69,7 @@ static void apply_welch_window_sse2(const int32_t *data, int len, double *w_data |
68 | 68 |
#undef WELCH |
69 | 69 |
} |
70 | 70 |
|
71 |
-void ff_lpc_compute_autocorr_sse2(const int32_t *data, int len, int lag, |
|
71 |
+static void lpc_compute_autocorr_sse2(const int32_t *data, int len, int lag, |
|
72 | 72 |
double *autoc) |
73 | 73 |
{ |
74 | 74 |
double tmp[len + lag + 2]; |
... | ... |
@@ -141,3 +142,12 @@ void ff_lpc_compute_autocorr_sse2(const int32_t *data, int len, int lag, |
141 | 141 |
} |
142 | 142 |
} |
143 | 143 |
} |
144 |
+ |
|
145 |
+av_cold void ff_lpc_init_x86(LPCContext *c) |
|
146 |
+{ |
|
147 |
+ int mm_flags = av_get_cpu_flags(); |
|
148 |
+ |
|
149 |
+ if (mm_flags & (AV_CPU_FLAG_SSE2|AV_CPU_FLAG_SSE2SLOW)) { |
|
150 |
+ c->lpc_compute_autocorr = lpc_compute_autocorr_sse2; |
|
151 |
+ } |
|
152 |
+} |