summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/metadata.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/apps/metadata.c b/apps/metadata.c
index 8838a83aa4..676108116d 100644
--- a/apps/metadata.c
+++ b/apps/metadata.c
@@ -1491,23 +1491,34 @@ bool get_metadata(struct track_info* track, int fd, const char* trackname,
1491 break; 1491 break;
1492 1492
1493 case AFMT_WAVPACK: 1493 case AFMT_WAVPACK:
1494 /* A simple parser to read basic information from a WavPack file. 1494 /* A simple parser to read basic information from a WavPack file. This
1495 * This will fail on WavPack files that don't have the WavPack header 1495 * now works with self-extrating WavPack files and also will fail on
1496 * as the first thing (i.e. self-extracting WavPack files) or WavPack 1496 * WavPack files containing floating-point audio data (although these
1497 * files that have so much extra RIFF data stored in the first block 1497 * should be possible to play in theory).
1498 * that they don't have samples (very rare, I would think).
1499 */ 1498 */
1500 1499
1501 /* Use the trackname part of the id3 structure as a temporary buffer */ 1500 /* Use the trackname part of the id3 structure as a temporary buffer */
1502 buf = track->id3.path; 1501 buf = track->id3.path;
1503 1502
1504 if ((lseek(fd, 0, SEEK_SET) < 0) || (read(fd, buf, 32) < 32)) 1503 for (i = 0; i < 256; ++i) {
1505 { 1504
1506 return false; 1505 /* at every 256 bytes into file, try to read a WavPack header */
1506
1507 if ((lseek(fd, i * 256, SEEK_SET) < 0) || (read(fd, buf, 32) < 32))
1508 {
1509 return false;
1510 }
1511
1512 /* if valid WavPack 4 header version & not floating data, break */
1513
1514 if (memcmp (buf, "wvpk", 4) == 0 && buf [9] == 4 &&
1515 (buf [8] >= 2 && buf [8] <= 0x10) && !(buf [24] & 0x80))
1516 {
1517 break;
1518 }
1507 } 1519 }
1508 1520
1509 if (memcmp (buf, "wvpk", 4) != 0 || buf [9] != 4 || buf [8] < 2) 1521 if (i == 256) {
1510 {
1511 logf ("%s is not a WavPack file\n", trackname); 1522 logf ("%s is not a WavPack file\n", trackname);
1512 return false; 1523 return false;
1513 } 1524 }