summaryrefslogtreecommitdiff
path: root/ffmpeg/libavcodec/lpc.c
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2013-12-29 12:19:38 +0000
committerTim Redfern <tim@eclectronics.org>2013-12-29 12:19:38 +0000
commitf7813a5324be39d13ab536c245d15dfc602a7849 (patch)
treefad99148b88823d34a5df2f0a25881a002eb291b /ffmpeg/libavcodec/lpc.c
parentb7a5a477b8ff4d4e3028b9dfb9a9df0a41463f92 (diff)
basic type mechanism working
Diffstat (limited to 'ffmpeg/libavcodec/lpc.c')
-rw-r--r--ffmpeg/libavcodec/lpc.c54
1 files changed, 30 insertions, 24 deletions
diff --git a/ffmpeg/libavcodec/lpc.c b/ffmpeg/libavcodec/lpc.c
index 4149135..a6f2377 100644
--- a/ffmpeg/libavcodec/lpc.c
+++ b/ffmpeg/libavcodec/lpc.c
@@ -20,7 +20,7 @@
*/
#include "libavutil/common.h"
-#include "libavutil/lls.h"
+#include "libavutil/lls2.h"
#define LPC_USE_DOUBLE
#include "lpc.h"
@@ -177,11 +177,12 @@ int ff_lpc_calc_coefs(LPCContext *s,
double autoc[MAX_LPC_ORDER+1];
double ref[MAX_LPC_ORDER];
double lpc[MAX_LPC_ORDER][MAX_LPC_ORDER];
- int i, j, pass;
+ int i, j, pass = 0;
int opt_order;
av_assert2(max_order >= MIN_LPC_ORDER && max_order <= MAX_LPC_ORDER &&
lpc_type > FF_LPC_TYPE_FIXED);
+ av_assert0(lpc_type == FF_LPC_TYPE_CHOLESKY || lpc_type == FF_LPC_TYPE_LEVINSON);
/* reinit LPC context if parameters have changed */
if (blocksize != s->blocksize || max_order != s->max_order ||
@@ -190,7 +191,10 @@ int ff_lpc_calc_coefs(LPCContext *s,
ff_lpc_init(s, blocksize, max_order, lpc_type);
}
- if (lpc_type == FF_LPC_TYPE_LEVINSON) {
+ if(lpc_passes <= 0)
+ lpc_passes = 2;
+
+ if (lpc_type == FF_LPC_TYPE_LEVINSON || (lpc_type == FF_LPC_TYPE_CHOLESKY && lpc_passes > 1)) {
s->lpc_apply_welch_window(samples, blocksize, s->windowed_samples);
s->lpc_compute_autocorr(s->windowed_samples, blocksize, max_order, autoc);
@@ -199,15 +203,21 @@ int ff_lpc_calc_coefs(LPCContext *s,
for(i=0; i<max_order; i++)
ref[i] = fabs(lpc[i][i]);
- } else if (lpc_type == FF_LPC_TYPE_CHOLESKY) {
- LLSModel m[2];
- double var[MAX_LPC_ORDER+1], av_uninit(weight);
- if(lpc_passes <= 0)
- lpc_passes = 2;
+ pass++;
+ }
+
+ if (lpc_type == FF_LPC_TYPE_CHOLESKY) {
+ LLSModel2 m[2];
+ LOCAL_ALIGNED(32, double, var, [FFALIGN(MAX_LPC_ORDER+1,4)]);
+ double av_uninit(weight);
+ memset(var, 0, FFALIGN(MAX_LPC_ORDER+1,4)*sizeof(*var));
+
+ for(j=0; j<max_order; j++)
+ m[0].coeff[max_order-1][j] = -lpc[max_order-1][j];
- for(pass=0; pass<lpc_passes; pass++){
- avpriv_init_lls(&m[pass&1], max_order);
+ for(; pass<lpc_passes; pass++){
+ avpriv_init_lls2(&m[pass&1], max_order);
weight=0;
for(i=max_order; i<blocksize; i++){
@@ -216,7 +226,7 @@ int ff_lpc_calc_coefs(LPCContext *s,
if(pass){
double eval, inv, rinv;
- eval= avpriv_evaluate_lls(&m[(pass-1)&1], var+1, max_order-1);
+ eval= m[pass&1].evaluate_lls(&m[(pass-1)&1], var+1, max_order-1);
eval= (512>>pass) + fabs(eval - var[0]);
inv = 1/eval;
rinv = sqrt(inv);
@@ -226,9 +236,9 @@ int ff_lpc_calc_coefs(LPCContext *s,
}else
weight++;
- avpriv_update_lls(&m[pass&1], var, 1.0);
+ m[pass&1].update_lls(&m[pass&1], var);
}
- avpriv_solve_lls(&m[pass&1], 0.001, 0);
+ avpriv_solve_lls2(&m[pass&1], 0.001, 0);
}
for(i=0; i<max_order; i++){
@@ -238,8 +248,8 @@ int ff_lpc_calc_coefs(LPCContext *s,
}
for(i=max_order-1; i>0; i--)
ref[i] = ref[i-1] - ref[i];
- } else
- av_assert0(0);
+ }
+
opt_order = max_order;
if(omethod == ORDER_METHOD_EST) {
@@ -262,15 +272,11 @@ av_cold int ff_lpc_init(LPCContext *s, int blocksize, int max_order,
s->max_order = max_order;
s->lpc_type = lpc_type;
- if (lpc_type == FF_LPC_TYPE_LEVINSON) {
- s->windowed_buffer = av_mallocz((blocksize + 2 + FFALIGN(max_order, 4)) *
- sizeof(*s->windowed_samples));
- if (!s->windowed_buffer)
- return AVERROR(ENOMEM);
- s->windowed_samples = s->windowed_buffer + FFALIGN(max_order, 4);
- } else {
- s->windowed_samples = NULL;
- }
+ s->windowed_buffer = av_mallocz((blocksize + 2 + FFALIGN(max_order, 4)) *
+ sizeof(*s->windowed_samples));
+ if (!s->windowed_buffer)
+ return AVERROR(ENOMEM);
+ s->windowed_samples = s->windowed_buffer + FFALIGN(max_order, 4);
s->lpc_apply_welch_window = lpc_apply_welch_window_c;
s->lpc_compute_autocorr = lpc_compute_autocorr_c;