Mercurial > libavcodec.hg
annotate alac.c @ 4900:36051a4c182a libavcodec
Move VC1 parser to its own file.
author | diego |
---|---|
date | Fri, 04 May 2007 00:09:33 +0000 |
parents | 05e932ddaaa9 |
children | 8256f8ec2fac |
rev | line source |
---|---|
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
1 /* |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
2 * ALAC (Apple Lossless Audio Codec) decoder |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
3 * Copyright (c) 2005 David Hammerton |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
4 * All rights reserved. |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
5 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3347
diff
changeset
|
6 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3347
diff
changeset
|
7 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3347
diff
changeset
|
8 * FFmpeg is free software; you can redistribute it and/or |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
10 * 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:
3347
diff
changeset
|
11 * version 2.1 of the License, or (at your option) any later version. |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
12 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3347
diff
changeset
|
13 * FFmpeg is distributed in the hope that it will be useful, |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
16 * Lesser General Public License for more details. |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
17 * |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
18 * 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:
3347
diff
changeset
|
19 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2967
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
21 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
22 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
23 /** |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
24 * @file alac.c |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
25 * ALAC (Apple Lossless Audio Codec) decoder |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
26 * @author 2005 David Hammerton |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
27 * |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
28 * For more information on the ALAC format, visit: |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
29 * http://crazney.net/programs/itunes/alac.html |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
30 * |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
31 * Note: This decoder expects a 36- (0x24-)byte QuickTime atom to be |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
32 * passed through the extradata[_size] fields. This atom is tacked onto |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
33 * the end of an 'alac' stsd atom and has the following format: |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
34 * bytes 0-3 atom size (0x24), big-endian |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
35 * bytes 4-7 atom type ('alac', not the 'alac' tag from start of stsd) |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
36 * bytes 8-35 data bytes needed by decoder |
3135 | 37 * |
38 * Extradata: | |
39 * 32bit size | |
40 * 32bit tag (=alac) | |
41 * 32bit zero? | |
42 * 32bit max sample per frame | |
43 * 8bit ?? (zero?) | |
44 * 8bit sample size | |
45 * 8bit history mult | |
46 * 8bit initial history | |
47 * 8bit kmodifier | |
48 * 8bit channels? | |
49 * 16bit ?? | |
50 * 32bit max coded frame size | |
51 * 32bit bitrate? | |
52 * 32bit samplerate | |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
53 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
54 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
55 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
56 #include "avcodec.h" |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
57 #include "bitstream.h" |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
58 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
59 #define ALAC_EXTRADATA_SIZE 36 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
60 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
61 typedef struct { |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
62 |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
63 AVCodecContext *avctx; |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
64 GetBitContext gb; |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
65 /* init to 0; first frame decode should initialize from extradata and |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
66 * set this to 1 */ |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
67 int context_initialized; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
68 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
69 int samplesize; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
70 int numchannels; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
71 int bytespersample; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
72 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
73 /* buffers */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
74 int32_t *predicterror_buffer_a; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
75 int32_t *predicterror_buffer_b; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
76 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
77 int32_t *outputsamples_buffer_a; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
78 int32_t *outputsamples_buffer_b; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
79 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
80 /* stuff from setinfo */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
81 uint32_t setinfo_max_samples_per_frame; /* 0x1000 = 4096 */ /* max samples per frame? */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
82 uint8_t setinfo_7a; /* 0x00 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
83 uint8_t setinfo_sample_size; /* 0x10 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
84 uint8_t setinfo_rice_historymult; /* 0x28 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
85 uint8_t setinfo_rice_initialhistory; /* 0x0a */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
86 uint8_t setinfo_rice_kmodifier; /* 0x0e */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
87 uint8_t setinfo_7f; /* 0x02 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
88 uint16_t setinfo_80; /* 0x00ff */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
89 uint32_t setinfo_82; /* 0x000020e7 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
90 uint32_t setinfo_86; /* 0x00069fe4 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
91 uint32_t setinfo_8a_rate; /* 0x0000ac44 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
92 /* end setinfo stuff */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
93 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
94 } ALACContext; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
95 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
96 static void allocate_buffers(ALACContext *alac) |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
97 { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
98 alac->predicterror_buffer_a = av_malloc(alac->setinfo_max_samples_per_frame * 4); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
99 alac->predicterror_buffer_b = av_malloc(alac->setinfo_max_samples_per_frame * 4); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
100 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
101 alac->outputsamples_buffer_a = av_malloc(alac->setinfo_max_samples_per_frame * 4); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
102 alac->outputsamples_buffer_b = av_malloc(alac->setinfo_max_samples_per_frame * 4); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
103 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
104 |
3303
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3299
diff
changeset
|
105 static int alac_set_info(ALACContext *alac) |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
106 { |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
107 unsigned char *ptr = alac->avctx->extradata; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
108 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
109 ptr += 4; /* size */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
110 ptr += 4; /* alac */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
111 ptr += 4; /* 0 ? */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
112 |
4364 | 113 if(AV_RB32(ptr) >= UINT_MAX/4){ |
3303
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3299
diff
changeset
|
114 av_log(alac->avctx, AV_LOG_ERROR, "setinfo_max_samples_per_frame too large\n"); |
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3299
diff
changeset
|
115 return -1; |
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3299
diff
changeset
|
116 } |
4364 | 117 alac->setinfo_max_samples_per_frame = AV_RB32(ptr); /* buffer size / 2 ? */ |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
118 ptr += 4; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
119 alac->setinfo_7a = *ptr++; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
120 alac->setinfo_sample_size = *ptr++; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
121 alac->setinfo_rice_historymult = *ptr++; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
122 alac->setinfo_rice_initialhistory = *ptr++; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
123 alac->setinfo_rice_kmodifier = *ptr++; |
3135 | 124 alac->setinfo_7f = *ptr++; // channels? |
4364 | 125 alac->setinfo_80 = AV_RB16(ptr); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
126 ptr += 2; |
4364 | 127 alac->setinfo_82 = AV_RB32(ptr); // max coded frame size |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
128 ptr += 4; |
4364 | 129 alac->setinfo_86 = AV_RB32(ptr); // bitrate ? |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
130 ptr += 4; |
4364 | 131 alac->setinfo_8a_rate = AV_RB32(ptr); // samplerate |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
132 ptr += 4; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
133 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
134 allocate_buffers(alac); |
3303
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3299
diff
changeset
|
135 |
68721b62a528
sanity checks, some might have been exploitable ...
michael
parents:
3299
diff
changeset
|
136 return 0; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
137 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
138 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
139 /* hideously inefficient. could use a bitmask search, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
140 * alternatively bsr on x86, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
141 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
142 static int count_leading_zeros(int32_t input) |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
143 { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
144 int i = 0; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
145 while (!(0x80000000 & input) && i < 32) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
146 i++; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
147 input = input << 1; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
148 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
149 return i; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
150 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
151 |
3071
cc0357a90e8f
make some functions static (patch by Dieter < freebsd at sopwith.solgatos.com >)
aurel
parents:
3036
diff
changeset
|
152 static void bastardized_rice_decompress(ALACContext *alac, |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
153 int32_t *output_buffer, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
154 int output_size, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
155 int readsamplesize, /* arg_10 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
156 int rice_initialhistory, /* arg424->b */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
157 int rice_kmodifier, /* arg424->d */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
158 int rice_historymult, /* arg424->c */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
159 int rice_kmodifier_mask /* arg424->e */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
160 ) |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
161 { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
162 int output_count; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
163 unsigned int history = rice_initialhistory; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
164 int sign_modifier = 0; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
165 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
166 for (output_count = 0; output_count < output_size; output_count++) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
167 int32_t x = 0; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
168 int32_t x_modified; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
169 int32_t final_val; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
170 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
171 /* read x - number of 1s before 0 represent the rice */ |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
172 while (x <= 8 && get_bits1(&alac->gb)) { |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
173 x++; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
174 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
175 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
176 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
177 if (x > 8) { /* RICE THRESHOLD */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
178 /* use alternative encoding */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
179 int32_t value; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
180 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
181 value = get_bits(&alac->gb, readsamplesize); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
182 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
183 /* mask value to readsamplesize size */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
184 if (readsamplesize != 32) |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
185 value &= (0xffffffff >> (32 - readsamplesize)); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
186 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
187 x = value; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
188 } else { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
189 /* standard rice encoding */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
190 int extrabits; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
191 int k; /* size of extra bits */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
192 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
193 /* read k, that is bits as is */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
194 k = 31 - rice_kmodifier - count_leading_zeros((history >> 9) + 3); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
195 |
2967 | 196 if (k < 0) |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
197 k += rice_kmodifier; |
2967 | 198 else |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
199 k = rice_kmodifier; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
200 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
201 if (k != 1) { |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
202 extrabits = show_bits(&alac->gb, k); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
203 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
204 /* multiply x by 2^k - 1, as part of their strange algorithm */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
205 x = (x << k) - x; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
206 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
207 if (extrabits > 1) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
208 x += extrabits - 1; |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
209 get_bits(&alac->gb, k); |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
210 } else { |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
211 get_bits(&alac->gb, k - 1); |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
212 } |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
213 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
214 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
215 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
216 x_modified = sign_modifier + x; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
217 final_val = (x_modified + 1) / 2; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
218 if (x_modified & 1) final_val *= -1; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
219 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
220 output_buffer[output_count] = final_val; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
221 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
222 sign_modifier = 0; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
223 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
224 /* now update the history */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
225 history += (x_modified * rice_historymult) |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
226 - ((history * rice_historymult) >> 9); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
227 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
228 if (x_modified > 0xffff) |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
229 history = 0xffff; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
230 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
231 /* special case: there may be compressed blocks of 0 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
232 if ((history < 128) && (output_count+1 < output_size)) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
233 int block_size; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
234 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
235 sign_modifier = 1; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
236 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
237 x = 0; |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
238 while (x <= 8 && get_bits1(&alac->gb)) { |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
239 x++; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
240 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
241 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
242 if (x > 8) { |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
243 block_size = get_bits(&alac->gb, 16); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
244 block_size &= 0xffff; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
245 } else { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
246 int k; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
247 int extrabits; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
248 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
249 k = count_leading_zeros(history) + ((history + 16) >> 6 /* / 64 */) - 24; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
250 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
251 extrabits = show_bits(&alac->gb, k); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
252 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
253 block_size = (((1 << k) - 1) & rice_kmodifier_mask) * x |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
254 + extrabits - 1; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
255 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
256 if (extrabits < 2) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
257 x = 1 - extrabits; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
258 block_size += x; |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
259 get_bits(&alac->gb, k - 1); |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
260 } else { |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
261 get_bits(&alac->gb, k); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
262 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
263 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
264 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
265 if (block_size > 0) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
266 memset(&output_buffer[output_count+1], 0, block_size * 4); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
267 output_count += block_size; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
268 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
269 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
270 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
271 if (block_size > 0xffff) |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
272 sign_modifier = 0; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
273 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
274 history = 0; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
275 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
276 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
277 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
278 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
279 #define SIGN_EXTENDED32(val, bits) ((val << (32 - bits)) >> (32 - bits)) |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
280 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
281 #define SIGN_ONLY(v) \ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
282 ((v < 0) ? (-1) : \ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
283 ((v > 0) ? (1) : \ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
284 (0))) |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
285 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
286 static void predictor_decompress_fir_adapt(int32_t *error_buffer, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
287 int32_t *buffer_out, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
288 int output_size, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
289 int readsamplesize, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
290 int16_t *predictor_coef_table, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
291 int predictor_coef_num, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
292 int predictor_quantitization) |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
293 { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
294 int i; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
295 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
296 /* first sample always copies */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
297 *buffer_out = *error_buffer; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
298 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
299 if (!predictor_coef_num) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
300 if (output_size <= 1) return; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
301 memcpy(buffer_out+1, error_buffer+1, (output_size-1) * 4); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
302 return; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
303 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
304 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
305 if (predictor_coef_num == 0x1f) { /* 11111 - max value of predictor_coef_num */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
306 /* second-best case scenario for fir decompression, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
307 * error describes a small difference from the previous sample only |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
308 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
309 if (output_size <= 1) return; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
310 for (i = 0; i < output_size - 1; i++) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
311 int32_t prev_value; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
312 int32_t error_value; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
313 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
314 prev_value = buffer_out[i]; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
315 error_value = error_buffer[i+1]; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
316 buffer_out[i+1] = SIGN_EXTENDED32((prev_value + error_value), readsamplesize); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
317 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
318 return; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
319 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
320 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
321 /* read warm-up samples */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
322 if (predictor_coef_num > 0) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
323 int i; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
324 for (i = 0; i < predictor_coef_num; i++) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
325 int32_t val; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
326 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
327 val = buffer_out[i] + error_buffer[i+1]; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
328 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
329 val = SIGN_EXTENDED32(val, readsamplesize); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
330 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
331 buffer_out[i+1] = val; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
332 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
333 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
334 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
335 #if 0 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
336 /* 4 and 8 are very common cases (the only ones i've seen). these |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
337 * should be unrolled and optimised |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
338 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
339 if (predictor_coef_num == 4) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
340 /* FIXME: optimised general case */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
341 return; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
342 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
343 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
344 if (predictor_coef_table == 8) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
345 /* FIXME: optimised general case */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
346 return; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
347 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
348 #endif |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
349 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
350 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
351 /* general case */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
352 if (predictor_coef_num > 0) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
353 for (i = predictor_coef_num + 1; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
354 i < output_size; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
355 i++) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
356 int j; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
357 int sum = 0; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
358 int outval; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
359 int error_val = error_buffer[i]; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
360 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
361 for (j = 0; j < predictor_coef_num; j++) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
362 sum += (buffer_out[predictor_coef_num-j] - buffer_out[0]) * |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
363 predictor_coef_table[j]; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
364 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
365 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
366 outval = (1 << (predictor_quantitization-1)) + sum; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
367 outval = outval >> predictor_quantitization; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
368 outval = outval + buffer_out[0] + error_val; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
369 outval = SIGN_EXTENDED32(outval, readsamplesize); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
370 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
371 buffer_out[predictor_coef_num+1] = outval; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
372 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
373 if (error_val > 0) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
374 int predictor_num = predictor_coef_num - 1; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
375 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
376 while (predictor_num >= 0 && error_val > 0) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
377 int val = buffer_out[0] - buffer_out[predictor_coef_num - predictor_num]; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
378 int sign = SIGN_ONLY(val); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
379 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
380 predictor_coef_table[predictor_num] -= sign; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
381 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
382 val *= sign; /* absolute value */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
383 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
384 error_val -= ((val >> predictor_quantitization) * |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
385 (predictor_coef_num - predictor_num)); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
386 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
387 predictor_num--; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
388 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
389 } else if (error_val < 0) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
390 int predictor_num = predictor_coef_num - 1; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
391 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
392 while (predictor_num >= 0 && error_val < 0) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
393 int val = buffer_out[0] - buffer_out[predictor_coef_num - predictor_num]; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
394 int sign = - SIGN_ONLY(val); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
395 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
396 predictor_coef_table[predictor_num] -= sign; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
397 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
398 val *= sign; /* neg value */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
399 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
400 error_val -= ((val >> predictor_quantitization) * |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
401 (predictor_coef_num - predictor_num)); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
402 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
403 predictor_num--; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
404 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
405 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
406 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
407 buffer_out++; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
408 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
409 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
410 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
411 |
3347
82277c821113
Add const to (mostly) char* and make some functions static, which aren't used
diego
parents:
3303
diff
changeset
|
412 static void deinterlace_16(int32_t *buffer_a, int32_t *buffer_b, |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
413 int16_t *buffer_out, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
414 int numchannels, int numsamples, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
415 uint8_t interlacing_shift, |
2543
e8f1f57215ad
do not use a variable before proper initialization
melanson
parents:
2542
diff
changeset
|
416 uint8_t interlacing_leftweight) |
e8f1f57215ad
do not use a variable before proper initialization
melanson
parents:
2542
diff
changeset
|
417 { |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
418 int i; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
419 if (numsamples <= 0) return; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
420 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
421 /* weighted interlacing */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
422 if (interlacing_leftweight) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
423 for (i = 0; i < numsamples; i++) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
424 int32_t difference, midright; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
425 int16_t left; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
426 int16_t right; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
427 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
428 midright = buffer_a[i]; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
429 difference = buffer_b[i]; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
430 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
431 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
432 right = midright - ((difference * interlacing_leftweight) >> interlacing_shift); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
433 left = (midright - ((difference * interlacing_leftweight) >> interlacing_shift)) |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
434 + difference; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
435 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
436 buffer_out[i*numchannels] = left; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
437 buffer_out[i*numchannels + 1] = right; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
438 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
439 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
440 return; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
441 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
442 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
443 /* otherwise basic interlacing took place */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
444 for (i = 0; i < numsamples; i++) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
445 int16_t left, right; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
446 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
447 left = buffer_a[i]; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
448 right = buffer_b[i]; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
449 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
450 buffer_out[i*numchannels] = left; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
451 buffer_out[i*numchannels + 1] = right; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
452 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
453 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
454 |
2544
8c426f5a09ae
decoder works fine now, when fed properly-sized chunks by the demuxer;
melanson
parents:
2543
diff
changeset
|
455 static int alac_decode_frame(AVCodecContext *avctx, |
8c426f5a09ae
decoder works fine now, when fed properly-sized chunks by the demuxer;
melanson
parents:
2543
diff
changeset
|
456 void *outbuffer, int *outputsize, |
8c426f5a09ae
decoder works fine now, when fed properly-sized chunks by the demuxer;
melanson
parents:
2543
diff
changeset
|
457 uint8_t *inbuffer, int input_buffer_size) |
2543
e8f1f57215ad
do not use a variable before proper initialization
melanson
parents:
2542
diff
changeset
|
458 { |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
459 ALACContext *alac = avctx->priv_data; |
2544
8c426f5a09ae
decoder works fine now, when fed properly-sized chunks by the demuxer;
melanson
parents:
2543
diff
changeset
|
460 |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
461 int channels; |
2543
e8f1f57215ad
do not use a variable before proper initialization
melanson
parents:
2542
diff
changeset
|
462 int32_t outputsamples; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
463 |
2544
8c426f5a09ae
decoder works fine now, when fed properly-sized chunks by the demuxer;
melanson
parents:
2543
diff
changeset
|
464 /* short-circuit null buffers */ |
8c426f5a09ae
decoder works fine now, when fed properly-sized chunks by the demuxer;
melanson
parents:
2543
diff
changeset
|
465 if (!inbuffer || !input_buffer_size) |
8c426f5a09ae
decoder works fine now, when fed properly-sized chunks by the demuxer;
melanson
parents:
2543
diff
changeset
|
466 return input_buffer_size; |
8c426f5a09ae
decoder works fine now, when fed properly-sized chunks by the demuxer;
melanson
parents:
2543
diff
changeset
|
467 |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
468 /* initialize from the extradata */ |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
469 if (!alac->context_initialized) { |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
470 if (alac->avctx->extradata_size != ALAC_EXTRADATA_SIZE) { |
3135 | 471 av_log(avctx, AV_LOG_ERROR, "alac: expected %d extradata bytes\n", |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
472 ALAC_EXTRADATA_SIZE); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
473 return input_buffer_size; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
474 } |
4226
43ebe9279fa0
fix some potential security issues, patch by Matthias Hopf, mat at mshopf dot de
bcoudurier
parents:
3947
diff
changeset
|
475 if (alac_set_info(alac)) { |
43ebe9279fa0
fix some potential security issues, patch by Matthias Hopf, mat at mshopf dot de
bcoudurier
parents:
3947
diff
changeset
|
476 av_log(avctx, AV_LOG_ERROR, "alac: set_info failed\n"); |
43ebe9279fa0
fix some potential security issues, patch by Matthias Hopf, mat at mshopf dot de
bcoudurier
parents:
3947
diff
changeset
|
477 return input_buffer_size; |
43ebe9279fa0
fix some potential security issues, patch by Matthias Hopf, mat at mshopf dot de
bcoudurier
parents:
3947
diff
changeset
|
478 } |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
479 alac->context_initialized = 1; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
480 } |
2543
e8f1f57215ad
do not use a variable before proper initialization
melanson
parents:
2542
diff
changeset
|
481 |
e8f1f57215ad
do not use a variable before proper initialization
melanson
parents:
2542
diff
changeset
|
482 outputsamples = alac->setinfo_max_samples_per_frame; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
483 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
484 init_get_bits(&alac->gb, inbuffer, input_buffer_size * 8); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
485 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
486 channels = get_bits(&alac->gb, 3); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
487 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
488 *outputsize = outputsamples * alac->bytespersample; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
489 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
490 switch(channels) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
491 case 0: { /* 1 channel */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
492 int hassize; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
493 int isnotcompressed; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
494 int readsamplesize; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
495 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
496 int wasted_bytes; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
497 int ricemodifier; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
498 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
499 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
500 /* 2^result = something to do with output waiting. |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
501 * perhaps matters if we read > 1 frame in a pass? |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
502 */ |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
503 get_bits(&alac->gb, 4); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
504 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
505 get_bits(&alac->gb, 12); /* unknown, skip 12 bits */ |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
506 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
507 hassize = get_bits(&alac->gb, 1); /* the output sample size is stored soon */ |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
508 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
509 wasted_bytes = get_bits(&alac->gb, 2); /* unknown ? */ |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
510 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
511 isnotcompressed = get_bits(&alac->gb, 1); /* whether the frame is compressed */ |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
512 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
513 if (hassize) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
514 /* now read the number of samples, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
515 * as a 32bit integer */ |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
516 outputsamples = get_bits(&alac->gb, 32); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
517 *outputsize = outputsamples * alac->bytespersample; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
518 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
519 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
520 readsamplesize = alac->setinfo_sample_size - (wasted_bytes * 8); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
521 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
522 if (!isnotcompressed) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
523 /* so it is compressed */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
524 int16_t predictor_coef_table[32]; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
525 int predictor_coef_num; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
526 int prediction_type; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
527 int prediction_quantitization; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
528 int i; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
529 |
3135 | 530 /* FIXME: skip 16 bits, not sure what they are. seem to be used in |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
531 * two channel case */ |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
532 get_bits(&alac->gb, 8); |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
533 get_bits(&alac->gb, 8); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
534 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
535 prediction_type = get_bits(&alac->gb, 4); |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
536 prediction_quantitization = get_bits(&alac->gb, 4); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
537 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
538 ricemodifier = get_bits(&alac->gb, 3); |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
539 predictor_coef_num = get_bits(&alac->gb, 5); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
540 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
541 /* read the predictor table */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
542 for (i = 0; i < predictor_coef_num; i++) { |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
543 predictor_coef_table[i] = (int16_t)get_bits(&alac->gb, 16); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
544 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
545 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
546 if (wasted_bytes) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
547 /* these bytes seem to have something to do with |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
548 * > 2 channel files. |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
549 */ |
3135 | 550 av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented, unhandling of wasted_bytes\n"); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
551 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
552 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
553 bastardized_rice_decompress(alac, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
554 alac->predicterror_buffer_a, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
555 outputsamples, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
556 readsamplesize, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
557 alac->setinfo_rice_initialhistory, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
558 alac->setinfo_rice_kmodifier, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
559 ricemodifier * alac->setinfo_rice_historymult / 4, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
560 (1 << alac->setinfo_rice_kmodifier) - 1); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
561 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
562 if (prediction_type == 0) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
563 /* adaptive fir */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
564 predictor_decompress_fir_adapt(alac->predicterror_buffer_a, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
565 alac->outputsamples_buffer_a, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
566 outputsamples, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
567 readsamplesize, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
568 predictor_coef_table, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
569 predictor_coef_num, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
570 prediction_quantitization); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
571 } else { |
3135 | 572 av_log(avctx, AV_LOG_ERROR, "FIXME: unhandled prediction type: %i\n", prediction_type); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
573 /* i think the only other prediction type (or perhaps this is just a |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
574 * boolean?) runs adaptive fir twice.. like: |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
575 * predictor_decompress_fir_adapt(predictor_error, tempout, ...) |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
576 * predictor_decompress_fir_adapt(predictor_error, outputsamples ...) |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
577 * little strange.. |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
578 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
579 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
580 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
581 } else { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
582 /* not compressed, easy case */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
583 if (readsamplesize <= 16) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
584 int i; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
585 for (i = 0; i < outputsamples; i++) { |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
586 int32_t audiobits = get_bits(&alac->gb, readsamplesize); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
587 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
588 audiobits = SIGN_EXTENDED32(audiobits, readsamplesize); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
589 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
590 alac->outputsamples_buffer_a[i] = audiobits; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
591 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
592 } else { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
593 int i; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
594 for (i = 0; i < outputsamples; i++) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
595 int32_t audiobits; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
596 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
597 audiobits = get_bits(&alac->gb, 16); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
598 /* special case of sign extension.. |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
599 * as we'll be ORing the low 16bits into this */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
600 audiobits = audiobits << 16; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
601 audiobits = audiobits >> (32 - readsamplesize); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
602 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
603 audiobits |= get_bits(&alac->gb, readsamplesize - 16); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
604 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
605 alac->outputsamples_buffer_a[i] = audiobits; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
606 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
607 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
608 /* wasted_bytes = 0; // unused */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
609 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
610 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
611 switch(alac->setinfo_sample_size) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
612 case 16: { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
613 int i; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
614 for (i = 0; i < outputsamples; i++) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
615 int16_t sample = alac->outputsamples_buffer_a[i]; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
616 ((int16_t*)outbuffer)[i * alac->numchannels] = sample; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
617 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
618 break; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
619 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
620 case 20: |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
621 case 24: |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
622 case 32: |
3135 | 623 av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented sample size %i\n", alac->setinfo_sample_size); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
624 break; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
625 default: |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
626 break; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
627 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
628 break; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
629 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
630 case 1: { /* 2 channels */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
631 int hassize; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
632 int isnotcompressed; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
633 int readsamplesize; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
634 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
635 int wasted_bytes; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
636 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
637 uint8_t interlacing_shift; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
638 uint8_t interlacing_leftweight; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
639 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
640 /* 2^result = something to do with output waiting. |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
641 * perhaps matters if we read > 1 frame in a pass? |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
642 */ |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
643 get_bits(&alac->gb, 4); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
644 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
645 get_bits(&alac->gb, 12); /* unknown, skip 12 bits */ |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
646 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
647 hassize = get_bits(&alac->gb, 1); /* the output sample size is stored soon */ |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
648 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
649 wasted_bytes = get_bits(&alac->gb, 2); /* unknown ? */ |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
650 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
651 isnotcompressed = get_bits(&alac->gb, 1); /* whether the frame is compressed */ |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
652 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
653 if (hassize) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
654 /* now read the number of samples, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
655 * as a 32bit integer */ |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
656 outputsamples = get_bits(&alac->gb, 32); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
657 *outputsize = outputsamples * alac->bytespersample; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
658 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
659 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
660 readsamplesize = alac->setinfo_sample_size - (wasted_bytes * 8) + 1; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
661 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
662 if (!isnotcompressed) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
663 /* compressed */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
664 int16_t predictor_coef_table_a[32]; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
665 int predictor_coef_num_a; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
666 int prediction_type_a; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
667 int prediction_quantitization_a; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
668 int ricemodifier_a; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
669 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
670 int16_t predictor_coef_table_b[32]; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
671 int predictor_coef_num_b; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
672 int prediction_type_b; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
673 int prediction_quantitization_b; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
674 int ricemodifier_b; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
675 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
676 int i; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
677 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
678 interlacing_shift = get_bits(&alac->gb, 8); |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
679 interlacing_leftweight = get_bits(&alac->gb, 8); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
680 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
681 /******** channel 1 ***********/ |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
682 prediction_type_a = get_bits(&alac->gb, 4); |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
683 prediction_quantitization_a = get_bits(&alac->gb, 4); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
684 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
685 ricemodifier_a = get_bits(&alac->gb, 3); |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
686 predictor_coef_num_a = get_bits(&alac->gb, 5); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
687 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
688 /* read the predictor table */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
689 for (i = 0; i < predictor_coef_num_a; i++) { |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
690 predictor_coef_table_a[i] = (int16_t)get_bits(&alac->gb, 16); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
691 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
692 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
693 /******** channel 2 *********/ |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
694 prediction_type_b = get_bits(&alac->gb, 4); |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
695 prediction_quantitization_b = get_bits(&alac->gb, 4); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
696 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
697 ricemodifier_b = get_bits(&alac->gb, 3); |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
698 predictor_coef_num_b = get_bits(&alac->gb, 5); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
699 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
700 /* read the predictor table */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
701 for (i = 0; i < predictor_coef_num_b; i++) { |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
702 predictor_coef_table_b[i] = (int16_t)get_bits(&alac->gb, 16); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
703 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
704 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
705 /*********************/ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
706 if (wasted_bytes) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
707 /* see mono case */ |
3135 | 708 av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented, unhandling of wasted_bytes\n"); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
709 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
710 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
711 /* channel 1 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
712 bastardized_rice_decompress(alac, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
713 alac->predicterror_buffer_a, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
714 outputsamples, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
715 readsamplesize, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
716 alac->setinfo_rice_initialhistory, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
717 alac->setinfo_rice_kmodifier, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
718 ricemodifier_a * alac->setinfo_rice_historymult / 4, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
719 (1 << alac->setinfo_rice_kmodifier) - 1); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
720 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
721 if (prediction_type_a == 0) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
722 /* adaptive fir */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
723 predictor_decompress_fir_adapt(alac->predicterror_buffer_a, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
724 alac->outputsamples_buffer_a, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
725 outputsamples, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
726 readsamplesize, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
727 predictor_coef_table_a, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
728 predictor_coef_num_a, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
729 prediction_quantitization_a); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
730 } else { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
731 /* see mono case */ |
3135 | 732 av_log(avctx, AV_LOG_ERROR, "FIXME: unhandled prediction type: %i\n", prediction_type_a); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
733 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
734 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
735 /* channel 2 */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
736 bastardized_rice_decompress(alac, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
737 alac->predicterror_buffer_b, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
738 outputsamples, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
739 readsamplesize, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
740 alac->setinfo_rice_initialhistory, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
741 alac->setinfo_rice_kmodifier, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
742 ricemodifier_b * alac->setinfo_rice_historymult / 4, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
743 (1 << alac->setinfo_rice_kmodifier) - 1); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
744 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
745 if (prediction_type_b == 0) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
746 /* adaptive fir */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
747 predictor_decompress_fir_adapt(alac->predicterror_buffer_b, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
748 alac->outputsamples_buffer_b, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
749 outputsamples, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
750 readsamplesize, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
751 predictor_coef_table_b, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
752 predictor_coef_num_b, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
753 prediction_quantitization_b); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
754 } else { |
3135 | 755 av_log(avctx, AV_LOG_ERROR, "FIXME: unhandled prediction type: %i\n", prediction_type_b); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
756 } |
2967 | 757 } else { |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
758 /* not compressed, easy case */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
759 if (alac->setinfo_sample_size <= 16) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
760 int i; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
761 for (i = 0; i < outputsamples; i++) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
762 int32_t audiobits_a, audiobits_b; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
763 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
764 audiobits_a = get_bits(&alac->gb, alac->setinfo_sample_size); |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
765 audiobits_b = get_bits(&alac->gb, alac->setinfo_sample_size); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
766 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
767 audiobits_a = SIGN_EXTENDED32(audiobits_a, alac->setinfo_sample_size); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
768 audiobits_b = SIGN_EXTENDED32(audiobits_b, alac->setinfo_sample_size); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
769 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
770 alac->outputsamples_buffer_a[i] = audiobits_a; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
771 alac->outputsamples_buffer_b[i] = audiobits_b; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
772 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
773 } else { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
774 int i; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
775 for (i = 0; i < outputsamples; i++) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
776 int32_t audiobits_a, audiobits_b; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
777 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
778 audiobits_a = get_bits(&alac->gb, 16); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
779 audiobits_a = audiobits_a << 16; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
780 audiobits_a = audiobits_a >> (32 - alac->setinfo_sample_size); |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
781 audiobits_a |= get_bits(&alac->gb, alac->setinfo_sample_size - 16); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
782 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
783 audiobits_b = get_bits(&alac->gb, 16); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
784 audiobits_b = audiobits_b << 16; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
785 audiobits_b = audiobits_b >> (32 - alac->setinfo_sample_size); |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
786 audiobits_b |= get_bits(&alac->gb, alac->setinfo_sample_size - 16); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
787 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
788 alac->outputsamples_buffer_a[i] = audiobits_a; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
789 alac->outputsamples_buffer_b[i] = audiobits_b; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
790 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
791 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
792 /* wasted_bytes = 0; */ |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
793 interlacing_shift = 0; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
794 interlacing_leftweight = 0; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
795 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
796 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
797 switch(alac->setinfo_sample_size) { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
798 case 16: { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
799 deinterlace_16(alac->outputsamples_buffer_a, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
800 alac->outputsamples_buffer_b, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
801 (int16_t*)outbuffer, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
802 alac->numchannels, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
803 outputsamples, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
804 interlacing_shift, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
805 interlacing_leftweight); |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
806 break; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
807 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
808 case 20: |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
809 case 24: |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
810 case 32: |
3135 | 811 av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented sample size %i\n", alac->setinfo_sample_size); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
812 break; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
813 default: |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
814 break; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
815 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
816 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
817 break; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
818 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
819 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
820 |
2544
8c426f5a09ae
decoder works fine now, when fed properly-sized chunks by the demuxer;
melanson
parents:
2543
diff
changeset
|
821 return input_buffer_size; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
822 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
823 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
824 static int alac_decode_init(AVCodecContext * avctx) |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
825 { |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
826 ALACContext *alac = avctx->priv_data; |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
827 alac->avctx = avctx; |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
828 alac->context_initialized = 0; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
829 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
830 alac->samplesize = alac->avctx->bits_per_sample; |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
831 alac->numchannels = alac->avctx->channels; |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
832 alac->bytespersample = (alac->samplesize / 8) * alac->numchannels; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
833 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
834 return 0; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
835 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
836 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
837 static int alac_decode_close(AVCodecContext *avctx) |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
838 { |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
839 ALACContext *alac = avctx->priv_data; |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
840 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
841 av_free(alac->predicterror_buffer_a); |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
842 av_free(alac->predicterror_buffer_b); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
843 |
2559
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
844 av_free(alac->outputsamples_buffer_a); |
7d8ba28e18d9
replace custom bit-reading functions with FFmpeg's internal function;
melanson
parents:
2546
diff
changeset
|
845 av_free(alac->outputsamples_buffer_b); |
2542
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
846 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
847 return 0; |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
848 } |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
849 |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
850 AVCodec alac_decoder = { |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
851 "alac", |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
852 CODEC_TYPE_AUDIO, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
853 CODEC_ID_ALAC, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
854 sizeof(ALACContext), |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
855 alac_decode_init, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
856 NULL, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
857 alac_decode_close, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
858 alac_decode_frame, |
a27a580f292e
first pass at ALAC decoder from David Hammerton; while David's original
melanson
parents:
diff
changeset
|
859 }; |