annotate binkaudio.c @ 12180:b24153464669 libavcodec

Attempt to fix x86-64 testsuite on fate.
author rbultje
date Fri, 16 Jul 2010 21:35:30 +0000
parents 7dd2a45249a9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11067
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
1 /*
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
2 * Bink Audio decoder
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
3 * Copyright (c) 2007-2010 Peter Ross (pross@xvid.org)
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
4 * Copyright (c) 2009 Daniel Verkamp (daniel@drv.nu)
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
5 *
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
6 * This file is part of FFmpeg.
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
7 *
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
12 *
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
16 * Lesser General Public License for more details.
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
17 *
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
21 */
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
22
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
23 /**
11644
7dd2a45249a9 Remove explicit filename from Doxygen @file commands.
diego
parents: 11582
diff changeset
24 * @file
11067
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
25 * Bink Audio decoder
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
26 *
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
27 * Technical details here:
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
28 * http://wiki.multimedia.cx/index.php?title=Bink_Audio
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
29 */
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
30
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
31 #include "avcodec.h"
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
32 #define ALT_BITSTREAM_READER_LE
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
33 #include "get_bits.h"
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
34 #include "dsputil.h"
11370
4b3da727d832 Move FFT parts from dsputil.h to fft.h
mru
parents: 11369
diff changeset
35 #include "fft.h"
4b3da727d832 Move FFT parts from dsputil.h to fft.h
mru
parents: 11369
diff changeset
36
11067
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
37 extern const uint16_t ff_wma_critical_freqs[25];
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
38
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
39 #define MAX_CHANNELS 2
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
40 #define BINK_BLOCK_MAX_SIZE (MAX_CHANNELS << 11)
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
41
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
42 typedef struct {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
43 AVCodecContext *avctx;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
44 GetBitContext gb;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
45 DSPContext dsp;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
46 int first;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
47 int channels;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
48 int frame_len; ///< transform size (samples)
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
49 int overlap_len; ///< overlap size (samples)
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
50 int block_size;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
51 int num_bands;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
52 unsigned int *bands;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
53 float root;
11369
98970e51365a Remove DECLARE_ALIGNED_{8,16} macros
mru
parents: 11337
diff changeset
54 DECLARE_ALIGNED(16, FFTSample, coeffs)[BINK_BLOCK_MAX_SIZE];
98970e51365a Remove DECLARE_ALIGNED_{8,16} macros
mru
parents: 11337
diff changeset
55 DECLARE_ALIGNED(16, short, previous)[BINK_BLOCK_MAX_SIZE / 16]; ///< coeffs from previous audio block
11067
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
56 float *coeffs_ptr[MAX_CHANNELS]; ///< pointers to the coeffs arrays for float_to_int16_interleave
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
57 union {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
58 RDFTContext rdft;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
59 DCTContext dct;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
60 } trans;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
61 } BinkAudioContext;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
62
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
63
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
64 static av_cold int decode_init(AVCodecContext *avctx)
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
65 {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
66 BinkAudioContext *s = avctx->priv_data;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
67 int sample_rate = avctx->sample_rate;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
68 int sample_rate_half;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
69 int i;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
70 int frame_len_bits;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
71
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
72 s->avctx = avctx;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
73 dsputil_init(&s->dsp, avctx);
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
74
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
75 /* determine frame length */
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
76 if (avctx->sample_rate < 22050) {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
77 frame_len_bits = 9;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
78 } else if (avctx->sample_rate < 44100) {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
79 frame_len_bits = 10;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
80 } else {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
81 frame_len_bits = 11;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
82 }
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
83 s->frame_len = 1 << frame_len_bits;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
84
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
85 if (s->channels > MAX_CHANNELS) {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
86 av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels);
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
87 return -1;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
88 }
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
89
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
90 if (avctx->codec->id == CODEC_ID_BINKAUDIO_RDFT) {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
91 // audio is already interleaved for the RDFT format variant
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
92 sample_rate *= avctx->channels;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
93 s->frame_len *= avctx->channels;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
94 s->channels = 1;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
95 if (avctx->channels == 2)
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
96 frame_len_bits++;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
97 } else {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
98 s->channels = avctx->channels;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
99 }
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
100
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
101 s->overlap_len = s->frame_len / 16;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
102 s->block_size = (s->frame_len - s->overlap_len) * s->channels;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
103 sample_rate_half = (sample_rate + 1) / 2;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
104 s->root = 2.0 / sqrt(s->frame_len);
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
105
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
106 /* calculate number of bands */
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
107 for (s->num_bands = 1; s->num_bands < 25; s->num_bands++)
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
108 if (sample_rate_half <= ff_wma_critical_freqs[s->num_bands - 1])
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
109 break;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
110
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
111 s->bands = av_malloc((s->num_bands + 1) * sizeof(*s->bands));
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
112 if (!s->bands)
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
113 return AVERROR(ENOMEM);
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
114
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
115 /* populate bands data */
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
116 s->bands[0] = 1;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
117 for (i = 1; i < s->num_bands; i++)
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
118 s->bands[i] = ff_wma_critical_freqs[i - 1] * (s->frame_len / 2) / sample_rate_half;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
119 s->bands[s->num_bands] = s->frame_len / 2;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
120
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
121 s->first = 1;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
122 avctx->sample_fmt = SAMPLE_FMT_S16;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
123
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
124 for (i = 0; i < s->channels; i++)
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
125 s->coeffs_ptr[i] = s->coeffs + i * s->frame_len;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
126
11216
359c8ba0698e Fix compilation of binkaudio_rdft when dct is disabled
daniel
parents: 11069
diff changeset
127 if (CONFIG_BINKAUDIO_RDFT_DECODER && avctx->codec->id == CODEC_ID_BINKAUDIO_RDFT)
11391
4c7afa50df6f Give RDFT types more meaningful names
mru
parents: 11370
diff changeset
128 ff_rdft_init(&s->trans.rdft, frame_len_bits, DFT_C2R);
11216
359c8ba0698e Fix compilation of binkaudio_rdft when dct is disabled
daniel
parents: 11069
diff changeset
129 else if (CONFIG_BINKAUDIO_DCT_DECODER)
11582
23cad4157bfb Make code using 1d-DCT consistent with the API change
vitor
parents: 11560
diff changeset
130 ff_dct_init(&s->trans.dct, frame_len_bits, DCT_III);
11067
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
131 else
11216
359c8ba0698e Fix compilation of binkaudio_rdft when dct is disabled
daniel
parents: 11069
diff changeset
132 return -1;
11067
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
133
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
134 return 0;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
135 }
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
136
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
137 static float get_float(GetBitContext *gb)
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
138 {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
139 int power = get_bits(gb, 5);
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
140 float f = ldexpf(get_bits_long(gb, 23), power - 23);
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
141 if (get_bits1(gb))
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
142 f = -f;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
143 return f;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
144 }
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
145
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
146 static const uint8_t rle_length_tab[16] = {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
147 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 32, 64
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
148 };
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
149
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
150 /**
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
151 * Decode Bink Audio block
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
152 * @param[out] out Output buffer (must contain s->block_size elements)
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
153 */
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
154 static void decode_block(BinkAudioContext *s, short *out, int use_dct)
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
155 {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
156 int ch, i, j, k;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
157 float q, quant[25];
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
158 int width, coeff;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
159 GetBitContext *gb = &s->gb;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
160
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
161 if (use_dct)
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
162 skip_bits(gb, 2);
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
163
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
164 for (ch = 0; ch < s->channels; ch++) {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
165 FFTSample *coeffs = s->coeffs_ptr[ch];
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
166 q = 0.0f;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
167 coeffs[0] = get_float(gb) * s->root;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
168 coeffs[1] = get_float(gb) * s->root;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
169
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
170 for (i = 0; i < s->num_bands; i++) {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
171 /* constant is result of 0.066399999/log10(M_E) */
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
172 int value = get_bits(gb, 8);
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
173 quant[i] = expf(FFMIN(value, 95) * 0.15289164787221953823f) * s->root;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
174 }
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
175
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
176 // find band (k)
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
177 for (k = 0; s->bands[k] < 1; k++) {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
178 q = quant[k];
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
179 }
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
180
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
181 // parse coefficients
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
182 i = 2;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
183 while (i < s->frame_len) {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
184 if (get_bits1(gb)) {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
185 j = i + rle_length_tab[get_bits(gb, 4)] * 8;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
186 } else {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
187 j = i + 8;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
188 }
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
189
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
190 j = FFMIN(j, s->frame_len);
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
191
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
192 width = get_bits(gb, 4);
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
193 if (width == 0) {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
194 memset(coeffs + i, 0, (j - i) * sizeof(*coeffs));
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
195 i = j;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
196 while (s->bands[k] * 2 < i)
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
197 q = quant[k++];
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
198 } else {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
199 while (i < j) {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
200 if (s->bands[k] * 2 == i)
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
201 q = quant[k++];
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
202 coeff = get_bits(gb, width);
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
203 if (coeff) {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
204 if (get_bits1(gb))
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
205 coeffs[i] = -q * coeff;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
206 else
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
207 coeffs[i] = q * coeff;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
208 } else {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
209 coeffs[i] = 0.0f;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
210 }
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
211 i++;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
212 }
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
213 }
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
214 }
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
215
11337
15dd07e86519 Perform coefficient transformations in Bink Audio DCT decoder (issue1770)
pross
parents: 11264
diff changeset
216 if (CONFIG_BINKAUDIO_DCT_DECODER && use_dct) {
15dd07e86519 Perform coefficient transformations in Bink Audio DCT decoder (issue1770)
pross
parents: 11264
diff changeset
217 coeffs[0] /= 0.5;
11067
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
218 ff_dct_calc (&s->trans.dct, coeffs);
11337
15dd07e86519 Perform coefficient transformations in Bink Audio DCT decoder (issue1770)
pross
parents: 11264
diff changeset
219 s->dsp.vector_fmul_scalar(coeffs, coeffs, s->frame_len / 2, s->frame_len);
15dd07e86519 Perform coefficient transformations in Bink Audio DCT decoder (issue1770)
pross
parents: 11264
diff changeset
220 }
11216
359c8ba0698e Fix compilation of binkaudio_rdft when dct is disabled
daniel
parents: 11069
diff changeset
221 else if (CONFIG_BINKAUDIO_RDFT_DECODER)
11067
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
222 ff_rdft_calc(&s->trans.rdft, coeffs);
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
223 }
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
224
11461
908cc63498ec Make binkaudio work with ff_float_to_int16_interleave_c (martin at martin dot st)
pross
parents: 11391
diff changeset
225 if (s->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) {
908cc63498ec Make binkaudio work with ff_float_to_int16_interleave_c (martin at martin dot st)
pross
parents: 11391
diff changeset
226 for (i = 0; i < s->channels; i++)
908cc63498ec Make binkaudio work with ff_float_to_int16_interleave_c (martin at martin dot st)
pross
parents: 11391
diff changeset
227 for (j = 0; j < s->frame_len; j++)
908cc63498ec Make binkaudio work with ff_float_to_int16_interleave_c (martin at martin dot st)
pross
parents: 11391
diff changeset
228 s->coeffs_ptr[i][j] = 385.0 + s->coeffs_ptr[i][j]*(1.0/32767.0);
908cc63498ec Make binkaudio work with ff_float_to_int16_interleave_c (martin at martin dot st)
pross
parents: 11391
diff changeset
229 }
11067
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
230 s->dsp.float_to_int16_interleave(out, (const float **)s->coeffs_ptr, s->frame_len, s->channels);
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
231
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
232 if (!s->first) {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
233 int count = s->overlap_len * s->channels;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
234 int shift = av_log2(count);
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
235 for (i = 0; i < count; i++) {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
236 out[i] = (s->previous[i] * (count - i) + out[i] * i) >> shift;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
237 }
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
238 }
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
239
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
240 memcpy(s->previous, out + s->block_size,
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
241 s->overlap_len * s->channels * sizeof(*out));
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
242
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
243 s->first = 0;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
244 }
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
245
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
246 static av_cold int decode_end(AVCodecContext *avctx)
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
247 {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
248 BinkAudioContext * s = avctx->priv_data;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
249 av_freep(&s->bands);
11216
359c8ba0698e Fix compilation of binkaudio_rdft when dct is disabled
daniel
parents: 11069
diff changeset
250 if (CONFIG_BINKAUDIO_RDFT_DECODER && avctx->codec->id == CODEC_ID_BINKAUDIO_RDFT)
11067
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
251 ff_rdft_end(&s->trans.rdft);
11216
359c8ba0698e Fix compilation of binkaudio_rdft when dct is disabled
daniel
parents: 11069
diff changeset
252 else if (CONFIG_BINKAUDIO_DCT_DECODER)
11067
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
253 ff_dct_end(&s->trans.dct);
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
254 return 0;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
255 }
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
256
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
257 static void get_bits_align32(GetBitContext *s)
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
258 {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
259 int n = (-get_bits_count(s)) & 31;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
260 if (n) skip_bits(s, n);
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
261 }
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
262
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
263 static int decode_frame(AVCodecContext *avctx,
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
264 void *data, int *data_size,
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
265 AVPacket *avpkt)
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
266 {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
267 BinkAudioContext *s = avctx->priv_data;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
268 const uint8_t *buf = avpkt->data;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
269 int buf_size = avpkt->size;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
270 short *samples = data;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
271 short *samples_end = (short*)((uint8_t*)data + *data_size);
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
272 int reported_size;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
273 GetBitContext *gb = &s->gb;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
274
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
275 init_get_bits(gb, buf, buf_size * 8);
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
276
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
277 reported_size = get_bits_long(gb, 32);
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
278 while (get_bits_count(gb) / 8 < buf_size &&
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
279 samples + s->block_size <= samples_end) {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
280 decode_block(s, samples, avctx->codec->id == CODEC_ID_BINKAUDIO_DCT);
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
281 samples += s->block_size;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
282 get_bits_align32(gb);
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
283 }
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
284
11264
bfffb50b80bc Use reported_size to truncate final Bink Audio frame
pross
parents: 11216
diff changeset
285 *data_size = FFMIN(reported_size, (uint8_t*)samples - (uint8_t*)data);
11067
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
286 return buf_size;
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
287 }
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
288
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
289 AVCodec binkaudio_rdft_decoder = {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
290 "binkaudio_rdft",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 11461
diff changeset
291 AVMEDIA_TYPE_AUDIO,
11067
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
292 CODEC_ID_BINKAUDIO_RDFT,
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
293 sizeof(BinkAudioContext),
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
294 decode_init,
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
295 NULL,
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
296 decode_end,
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
297 decode_frame,
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
298 .long_name = NULL_IF_CONFIG_SMALL("Bink Audio (RDFT)")
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
299 };
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
300
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
301 AVCodec binkaudio_dct_decoder = {
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
302 "binkaudio_dct",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 11461
diff changeset
303 AVMEDIA_TYPE_AUDIO,
11067
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
304 CODEC_ID_BINKAUDIO_DCT,
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
305 sizeof(BinkAudioContext),
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
306 decode_init,
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
307 NULL,
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
308 decode_end,
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
309 decode_frame,
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
310 .long_name = NULL_IF_CONFIG_SMALL("Bink Audio (DCT)")
91b1e4327340 Bink Audio decoder
pross
parents:
diff changeset
311 };