summaryrefslogtreecommitdiff
path: root/apps/metadata/wave.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/metadata/wave.c')
-rw-r--r--apps/metadata/wave.c43
1 files changed, 15 insertions, 28 deletions
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
54enum 53enum
@@ -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;