Mercurial > libavcodec.hg
annotate lpc.h @ 12260:65619c2230e7 libavcodec
aacdec: Only load and write each predictor variable one.
This is slightly faster and opens the door for further optimization.
author | alexc |
---|---|
date | Sat, 24 Jul 2010 02:57:08 +0000 |
parents | e59926e2c50c |
children |
rev | line source |
---|---|
3353
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
diff
changeset
|
1 /** |
7589
8b695a99e8df
flacenc, lpc: Move LPC code from flacenc.c to new lpc.[ch] files.
ramiro
parents:
7588
diff
changeset
|
2 * LPC utility code |
7594
cd6217c9ce92
update my email address to one which does not depend on my service provider
jbr
parents:
7592
diff
changeset
|
3 * Copyright (c) 2006 Justin Ruggles <justin.ruggles@gmail.com> |
3353
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
diff
changeset
|
4 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3481
diff
changeset
|
5 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3481
diff
changeset
|
6 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3481
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
3353
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3481
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
3353
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
diff
changeset
|
11 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3481
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
3353
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
diff
changeset
|
16 * |
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3481
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
3353
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
diff
changeset
|
20 */ |
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
diff
changeset
|
21 |
7760 | 22 #ifndef AVCODEC_LPC_H |
23 #define AVCODEC_LPC_H | |
3353
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
diff
changeset
|
24 |
7602
a8a999207b1a
Add missing header includes to fix 'make checkheaders'.
diego
parents:
7594
diff
changeset
|
25 #include <stdint.h> |
a8a999207b1a
Add missing header includes to fix 'make checkheaders'.
diego
parents:
7594
diff
changeset
|
26 #include "dsputil.h" |
3353
5b901881d6ed
first rudimentary version of (Justin Ruggles jruggle earthlink net) flac encoder
michael
parents:
diff
changeset
|
27 |
3385
340e5d35b326
flac-lpc patch by (Justin Ruggles jruggle earthlink net)
michael
parents:
3384
diff
changeset
|
28 #define ORDER_METHOD_EST 0 |
340e5d35b326
flac-lpc patch by (Justin Ruggles jruggle earthlink net)
michael
parents:
3384
diff
changeset
|
29 #define ORDER_METHOD_2LEVEL 1 |
340e5d35b326
flac-lpc patch by (Justin Ruggles jruggle earthlink net)
michael
parents:
3384
diff
changeset
|
30 #define ORDER_METHOD_4LEVEL 2 |
340e5d35b326
flac-lpc patch by (Justin Ruggles jruggle earthlink net)
michael
parents:
3384
diff
changeset
|
31 #define ORDER_METHOD_8LEVEL 3 |
340e5d35b326
flac-lpc patch by (Justin Ruggles jruggle earthlink net)
michael
parents:
3384
diff
changeset
|
32 #define ORDER_METHOD_SEARCH 4 |
3478 | 33 #define ORDER_METHOD_LOG 5 |
3385
340e5d35b326
flac-lpc patch by (Justin Ruggles jruggle earthlink net)
michael
parents:
3384
diff
changeset
|
34 |
7590
d6126c8b57e9
lpc: cosmetics: vertically align declarations and definitions.
ramiro
parents:
7589
diff
changeset
|
35 #define MIN_LPC_ORDER 1 |
d6126c8b57e9
lpc: cosmetics: vertically align declarations and definitions.
ramiro
parents:
7589
diff
changeset
|
36 #define MAX_LPC_ORDER 32 |
3385
340e5d35b326
flac-lpc patch by (Justin Ruggles jruggle earthlink net)
michael
parents:
3384
diff
changeset
|
37 |
340e5d35b326
flac-lpc patch by (Justin Ruggles jruggle earthlink net)
michael
parents:
3384
diff
changeset
|
38 |
340e5d35b326
flac-lpc patch by (Justin Ruggles jruggle earthlink net)
michael
parents:
3384
diff
changeset
|
39 /** |
340e5d35b326
flac-lpc patch by (Justin Ruggles jruggle earthlink net)
michael
parents:
3384
diff
changeset
|
40 * Calculate LPC coefficients for multiple orders |
340e5d35b326
flac-lpc patch by (Justin Ruggles jruggle earthlink net)
michael
parents:
3384
diff
changeset
|
41 */ |
7589
8b695a99e8df
flacenc, lpc: Move LPC code from flacenc.c to new lpc.[ch] files.
ramiro
parents:
7588
diff
changeset
|
42 int ff_lpc_calc_coefs(DSPContext *s, |
7592 | 43 const int32_t *samples, int blocksize, int min_order, |
44 int max_order, int precision, | |
12139
e59926e2c50c
Add AVCodecContext.lpc_type and Add AVCodecContext.lpc_passes fields.
jbr
parents:
12024
diff
changeset
|
45 int32_t coefs[][MAX_LPC_ORDER], int *shift, |
e59926e2c50c
Add AVCodecContext.lpc_type and Add AVCodecContext.lpc_passes fields.
jbr
parents:
12024
diff
changeset
|
46 enum AVLPCType lpc_type, int lpc_passes, |
7592 | 47 int omethod, int max_shift, int zero_shift); |
3365
84f29207af3a
flacenc - rice param search patch by (Justin Ruggles jruggle earthlink net
michael
parents:
3358
diff
changeset
|
48 |
11375
84963c795459
Move some prototypes from dsputil.c to reasonable header files
mru
parents:
7791
diff
changeset
|
49 void ff_lpc_compute_autocorr(const int32_t *data, int len, int lag, |
84963c795459
Move some prototypes from dsputil.c to reasonable header files
mru
parents:
7791
diff
changeset
|
50 double *autoc); |
84963c795459
Move some prototypes from dsputil.c to reasonable header files
mru
parents:
7791
diff
changeset
|
51 |
7788
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
52 #ifdef LPC_USE_DOUBLE |
7791 | 53 #define LPC_TYPE double |
7788
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
54 #else |
7791 | 55 #define LPC_TYPE float |
7788
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
56 #endif |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
57 |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
58 /** |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
59 * Levinson-Durbin recursion. |
12024 | 60 * Produce LPC coefficients from autocorrelation data. |
7788
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
61 */ |
7791 | 62 static inline int compute_lpc_coefs(const LPC_TYPE *autoc, int max_order, |
63 LPC_TYPE *lpc, int lpc_stride, int fail, | |
7788
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
64 int normalize) |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
65 { |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
66 int i, j; |
7791 | 67 LPC_TYPE err; |
68 LPC_TYPE *lpc_last = lpc; | |
7788
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
69 |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
70 if (normalize) |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
71 err = *autoc++; |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
72 |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
73 if (fail && (autoc[max_order - 1] == 0 || err <= 0)) |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
74 return -1; |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
75 |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
76 for(i=0; i<max_order; i++) { |
7791 | 77 LPC_TYPE r = -autoc[i]; |
7788
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
78 |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
79 if (normalize) { |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
80 for(j=0; j<i; j++) |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
81 r -= lpc_last[j] * autoc[i-j-1]; |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
82 |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
83 r /= err; |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
84 err *= 1.0 - (r * r); |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
85 } |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
86 |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
87 lpc[i] = r; |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
88 |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
89 for(j=0; j < (i+1)>>1; j++) { |
7791 | 90 LPC_TYPE f = lpc_last[ j]; |
91 LPC_TYPE b = lpc_last[i-1-j]; | |
7788
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
92 lpc[ j] = f + r * b; |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
93 lpc[i-1-j] = b + r * f; |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
94 } |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
95 |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
96 if (fail && err < 0) |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
97 return -1; |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
98 |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
99 lpc_last = lpc; |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
100 lpc += lpc_stride; |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
101 } |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
102 |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
103 return 0; |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
104 } |
ffd4b1364b62
Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents:
7760
diff
changeset
|
105 |
7760 | 106 #endif /* AVCODEC_LPC_H */ |