diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/metadata/aiff.c | 51 | ||||
-rw-r--r-- | apps/metadata/vox.c | 15 | ||||
-rw-r--r-- | apps/metadata/wave.c | 43 |
3 files changed, 40 insertions, 69 deletions
diff --git a/apps/metadata/aiff.c b/apps/metadata/aiff.c index aba327f8c8..063e5d56af 100644 --- a/apps/metadata/aiff.c +++ b/apps/metadata/aiff.c | |||
@@ -38,35 +38,25 @@ bool get_aiff_metadata(int fd, struct mp3entry* id3) | |||
38 | unsigned char* buf = (unsigned char *)id3->path; | 38 | unsigned char* buf = (unsigned char *)id3->path; |
39 | unsigned long numChannels = 0; | 39 | unsigned long numChannels = 0; |
40 | unsigned long numSampleFrames = 0; | 40 | unsigned long numSampleFrames = 0; |
41 | unsigned long sampleSize = 0; | ||
42 | unsigned long sampleRate = 0; | ||
43 | unsigned long numbytes = 0; | 41 | unsigned long numbytes = 0; |
44 | int read_bytes; | 42 | int read_bytes; |
45 | int i; | 43 | int i; |
46 | bool is_aifc = false; | 44 | bool is_aifc = false; |
47 | 45 | ||
48 | if ((lseek(fd, 0, SEEK_SET) < 0) | 46 | if ((lseek(fd, 0, SEEK_SET) < 0) || |
49 | || ((read_bytes = read(fd, buf, sizeof(id3->path))) < 54)) | 47 | ((read_bytes = read(fd, buf, sizeof(id3->path))) < 54) || |
48 | (memcmp(buf, "FORM", 4) != 0) || (memcmp(buf + 8, "AIF", 3) != 0) || | ||
49 | (!(is_aifc = (buf[11] == 'C')) && buf[11] != 'F')) | ||
50 | { | 50 | { |
51 | return false; | 51 | return false; |
52 | } | 52 | } |
53 | |||
54 | if (memcmp(buf, "FORM",4) != 0) | ||
55 | return false; | ||
56 | |||
57 | if (memcmp(&buf[8], "AIFF", 4) != 0) | ||
58 | { | ||
59 | if (memcmp(&buf[8], "AIFC", 4) != 0) | ||
60 | return false; | ||
61 | |||
62 | is_aifc = true; | ||
63 | } | ||
64 | |||
65 | buf += 12; | ||
66 | read_bytes -= 12; | ||
67 | 53 | ||
54 | i = 12; | ||
68 | while ((numbytes == 0) && (read_bytes >= 8)) | 55 | while ((numbytes == 0) && (read_bytes >= 8)) |
69 | { | 56 | { |
57 | buf += i; | ||
58 | read_bytes -= i; | ||
59 | |||
70 | /* chunkSize */ | 60 | /* chunkSize */ |
71 | i = get_long_be(&buf[4]); | 61 | i = get_long_be(&buf[4]); |
72 | 62 | ||
@@ -76,20 +66,17 @@ bool get_aiff_metadata(int fd, struct mp3entry* id3) | |||
76 | numChannels = ((buf[8]<<8)|buf[9]); | 66 | numChannels = ((buf[8]<<8)|buf[9]); |
77 | /* numSampleFrames */ | 67 | /* numSampleFrames */ |
78 | numSampleFrames = get_long_be(&buf[10]); | 68 | numSampleFrames = get_long_be(&buf[10]); |
79 | /* sampleSize */ | ||
80 | sampleSize = ((buf[14]<<8)|buf[15]); | ||
81 | /* sampleRate */ | 69 | /* sampleRate */ |
82 | sampleRate = get_long_be(&buf[18]); | 70 | id3->frequency = get_long_be(&buf[18]); |
83 | sampleRate = sampleRate >> (16+14-buf[17]); | 71 | id3->frequency >>= (16+14-buf[17]); |
84 | /* save format infos */ | 72 | /* save format infos */ |
85 | id3->bitrate = (sampleSize * numChannels * sampleRate) / 1000; | 73 | id3->bitrate = (((buf[14]<<8)|buf[15]) * numChannels * id3->frequency) / 1000; |
86 | id3->frequency = sampleRate; | ||
87 | if (!is_aifc || memcmp(&buf[26], AIFC_FORMAT_QT_IMA_ADPCM, 4) != 0) | 74 | if (!is_aifc || memcmp(&buf[26], AIFC_FORMAT_QT_IMA_ADPCM, 4) != 0) |
88 | id3->length = ((int64_t) numSampleFrames * 1000) / id3->frequency; | 75 | id3->length = ((int64_t) numSampleFrames * 1000) / id3->frequency; |
89 | else | 76 | else |
90 | { | 77 | { |
91 | /* QuickTime IMA ADPCM is 1block = 64 data for each channel */ | 78 | /* QuickTime IMA ADPCM is 1block = 64 data for each channel */ |
92 | id3->length = (int64_t)(numSampleFrames * 64000LL) / id3->frequency; | 79 | id3->length = ((int64_t) numSampleFrames * 64000LL) / id3->frequency; |
93 | } | 80 | } |
94 | 81 | ||
95 | id3->vbr = false; /* AIFF files are CBR */ | 82 | id3->vbr = false; /* AIFF files are CBR */ |
@@ -100,17 +87,9 @@ bool get_aiff_metadata(int fd, struct mp3entry* id3) | |||
100 | numbytes = i - 8; | 87 | numbytes = i - 8; |
101 | } | 88 | } |
102 | 89 | ||
103 | if (i & 0x01) | 90 | /* odd chunk sizes must be padded */ |
104 | { | 91 | i += 8 + (i & 0x01); |
105 | i++; /* odd chunk sizes must be padded */ | ||
106 | } | ||
107 | buf += i + 8; | ||
108 | read_bytes -= i + 8; | ||
109 | } | 92 | } |
110 | 93 | ||
111 | if ((numbytes == 0) || (numChannels == 0)) | 94 | return ((numbytes != 0) && (numChannels != 0)); |
112 | { | ||
113 | return false; | ||
114 | } | ||
115 | return true; | ||
116 | } | 95 | } |
diff --git a/apps/metadata/vox.c b/apps/metadata/vox.c index 2d937e2c73..3f4e5d553c 100644 --- a/apps/metadata/vox.c +++ b/apps/metadata/vox.c | |||
@@ -32,12 +32,17 @@ | |||
32 | 32 | ||
33 | bool get_vox_metadata(int fd, struct mp3entry* id3) | 33 | bool get_vox_metadata(int fd, struct mp3entry* id3) |
34 | { | 34 | { |
35 | /* vox is headerless format */ | 35 | /* |
36 | 36 | * vox is headerless format | |
37 | * | ||
38 | * frequency: 8000 Hz | ||
39 | * channels: mono | ||
40 | * bitspersample: 4 | ||
41 | */ | ||
37 | id3->frequency = 8000; | 42 | id3->frequency = 8000; |
38 | id3->vbr = false; /* All VOX files are CBR */ | 43 | id3->vbr = false; /* All VOX files are CBR */ |
39 | id3->filesize = filesize(fd); | 44 | id3->filesize = filesize(fd); |
40 | id3->length = ((int64_t) id3->filesize * 2000) / id3->frequency; | 45 | id3->length = id3->filesize >> 2; |
41 | 46 | ||
42 | return true; | 47 | return true; |
43 | } | 48 | } |
diff --git a/apps/metadata/wave.c b/apps/metadata/wave.c index 8fe755735d..c9291cbe54 100644 --- a/apps/metadata/wave.c +++ b/apps/metadata/wave.c | |||
@@ -48,7 +48,6 @@ | |||
48 | #define WAVE64_GUID_RIFF "riff\x2e\x91\xcf\x11\xa5\xd6\x28\xdb\x04\xc1\x00\x00" | 48 | #define WAVE64_GUID_RIFF "riff\x2e\x91\xcf\x11\xa5\xd6\x28\xdb\x04\xc1\x00\x00" |
49 | #define WAVE64_GUID_WAVE "wave\xf3\xac\xd3\x11\x8c\xd1\x00\xc0\x4f\x8e\xdb\x8a" | 49 | #define WAVE64_GUID_WAVE "wave\xf3\xac\xd3\x11\x8c\xd1\x00\xc0\x4f\x8e\xdb\x8a" |
50 | #define WAVE64_GUID_FMT "fmt \xf3\xac\xd3\x11\x8c\xd1\x00\xc0\x4f\x8e\xdb\x8a" | 50 | #define WAVE64_GUID_FMT "fmt \xf3\xac\xd3\x11\x8c\xd1\x00\xc0\x4f\x8e\xdb\x8a" |
51 | #define WAVE64_GUID_FACT "fact\xf3\xac\xd3\x11\x8c\xd1\x00\xc0\x4f\x8e\xdb\x8a" | ||
52 | #define WAVE64_GUID_DATA "data\xf3\xac\xd3\x11\x8c\xd1\x00\xc0\x4f\x8e\xdb\x8a" | 51 | #define WAVE64_GUID_DATA "data\xf3\xac\xd3\x11\x8c\xd1\x00\xc0\x4f\x8e\xdb\x8a" |
53 | 52 | ||
54 | enum | 53 | enum |
@@ -90,7 +89,7 @@ static unsigned long get_totalsamples(struct wave_fmt *fmt, struct mp3entry* id3 | |||
90 | case IBM_FORMAT_ALAW: | 89 | case IBM_FORMAT_ALAW: |
91 | case IBM_FORMAT_MULAW: | 90 | case IBM_FORMAT_MULAW: |
92 | totalsamples = | 91 | totalsamples = |
93 | fmt->numbytes / ((((fmt->bitspersample - 1) / 8) + 1) * fmt->channels); | 92 | fmt->numbytes / ((fmt->bitspersample >> 3) * fmt->channels); |
94 | break; | 93 | break; |
95 | case WAVE_FORMAT_ADPCM: | 94 | case WAVE_FORMAT_ADPCM: |
96 | case WAVE_FORMAT_DVI_ADPCM: | 95 | case WAVE_FORMAT_DVI_ADPCM: |
@@ -103,12 +102,12 @@ static unsigned long get_totalsamples(struct wave_fmt *fmt, struct mp3entry* id3 | |||
103 | if (fmt->blockalign == ((id3->frequency / 60) + 4) * fmt->channels) | 102 | if (fmt->blockalign == ((id3->frequency / 60) + 4) * fmt->channels) |
104 | fmt->samplesperblock = id3->frequency / 30; | 103 | fmt->samplesperblock = id3->frequency / 30; |
105 | else | 104 | else |
106 | fmt->samplesperblock = fmt->blockalign * 2 / fmt->channels; | 105 | fmt->samplesperblock = (fmt->blockalign << 1) / fmt->channels; |
107 | } | 106 | } |
108 | totalsamples = (fmt->numbytes / fmt->blockalign) * fmt->samplesperblock; | 107 | totalsamples = (fmt->numbytes / fmt->blockalign) * fmt->samplesperblock; |
109 | break; | 108 | break; |
110 | case WAVE_FORMAT_DIALOGIC_OKI_ADPCM: | 109 | case WAVE_FORMAT_DIALOGIC_OKI_ADPCM: |
111 | totalsamples = 2 * fmt->numbytes; | 110 | totalsamples = fmt->numbytes << 1; |
112 | break; | 111 | break; |
113 | case WAVE_FORMAT_SWF_ADPCM: | 112 | case WAVE_FORMAT_SWF_ADPCM: |
114 | if (fmt->samplesperblock == 0) | 113 | if (fmt->samplesperblock == 0) |
@@ -188,9 +187,7 @@ bool get_wave_metadata(int fd, struct mp3entry* id3) | |||
188 | if (i < 16) | 187 | if (i < 16) |
189 | return false; | 188 | return false; |
190 | 189 | ||
191 | read_bytes = 16; | 190 | read_bytes = (i > 19)? 20 : 16; |
192 | if (i > 19) | ||
193 | read_bytes = 20; | ||
194 | 191 | ||
195 | if (read(fd, buf, read_bytes) != read_bytes) | 192 | if (read(fd, buf, read_bytes) != read_bytes) |
196 | return false; | 193 | return false; |
@@ -198,7 +195,7 @@ bool get_wave_metadata(int fd, struct mp3entry* id3) | |||
198 | offset += read_bytes; | 195 | offset += read_bytes; |
199 | i -= read_bytes; | 196 | i -= read_bytes; |
200 | 197 | ||
201 | parse_riff_format(buf, i, &fmt, id3); | 198 | parse_riff_format(buf, read_bytes, &fmt, id3); |
202 | 199 | ||
203 | /* Check for ATRAC3 stream */ | 200 | /* Check for ATRAC3 stream */ |
204 | if (fmt.formattag == WAVE_FORMAT_ATRAC3) | 201 | if (fmt.formattag == WAVE_FORMAT_ATRAC3) |
@@ -241,8 +238,7 @@ bool get_wave_metadata(int fd, struct mp3entry* id3) | |||
241 | } | 238 | } |
242 | 239 | ||
243 | /* seek to next chunk (even chunk sizes must be padded) */ | 240 | /* seek to next chunk (even chunk sizes must be padded) */ |
244 | if (i & 0x01) | 241 | i += (i & 0x01); |
245 | i++; | ||
246 | 242 | ||
247 | if(lseek(fd, i, SEEK_CUR) < 0) | 243 | if(lseek(fd, i, SEEK_CUR) < 0) |
248 | return false; | 244 | return false; |
@@ -290,7 +286,7 @@ bool get_wave64_metadata(int fd, struct mp3entry* id3) | |||
290 | if ((memcmp(buf , WAVE64_GUID_RIFF, 16) != 0)|| | 286 | if ((memcmp(buf , WAVE64_GUID_RIFF, 16) != 0)|| |
291 | (memcmp(buf+24, WAVE64_GUID_WAVE, 16) != 0)) | 287 | (memcmp(buf+24, WAVE64_GUID_WAVE, 16) != 0)) |
292 | { | 288 | { |
293 | DEBUGF("metada error: does not wave64 file\n"); | 289 | DEBUGF("metadata error: does not wave64 file\n"); |
294 | return false; | 290 | return false; |
295 | } | 291 | } |
296 | 292 | ||
@@ -302,7 +298,7 @@ bool get_wave64_metadata(int fd, struct mp3entry* id3) | |||
302 | return false; | 298 | return false; |
303 | 299 | ||
304 | /* chunkSize (excludes GUID and size length) */ | 300 | /* chunkSize (excludes GUID and size length) */ |
305 | i = get_uint64_le(&buf[16]) - 24; | 301 | i = get_uint64_le(buf + 16) - 24; |
306 | 302 | ||
307 | if (memcmp(buf, WAVE64_GUID_FMT, 16) == 0) | 303 | if (memcmp(buf, WAVE64_GUID_FMT, 16) == 0) |
308 | { | 304 | { |
@@ -310,19 +306,16 @@ bool get_wave64_metadata(int fd, struct mp3entry* id3) | |||
310 | if (i < 16) | 306 | if (i < 16) |
311 | return false; | 307 | return false; |
312 | 308 | ||
313 | read_bytes = 16; | 309 | read_bytes = (i > 16)? 24 : 16; |
314 | if (i > 16) | 310 | if ((int)i < read_bytes) |
315 | { | 311 | i = 0; |
316 | read_bytes = 24; | 312 | else |
317 | if (i < 24) | 313 | i -= read_bytes; |
318 | i = 24; | ||
319 | } | ||
320 | 314 | ||
321 | /* get rest of chunk */ | 315 | /* get rest of chunk */ |
322 | if (read(fd, buf, read_bytes) < read_bytes) | 316 | if (read(fd, buf, read_bytes) < read_bytes) |
323 | return false; | 317 | return false; |
324 | 318 | ||
325 | i -= read_bytes; | ||
326 | parse_riff_format(buf, read_bytes, &fmt, id3); | 319 | parse_riff_format(buf, read_bytes, &fmt, id3); |
327 | } | 320 | } |
328 | else if (memcmp(buf, WAVE64_GUID_DATA, 16) == 0) | 321 | else if (memcmp(buf, WAVE64_GUID_DATA, 16) == 0) |
@@ -331,15 +324,9 @@ bool get_wave64_metadata(int fd, struct mp3entry* id3) | |||
331 | fmt.numbytes = i; | 324 | fmt.numbytes = i; |
332 | break; | 325 | break; |
333 | } | 326 | } |
334 | else if (memcmp(buf, WAVE64_GUID_FACT, 16) == 0) | ||
335 | { | ||
336 | /* Skip 'fact' chunk */ | ||
337 | DEBUGF("find 'fact' chunk\n"); | ||
338 | } | ||
339 | 327 | ||
340 | /* seek to next chunk (8byte bound) */ | 328 | /* seek to next chunk (8byte bound) */ |
341 | if (i & 0x07) | 329 | i += (1 + ~i) & 0x07; |
342 | i += 8 - (i & 0x7); | ||
343 | 330 | ||
344 | if(lseek(fd, i, SEEK_CUR) < 0) | 331 | if(lseek(fd, i, SEEK_CUR) < 0) |
345 | return false; | 332 | return false; |
@@ -359,7 +346,7 @@ bool get_wave64_metadata(int fd, struct mp3entry* id3) | |||
359 | id3->vbr = false; /* All Wave64 files are CBR */ | 346 | id3->vbr = false; /* All Wave64 files are CBR */ |
360 | id3->filesize = filesize(fd); | 347 | id3->filesize = filesize(fd); |
361 | 348 | ||
362 | /* Calculate track length (in ms) and estimate the bitrate (in kbit/s) */ | 349 | /* Calculate track length [ms] */ |
363 | id3->length = ((int64_t) totalsamples * 1000) / id3->frequency; | 350 | id3->length = ((int64_t) totalsamples * 1000) / id3->frequency; |
364 | 351 | ||
365 | return true; | 352 | return true; |