diff options
-rw-r--r-- | apps/metadata/wavpack.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/apps/metadata/wavpack.c b/apps/metadata/wavpack.c index 5d33c0dffd..a56a59231f 100644 --- a/apps/metadata/wavpack.c +++ b/apps/metadata/wavpack.c | |||
@@ -31,6 +31,9 @@ | |||
31 | #define ID_LARGE 0x80 | 31 | #define ID_LARGE 0x80 |
32 | #define ID_SAMPLE_RATE 0x27 | 32 | #define ID_SAMPLE_RATE 0x27 |
33 | 33 | ||
34 | #define MONO_FLAG 4 | ||
35 | #define HYBRID_FLAG 8 | ||
36 | |||
34 | static const long wavpack_sample_rates [] = | 37 | static const long wavpack_sample_rates [] = |
35 | { | 38 | { |
36 | 6000, 8000, 9600, 11025, 12000, 16000, 22050, 24000, | 39 | 6000, 8000, 9600, 11025, 12000, 16000, 22050, 24000, |
@@ -48,7 +51,7 @@ bool get_wavpack_metadata(int fd, struct mp3entry* id3) | |||
48 | { | 51 | { |
49 | /* Use the trackname part of the id3 structure as a temporary buffer */ | 52 | /* Use the trackname part of the id3 structure as a temporary buffer */ |
50 | unsigned char* buf = (unsigned char *)id3->path; | 53 | unsigned char* buf = (unsigned char *)id3->path; |
51 | uint32_t totalsamples, blocksamples; | 54 | uint32_t totalsamples, blocksamples, flags; |
52 | int i; | 55 | int i; |
53 | 56 | ||
54 | for (i = 0; i < 256; ++i) { | 57 | for (i = 0; i < 256; ++i) { |
@@ -74,8 +77,9 @@ bool get_wavpack_metadata(int fd, struct mp3entry* id3) | |||
74 | id3->filesize = filesize (fd); | 77 | id3->filesize = filesize (fd); |
75 | totalsamples = get_long_le(&buf[12]); | 78 | totalsamples = get_long_le(&buf[12]); |
76 | blocksamples = get_long_le(&buf[20]); | 79 | blocksamples = get_long_le(&buf[20]); |
80 | flags = get_long_le(&buf[24]); | ||
77 | 81 | ||
78 | if (blocksamples && totalsamples != (uint32_t) -1) { | 82 | if (blocksamples) { |
79 | int srindx = ((buf [26] >> 7) & 1) + ((buf [27] << 1) & 14); | 83 | int srindx = ((buf [26] >> 7) & 1) + ((buf [27] << 1) & 14); |
80 | 84 | ||
81 | if (srindx == 15) { | 85 | if (srindx == 15) { |
@@ -114,9 +118,23 @@ bool get_wavpack_metadata(int fd, struct mp3entry* id3) | |||
114 | else | 118 | else |
115 | id3->frequency = wavpack_sample_rates[srindx]; | 119 | id3->frequency = wavpack_sample_rates[srindx]; |
116 | 120 | ||
121 | /* if the total number of samples is unknown, make a guess on the high side (for now) */ | ||
122 | |||
123 | if (totalsamples == (uint32_t) -1) { | ||
124 | totalsamples = filesize (fd) * 3; | ||
125 | |||
126 | if (!(flags & HYBRID_FLAG)) | ||
127 | totalsamples /= 2; | ||
128 | |||
129 | if (!(flags & MONO_FLAG)) | ||
130 | totalsamples /= 2; | ||
131 | } | ||
132 | |||
117 | id3->length = ((int64_t) totalsamples * 1000) / id3->frequency; | 133 | id3->length = ((int64_t) totalsamples * 1000) / id3->frequency; |
118 | id3->bitrate = filesize (fd) / (id3->length / 8); | 134 | id3->bitrate = filesize (fd) / (id3->length / 8); |
135 | |||
136 | return true; | ||
119 | } | 137 | } |
120 | 138 | ||
121 | return true; | 139 | return false; |
122 | } | 140 | } |