Mercurial > audlegacy-plugins
comparison src/tta/ttadec.c @ 1237:0d5b0f861bf0
- quick fix for link breakage to libaudid3tag.so when --prefix is specified.
- adaptation for file:// scheme in cuesheet and tta.
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Thu, 12 Jul 2007 04:36:03 +0900 |
parents | ed2d7787779e |
children | fa9f85cebade |
comparison
equal
deleted
inserted
replaced
1236:e6c69ef37b7b | 1237:0d5b0f861bf0 |
---|---|
85 } | 85 } |
86 | 86 |
87 __inline void get_binary(unsigned int *value, unsigned int bits) { | 87 __inline void get_binary(unsigned int *value, unsigned int bits) { |
88 while (bit_count < bits) { | 88 while (bit_count < bits) { |
89 if (bitpos == iso_buffers_end) { | 89 if (bitpos == iso_buffers_end) { |
90 int res = fread(isobuffers, 1, | 90 int res = vfs_fread(isobuffers, 1, |
91 ISO_BUFFERS_SIZE, ttainfo->HANDLE); | 91 ISO_BUFFERS_SIZE, ttainfo->HANDLE); |
92 if (!res) { | 92 if (!res) { |
93 ttainfo->STATE = READ_ERROR; | 93 ttainfo->STATE = READ_ERROR; |
94 return; | 94 return; |
95 } | 95 } |
111 __inline void get_unary(unsigned int *value) { | 111 __inline void get_unary(unsigned int *value) { |
112 *value = 0; | 112 *value = 0; |
113 | 113 |
114 while (!(bit_cache ^ bit_mask[bit_count])) { | 114 while (!(bit_cache ^ bit_mask[bit_count])) { |
115 if (bitpos == iso_buffers_end) { | 115 if (bitpos == iso_buffers_end) { |
116 int res = fread(isobuffers, 1, | 116 int res = vfs_fread(isobuffers, 1, |
117 ISO_BUFFERS_SIZE, ttainfo->HANDLE); | 117 ISO_BUFFERS_SIZE, ttainfo->HANDLE); |
118 if (!res) { | 118 if (!res) { |
119 ttainfo->STATE = READ_ERROR; | 119 ttainfo->STATE = READ_ERROR; |
120 return; | 120 return; |
121 } | 121 } |
143 frame_crc32 ^= 0xFFFFFFFFUL; | 143 frame_crc32 ^= 0xFFFFFFFFUL; |
144 | 144 |
145 rbytes = iso_buffers_end - bitpos; | 145 rbytes = iso_buffers_end - bitpos; |
146 if (rbytes < sizeof(int)) { | 146 if (rbytes < sizeof(int)) { |
147 memcpy(isobuffers, bitpos, 4); | 147 memcpy(isobuffers, bitpos, 4); |
148 res = fread(isobuffers + rbytes, 1, | 148 res = vfs_fread(isobuffers + rbytes, 1, |
149 ISO_BUFFERS_SIZE - rbytes, ttainfo->HANDLE); | 149 ISO_BUFFERS_SIZE - rbytes, ttainfo->HANDLE); |
150 if (!res) { | 150 if (!res) { |
151 ttainfo->STATE = READ_ERROR; | 151 ttainfo->STATE = READ_ERROR; |
152 return 0; | 152 return 0; |
153 } | 153 } |
258 unsigned char flags; | 258 unsigned char flags; |
259 unsigned char size[4]; | 259 unsigned char size[4]; |
260 } __ATTRIBUTE_PACKED__ id3v2; | 260 } __ATTRIBUTE_PACKED__ id3v2; |
261 unsigned int len = 0; | 261 unsigned int len = 0; |
262 | 262 |
263 if (!fread(&id3v2, sizeof(id3v2), 1, ttainfo->HANDLE) || | 263 if (!vfs_fread(&id3v2, sizeof(id3v2), 1, ttainfo->HANDLE) || |
264 memcmp(id3v2.id, "ID3", 3) || | 264 memcmp(id3v2.id, "ID3", 3) || |
265 id3v2.size[0] & 0x80) | 265 id3v2.size[0] & 0x80) |
266 { | 266 { |
267 fseek (ttainfo->HANDLE, 0, SEEK_SET); | 267 fseek (ttainfo->HANDLE, 0, SEEK_SET); |
268 return 0; | 268 return 0; |
277 | 277 |
278 return len; | 278 return len; |
279 } | 279 } |
280 | 280 |
281 int open_tta_file (const char *filename, tta_info *info, unsigned int data_offset) { | 281 int open_tta_file (const char *filename, tta_info *info, unsigned int data_offset) { |
282 FILE *infile; | 282 VFSFile *infile; |
283 tta_hdr ttahdr; | 283 tta_hdr ttahdr; |
284 unsigned int checksum; | 284 unsigned int checksum; |
285 | 285 |
286 // clear the memory | 286 // clear the memory |
287 memset (info, 0, sizeof(tta_info)); | 287 memset (info, 0, sizeof(tta_info)); |
288 | 288 |
289 info->HANDLE = infile = fopen(filename, "rb"); | 289 info->HANDLE = infile = vfs_fopen(filename, "rb"); |
290 if (!infile) return OPEN_ERROR; | 290 if (!infile) return OPEN_ERROR; |
291 | 291 |
292 // read id3v2 header | 292 // read id3v2 header |
293 // if (!data_offset) | 293 // if (!data_offset) |
294 // data_offset = id3v2_header_length(info); | 294 // data_offset = id3v2_header_length(info); |
295 | 295 |
296 data_offset = get_id3_tags (filename, info); | 296 data_offset = get_id3_tags (filename, info); |
297 fseek (infile, data_offset, SEEK_SET); | 297 vfs_fseek (infile, data_offset, SEEK_SET); |
298 | 298 |
299 // read TTA header | 299 // read TTA header |
300 if (fread (&ttahdr, 1, sizeof (ttahdr), infile) == 0) { | 300 if (vfs_fread (&ttahdr, 1, sizeof (ttahdr), infile) == 0) { |
301 fclose (infile); | 301 vfs_fclose (infile); |
302 info->STATE = READ_ERROR; | 302 info->STATE = READ_ERROR; |
303 return -1; | 303 return -1; |
304 } | 304 } |
305 | 305 |
306 // check for TTA3 signature | 306 // check for TTA3 signature |
307 if (ENDSWAP_INT32(ttahdr.TTAid) != TTA1_SIGN) { | 307 if (ENDSWAP_INT32(ttahdr.TTAid) != TTA1_SIGN) { |
308 fclose (infile); | 308 vfs_fclose (infile); |
309 info->STATE = FORMAT_ERROR; | 309 info->STATE = FORMAT_ERROR; |
310 return -1; | 310 return -1; |
311 } | 311 } |
312 | 312 |
313 ttahdr.CRC32 = ENDSWAP_INT32(ttahdr.CRC32); | 313 ttahdr.CRC32 = ENDSWAP_INT32(ttahdr.CRC32); |
314 checksum = crc32((unsigned char *) &ttahdr, | 314 checksum = crc32((unsigned char *) &ttahdr, |
315 sizeof(tta_hdr) - sizeof(int)); | 315 sizeof(tta_hdr) - sizeof(int)); |
316 if (checksum != ttahdr.CRC32) { | 316 if (checksum != ttahdr.CRC32) { |
317 fclose (infile); | 317 vfs_fclose (infile); |
318 info->STATE = FILE_ERROR; | 318 info->STATE = FILE_ERROR; |
319 return -1; | 319 return -1; |
320 } | 320 } |
321 | 321 |
322 ttahdr.AudioFormat = ENDSWAP_INT16(ttahdr.AudioFormat); | 322 ttahdr.AudioFormat = ENDSWAP_INT16(ttahdr.AudioFormat); |
336 ttahdr.SampleRate != 44100 && | 336 ttahdr.SampleRate != 44100 && |
337 ttahdr.SampleRate != 48000 && | 337 ttahdr.SampleRate != 48000 && |
338 ttahdr.SampleRate != 64000 && | 338 ttahdr.SampleRate != 64000 && |
339 ttahdr.SampleRate != 88200 && | 339 ttahdr.SampleRate != 88200 && |
340 ttahdr.SampleRate != 96000)) { | 340 ttahdr.SampleRate != 96000)) { |
341 fclose (infile); | 341 vfs_fclose (infile); |
342 info->STATE = FORMAT_ERROR; | 342 info->STATE = FORMAT_ERROR; |
343 return FORMAT_ERROR; | 343 return FORMAT_ERROR; |
344 } | 344 } |
345 | 345 |
346 // fill the File Info | 346 // fill the File Info |
396 ttainfo->STATE = FILE_ERROR; | 396 ttainfo->STATE = FILE_ERROR; |
397 return -1; | 397 return -1; |
398 } | 398 } |
399 | 399 |
400 seek_pos = ttainfo->DATAPOS + seek_table[data_pos = pos]; | 400 seek_pos = ttainfo->DATAPOS + seek_table[data_pos = pos]; |
401 fseek(ttainfo->HANDLE, seek_pos, SEEK_SET); | 401 vfs_fseek(ttainfo->HANDLE, seek_pos, SEEK_SET); |
402 | 402 |
403 data_cur = 0; | 403 data_cur = 0; |
404 framelen = 0; | 404 framelen = 0; |
405 | 405 |
406 // init bit reader | 406 // init bit reader |
430 ttainfo->STATE = MEMORY_ERROR; | 430 ttainfo->STATE = MEMORY_ERROR; |
431 return -1; | 431 return -1; |
432 } | 432 } |
433 | 433 |
434 // read seek table | 434 // read seek table |
435 if (!fread(seek_table, st_size, 1, ttainfo->HANDLE)) { | 435 if (!vfs_fread(seek_table, st_size, 1, ttainfo->HANDLE)) { |
436 ttainfo->STATE = READ_ERROR; | 436 ttainfo->STATE = READ_ERROR; |
437 return -1; | 437 return -1; |
438 } | 438 } |
439 | 439 |
440 checksum = crc32((unsigned char *) seek_table, st_size - sizeof(int)); | 440 checksum = crc32((unsigned char *) seek_table, st_size - sizeof(int)); |
453 return 0; | 453 return 0; |
454 } | 454 } |
455 | 455 |
456 void close_tta_file (tta_info *info) { | 456 void close_tta_file (tta_info *info) { |
457 if (info->HANDLE) { | 457 if (info->HANDLE) { |
458 fclose (info->HANDLE); | 458 vfs_fclose (info->HANDLE); |
459 info->HANDLE = NULL; | 459 info->HANDLE = NULL; |
460 } | 460 } |
461 } | 461 } |
462 | 462 |
463 void player_stop () { | 463 void player_stop () { |
528 rice->k0--; | 528 rice->k0--; |
529 else if (rice->sum0 > shift_16[rice->k0 + 1]) | 529 else if (rice->sum0 > shift_16[rice->k0 + 1]) |
530 rice->k0++; | 530 rice->k0++; |
531 } | 531 } |
532 | 532 |
533 // DEC is not defined?? | 533 value = DEC(value); |
534 // value = DEC(value); | |
535 | 534 |
536 // decompress stage 1: adaptive hybrid filter | 535 // decompress stage 1: adaptive hybrid filter |
537 hybrid_filter(fst, &value); | 536 hybrid_filter(fst, &value); |
538 | 537 |
539 // decompress stage 2: fixed order 1 prediction | 538 // decompress stage 2: fixed order 1 prediction |