annotate ra288.c @ 7900:37f62a3dc645 libavcodec

Correct comment in the direct mode code. (note, yes this is unrelated to the previous simplification, the code always behaved like it is documented now.)
author michael
date Sun, 21 Sep 2008 23:49:53 +0000
parents 29010c2697da
children 9fbae87668db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
9176fe6f17c9 Rewrite unpack() using the bitstream reader
vitor
parents: 7169
diff changeset
23 #define ALT_BITSTREAM_READER_LE
9176fe6f17c9 Rewrite unpack() using the bitstream reader
vitor
parents: 7169
diff changeset
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"
7788
ffd4b1364b62 Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents: 7505
diff changeset
26 #include "lpc.h"
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2956
diff changeset
27
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
28 typedef struct {
7439
deea146537af Cosmetics: align comments
vitor
parents: 7438
diff changeset
29 float sp_lpc[36]; ///< LPC coefficients for speech data (spec: A)
7849
2bfde5b45e01 Cosmetics: align spec references
vitor
parents: 7848
diff changeset
30 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
31
7853
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
32 /** speech data history (spec: SB).
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
33 * Its first 70 coefficients are updated only at backward filtering.
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
34 */
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
35 float sp_hist[111];
7418
83d005a098b5 Rename st{1,2}{a,b} context variables to more meaningful names: {sp,gain}_{rec,hist}
vitor
parents: 7416
diff changeset
36
7849
2bfde5b45e01 Cosmetics: align spec references
vitor
parents: 7848
diff changeset
37 /// speech part of the gain autocorrelation (spec: REXP)
7418
83d005a098b5 Rename st{1,2}{a,b} context variables to more meaningful names: {sp,gain}_{rec,hist}
vitor
parents: 7416
diff changeset
38 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
39
7853
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
40 /** log-gain history (spec: SBLG).
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
41 * Its first 28 coefficients are updated only at backward filtering.
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
42 */
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
43 float gain_hist[38];
7418
83d005a098b5 Rename st{1,2}{a,b} context variables to more meaningful names: {sp,gain}_{rec,hist}
vitor
parents: 7416
diff changeset
44
7849
2bfde5b45e01 Cosmetics: align spec references
vitor
parents: 7848
diff changeset
45 /// recursive part of the gain autocorrelation (spec: REXPLG)
7418
83d005a098b5 Rename st{1,2}{a,b} context variables to more meaningful names: {sp,gain}_{rec,hist}
vitor
parents: 7416
diff changeset
46 float gain_rec[11];
7411
d41948bf80a1 Give the context structure of ra288 a better name: s/Real288_internal/RA288Context/
vitor
parents: 7375
diff changeset
47 } 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
48
7451
85ab7655ad4d Modify all codecs to report their supported input and output sample format(s).
pross
parents: 7449
diff changeset
49 static av_cold int ra288_decode_init(AVCodecContext *avctx)
85ab7655ad4d Modify all codecs to report their supported input and output sample format(s).
pross
parents: 7449
diff changeset
50 {
7874
29010c2697da Use SAMPLE_FMT_FLT instead of doing the float->int conversion in the
vitor
parents: 7854
diff changeset
51 avctx->sample_fmt = SAMPLE_FMT_FLT;
7451
85ab7655ad4d Modify all codecs to report their supported input and output sample format(s).
pross
parents: 7449
diff changeset
52 return 0;
85ab7655ad4d Modify all codecs to report their supported input and output sample format(s).
pross
parents: 7449
diff changeset
53 }
85ab7655ad4d Modify all codecs to report their supported input and output sample format(s).
pross
parents: 7449
diff changeset
54
7294
bf3952d5e76c Declare function parameters as const
vitor
parents: 7275
diff changeset
55 static inline float scalar_product_float(const float * v1, const float * v2,
bf3952d5e76c Declare function parameters as const
vitor
parents: 7275
diff changeset
56 int size)
7201
4d441356fa23 Create a function for float dot product instead of duplicating all over the file
vitor
parents: 7195
diff changeset
57 {
4d441356fa23 Create a function for float dot product instead of duplicating all over the file
vitor
parents: 7195
diff changeset
58 float res = 0.;
4d441356fa23 Create a function for float dot product instead of duplicating all over the file
vitor
parents: 7195
diff changeset
59
4d441356fa23 Create a function for float dot product instead of duplicating all over the file
vitor
parents: 7195
diff changeset
60 while (size--)
4d441356fa23 Create a function for float dot product instead of duplicating all over the file
vitor
parents: 7195
diff changeset
61 res += *v1++ * *v2++;
4d441356fa23 Create a function for float dot product instead of duplicating all over the file
vitor
parents: 7195
diff changeset
62
4d441356fa23 Create a function for float dot product instead of duplicating all over the file
vitor
parents: 7195
diff changeset
63 return res;
4d441356fa23 Create a function for float dot product instead of duplicating all over the file
vitor
parents: 7195
diff changeset
64 }
4d441356fa23 Create a function for float dot product instead of duplicating all over the file
vitor
parents: 7195
diff changeset
65
7848
f29ec8e5d186 Rename function: s/colmult/apply_window/
vitor
parents: 7847
diff changeset
66 static void apply_window(float *tgt, const float *m1, const float *m2, int n)
7415
649496faa1d2 Move colmult() function to the beginning of file to group DSP-related functions.
vitor
parents: 7414
diff changeset
67 {
649496faa1d2 Move colmult() function to the beginning of file to group DSP-related functions.
vitor
parents: 7414
diff changeset
68 while (n--)
7416
a65363f8ab4b Cosmetics: remove useless parenthesis
vitor
parents: 7415
diff changeset
69 *tgt++ = *m1++ * *m2++;
7415
649496faa1d2 Move colmult() function to the beginning of file to group DSP-related functions.
vitor
parents: 7414
diff changeset
70 }
649496faa1d2 Move colmult() function to the beginning of file to group DSP-related functions.
vitor
parents: 7414
diff changeset
71
7412
51da3d8200d0 Give the context variables of ra288 a better name: s/glob/ractx/
vitor
parents: 7411
diff changeset
72 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
73 {
7448
b15534513059 Cosmetics: rename loop counter vars to i,j
vitor
parents: 7443
diff changeset
74 int i, j;
7268
7e51fc7805ac Do not declare as double a var that only stores a float
vitor
parents: 7267
diff changeset
75 double sumsum;
7e51fc7805ac Do not declare as double a var that only stores a float
vitor
parents: 7267
diff changeset
76 float sum, buffer[5];
7853
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
77 float *block = ractx->sp_hist + 70 + 36; // current block
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
78 float *gain_block = ractx->gain_hist + 28;
7167
9b93a3cf6440 Reindent the whole file
vitor
parents: 7040
diff changeset
79
7853
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
80 memmove(ractx->sp_hist + 70, ractx->sp_hist + 75, 36*sizeof(*block));
7167
9b93a3cf6440 Reindent the whole file
vitor
parents: 7040
diff changeset
81
7503
d85a0a151344 Flip (by making buf[i] -> buf[size-i-1]) two buffers: {sp,gain}_block. This
vitor
parents: 7492
diff changeset
82 for (i=0; i < 5; i++) {
d85a0a151344 Flip (by making buf[i] -> buf[size-i-1]) two buffers: {sp,gain}_block. This
vitor
parents: 7492
diff changeset
83 block[i] = 0.;
d85a0a151344 Flip (by making buf[i] -> buf[size-i-1]) two buffers: {sp,gain}_block. This
vitor
parents: 7492
diff changeset
84 for (j=0; j < 36; j++)
d85a0a151344 Flip (by making buf[i] -> buf[size-i-1]) two buffers: {sp,gain}_block. This
vitor
parents: 7492
diff changeset
85 block[i] -= block[i-1-j]*ractx->sp_lpc[j];
d85a0a151344 Flip (by making buf[i] -> buf[size-i-1]) two buffers: {sp,gain}_block. This
vitor
parents: 7492
diff changeset
86 }
7167
9b93a3cf6440 Reindent the whole file
vitor
parents: 7040
diff changeset
87
7431
da24b77f46f6 Add a few comments pointing to the G.728 specification
vitor
parents: 7430
diff changeset
88 /* block 46 of G.728 spec */
7503
d85a0a151344 Flip (by making buf[i] -> buf[size-i-1]) two buffers: {sp,gain}_block. This
vitor
parents: 7492
diff changeset
89 sum = 32.;
d85a0a151344 Flip (by making buf[i] -> buf[size-i-1]) two buffers: {sp,gain}_block. This
vitor
parents: 7492
diff changeset
90 for (i=0; i < 10; i++)
7853
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
91 sum -= gain_block[9-i] * ractx->gain_lpc[i];
7167
9b93a3cf6440 Reindent the whole file
vitor
parents: 7040
diff changeset
92
7431
da24b77f46f6 Add a few comments pointing to the G.728 specification
vitor
parents: 7430
diff changeset
93 /* block 47 of G.728 spec */
7269
04ecb6594999 Another av_clipf() usage
vitor
parents: 7268
diff changeset
94 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
95
7431
da24b77f46f6 Add a few comments pointing to the G.728 specification
vitor
parents: 7430
diff changeset
96 /* block 48 of G.728 spec */
7440
0ca4275b5c6f Cosmetics: make comment match var name
vitor
parents: 7439
diff changeset
97 sumsum = exp(sum * 0.1151292546497) * gain; /* pow(10.0,sum/20)*gain */
7167
9b93a3cf6440 Reindent the whole file
vitor
parents: 7040
diff changeset
98
7448
b15534513059 Cosmetics: rename loop counter vars to i,j
vitor
parents: 7443
diff changeset
99 for (i=0; i < 5; i++)
7843
58f33e404d6a Convert table to integer.
vitor
parents: 7788
diff changeset
100 buffer[i] = codetable[cb_coef][i] * sumsum * (1./2048.);
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
101
7275
c5bcb9e4c5b2 Revert r14218. FFMAX is a macro, so
vitor
parents: 7270
diff changeset
102 sum = scalar_product_float(buffer, buffer, 5) / 5;
c5bcb9e4c5b2 Revert r14218. FFMAX is a macro, so
vitor
parents: 7270
diff changeset
103
c5bcb9e4c5b2 Revert r14218. FFMAX is a macro, so
vitor
parents: 7270
diff changeset
104 sum = FFMAX(sum, 1);
7167
9b93a3cf6440 Reindent the whole file
vitor
parents: 7040
diff changeset
105
9b93a3cf6440 Reindent the whole file
vitor
parents: 7040
diff changeset
106 /* shift and store */
7853
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
107 memmove(gain_block, gain_block + 1, 9 * sizeof(*gain_block));
7167
9b93a3cf6440 Reindent the whole file
vitor
parents: 7040
diff changeset
108
7853
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
109 gain_block[9] = 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
110
7448
b15534513059 Cosmetics: rename loop counter vars to i,j
vitor
parents: 7443
diff changeset
111 for (i=1; i < 5; i++)
b15534513059 Cosmetics: rename loop counter vars to i,j
vitor
parents: 7443
diff changeset
112 for (j=i-1; j >= 0; j--)
b15534513059 Cosmetics: rename loop counter vars to i,j
vitor
parents: 7443
diff changeset
113 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
114
7167
9b93a3cf6440 Reindent the whole file
vitor
parents: 7040
diff changeset
115 /* output */
7448
b15534513059 Cosmetics: rename loop counter vars to i,j
vitor
parents: 7443
diff changeset
116 for (i=0; i < 5; i++)
7503
d85a0a151344 Flip (by making buf[i] -> buf[size-i-1]) two buffers: {sp,gain}_block. This
vitor
parents: 7492
diff changeset
117 block[i] = av_clipf(block[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
118 }
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
7492
50e0b25882cd Rename prodsum() function to convolve()
vitor
parents: 7451
diff changeset
120 static void convolve(float *tgt, const float *src, int len, int n)
7169
f12513065d85 Move function to avoid forward declaration
vitor
parents: 7168
diff changeset
121 {
7201
4d441356fa23 Create a function for float dot product instead of duplicating all over the file
vitor
parents: 7195
diff changeset
122 for (; n >= 0; n--)
4d441356fa23 Create a function for float dot product instead of duplicating all over the file
vitor
parents: 7195
diff changeset
123 tgt[n] = scalar_product_float(src, src - n, len);
7169
f12513065d85 Move function to avoid forward declaration
vitor
parents: 7168
diff changeset
124
f12513065d85 Move function to avoid forward declaration
vitor
parents: 7168
diff changeset
125 }
f12513065d85 Move function to avoid forward declaration
vitor
parents: 7168
diff changeset
126
7367
f8e1a1ef4a56 Add comments to do_hybrid_window()
vitor
parents: 7366
diff changeset
127 /**
7847
5a114f24632a misc spelling/wording/grammar fixes
diego
parents: 7843
diff changeset
128 * Hybrid window filtering, see blocks 36 and 49 of the G.728 specification.
7367
f8e1a1ef4a56 Add comments to do_hybrid_window()
vitor
parents: 7366
diff changeset
129 *
7847
5a114f24632a misc spelling/wording/grammar fixes
diego
parents: 7843
diff changeset
130 * @param order filter order
5a114f24632a misc spelling/wording/grammar fixes
diego
parents: 7843
diff changeset
131 * @param n input length
5a114f24632a misc spelling/wording/grammar fixes
diego
parents: 7843
diff changeset
132 * @param non_rec number of non-recursive samples
5a114f24632a misc spelling/wording/grammar fixes
diego
parents: 7843
diff changeset
133 * @param out filter output
7853
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
134 * @param hist pointer to the input history of the filter
7375
981b14d8b0e9 Cosmetics: grammar nits
vitor
parents: 7372
diff changeset
135 * @param out pointer to the non-recursive part of the output
7367
f8e1a1ef4a56 Add comments to do_hybrid_window()
vitor
parents: 7366
diff changeset
136 * @param out2 pointer to the recursive part of the output
f8e1a1ef4a56 Add comments to do_hybrid_window()
vitor
parents: 7366
diff changeset
137 * @param window pointer to the windowing function table
f8e1a1ef4a56 Add comments to do_hybrid_window()
vitor
parents: 7366
diff changeset
138 */
7854
e5e3c56c358c Cosmetics: line breaks
vitor
parents: 7853
diff changeset
139 static void do_hybrid_window(int order, int n, int non_rec, float *out,
e5e3c56c358c Cosmetics: line breaks
vitor
parents: 7853
diff changeset
140 float *hist, float *out2, 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
141 {
7449
18fc253b4991 Do not declare a counter as unsigned when it is not needed
vitor
parents: 7448
diff changeset
142 int i;
7437
d36ec42eef9c Declare temporary buffers to be only of the necessary size
vitor
parents: 7436
diff changeset
143 float buffer1[order + 1];
d36ec42eef9c Declare temporary buffers to be only of the necessary size
vitor
parents: 7436
diff changeset
144 float buffer2[order + 1];
d36ec42eef9c Declare temporary buffers to be only of the necessary size
vitor
parents: 7436
diff changeset
145 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
146
7848
f29ec8e5d186 Rename function: s/colmult/apply_window/
vitor
parents: 7847
diff changeset
147 apply_window(work, window, hist, order + n + non_rec);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2956
diff changeset
148
7492
50e0b25882cd Rename prodsum() function to convolve()
vitor
parents: 7451
diff changeset
149 convolve(buffer1, work + order , n , order);
50e0b25882cd Rename prodsum() function to convolve()
vitor
parents: 7451
diff changeset
150 convolve(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
151
7448
b15534513059 Cosmetics: rename loop counter vars to i,j
vitor
parents: 7443
diff changeset
152 for (i=0; i <= order; i++) {
b15534513059 Cosmetics: rename loop counter vars to i,j
vitor
parents: 7443
diff changeset
153 out2[i] = out2[i] * 0.5625 + buffer1[i];
b15534513059 Cosmetics: rename loop counter vars to i,j
vitor
parents: 7443
diff changeset
154 out [i] = out2[i] + buffer2[i];
7167
9b93a3cf6440 Reindent the whole file
vitor
parents: 7040
diff changeset
155 }
7365
031d4866b192 Rename co() function to the much more descriptive name of
vitor
parents: 7364
diff changeset
156
7847
5a114f24632a misc spelling/wording/grammar fixes
diego
parents: 7843
diff changeset
157 /* Multiply by the white noise correcting factor (WNCF). */
7365
031d4866b192 Rename co() function to the much more descriptive name of
vitor
parents: 7364
diff changeset
158 *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
159 }
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
160
7372
e97d0795ee70 Rename update() function to backward_filter() and add a doxy comment
vitor
parents: 7371
diff changeset
161 /**
7847
5a114f24632a misc spelling/wording/grammar fixes
diego
parents: 7843
diff changeset
162 * Backward synthesis filter, find the LPC coefficients from past speech data.
7372
e97d0795ee70 Rename update() function to backward_filter() and add a doxy comment
vitor
parents: 7371
diff changeset
163 */
7412
51da3d8200d0 Give the context variables of ra288 a better name: s/glob/ractx/
vitor
parents: 7411
diff changeset
164 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
165 {
7428
e8eca33561c7 Rename two context buffers: pr{1,2} -> {sp,gain}_lpc. Also add a few doxy
vitor
parents: 7426
diff changeset
166 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
167 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
168
7853
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
169 do_hybrid_window(36, 40, 35, 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
170 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
171
7788
ffd4b1364b62 Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents: 7505
diff changeset
172 if (!compute_lpc_coefs(temp1, 36, ractx->sp_lpc, 0, 1, 1))
7848
f29ec8e5d186 Rename function: s/colmult/apply_window/
vitor
parents: 7847
diff changeset
173 apply_window(ractx->sp_lpc, ractx->sp_lpc, syn_bw_tab, 36);
7169
f12513065d85 Move function to avoid forward declaration
vitor
parents: 7168
diff changeset
174
7853
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
175 do_hybrid_window(10, 8, 20, 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
176 ractx->gain_rec, gain_window);
7169
f12513065d85 Move function to avoid forward declaration
vitor
parents: 7168
diff changeset
177
7788
ffd4b1364b62 Avoid duplicating compute_lpc_coefs() function in both the RA288 and AAC decoders.
vitor
parents: 7505
diff changeset
178 if (!compute_lpc_coefs(temp2, 10, ractx->gain_lpc, 0, 1, 1))
7848
f29ec8e5d186 Rename function: s/colmult/apply_window/
vitor
parents: 7847
diff changeset
179 apply_window(ractx->gain_lpc, ractx->gain_lpc, gain_bw_tab, 10);
7853
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
180
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
181 memmove(ractx->gain_hist, ractx->gain_hist + 8,
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
182 28*sizeof(*ractx->gain_hist));
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
183
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
184 memmove(ractx->sp_hist , ractx->sp_hist + 40,
21ab545aed8b Simplify: use a single history buffer for gain and a single one for
vitor
parents: 7849
diff changeset
185 70*sizeof(*ractx->sp_hist ));
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
186 }
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
187
7174
7c4589349c01 Remove useless wrapper around ra288_decode_frame()
vitor
parents: 7173
diff changeset
188 static int ra288_decode_frame(AVCodecContext * avctx, void *data,
7c4589349c01 Remove useless wrapper around ra288_decode_frame()
vitor
parents: 7173
diff changeset
189 int *data_size, const uint8_t * buf,
7c4589349c01 Remove useless wrapper around ra288_decode_frame()
vitor
parents: 7173
diff changeset
190 int buf_size)
1313
d6da658fe6c6 finally works now
nickols_k
parents: 1308
diff changeset
191 {
7874
29010c2697da Use SAMPLE_FMT_FLT instead of doing the float->int conversion in the
vitor
parents: 7854
diff changeset
192 float *out = data;
7448
b15534513059 Cosmetics: rename loop counter vars to i,j
vitor
parents: 7443
diff changeset
193 int i, j;
7412
51da3d8200d0 Give the context variables of ra288 a better name: s/glob/ractx/
vitor
parents: 7411
diff changeset
194 RA288Context *ractx = avctx->priv_data;
7173
bc2fd265f52b Remove unpack() function, read the bitstream as needed
vitor
parents: 7172
diff changeset
195 GetBitContext gb;
7167
9b93a3cf6440 Reindent the whole file
vitor
parents: 7040
diff changeset
196
7174
7c4589349c01 Remove useless wrapper around ra288_decode_frame()
vitor
parents: 7173
diff changeset
197 if (buf_size < avctx->block_align) {
7c4589349c01 Remove useless wrapper around ra288_decode_frame()
vitor
parents: 7173
diff changeset
198 av_log(avctx, AV_LOG_ERROR,
7c4589349c01 Remove useless wrapper around ra288_decode_frame()
vitor
parents: 7173
diff changeset
199 "Error! Input buffer is too small [%d<%d]\n",
7c4589349c01 Remove useless wrapper around ra288_decode_frame()
vitor
parents: 7173
diff changeset
200 buf_size, avctx->block_align);
7c4589349c01 Remove useless wrapper around ra288_decode_frame()
vitor
parents: 7173
diff changeset
201 return 0;
7c4589349c01 Remove useless wrapper around ra288_decode_frame()
vitor
parents: 7173
diff changeset
202 }
7c4589349c01 Remove useless wrapper around ra288_decode_frame()
vitor
parents: 7173
diff changeset
203
7874
29010c2697da Use SAMPLE_FMT_FLT instead of doing the float->int conversion in the
vitor
parents: 7854
diff changeset
204 if (*data_size < 32*5*4)
7505
2c22852d1998 Check *data_size in decode_frame()
vitor
parents: 7504
diff changeset
205 return -1;
2c22852d1998 Check *data_size in decode_frame()
vitor
parents: 7504
diff changeset
206
7174
7c4589349c01 Remove useless wrapper around ra288_decode_frame()
vitor
parents: 7173
diff changeset
207 init_get_bits(&gb, buf, avctx->block_align * 8);
1313
d6da658fe6c6 finally works now
nickols_k
parents: 1308
diff changeset
208
7448
b15534513059 Cosmetics: rename loop counter vars to i,j
vitor
parents: 7443
diff changeset
209 for (i=0; i < 32; i++) {
7192
9517beb3b491 Simplify
vitor
parents: 7191
diff changeset
210 float gain = amptable[get_bits(&gb, 3)];
7448
b15534513059 Cosmetics: rename loop counter vars to i,j
vitor
parents: 7443
diff changeset
211 int cb_coef = get_bits(&gb, 6 + (i&1));
7443
a8b985890c34 Cosmetics: new line
vitor
parents: 7442
diff changeset
212
7412
51da3d8200d0 Give the context variables of ra288 a better name: s/glob/ractx/
vitor
parents: 7411
diff changeset
213 decode(ractx, gain, cb_coef);
7167
9b93a3cf6440 Reindent the whole file
vitor
parents: 7040
diff changeset
214
7448
b15534513059 Cosmetics: rename loop counter vars to i,j
vitor
parents: 7443
diff changeset
215 for (j=0; j < 5; j++)
7874
29010c2697da Use SAMPLE_FMT_FLT instead of doing the float->int conversion in the
vitor
parents: 7854
diff changeset
216 *(out++) = (1/4096.) * ractx->sp_hist[70 + 36 + j];
7167
9b93a3cf6440 Reindent the whole file
vitor
parents: 7040
diff changeset
217
7448
b15534513059 Cosmetics: rename loop counter vars to i,j
vitor
parents: 7443
diff changeset
218 if ((i & 7) == 3)
7412
51da3d8200d0 Give the context variables of ra288 a better name: s/glob/ractx/
vitor
parents: 7411
diff changeset
219 backward_filter(ractx);
7167
9b93a3cf6440 Reindent the whole file
vitor
parents: 7040
diff changeset
220 }
9b93a3cf6440 Reindent the whole file
vitor
parents: 7040
diff changeset
221
7174
7c4589349c01 Remove useless wrapper around ra288_decode_frame()
vitor
parents: 7173
diff changeset
222 *data_size = (char *)out - (char *)data;
2956
5f51b1e0bed6 Cook compatibe decoder, patch by Benjamin Larsson
rtognimp
parents: 2288
diff changeset
223 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
224 }
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
225
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
226 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
227 {
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
228 "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
229 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
230 CODEC_ID_RA_288,
7411
d41948bf80a1 Give the context structure of ra288 a better name: s/Real288_internal/RA288Context/
vitor
parents: 7375
diff changeset
231 sizeof(RA288Context),
7451
85ab7655ad4d Modify all codecs to report their supported input and output sample format(s).
pross
parents: 7449
diff changeset
232 ra288_decode_init,
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
233 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
234 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
235 ra288_decode_frame,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6712
diff changeset
236 .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
237 };