summaryrefslogtreecommitdiff
path: root/apps/metadata.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/metadata.c')
-rw-r--r--apps/metadata.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/apps/metadata.c b/apps/metadata.c
index 1bbff1d370..60191b1eb8 100644
--- a/apps/metadata.c
+++ b/apps/metadata.c
@@ -982,6 +982,56 @@ static bool get_flac_metadata(int fd, struct mp3entry* id3)
982 return true; 982 return true;
983} 983}
984 984
985static bool get_monkeys_metadata(int fd, struct mp3entry* id3)
986{
987 /* Use the trackname part of the id3 structure as a temporary buffer */
988 unsigned char* buf = (unsigned char *)id3->path;
989 unsigned char* header;
990 bool rc = false;
991 uint32_t descriptorlength;
992 uint32_t totalsamples;
993 uint32_t blocksperframe, finalframeblocks, totalframes;
994
995 lseek(fd, 0, SEEK_SET);
996
997 if (read(fd, buf, 4) < 4)
998 {
999 return rc;
1000 }
1001
1002 if (memcmp(buf, "MAC ", 4) != 0)
1003 {
1004 return rc;
1005 }
1006
1007 read(fd, buf + 4, MAX_PATH - 4);
1008
1009 descriptorlength = buf[8] | (buf[9] << 8) |
1010 (buf[10] << 16) | (buf[11] << 24);
1011
1012 header = buf + descriptorlength;
1013
1014 blocksperframe = header[4] | (header[5] << 8) |
1015 (header[6] << 16) | (header[7] << 24);
1016 finalframeblocks = header[8] | (header[9] << 8) |
1017 (header[10] << 16) | (header[11] << 24);
1018 totalframes = header[12] | (header[13] << 8) |
1019 (header[14] << 16) | (header[15] << 24);
1020
1021 id3->vbr = true; /* All FLAC files are VBR */
1022 id3->filesize = filesize(fd);
1023 id3->frequency = header[20] | (header[21] << 8) |
1024 (header[22] << 16) | (header[23] << 24);
1025
1026 totalsamples = finalframeblocks;
1027 if (totalframes > 1)
1028 totalsamples += blocksperframe * (totalframes-1);
1029
1030 id3->length = ((int64_t) totalsamples * 1000) / id3->frequency;
1031 id3->bitrate = (id3->filesize * 8) / id3->length;
1032 return true;
1033}
1034
985static bool get_wave_metadata(int fd, struct mp3entry* id3) 1035static bool get_wave_metadata(int fd, struct mp3entry* id3)
986{ 1036{
987 /* Use the trackname part of the id3 structure as a temporary buffer */ 1037 /* Use the trackname part of the id3 structure as a temporary buffer */
@@ -2152,6 +2202,14 @@ bool get_metadata(struct track_info* track, int fd, const char* trackname,
2152 2202
2153 break; 2203 break;
2154 2204
2205 case AFMT_APE:
2206 if (!get_monkeys_metadata(fd, &(track->id3)))
2207 {
2208 return false;
2209 }
2210 read_ape_tags(fd, &(track->id3));
2211 break;
2212
2155 case AFMT_MPC: 2213 case AFMT_MPC:
2156 if (!get_musepack_metadata(fd, &(track->id3))) 2214 if (!get_musepack_metadata(fd, &(track->id3)))
2157 return false; 2215 return false;