Mercurial > audlegacy-plugins
annotate src/tta/ttadec.c @ 912:5bd17596c7e9 trunk
[svn] - patches from upstream TTA author. see http://boards.nenolod.net/viewtopic.php?t=375
author | nenolod |
---|---|
date | Wed, 04 Apr 2007 10:52:15 -0700 |
parents | c0f69d57483b |
children | d0d99b22e393 |
rev | line source |
---|---|
290 | 1 /* |
2 * ttadec.c | |
3 * | |
4 * Description: TTAv1 decoder library for HW players. | |
5 * Developed by: Alexander Djourik <sasha@iszf.irk.ru> | |
6 * Pavel Zhilin <pzh@iszf.irk.ru> | |
7 * | |
8 * Copyright (c) 1999-2004 Alexander Djourik. All rights reserved. | |
9 * | |
10 */ | |
11 | |
12 /* | |
13 * This library is free software; you can redistribute it and/or | |
14 * modify it under the terms of the GNU Lesser General Public | |
15 * License as published by the Free Software Foundation; either | |
16 * version 2.1 of the License, or (at your option) any later version. | |
17 * | |
18 * This library is distributed in the hope that it will be useful, | |
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
21 * Lesser General Public License for more details. | |
22 * | |
23 * You should have received a copy of the GNU Lesser General Public | |
24 * License along with this library; if not, write to the Free Software | |
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
26 * | |
27 * Please see the file COPYING in this directory for full copyright | |
28 * information. | |
29 */ | |
30 | |
31 #include <stdlib.h> | |
32 #include <stdio.h> | |
33 #include <string.h> | |
34 | |
912
5bd17596c7e9
[svn] - patches from upstream TTA author. see http://boards.nenolod.net/viewtopic.php?t=375
nenolod
parents:
551
diff
changeset
|
35 #include "ttadec.h" |
290 | 36 #include "ttalib.h" |
37 #include "crc32.h" | |
38 #include "filters.h" | |
39 | |
40 /******************* static variables and structures *******************/ | |
41 | |
42 static unsigned char isobuffers[ISO_BUFFERS_SIZE + 4]; | |
43 static unsigned char *iso_buffers_end = isobuffers + ISO_BUFFERS_SIZE; | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
44 static unsigned int pcm_buffer_size; |
290 | 45 |
46 static decoder tta[MAX_NCH]; // decoder state | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
47 static int cache[MAX_NCH]; // decoder cache |
290 | 48 |
49 tta_info *ttainfo; // currently playing file info | |
50 | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
51 static unsigned int fframes; // number of frames in file |
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
52 static unsigned int framelen; // the frame length in samples |
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
53 static unsigned int lastlen; // the length of the last frame in samples |
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
54 static unsigned int data_pos; // currently playing frame index |
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
55 static unsigned int data_cur; // the playing position in frame |
290 | 56 |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
57 static int maxvalue; // output data max value |
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
58 static unsigned int *seek_table; // the playing position table |
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
59 static unsigned int st_state; //seek table status |
290 | 60 |
912
5bd17596c7e9
[svn] - patches from upstream TTA author. see http://boards.nenolod.net/viewtopic.php?t=375
nenolod
parents:
551
diff
changeset
|
61 static __uint32_t frame_crc32; |
5bd17596c7e9
[svn] - patches from upstream TTA author. see http://boards.nenolod.net/viewtopic.php?t=375
nenolod
parents:
551
diff
changeset
|
62 static __uint32_t bit_count; |
5bd17596c7e9
[svn] - patches from upstream TTA author. see http://boards.nenolod.net/viewtopic.php?t=375
nenolod
parents:
551
diff
changeset
|
63 static __uint32_t bit_cache; |
290 | 64 static unsigned char *bitpos; |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
65 static unsigned int bitrate; |
290 | 66 |
67 void get_id3v1_tag (tta_info *ttainfo); | |
68 int get_id3v2_tag (tta_info *ttainfo); | |
69 | |
70 /************************* bit operations ******************************/ | |
71 | |
72 static void init_buffer_read() { | |
73 frame_crc32 = 0xFFFFFFFFUL; | |
74 bit_count = bit_cache = 0; | |
75 bitpos = iso_buffers_end; | |
76 } | |
77 | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
78 __inline void get_binary(unsigned int *value, unsigned int bits) { |
290 | 79 while (bit_count < bits) { |
80 if (bitpos == iso_buffers_end) { | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
81 int res = fread(isobuffers, 1, |
290 | 82 ISO_BUFFERS_SIZE, ttainfo->HANDLE); |
83 if (!res) { | |
84 ttainfo->STATE = READ_ERROR; | |
85 return; | |
86 } | |
87 bitpos = isobuffers; | |
88 } | |
89 | |
90 UPDATE_CRC32(*bitpos, frame_crc32); | |
91 bit_cache |= *bitpos << bit_count; | |
92 bit_count += 8; | |
93 bitpos++; | |
94 } | |
95 | |
96 *value = bit_cache & bit_mask[bits]; | |
97 bit_cache >>= bits; | |
98 bit_count -= bits; | |
99 bit_cache &= bit_mask[bit_count]; | |
100 } | |
101 | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
102 __inline void get_unary(unsigned int *value) { |
290 | 103 *value = 0; |
104 | |
105 while (!(bit_cache ^ bit_mask[bit_count])) { | |
106 if (bitpos == iso_buffers_end) { | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
107 int res = fread(isobuffers, 1, |
290 | 108 ISO_BUFFERS_SIZE, ttainfo->HANDLE); |
109 if (!res) { | |
110 ttainfo->STATE = READ_ERROR; | |
111 return; | |
112 } | |
113 bitpos = isobuffers; | |
114 } | |
115 | |
116 *value += bit_count; | |
117 bit_cache = *bitpos++; | |
118 UPDATE_CRC32(bit_cache, frame_crc32); | |
119 bit_count = 8; | |
120 } | |
121 | |
122 while (bit_cache & 1) { | |
123 (*value)++; | |
124 bit_cache >>= 1; | |
125 bit_count--; | |
126 } | |
127 | |
128 bit_cache >>= 1; | |
129 bit_count--; | |
130 } | |
131 | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
132 static int done_buffer_read() { |
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
133 unsigned int crc32, rbytes, res; |
290 | 134 frame_crc32 ^= 0xFFFFFFFFUL; |
135 | |
136 rbytes = iso_buffers_end - bitpos; | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
137 if (rbytes < sizeof(int)) { |
290 | 138 memcpy(isobuffers, bitpos, 4); |
139 res = fread(isobuffers + rbytes, 1, | |
140 ISO_BUFFERS_SIZE - rbytes, ttainfo->HANDLE); | |
141 if (!res) { | |
142 ttainfo->STATE = READ_ERROR; | |
143 return 0; | |
144 } | |
145 bitpos = isobuffers; | |
146 } | |
147 | |
148 memcpy(&crc32, bitpos, 4); | |
149 crc32 = ENDSWAP_INT32(crc32); | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
150 bitpos += sizeof(int); |
290 | 151 res = (crc32 != frame_crc32); |
152 | |
153 bit_cache = bit_count = 0; | |
154 frame_crc32 = 0xFFFFFFFFUL; | |
155 | |
156 // calculate dynamic bitrate | |
157 if (data_pos < fframes) { | |
158 rbytes = seek_table[data_pos] - | |
159 seek_table[data_pos - 1]; | |
160 bitrate = (rbytes << 3) / 1070; | |
161 } | |
162 | |
163 return res; | |
164 } | |
165 | |
166 /************************* decoder functions ****************************/ | |
167 | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
168 static int skip_id3v2_header (FILE *infile) { |
290 | 169 struct { |
170 unsigned char id[3]; | |
171 unsigned short version; | |
172 unsigned char flags; | |
173 unsigned char size[4]; | |
174 } __ATTRIBUTE_PACKED__ id3v2; | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
175 unsigned int len = 0; |
290 | 176 |
177 // read ID3V2 header | |
178 if (fread (&id3v2, sizeof(id3v2), 1, infile) == 0) { | |
179 fclose (infile); | |
180 ttainfo->STATE = READ_ERROR; | |
181 return -1; | |
182 } | |
183 | |
184 // skip ID3V2 header | |
185 if (!memcmp (id3v2.id, "ID3", 3)) { | |
186 if (id3v2.size[0] & 0x80) { | |
187 fclose (infile); | |
188 ttainfo->STATE = FILE_ERROR; | |
189 return FILE_ERROR; | |
190 } | |
191 len = (id3v2.size[0] & 0x7f); | |
192 len = (len << 7) | (id3v2.size[1] & 0x7f); | |
193 len = (len << 7) | (id3v2.size[2] & 0x7f); | |
194 len = (len << 7) | (id3v2.size[3] & 0x7f); | |
195 len += 10; | |
196 if (id3v2.flags & (1 << 4)) len += 10; | |
197 fseek (infile, len, SEEK_SET); | |
198 } else fseek (infile, 0, SEEK_SET); | |
199 | |
200 return len; | |
201 } | |
202 | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
203 int open_tta_file (const char *filename, tta_info *info, unsigned int data_offset) { |
290 | 204 FILE *infile; |
205 tta_hdr ttahdr; | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
206 unsigned int checksum; |
290 | 207 |
208 // clear the memory | |
209 memset (info, 0, sizeof(tta_info)); | |
210 | |
211 // printf("0: open_tta_file\n"); | |
212 info->HANDLE = infile = fopen(filename, "rb"); | |
213 if (!infile) return OPEN_ERROR; | |
214 | |
215 // printf("1: data_offset %ld\n", data_offset); | |
216 // read id3v2 header | |
217 if (!data_offset) { | |
218 // data_offset = skip_id3v2_header(infile); | |
219 // data_offset = get_id3v2_tag(info); | |
220 data_offset = skip_v2_header(info); | |
221 // printf("2: data_offset %ld\n", data_offset); | |
222 // get_id3v1_tag (info); | |
223 if (data_offset < 0) return -1; | |
224 } else fseek (infile, data_offset, SEEK_SET); | |
225 | |
226 get_id3_tags (filename, info); | |
227 | |
228 // read TTA header | |
229 if (fread (&ttahdr, 1, sizeof (ttahdr), infile) == 0) { | |
230 fclose (infile); | |
231 info->STATE = READ_ERROR; | |
232 return -1; | |
233 } | |
234 | |
235 // check for TTA3 signature | |
236 if (ENDSWAP_INT32(ttahdr.TTAid) != TTA1_SIGN) { | |
237 fclose (infile); | |
238 info->STATE = FORMAT_ERROR; | |
239 return -1; | |
240 } | |
241 | |
242 ttahdr.CRC32 = ENDSWAP_INT32(ttahdr.CRC32); | |
243 checksum = crc32((unsigned char *) &ttahdr, | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
244 sizeof(tta_hdr) - sizeof(int)); |
290 | 245 if (checksum != ttahdr.CRC32) { |
246 fclose (infile); | |
247 info->STATE = FILE_ERROR; | |
248 return -1; | |
249 } | |
250 | |
251 ttahdr.AudioFormat = ENDSWAP_INT16(ttahdr.AudioFormat); | |
252 ttahdr.NumChannels = ENDSWAP_INT16(ttahdr.NumChannels); | |
253 ttahdr.BitsPerSample = ENDSWAP_INT16(ttahdr.BitsPerSample); | |
254 ttahdr.SampleRate = ENDSWAP_INT32(ttahdr.SampleRate); | |
255 ttahdr.DataLength = ENDSWAP_INT32(ttahdr.DataLength); | |
256 | |
257 // check for player supported formats | |
258 if (ttahdr.AudioFormat != WAVE_FORMAT_PCM || | |
259 ttahdr.NumChannels > MAX_NCH || | |
260 ttahdr.BitsPerSample > MAX_BPS ||( | |
261 ttahdr.SampleRate != 16000 && | |
262 ttahdr.SampleRate != 22050 && | |
263 ttahdr.SampleRate != 24000 && | |
264 ttahdr.SampleRate != 32000 && | |
265 ttahdr.SampleRate != 44100 && | |
266 ttahdr.SampleRate != 48000 && | |
267 ttahdr.SampleRate != 64000 && | |
268 ttahdr.SampleRate != 88200 && | |
269 ttahdr.SampleRate != 96000)) { | |
270 fclose (infile); | |
271 info->STATE = FORMAT_ERROR; | |
272 return FORMAT_ERROR; | |
273 } | |
274 | |
275 // fill the File Info | |
276 info->HANDLE = infile; | |
277 info->NCH = ttahdr.NumChannels; | |
278 info->BPS = ttahdr.BitsPerSample; | |
279 info->BSIZE = (ttahdr.BitsPerSample + 7)/8; | |
280 info->FORMAT = ttahdr.AudioFormat; | |
281 info->SAMPLERATE = ttahdr.SampleRate; | |
282 info->DATALENGTH = ttahdr.DataLength; | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
283 info->FRAMELEN = (int) (FRAME_TIME * ttahdr.SampleRate); |
290 | 284 info->LENGTH = ttahdr.DataLength / ttahdr.SampleRate; |
285 info->DATAPOS = data_offset; | |
286 | |
287 | |
288 return 0; | |
289 } | |
290 | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
291 static void rice_init(adapt *rice, unsigned int k0, unsigned int k1) { |
290 | 292 rice->k0 = k0; |
293 rice->k1 = k1; | |
294 rice->sum0 = shift_16[k0]; | |
295 rice->sum1 = shift_16[k1]; | |
296 } | |
297 | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
298 static void decoder_init(decoder *tta, int nch, int byte_size) { |
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
299 int shift = flt_set[byte_size - 1]; |
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
300 int i; |
290 | 301 |
302 for (i = 0; i < nch; i++) { | |
303 filter_init(&tta[i].fst, shift); | |
304 rice_init(&tta[i].rice, 10, 10); | |
305 tta[i].last = 0; | |
306 } | |
307 } | |
308 | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
309 static void seek_table_init (unsigned int *seek_table, |
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
310 unsigned int len, unsigned int data_offset) { |
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
311 unsigned int *st, frame_len; |
290 | 312 |
313 for (st = seek_table; st < (seek_table + len); st++) { | |
314 frame_len = ENDSWAP_INT32(*st); | |
315 *st = data_offset; | |
316 data_offset += frame_len; | |
317 } | |
318 } | |
319 | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
320 int set_position (unsigned int pos) { |
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
321 unsigned int seek_pos; |
290 | 322 |
323 if (pos >= fframes) return 0; | |
324 if (!st_state) { | |
325 ttainfo->STATE = FILE_ERROR; | |
326 return -1; | |
327 } | |
328 | |
329 seek_pos = ttainfo->DATAPOS + seek_table[data_pos = pos]; | |
330 fseek(ttainfo->HANDLE, seek_pos, SEEK_SET); | |
331 | |
332 data_cur = 0; | |
333 framelen = 0; | |
334 | |
335 // init bit reader | |
336 init_buffer_read(); | |
337 | |
338 return 0; | |
339 } | |
340 | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
341 int player_init (tta_info *info) { |
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
342 unsigned int checksum; |
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
343 unsigned int data_offset; |
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
344 unsigned int st_size; |
290 | 345 |
346 ttainfo = info; | |
347 | |
348 framelen = 0; | |
349 data_pos = 0; | |
350 data_cur = 0; | |
351 bitrate = 0; | |
352 | |
353 lastlen = ttainfo->DATALENGTH % ttainfo->FRAMELEN; | |
354 fframes = ttainfo->DATALENGTH / ttainfo->FRAMELEN + (lastlen ? 1:0); | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
355 st_size = (fframes + 1) * sizeof(int); |
290 | 356 |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
357 seek_table = (unsigned int *) malloc(st_size); |
290 | 358 if (!seek_table) { |
359 ttainfo->STATE = MEMORY_ERROR; | |
360 return -1; | |
361 } | |
362 | |
363 // read seek table | |
364 if (!fread(seek_table, st_size, 1, ttainfo->HANDLE)) { | |
365 ttainfo->STATE = READ_ERROR; | |
366 return -1; | |
367 } | |
368 | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
369 checksum = crc32((unsigned char *) seek_table, st_size - sizeof(int)); |
290 | 370 st_state = (checksum == ENDSWAP_INT32(seek_table[fframes])); |
371 data_offset = sizeof(tta_hdr) + st_size; | |
372 | |
373 // init seek table | |
374 seek_table_init(seek_table, fframes, data_offset); | |
375 | |
376 // init bit reader | |
377 init_buffer_read(); | |
378 | |
379 pcm_buffer_size = PCM_BUFFER_LENGTH * ttainfo->BSIZE * ttainfo->NCH; | |
380 maxvalue = (1UL << ttainfo->BPS) - 1; | |
381 | |
382 return 0; | |
383 } | |
384 | |
385 void close_tta_file (tta_info *info) { | |
386 if (info->HANDLE) { | |
387 fclose (info->HANDLE); | |
388 info->HANDLE = NULL; | |
389 } | |
390 } | |
391 | |
392 void player_stop () { | |
393 if (seek_table) { | |
394 free(seek_table); | |
395 seek_table = NULL; | |
396 } | |
397 } | |
398 | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
399 int get_bitrate () { |
290 | 400 return bitrate; |
401 } | |
402 | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
403 int get_samples (byte *buffer) { |
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
404 unsigned int k, depth, unary, binary; |
290 | 405 byte *p = buffer; |
406 decoder *dec = tta; | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
407 int *prev = cache; |
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
408 int value, res; |
290 | 409 |
410 for (res = 0; p < buffer + pcm_buffer_size;) { | |
411 fltst *fst = &dec->fst; | |
412 adapt *rice = &dec->rice; | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
413 int *last = &dec->last; |
290 | 414 |
415 if (data_cur == framelen) { | |
416 if (data_pos == fframes) break; | |
417 if (framelen && done_buffer_read()) { | |
418 if (set_position(data_pos) < 0) | |
419 return -1; | |
420 if (res) break; | |
421 } | |
422 | |
423 if (data_pos == fframes - 1 && lastlen) | |
424 framelen = lastlen; | |
425 else framelen = ttainfo->FRAMELEN; | |
426 | |
427 decoder_init(tta, ttainfo->NCH, ttainfo->BSIZE); | |
428 data_pos++; data_cur = 0; | |
429 } | |
430 | |
431 // decode Rice unsigned | |
432 get_unary(&unary); | |
433 | |
434 switch (unary) { | |
435 case 0: depth = 0; k = rice->k0; break; | |
436 default: | |
437 depth = 1; k = rice->k1; | |
438 unary--; | |
439 } | |
440 | |
441 if (k) { | |
442 get_binary(&binary, k); | |
443 value = (unary << k) + binary; | |
444 } else value = unary; | |
445 | |
446 switch (depth) { | |
447 case 1: | |
448 rice->sum1 += value - (rice->sum1 >> 4); | |
449 if (rice->k1 > 0 && rice->sum1 < shift_16[rice->k1]) | |
450 rice->k1--; | |
451 else if (rice->sum1 > shift_16[rice->k1 + 1]) | |
452 rice->k1++; | |
453 value += bit_shift[rice->k0]; | |
454 default: | |
455 rice->sum0 += value - (rice->sum0 >> 4); | |
456 if (rice->k0 > 0 && rice->sum0 < shift_16[rice->k0]) | |
457 rice->k0--; | |
458 else if (rice->sum0 > shift_16[rice->k0 + 1]) | |
459 rice->k0++; | |
460 } | |
461 | |
462 value = DEC(value); | |
463 | |
464 // decompress stage 1: adaptive hybrid filter | |
465 hybrid_filter(fst, &value); | |
466 | |
467 // decompress stage 2: fixed order 1 prediction | |
468 switch (ttainfo->BSIZE) { | |
469 case 1: value += PREDICTOR1(*last, 4); break; // bps 8 | |
470 case 2: value += PREDICTOR1(*last, 5); break; // bps 16 | |
471 case 3: value += PREDICTOR1(*last, 5); break; // bps 24 | |
472 case 4: value += *last; break; // bps 32 | |
473 } *last = value; | |
474 | |
475 // check for errors | |
476 if (abs(value) > maxvalue) { | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
477 unsigned int tail = |
290 | 478 pcm_buffer_size / (ttainfo->BSIZE * ttainfo->NCH) - res; |
479 memset(buffer, 0, pcm_buffer_size); | |
480 data_cur += tail; res += tail; | |
481 break; | |
482 } | |
483 | |
484 if (dec < tta + (ttainfo->NCH - 1)) { | |
485 *prev++ = value; dec++; | |
486 } else { | |
487 *prev = value; | |
488 if (ttainfo->NCH > 1) { | |
551
c0f69d57483b
[svn] - change some references for long to int, reported by and patch by
nenolod
parents:
290
diff
changeset
|
489 int *r = prev - 1; |
290 | 490 for (*prev += *r/2; r >= cache; r--) |
491 *r = *(r + 1) - *r; | |
492 for (r = cache; r < prev; r++) | |
493 WRITE_BUFFER(r, ttainfo->BSIZE, p) | |
494 } | |
495 WRITE_BUFFER(prev, ttainfo->BSIZE, p) | |
496 prev = cache; | |
497 data_cur++; res++; | |
498 dec = tta; | |
499 } | |
500 } | |
501 | |
502 return res; | |
503 } | |
504 | |
505 /* end */ | |
506 |