diff options
author | Jean-Philippe Bernardy <jeanphilippe.bernardy@gmail.com> | 2005-01-30 14:11:50 +0000 |
---|---|---|
committer | Jean-Philippe Bernardy <jeanphilippe.bernardy@gmail.com> | 2005-01-30 14:11:50 +0000 |
commit | 98a8132155a9c390395c3d1f570883da3e3f560d (patch) | |
tree | fbd3edb73084af28570ea4c40011916bffdafbcd | |
parent | 9d42e2b39632047b0ba272c03ec154b3931c43de (diff) | |
download | rockbox-98a8132155a9c390395c3d1f570883da3e3f560d.tar.gz rockbox-98a8132155a9c390395c3d1f570883da3e3f560d.zip |
long policy
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5712 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | firmware/export/mp3data.h | 10 | ||||
-rw-r--r-- | firmware/mp3data.c | 88 |
2 files changed, 50 insertions, 48 deletions
diff --git a/firmware/export/mp3data.h b/firmware/export/mp3data.h index 833a4c9dfa..c031cc20ce 100644 --- a/firmware/export/mp3data.h +++ b/firmware/export/mp3data.h | |||
@@ -43,9 +43,9 @@ struct mp3info { | |||
43 | bool is_xing_vbr; /* True if the VBR header is of Xing type */ | 43 | bool is_xing_vbr; /* True if the VBR header is of Xing type */ |
44 | bool is_vbri_vbr; /* True if the VBR header is of VBRI type */ | 44 | bool is_vbri_vbr; /* True if the VBR header is of VBRI type */ |
45 | unsigned char toc[100]; | 45 | unsigned char toc[100]; |
46 | int frame_count; /* Number of frames in the file (if VBR) */ | 46 | long frame_count; /* Number of frames in the file (if VBR) */ |
47 | int byte_count; /* File size in bytes */ | 47 | long byte_count; /* File size in bytes */ |
48 | int file_time; /* Length of the whole file in milliseconds */ | 48 | long file_time; /* Length of the whole file in milliseconds */ |
49 | int vbr_header_pos; | 49 | int vbr_header_pos; |
50 | }; | 50 | }; |
51 | 51 | ||
@@ -55,8 +55,8 @@ struct mp3info { | |||
55 | #define VBR_TOC_FLAG 0x04 | 55 | #define VBR_TOC_FLAG 0x04 |
56 | 56 | ||
57 | 57 | ||
58 | unsigned long find_next_frame(int fd, int *offset, int max_offset, unsigned long last_header); | 58 | unsigned long find_next_frame(int fd, long *offset, long max_offset, unsigned long last_header); |
59 | unsigned long mem_find_next_frame(int startpos, int *offset, int max_offset, | 59 | unsigned long mem_find_next_frame(int startpos, long *offset, long max_offset, |
60 | unsigned long last_header); | 60 | unsigned long last_header); |
61 | int get_mp3file_info(int fd, struct mp3info *info); | 61 | int get_mp3file_info(int fd, struct mp3info *info); |
62 | int count_mp3_frames(int fd, int startpos, int filesize, | 62 | int count_mp3_frames(int fd, int startpos, int filesize, |
diff --git a/firmware/mp3data.c b/firmware/mp3data.c index 38cfc9d322..7b6da1144f 100644 --- a/firmware/mp3data.c +++ b/firmware/mp3data.c | |||
@@ -38,24 +38,24 @@ | |||
38 | 38 | ||
39 | #define DEBUG_VERBOSE | 39 | #define DEBUG_VERBOSE |
40 | 40 | ||
41 | #define BYTES2INT(b1,b2,b3,b4) (((b1 & 0xFF) << (3*8)) | \ | 41 | #define BYTES2INT(b1,b2,b3,b4) (((long)(b1 & 0xFF) << (3*8)) | \ |
42 | ((b2 & 0xFF) << (2*8)) | \ | 42 | ((long)(b2 & 0xFF) << (2*8)) | \ |
43 | ((b3 & 0xFF) << (1*8)) | \ | 43 | ((long)(b3 & 0xFF) << (1*8)) | \ |
44 | ((b4 & 0xFF) << (0*8))) | 44 | ((long)(b4 & 0xFF) << (0*8))) |
45 | 45 | ||
46 | #define SYNC_MASK (0x7ff << 21) | 46 | #define SYNC_MASK (0x7ffL << 21) |
47 | #define VERSION_MASK (3 << 19) | 47 | #define VERSION_MASK (3L << 19) |
48 | #define LAYER_MASK (3 << 17) | 48 | #define LAYER_MASK (3L << 17) |
49 | #define PROTECTION_MASK (1 << 16) | 49 | #define PROTECTION_MASK (1L << 16) |
50 | #define BITRATE_MASK (0xf << 12) | 50 | #define BITRATE_MASK (0xfL << 12) |
51 | #define SAMPLERATE_MASK (3 << 10) | 51 | #define SAMPLERATE_MASK (3L << 10) |
52 | #define PADDING_MASK (1 << 9) | 52 | #define PADDING_MASK (1L << 9) |
53 | #define PRIVATE_MASK (1 << 8) | 53 | #define PRIVATE_MASK (1L << 8) |
54 | #define CHANNELMODE_MASK (3 << 6) | 54 | #define CHANNELMODE_MASK (3L << 6) |
55 | #define MODE_EXT_MASK (3 << 4) | 55 | #define MODE_EXT_MASK (3L << 4) |
56 | #define COPYRIGHT_MASK (1 << 3) | 56 | #define COPYRIGHT_MASK (1L << 3) |
57 | #define ORIGINAL_MASK (1 << 2) | 57 | #define ORIGINAL_MASK (1L << 2) |
58 | #define EMPHASIS_MASK 3 | 58 | #define EMPHASIS_MASK 3L |
59 | 59 | ||
60 | /* Table of bitrates for MP3 files, all values in kilo. | 60 | /* Table of bitrates for MP3 files, all values in kilo. |
61 | * Indexed by version, layer and value of bit 15-12 in header. | 61 | * Indexed by version, layer and value of bit 15-12 in header. |
@@ -77,7 +77,7 @@ const int bitrate_table[2][3][16] = | |||
77 | /* Table of samples per frame for MP3 files. | 77 | /* Table of samples per frame for MP3 files. |
78 | * Indexed by layer. Multiplied with 1000. | 78 | * Indexed by layer. Multiplied with 1000. |
79 | */ | 79 | */ |
80 | const int bs[3] = {384000, 1152000, 1152000}; | 80 | const long bs[3] = {384000, 1152000, 1152000}; |
81 | 81 | ||
82 | /* Table of sample frequency for MP3 files. | 82 | /* Table of sample frequency for MP3 files. |
83 | * Indexed by version and layer. | 83 | * Indexed by version and layer. |
@@ -95,7 +95,7 @@ static bool is_mp3frameheader(unsigned long head) | |||
95 | { | 95 | { |
96 | if ((head & SYNC_MASK) != (unsigned long)SYNC_MASK) /* bad sync? */ | 96 | if ((head & SYNC_MASK) != (unsigned long)SYNC_MASK) /* bad sync? */ |
97 | return false; | 97 | return false; |
98 | if ((head & VERSION_MASK) == (1 << 19)) /* bad version? */ | 98 | if ((head & VERSION_MASK) == (1L << 19)) /* bad version? */ |
99 | return false; | 99 | return false; |
100 | if (!(head & LAYER_MASK)) /* no layer? */ | 100 | if (!(head & LAYER_MASK)) /* no layer? */ |
101 | return false; | 101 | return false; |
@@ -129,16 +129,16 @@ static bool mp3headerinfo(struct mp3info *info, unsigned long header) | |||
129 | bittable = MPEG_VERSION2 - 1; /* use the V2 bit rate table */ | 129 | bittable = MPEG_VERSION2 - 1; /* use the V2 bit rate table */ |
130 | break; | 130 | break; |
131 | 131 | ||
132 | case (1 << 19): | 132 | case (1L << 19): |
133 | return false; | 133 | return false; |
134 | 134 | ||
135 | case (2 << 19): | 135 | case (2L << 19): |
136 | /* MPEG version 2 (ISO/IEC 13818-3) */ | 136 | /* MPEG version 2 (ISO/IEC 13818-3) */ |
137 | info->version = MPEG_VERSION2; | 137 | info->version = MPEG_VERSION2; |
138 | bittable = MPEG_VERSION2 - 1; | 138 | bittable = MPEG_VERSION2 - 1; |
139 | break; | 139 | break; |
140 | 140 | ||
141 | case (3 << 19): | 141 | case (3L << 19): |
142 | /* MPEG version 1 (ISO/IEC 11172-3) */ | 142 | /* MPEG version 1 (ISO/IEC 11172-3) */ |
143 | info->version = MPEG_VERSION1; | 143 | info->version = MPEG_VERSION1; |
144 | bittable = MPEG_VERSION1 - 1; | 144 | bittable = MPEG_VERSION1 - 1; |
@@ -148,13 +148,13 @@ static bool mp3headerinfo(struct mp3info *info, unsigned long header) | |||
148 | switch(header & LAYER_MASK) { | 148 | switch(header & LAYER_MASK) { |
149 | case 0: | 149 | case 0: |
150 | return false; | 150 | return false; |
151 | case (1 << 17): | 151 | case (1L << 17): |
152 | info->layer = 2; | 152 | info->layer = 2; |
153 | break; | 153 | break; |
154 | case (2 << 17): | 154 | case (2L << 17): |
155 | info->layer = 1; | 155 | info->layer = 1; |
156 | break; | 156 | break; |
157 | case (3 << 17): | 157 | case (3L << 17): |
158 | info->layer = 0; | 158 | info->layer = 0; |
159 | break; | 159 | break; |
160 | } | 160 | } |
@@ -212,13 +212,15 @@ static bool mp3headerinfo(struct mp3info *info, unsigned long header) | |||
212 | return true; | 212 | return true; |
213 | } | 213 | } |
214 | 214 | ||
215 | static unsigned long __find_next_frame(int fd, int *offset, int max_offset, unsigned long last_header, int(*getfunc)(int fd, unsigned char *c)) | 215 | static unsigned long __find_next_frame(int fd, long *offset, long max_offset, |
216 | unsigned long last_header, | ||
217 | int(*getfunc)(int fd, unsigned char *c)) | ||
216 | { | 218 | { |
217 | unsigned long header=0; | 219 | unsigned long header=0; |
218 | unsigned char tmp; | 220 | unsigned char tmp; |
219 | int i; | 221 | int i; |
220 | 222 | ||
221 | int pos = 0; | 223 | long pos = 0; |
222 | 224 | ||
223 | /* We remember the last header we found, to use as a template to see if | 225 | /* We remember the last header we found, to use as a template to see if |
224 | the header we find has the same frequency, layer etc */ | 226 | the header we find has the same frequency, layer etc */ |
@@ -259,7 +261,7 @@ static int fileread(int fd, unsigned char *c) | |||
259 | return read(fd, c, 1); | 261 | return read(fd, c, 1); |
260 | } | 262 | } |
261 | 263 | ||
262 | unsigned long find_next_frame(int fd, int *offset, int max_offset, unsigned long last_header) | 264 | unsigned long find_next_frame(int fd, long *offset, long max_offset, unsigned long last_header) |
263 | { | 265 | { |
264 | return __find_next_frame(fd, offset, max_offset, last_header, fileread); | 266 | return __find_next_frame(fd, offset, max_offset, last_header, fileread); |
265 | } | 267 | } |
@@ -322,7 +324,7 @@ static void buf_init(void) | |||
322 | fnf_read_index = 0; | 324 | fnf_read_index = 0; |
323 | } | 325 | } |
324 | 326 | ||
325 | unsigned long buf_find_next_frame(int fd, int *offset, int max_offset, | 327 | unsigned long buf_find_next_frame(int fd, long *offset, long max_offset, |
326 | unsigned long last_header) | 328 | unsigned long last_header) |
327 | { | 329 | { |
328 | return __find_next_frame(fd, offset, max_offset, last_header, buf_getbyte); | 330 | return __find_next_frame(fd, offset, max_offset, last_header, buf_getbyte); |
@@ -347,7 +349,7 @@ static int mem_getbyte(int dummy, unsigned char *c) | |||
347 | return 1; | 349 | return 1; |
348 | } | 350 | } |
349 | 351 | ||
350 | unsigned long mem_find_next_frame(int startpos, int *offset, int max_offset, | 352 | unsigned long mem_find_next_frame(int startpos, long *offset, long max_offset, |
351 | unsigned long last_header) | 353 | unsigned long last_header) |
352 | { | 354 | { |
353 | mp3buflen = mp3end - mp3buf; | 355 | mp3buflen = mp3end - mp3buf; |
@@ -363,13 +365,13 @@ int get_mp3file_info(int fd, struct mp3info *info) | |||
363 | unsigned char frame[1800]; | 365 | unsigned char frame[1800]; |
364 | unsigned char *vbrheader; | 366 | unsigned char *vbrheader; |
365 | unsigned long header; | 367 | unsigned long header; |
366 | int bytecount; | 368 | long bytecount; |
367 | int num_offsets; | 369 | int num_offsets; |
368 | int frames_per_entry; | 370 | int frames_per_entry; |
369 | int i; | 371 | int i; |
370 | int offset; | 372 | long offset; |
371 | int j; | 373 | int j; |
372 | int tmp; | 374 | long tmp; |
373 | 375 | ||
374 | header = find_next_frame(fd, &bytecount, 0x20000, 0); | 376 | header = find_next_frame(fd, &bytecount, 0x20000, 0); |
375 | /* Quit if we haven't found a valid header within 128K */ | 377 | /* Quit if we haven't found a valid header within 128K */ |
@@ -520,7 +522,7 @@ int get_mp3file_info(int fd, struct mp3info *info) | |||
520 | return bytecount; | 522 | return bytecount; |
521 | } | 523 | } |
522 | 524 | ||
523 | static void int2bytes(unsigned char *buf, int val) | 525 | static void long2bytes(unsigned char *buf, long val) |
524 | { | 526 | { |
525 | buf[0] = (val >> 24) & 0xff; | 527 | buf[0] = (val >> 24) & 0xff; |
526 | buf[1] = (val >> 16) & 0xff; | 528 | buf[1] = (val >> 16) & 0xff; |
@@ -534,9 +536,9 @@ int count_mp3_frames(int fd, int startpos, int filesize, | |||
534 | unsigned long header = 0; | 536 | unsigned long header = 0; |
535 | struct mp3info info; | 537 | struct mp3info info; |
536 | int num_frames; | 538 | int num_frames; |
537 | int bytes; | 539 | long bytes; |
538 | int cnt; | 540 | int cnt; |
539 | int progress_chunk = filesize / 50; /* Max is 50%, in 1% increments */ | 541 | long progress_chunk = filesize / 50; /* Max is 50%, in 1% increments */ |
540 | int progress_cnt = 0; | 542 | int progress_cnt = 0; |
541 | bool is_vbr = false; | 543 | bool is_vbr = false; |
542 | int last_bitrate = 0; | 544 | int last_bitrate = 0; |
@@ -599,8 +601,8 @@ int create_xing_header(int fd, int startpos, int filesize, | |||
599 | struct mp3info info; | 601 | struct mp3info info; |
600 | int pos, last_pos; | 602 | int pos, last_pos; |
601 | int i, j; | 603 | int i, j; |
602 | int bytes; | 604 | long bytes; |
603 | unsigned int filepos; | 605 | unsigned long filepos; |
604 | int x; | 606 | int x; |
605 | int index; | 607 | int index; |
606 | unsigned char toc[100]; | 608 | unsigned char toc[100]; |
@@ -702,7 +704,7 @@ int create_xing_header(int fd, int startpos, int filesize, | |||
702 | header |= 8 << 12; /* This gives us plenty of space, at least 192 bytes */ | 704 | header |= 8 << 12; /* This gives us plenty of space, at least 192 bytes */ |
703 | 705 | ||
704 | /* Write the header to the buffer */ | 706 | /* Write the header to the buffer */ |
705 | int2bytes(buf, header); | 707 | long2bytes(buf, header); |
706 | 708 | ||
707 | /* Now get the length of the newly created frame */ | 709 | /* Now get the length of the newly created frame */ |
708 | mp3headerinfo(&info, header); | 710 | mp3headerinfo(&info, header); |
@@ -712,19 +714,19 @@ int create_xing_header(int fd, int startpos, int filesize, | |||
712 | buf[index+1] = 'i'; | 714 | buf[index+1] = 'i'; |
713 | buf[index+2] = 'n'; | 715 | buf[index+2] = 'n'; |
714 | buf[index+3] = 'g'; | 716 | buf[index+3] = 'g'; |
715 | int2bytes(&buf[index+4], ((num_frames?VBR_FRAMES_FLAG:0) | | 717 | long2bytes(&buf[index+4], ((num_frames?VBR_FRAMES_FLAG:0) | |
716 | (filesize?VBR_BYTES_FLAG:0) | | 718 | (filesize?VBR_BYTES_FLAG:0) | |
717 | (generate_toc?VBR_TOC_FLAG:0))); | 719 | (generate_toc?VBR_TOC_FLAG:0))); |
718 | index = index+8; | 720 | index = index+8; |
719 | if(num_frames) | 721 | if(num_frames) |
720 | { | 722 | { |
721 | int2bytes(&buf[index], num_frames); | 723 | long2bytes(&buf[index], num_frames); |
722 | index += 4; | 724 | index += 4; |
723 | } | 725 | } |
724 | 726 | ||
725 | if(filesize) | 727 | if(filesize) |
726 | { | 728 | { |
727 | int2bytes(&buf[index], filesize - startpos); | 729 | long2bytes(&buf[index], filesize - startpos); |
728 | index += 4; | 730 | index += 4; |
729 | } | 731 | } |
730 | 732 | ||