Mercurial > libavcodec.hg
annotate ra288.c @ 7448:b15534513059 libavcodec
Cosmetics: rename loop counter vars to i,j
author | vitor |
---|---|
date | Tue, 29 Jul 2008 18:20:49 +0000 |
parents | a8b985890c34 |
children | 18fc253b4991 |
rev | line source |
---|---|
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
1 /* |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
2 * RealAudio 2.0 (28.8K) |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
3 * Copyright (c) 2003 the ffmpeg project |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
4 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
5 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
6 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
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:
3036
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
11 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
16 * |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
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:
3036
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2979
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
20 */ |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
21 |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
22 #include "avcodec.h" |
7171 | 23 #define ALT_BITSTREAM_READER_LE |
24 #include "bitstream.h" | |
1335
b4a72edb3a71
moved the tables into header files (and applied the 'static' patch). Nick: why do you like mergeing tables and code into one file, so making it unusable big?
al3x
parents:
1316
diff
changeset
|
25 #include "ra288.h" |
2967 | 26 |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
27 typedef struct { |
7439 | 28 float sp_lpc[36]; ///< LPC coefficients for speech data (spec: A) |
29 float gain_lpc[10]; ///< LPC coefficients for gain (spec: GB) | |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
30 |
7439 | 31 float sp_hist[111]; ///< Speech data history (spec: SB) |
7418
83d005a098b5
Rename st{1,2}{a,b} context variables to more meaningful names: {sp,gain}_{rec,hist}
vitor
parents:
7416
diff
changeset
|
32 |
83d005a098b5
Rename st{1,2}{a,b} context variables to more meaningful names: {sp,gain}_{rec,hist}
vitor
parents:
7416
diff
changeset
|
33 /** Speech part of the gain autocorrelation (spec: REXP) */ |
83d005a098b5
Rename st{1,2}{a,b} context variables to more meaningful names: {sp,gain}_{rec,hist}
vitor
parents:
7416
diff
changeset
|
34 float sp_rec[37]; |
83d005a098b5
Rename st{1,2}{a,b} context variables to more meaningful names: {sp,gain}_{rec,hist}
vitor
parents:
7416
diff
changeset
|
35 |
83d005a098b5
Rename st{1,2}{a,b} context variables to more meaningful names: {sp,gain}_{rec,hist}
vitor
parents:
7416
diff
changeset
|
36 float gain_hist[38]; ///< Log-gain history (spec: SBLG) |
83d005a098b5
Rename st{1,2}{a,b} context variables to more meaningful names: {sp,gain}_{rec,hist}
vitor
parents:
7416
diff
changeset
|
37 |
83d005a098b5
Rename st{1,2}{a,b} context variables to more meaningful names: {sp,gain}_{rec,hist}
vitor
parents:
7416
diff
changeset
|
38 /** Recursive part of the gain autocorrelation (spec: REXPLG) */ |
83d005a098b5
Rename st{1,2}{a,b} context variables to more meaningful names: {sp,gain}_{rec,hist}
vitor
parents:
7416
diff
changeset
|
39 float gain_rec[11]; |
83d005a098b5
Rename st{1,2}{a,b} context variables to more meaningful names: {sp,gain}_{rec,hist}
vitor
parents:
7416
diff
changeset
|
40 |
7438
d9d070ff46bf
Rename two context vars: s/sb/sp_block/, s/lhist/gain_block/
vitor
parents:
7437
diff
changeset
|
41 float sp_block[41]; ///< Speech data of four blocks (spec: STTMP) |
d9d070ff46bf
Rename two context vars: s/sb/sp_block/, s/lhist/gain_block/
vitor
parents:
7437
diff
changeset
|
42 float gain_block[10]; ///< Gain data of four blocks (spec: GSTATE) |
7411
d41948bf80a1
Give the context structure of ra288 a better name: s/Real288_internal/RA288Context/
vitor
parents:
7375
diff
changeset
|
43 } RA288Context; |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
44 |
7294 | 45 static inline float scalar_product_float(const float * v1, const float * v2, |
46 int size) | |
7201
4d441356fa23
Create a function for float dot product instead of duplicating all over the file
vitor
parents:
7195
diff
changeset
|
47 { |
4d441356fa23
Create a function for float dot product instead of duplicating all over the file
vitor
parents:
7195
diff
changeset
|
48 float res = 0.; |
4d441356fa23
Create a function for float dot product instead of duplicating all over the file
vitor
parents:
7195
diff
changeset
|
49 |
4d441356fa23
Create a function for float dot product instead of duplicating all over the file
vitor
parents:
7195
diff
changeset
|
50 while (size--) |
4d441356fa23
Create a function for float dot product instead of duplicating all over the file
vitor
parents:
7195
diff
changeset
|
51 res += *v1++ * *v2++; |
4d441356fa23
Create a function for float dot product instead of duplicating all over the file
vitor
parents:
7195
diff
changeset
|
52 |
4d441356fa23
Create a function for float dot product instead of duplicating all over the file
vitor
parents:
7195
diff
changeset
|
53 return res; |
4d441356fa23
Create a function for float dot product instead of duplicating all over the file
vitor
parents:
7195
diff
changeset
|
54 } |
4d441356fa23
Create a function for float dot product instead of duplicating all over the file
vitor
parents:
7195
diff
changeset
|
55 |
7415
649496faa1d2
Move colmult() function to the beginning of file to group DSP-related functions.
vitor
parents:
7414
diff
changeset
|
56 static void colmult(float *tgt, const float *m1, const float *m2, int n) |
649496faa1d2
Move colmult() function to the beginning of file to group DSP-related functions.
vitor
parents:
7414
diff
changeset
|
57 { |
649496faa1d2
Move colmult() function to the beginning of file to group DSP-related functions.
vitor
parents:
7414
diff
changeset
|
58 while (n--) |
7416 | 59 *tgt++ = *m1++ * *m2++; |
7415
649496faa1d2
Move colmult() function to the beginning of file to group DSP-related functions.
vitor
parents:
7414
diff
changeset
|
60 } |
649496faa1d2
Move colmult() function to the beginning of file to group DSP-related functions.
vitor
parents:
7414
diff
changeset
|
61 |
7412
51da3d8200d0
Give the context variables of ra288 a better name: s/glob/ractx/
vitor
parents:
7411
diff
changeset
|
62 static void decode(RA288Context *ractx, float gain, int cb_coef) |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
63 { |
7448 | 64 int i, j; |
7268
7e51fc7805ac
Do not declare as double a var that only stores a float
vitor
parents:
7267
diff
changeset
|
65 double sumsum; |
7e51fc7805ac
Do not declare as double a var that only stores a float
vitor
parents:
7267
diff
changeset
|
66 float sum, buffer[5]; |
7167 | 67 |
7438
d9d070ff46bf
Rename two context vars: s/sb/sp_block/, s/lhist/gain_block/
vitor
parents:
7437
diff
changeset
|
68 memmove(ractx->sp_block + 5, ractx->sp_block, 36*sizeof(*ractx->sp_block)); |
7167 | 69 |
7448 | 70 for (i=4; i >= 0; i--) |
71 ractx->sp_block[i] = -scalar_product_float(ractx->sp_block + i + 1, | |
7428
e8eca33561c7
Rename two context buffers: pr{1,2} -> {sp,gain}_lpc. Also add a few doxy
vitor
parents:
7426
diff
changeset
|
72 ractx->sp_lpc, 36); |
7167 | 73 |
7431
da24b77f46f6
Add a few comments pointing to the G.728 specification
vitor
parents:
7430
diff
changeset
|
74 /* block 46 of G.728 spec */ |
7438
d9d070ff46bf
Rename two context vars: s/sb/sp_block/, s/lhist/gain_block/
vitor
parents:
7437
diff
changeset
|
75 sum = 32. - scalar_product_float(ractx->gain_lpc, ractx->gain_block, 10); |
7167 | 76 |
7431
da24b77f46f6
Add a few comments pointing to the G.728 specification
vitor
parents:
7430
diff
changeset
|
77 /* block 47 of G.728 spec */ |
7269 | 78 sum = av_clipf(sum, 0, 60); |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
79 |
7431
da24b77f46f6
Add a few comments pointing to the G.728 specification
vitor
parents:
7430
diff
changeset
|
80 /* block 48 of G.728 spec */ |
7440 | 81 sumsum = exp(sum * 0.1151292546497) * gain; /* pow(10.0,sum/20)*gain */ |
7167 | 82 |
7448 | 83 for (i=0; i < 5; i++) |
84 buffer[i] = codetable[cb_coef][i] * sumsum; | |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
85 |
7275 | 86 sum = scalar_product_float(buffer, buffer, 5) / 5; |
87 | |
88 sum = FFMAX(sum, 1); | |
7167 | 89 |
90 /* shift and store */ | |
7438
d9d070ff46bf
Rename two context vars: s/sb/sp_block/, s/lhist/gain_block/
vitor
parents:
7437
diff
changeset
|
91 memmove(ractx->gain_block, ractx->gain_block - 1, |
d9d070ff46bf
Rename two context vars: s/sb/sp_block/, s/lhist/gain_block/
vitor
parents:
7437
diff
changeset
|
92 10 * sizeof(*ractx->gain_block)); |
7167 | 93 |
7438
d9d070ff46bf
Rename two context vars: s/sb/sp_block/, s/lhist/gain_block/
vitor
parents:
7437
diff
changeset
|
94 *ractx->gain_block = 10 * log10(sum) - 32; |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
95 |
7448 | 96 for (i=1; i < 5; i++) |
97 for (j=i-1; j >= 0; j--) | |
98 buffer[i] -= ractx->sp_lpc[i-j-1] * buffer[j]; | |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
99 |
7167 | 100 /* output */ |
7448 | 101 for (i=0; i < 5; i++) |
102 ractx->sp_block[4-i] = | |
103 av_clipf(ractx->sp_block[4-i] + buffer[i], -4095, 4095); | |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
104 } |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
105 |
7369
b0d8a3985f96
Rename pred() to eval_lpc_coeffs() and add a doxy comment
vitor
parents:
7368
diff
changeset
|
106 /** |
b0d8a3985f96
Rename pred() to eval_lpc_coeffs() and add a doxy comment
vitor
parents:
7368
diff
changeset
|
107 * Converts autocorrelation coefficients to LPC coefficients using the |
b0d8a3985f96
Rename pred() to eval_lpc_coeffs() and add a doxy comment
vitor
parents:
7368
diff
changeset
|
108 * Levinson-Durbin algorithm. See blocks 37 and 50 of the G.728 specification. |
b0d8a3985f96
Rename pred() to eval_lpc_coeffs() and add a doxy comment
vitor
parents:
7368
diff
changeset
|
109 * |
7370
61df1ddb1001
Follow FFmpeg convention of returning negative values on error in eval_lpc_coeffs()
vitor
parents:
7369
diff
changeset
|
110 * @return 0 if success, -1 if fail |
7369
b0d8a3985f96
Rename pred() to eval_lpc_coeffs() and add a doxy comment
vitor
parents:
7368
diff
changeset
|
111 */ |
b0d8a3985f96
Rename pred() to eval_lpc_coeffs() and add a doxy comment
vitor
parents:
7368
diff
changeset
|
112 static int eval_lpc_coeffs(const float *in, float *tgt, int n) |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
113 { |
7448 | 114 int i, j; |
7167 | 115 double f0, f1, f2; |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
116 |
7167 | 117 if (in[n] == 0) |
7370
61df1ddb1001
Follow FFmpeg convention of returning negative values on error in eval_lpc_coeffs()
vitor
parents:
7369
diff
changeset
|
118 return -1; |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
119 |
7167 | 120 if ((f0 = *in) <= 0) |
7370
61df1ddb1001
Follow FFmpeg convention of returning negative values on error in eval_lpc_coeffs()
vitor
parents:
7369
diff
changeset
|
121 return -1; |
7167 | 122 |
7296 | 123 in--; // To avoid a -1 subtraction in the inner loop |
124 | |
7448 | 125 for (i=1; i <= n; i++) { |
126 f1 = in[i+1]; | |
7195
5e5c1178ae9a
Write for loops in a more standard way. In my opinion, they are much more readable now.
vitor
parents:
7193
diff
changeset
|
127 |
7448 | 128 for (j=0; j < i - 1; j++) |
129 f1 += in[i-j]*tgt[j]; | |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
130 |
7448 | 131 tgt[i-1] = f2 = -f1/f0; |
132 for (j=0; j < i >> 1; j++) { | |
133 float temp = tgt[j] + tgt[i-j-2]*f2; | |
134 tgt[i-j-2] += tgt[j]*f2; | |
135 tgt[j] = temp; | |
7167 | 136 } |
137 if ((f0 += f1*f2) < 0) | |
7370
61df1ddb1001
Follow FFmpeg convention of returning negative values on error in eval_lpc_coeffs()
vitor
parents:
7369
diff
changeset
|
138 return -1; |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
139 } |
7295 | 140 |
7370
61df1ddb1001
Follow FFmpeg convention of returning negative values on error in eval_lpc_coeffs()
vitor
parents:
7369
diff
changeset
|
141 return 0; |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
142 } |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
143 |
7294 | 144 static void prodsum(float *tgt, const float *src, int len, int n) |
7169 | 145 { |
7201
4d441356fa23
Create a function for float dot product instead of duplicating all over the file
vitor
parents:
7195
diff
changeset
|
146 for (; n >= 0; n--) |
4d441356fa23
Create a function for float dot product instead of duplicating all over the file
vitor
parents:
7195
diff
changeset
|
147 tgt[n] = scalar_product_float(src, src - n, len); |
7169 | 148 |
149 } | |
150 | |
7367 | 151 /** |
152 * Hybrid window filtering. See blocks 36 and 49 of the G.728 specification. | |
153 * | |
7433
21ecdb66d5b0
Change the way the input is passed to do_hybrid_filter(). Before, in[0] was
vitor
parents:
7432
diff
changeset
|
154 * @note This function is slightly different from that described in the spec. |
21ecdb66d5b0
Change the way the input is passed to do_hybrid_filter(). Before, in[0] was
vitor
parents:
7432
diff
changeset
|
155 * It expects in[0] to be the newest sample and in[n-1] to be the oldest |
21ecdb66d5b0
Change the way the input is passed to do_hybrid_filter(). Before, in[0] was
vitor
parents:
7432
diff
changeset
|
156 * one stored. The spec has in the more ordinary way (in[0] the oldest |
21ecdb66d5b0
Change the way the input is passed to do_hybrid_filter(). Before, in[0] was
vitor
parents:
7432
diff
changeset
|
157 * and in[n-1] the newest). |
21ecdb66d5b0
Change the way the input is passed to do_hybrid_filter(). Before, in[0] was
vitor
parents:
7432
diff
changeset
|
158 * |
7367 | 159 * @param order the order of the filter |
160 * @param n the length of the input | |
7375 | 161 * @param non_rec the number of non-recursive samples |
7367 | 162 * @param out the filter output |
163 * @param in pointer to the input of the filter | |
164 * @param hist pointer to the input history of the filter. It is updated by | |
165 * this function. | |
7375 | 166 * @param out pointer to the non-recursive part of the output |
7367 | 167 * @param out2 pointer to the recursive part of the output |
168 * @param window pointer to the windowing function table | |
169 */ | |
7366
d74804a3a18b
Give parameters of do_hybrid_window() more meaningful names
vitor
parents:
7365
diff
changeset
|
170 static void do_hybrid_window(int order, int n, int non_rec, const float *in, |
d74804a3a18b
Give parameters of do_hybrid_window() more meaningful names
vitor
parents:
7365
diff
changeset
|
171 float *out, float *hist, float *out2, |
d74804a3a18b
Give parameters of do_hybrid_window() more meaningful names
vitor
parents:
7365
diff
changeset
|
172 const float *window) |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
173 { |
7448 | 174 unsigned int i; |
7437
d36ec42eef9c
Declare temporary buffers to be only of the necessary size
vitor
parents:
7436
diff
changeset
|
175 float buffer1[order + 1]; |
d36ec42eef9c
Declare temporary buffers to be only of the necessary size
vitor
parents:
7436
diff
changeset
|
176 float buffer2[order + 1]; |
d36ec42eef9c
Declare temporary buffers to be only of the necessary size
vitor
parents:
7436
diff
changeset
|
177 float work[order + n + non_rec]; |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
178 |
7367 | 179 /* update history */ |
7435
014780c09494
Cosmetics: do not align with now removed next instruction
vitor
parents:
7434
diff
changeset
|
180 memmove(hist, hist + n, (order + non_rec)*sizeof(*hist)); |
7433
21ecdb66d5b0
Change the way the input is passed to do_hybrid_filter(). Before, in[0] was
vitor
parents:
7432
diff
changeset
|
181 |
7448 | 182 for (i=0; i < n; i++) |
183 hist[order + non_rec + i] = in[n-i-1]; | |
7363
d346c4da00bd
Simplify co(), use memcpy/memmove and colmult() when useful.
vitor
parents:
7322
diff
changeset
|
184 |
7366
d74804a3a18b
Give parameters of do_hybrid_window() more meaningful names
vitor
parents:
7365
diff
changeset
|
185 colmult(work, window, hist, order + n + non_rec); |
2967 | 186 |
7366
d74804a3a18b
Give parameters of do_hybrid_window() more meaningful names
vitor
parents:
7365
diff
changeset
|
187 prodsum(buffer1, work + order , n , order); |
d74804a3a18b
Give parameters of do_hybrid_window() more meaningful names
vitor
parents:
7365
diff
changeset
|
188 prodsum(buffer2, work + order + n, non_rec, order); |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
189 |
7448 | 190 for (i=0; i <= order; i++) { |
191 out2[i] = out2[i] * 0.5625 + buffer1[i]; | |
192 out [i] = out2[i] + buffer2[i]; | |
7167 | 193 } |
7365
031d4866b192
Rename co() function to the much more descriptive name of
vitor
parents:
7364
diff
changeset
|
194 |
031d4866b192
Rename co() function to the much more descriptive name of
vitor
parents:
7364
diff
changeset
|
195 /* Multiply by the white noise correcting factor (WNCF) */ |
031d4866b192
Rename co() function to the much more descriptive name of
vitor
parents:
7364
diff
changeset
|
196 *out *= 257./256.; |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
197 } |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
198 |
7372
e97d0795ee70
Rename update() function to backward_filter() and add a doxy comment
vitor
parents:
7371
diff
changeset
|
199 /** |
e97d0795ee70
Rename update() function to backward_filter() and add a doxy comment
vitor
parents:
7371
diff
changeset
|
200 * Backward synthesis filter. Find the LPC coefficients from past speech data. |
e97d0795ee70
Rename update() function to backward_filter() and add a doxy comment
vitor
parents:
7371
diff
changeset
|
201 */ |
7412
51da3d8200d0
Give the context variables of ra288 a better name: s/glob/ractx/
vitor
parents:
7411
diff
changeset
|
202 static void backward_filter(RA288Context *ractx) |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
203 { |
7428
e8eca33561c7
Rename two context buffers: pr{1,2} -> {sp,gain}_lpc. Also add a few doxy
vitor
parents:
7426
diff
changeset
|
204 float temp1[37]; // RTMP in the spec |
e8eca33561c7
Rename two context buffers: pr{1,2} -> {sp,gain}_lpc. Also add a few doxy
vitor
parents:
7426
diff
changeset
|
205 float temp2[11]; // GPTPMP in the spec |
7430
4ebfb53ff2df
Remove the history buffer from the context. It can easily be evaluated
vitor
parents:
7428
diff
changeset
|
206 |
7438
d9d070ff46bf
Rename two context vars: s/sb/sp_block/, s/lhist/gain_block/
vitor
parents:
7437
diff
changeset
|
207 do_hybrid_window(36, 40, 35, ractx->sp_block, temp1, ractx->sp_hist, |
7428
e8eca33561c7
Rename two context buffers: pr{1,2} -> {sp,gain}_lpc. Also add a few doxy
vitor
parents:
7426
diff
changeset
|
208 ractx->sp_rec, syn_window); |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
209 |
7428
e8eca33561c7
Rename two context buffers: pr{1,2} -> {sp,gain}_lpc. Also add a few doxy
vitor
parents:
7426
diff
changeset
|
210 if (!eval_lpc_coeffs(temp1, ractx->sp_lpc, 36)) |
e8eca33561c7
Rename two context buffers: pr{1,2} -> {sp,gain}_lpc. Also add a few doxy
vitor
parents:
7426
diff
changeset
|
211 colmult(ractx->sp_lpc, ractx->sp_lpc, syn_bw_tab, 36); |
7169 | 212 |
7438
d9d070ff46bf
Rename two context vars: s/sb/sp_block/, s/lhist/gain_block/
vitor
parents:
7437
diff
changeset
|
213 do_hybrid_window(10, 8, 20, ractx->gain_block, temp2, ractx->gain_hist, |
7428
e8eca33561c7
Rename two context buffers: pr{1,2} -> {sp,gain}_lpc. Also add a few doxy
vitor
parents:
7426
diff
changeset
|
214 ractx->gain_rec, gain_window); |
7169 | 215 |
7428
e8eca33561c7
Rename two context buffers: pr{1,2} -> {sp,gain}_lpc. Also add a few doxy
vitor
parents:
7426
diff
changeset
|
216 if (!eval_lpc_coeffs(temp2, ractx->gain_lpc, 10)) |
e8eca33561c7
Rename two context buffers: pr{1,2} -> {sp,gain}_lpc. Also add a few doxy
vitor
parents:
7426
diff
changeset
|
217 colmult(ractx->gain_lpc, ractx->gain_lpc, gain_bw_tab, 10); |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
218 } |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
219 |
7174 | 220 static int ra288_decode_frame(AVCodecContext * avctx, void *data, |
221 int *data_size, const uint8_t * buf, | |
222 int buf_size) | |
1313 | 223 { |
7174 | 224 int16_t *out = data; |
7448 | 225 int i, j; |
7412
51da3d8200d0
Give the context variables of ra288 a better name: s/glob/ractx/
vitor
parents:
7411
diff
changeset
|
226 RA288Context *ractx = avctx->priv_data; |
7173
bc2fd265f52b
Remove unpack() function, read the bitstream as needed
vitor
parents:
7172
diff
changeset
|
227 GetBitContext gb; |
7167 | 228 |
7174 | 229 if (buf_size < avctx->block_align) { |
230 av_log(avctx, AV_LOG_ERROR, | |
231 "Error! Input buffer is too small [%d<%d]\n", | |
232 buf_size, avctx->block_align); | |
233 return 0; | |
234 } | |
235 | |
236 init_get_bits(&gb, buf, avctx->block_align * 8); | |
1313 | 237 |
7448 | 238 for (i=0; i < 32; i++) { |
7192 | 239 float gain = amptable[get_bits(&gb, 3)]; |
7448 | 240 int cb_coef = get_bits(&gb, 6 + (i&1)); |
7443 | 241 |
7412
51da3d8200d0
Give the context variables of ra288 a better name: s/glob/ractx/
vitor
parents:
7411
diff
changeset
|
242 decode(ractx, gain, cb_coef); |
7167 | 243 |
7448 | 244 for (j=0; j < 5; j++) |
245 *(out++) = 8 * ractx->sp_block[4 - j]; | |
7167 | 246 |
7448 | 247 if ((i & 7) == 3) |
7412
51da3d8200d0
Give the context variables of ra288 a better name: s/glob/ractx/
vitor
parents:
7411
diff
changeset
|
248 backward_filter(ractx); |
7167 | 249 } |
250 | |
7174 | 251 *data_size = (char *)out - (char *)data; |
2956
5f51b1e0bed6
Cook compatibe decoder, patch by Benjamin Larsson
rtognimp
parents:
2288
diff
changeset
|
252 return avctx->block_align; |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
253 } |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
254 |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
255 AVCodec ra_288_decoder = |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
256 { |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
257 "real_288", |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
258 CODEC_TYPE_AUDIO, |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
259 CODEC_ID_RA_288, |
7411
d41948bf80a1
Give the context structure of ra288 a better name: s/Real288_internal/RA288Context/
vitor
parents:
7375
diff
changeset
|
260 sizeof(RA288Context), |
7168 | 261 NULL, |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
262 NULL, |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
263 NULL, |
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
264 ra288_decode_frame, |
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6712
diff
changeset
|
265 .long_name = NULL_IF_CONFIG_SMALL("RealAudio 2.0 (28.8K)"), |
1304
e8543aab0cc9
RealAudio 1.0 (14_4) and 2.0 (28_8) native decoders. Author unknown, code from a mplayerhq (originally from public domain player for Amiga
nickols_k
parents:
diff
changeset
|
266 }; |