summaryrefslogtreecommitdiff
path: root/firmware/mp3data.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/mp3data.c')
-rw-r--r--firmware/mp3data.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/firmware/mp3data.c b/firmware/mp3data.c
index 49b95f2d9e..2ebb620ed6 100644
--- a/firmware/mp3data.c
+++ b/firmware/mp3data.c
@@ -40,11 +40,6 @@
40 40
41#define DEBUG_VERBOSE 41#define DEBUG_VERBOSE
42 42
43#define BYTES2INT(b1,b2,b3,b4) (((long)(b1 & 0xFF) << (3*8)) | \
44 ((long)(b2 & 0xFF) << (2*8)) | \
45 ((long)(b3 & 0xFF) << (1*8)) | \
46 ((long)(b4 & 0xFF) << (0*8)))
47
48#define SYNC_MASK (0x7ffL << 21) 43#define SYNC_MASK (0x7ffL << 21)
49#define VERSION_MASK (3L << 19) 44#define VERSION_MASK (3L << 19)
50#define LAYER_MASK (3L << 17) 45#define LAYER_MASK (3L << 17)
@@ -82,13 +77,24 @@ static const short *bitrate_table[3][3] =
82}; 77};
83 78
84/* Sampling frequency table, indexed by version and frequency index */ 79/* Sampling frequency table, indexed by version and frequency index */
85static const long freq_table[3][3] = 80static const unsigned short freq_table[3][3] =
86{ 81{
87 {44100, 48000, 32000}, /* MPEG Version 1 */ 82 {44100, 48000, 32000}, /* MPEG Version 1 */
88 {22050, 24000, 16000}, /* MPEG version 2 */ 83 {22050, 24000, 16000}, /* MPEG version 2 */
89 {11025, 12000, 8000}, /* MPEG version 2.5 */ 84 {11025, 12000, 8000}, /* MPEG version 2.5 */
90}; 85};
91 86
87unsigned long bytes2int(unsigned long b0,
88 unsigned long b1,
89 unsigned long b2,
90 unsigned long b3)
91{
92 return (((long)(b0 & 0xFF) << (3*8)) |
93 ((long)(b1 & 0xFF) << (2*8)) |
94 ((long)(b2 & 0xFF) << (1*8)) |
95 ((long)(b3 & 0xFF) << (0*8)));
96}
97
92/* check if 'head' is a valid mp3 frame header */ 98/* check if 'head' is a valid mp3 frame header */
93static bool is_mp3frameheader(unsigned long head) 99static bool is_mp3frameheader(unsigned long head)
94{ 100{
@@ -357,9 +363,11 @@ int get_mp3file_info(int fd, struct mp3info *info)
357 return -1; 363 return -1;
358 364
359 memset(info, 0, sizeof(struct mp3info)); 365 memset(info, 0, sizeof(struct mp3info));
366#if CONFIG_CODEC==SWCODEC
360 /* These two are needed for proper LAME gapless MP3 playback */ 367 /* These two are needed for proper LAME gapless MP3 playback */
361 info->enc_delay = -1; 368 info->enc_delay = -1;
362 info->enc_padding = -1; 369 info->enc_padding = -1;
370#endif
363 if(!mp3headerinfo(info, header)) 371 if(!mp3headerinfo(info, header))
364 return -2; 372 return -2;
365 373
@@ -416,7 +424,7 @@ int get_mp3file_info(int fd, struct mp3info *info)
416 424
417 if (vbrheader[7] & VBR_FRAMES_FLAG) /* Is the frame count there? */ 425 if (vbrheader[7] & VBR_FRAMES_FLAG) /* Is the frame count there? */
418 { 426 {
419 info->frame_count = BYTES2INT(vbrheader[i], vbrheader[i+1], 427 info->frame_count = bytes2int(vbrheader[i], vbrheader[i+1],
420 vbrheader[i+2], vbrheader[i+3]); 428 vbrheader[i+2], vbrheader[i+3]);
421 if (info->frame_count <= ULONG_MAX / info->ft_num) 429 if (info->frame_count <= ULONG_MAX / info->ft_num)
422 info->file_time = info->frame_count * info->ft_num / info->ft_den; 430 info->file_time = info->frame_count * info->ft_num / info->ft_den;
@@ -427,7 +435,7 @@ int get_mp3file_info(int fd, struct mp3info *info)
427 435
428 if (vbrheader[7] & VBR_BYTES_FLAG) /* Is byte count there? */ 436 if (vbrheader[7] & VBR_BYTES_FLAG) /* Is byte count there? */
429 { 437 {
430 info->byte_count = BYTES2INT(vbrheader[i], vbrheader[i+1], 438 info->byte_count = bytes2int(vbrheader[i], vbrheader[i+1],
431 vbrheader[i+2], vbrheader[i+3]); 439 vbrheader[i+2], vbrheader[i+3]);
432 i += 4; 440 i += 4;
433 } 441 }
@@ -453,6 +461,7 @@ int get_mp3file_info(int fd, struct mp3info *info)
453 /* We don't care about this, but need to skip it */ 461 /* We don't care about this, but need to skip it */
454 i += 4; 462 i += 4;
455 } 463 }
464#if CONFIG_CODEC==SWCODEC
456 i += 21; 465 i += 21;
457 info->enc_delay = (vbrheader[i] << 4) | (vbrheader[i + 1] >> 4); 466 info->enc_delay = (vbrheader[i] << 4) | (vbrheader[i + 1] >> 4);
458 info->enc_padding = ((vbrheader[i + 1] & 0x0f) << 8) | vbrheader[i + 2]; 467 info->enc_padding = ((vbrheader[i + 1] & 0x0f) << 8) | vbrheader[i + 2];
@@ -465,6 +474,7 @@ int get_mp3file_info(int fd, struct mp3info *info)
465 info->enc_delay = -1; 474 info->enc_delay = -1;
466 info->enc_padding = -1; 475 info->enc_padding = -1;
467 } 476 }
477#endif
468 } 478 }
469 479
470 if (!memcmp(vbrheader, "VBRI", 4)) 480 if (!memcmp(vbrheader, "VBRI", 4))
@@ -500,9 +510,9 @@ int get_mp3file_info(int fd, struct mp3info *info)
500 info->is_vbri_vbr = true; 510 info->is_vbri_vbr = true;
501 info->has_toc = false; /* We don't parse the TOC (yet) */ 511 info->has_toc = false; /* We don't parse the TOC (yet) */
502 512
503 info->byte_count = BYTES2INT(vbrheader[10], vbrheader[11], 513 info->byte_count = bytes2int(vbrheader[10], vbrheader[11],
504 vbrheader[12], vbrheader[13]); 514 vbrheader[12], vbrheader[13]);
505 info->frame_count = BYTES2INT(vbrheader[14], vbrheader[15], 515 info->frame_count = bytes2int(vbrheader[14], vbrheader[15],
506 vbrheader[16], vbrheader[17]); 516 vbrheader[16], vbrheader[17]);
507 if (info->frame_count <= ULONG_MAX / info->ft_num) 517 if (info->frame_count <= ULONG_MAX / info->ft_num)
508 info->file_time = info->frame_count * info->ft_num / info->ft_den; 518 info->file_time = info->frame_count * info->ft_num / info->ft_den;
@@ -515,8 +525,8 @@ int get_mp3file_info(int fd, struct mp3info *info)
515 info->bitrate = info->byte_count / (info->file_time >> 3); 525 info->bitrate = info->byte_count / (info->file_time >> 3);
516 526
517 /* We don't parse the TOC, since we don't yet know how to (FIXME) */ 527 /* We don't parse the TOC, since we don't yet know how to (FIXME) */
518 num_offsets = BYTES2INT(0, 0, vbrheader[18], vbrheader[19]); 528 num_offsets = bytes2int(0, 0, vbrheader[18], vbrheader[19]);
519 frames_per_entry = BYTES2INT(0, 0, vbrheader[24], vbrheader[25]); 529 frames_per_entry = bytes2int(0, 0, vbrheader[24], vbrheader[25]);
520 DEBUGF("Frame size (%dkpbs): %d bytes (0x%x)\n", 530 DEBUGF("Frame size (%dkpbs): %d bytes (0x%x)\n",
521 info->bitrate, info->frame_size, info->frame_size); 531 info->bitrate, info->frame_size, info->frame_size);
522 DEBUGF("Frame count: %x\n", info->frame_count); 532 DEBUGF("Frame count: %x\n", info->frame_count);
@@ -528,7 +538,7 @@ int get_mp3file_info(int fd, struct mp3info *info)
528 538
529 for(i = 0;i < num_offsets;i++) 539 for(i = 0;i < num_offsets;i++)
530 { 540 {
531 j = BYTES2INT(0, 0, vbrheader[26+i*2], vbrheader[27+i*2]); 541 j = bytes2int(0, 0, vbrheader[26+i*2], vbrheader[27+i*2]);
532 offset += j; 542 offset += j;
533 DEBUGF("%03d: %x (%x)\n", i, offset - bytecount, j); 543 DEBUGF("%03d: %x (%x)\n", i, offset - bytecount, j);
534 } 544 }