1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 Dave Chapman
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
29 #include "metadata_common.h"
30 #include "metadata_parsers.h"
32 bool get_monkeys_metadata(int fd
, struct mp3entry
* id3
)
34 /* Use the trackname part of the id3 structure as a temporary buffer */
35 unsigned char* buf
= (unsigned char *)id3
->path
;
36 unsigned char* header
;
38 uint32_t descriptorlength
;
39 uint32_t totalsamples
;
40 uint32_t blocksperframe
, finalframeblocks
, totalframes
;
43 lseek(fd
, 0, SEEK_SET
);
45 if (read(fd
, buf
, 4) < 4)
50 if (memcmp(buf
, "MAC ", 4) != 0)
55 read(fd
, buf
+ 4, MAX_PATH
- 4);
57 fileversion
= get_short_le(buf
+4);
58 if (fileversion
< 3970)
64 if (fileversion
>= 3980)
66 descriptorlength
= get_long_le(buf
+8);
68 header
= buf
+ descriptorlength
;
70 blocksperframe
= get_long_le(header
+4);
71 finalframeblocks
= get_long_le(header
+8);
72 totalframes
= get_long_le(header
+12);
73 id3
->frequency
= get_long_le(header
+20);
77 /* v3.95 and later files all have a fixed framesize */
78 blocksperframe
= 73728 * 4;
80 finalframeblocks
= get_long_le(buf
+28);
81 totalframes
= get_long_le(buf
+24);
82 id3
->frequency
= get_long_le(buf
+12);
85 id3
->vbr
= true; /* All APE files are VBR */
86 id3
->filesize
= filesize(fd
);
88 totalsamples
= finalframeblocks
;
90 totalsamples
+= blocksperframe
* (totalframes
-1);
92 id3
->length
= ((int64_t) totalsamples
* 1000) / id3
->frequency
;
93 id3
->bitrate
= (id3
->filesize
* 8) / id3
->length
;