1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 Dave Chapman
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
27 #include "metadata_common.h"
29 bool get_monkeys_metadata(int fd
, struct mp3entry
* id3
)
31 /* Use the trackname part of the id3 structure as a temporary buffer */
32 unsigned char* buf
= (unsigned char *)id3
->path
;
33 unsigned char* header
;
35 uint32_t descriptorlength
;
36 uint32_t totalsamples
;
37 uint32_t blocksperframe
, finalframeblocks
, totalframes
;
40 lseek(fd
, 0, SEEK_SET
);
42 if (read(fd
, buf
, 4) < 4)
47 if (memcmp(buf
, "MAC ", 4) != 0)
52 read(fd
, buf
+ 4, MAX_PATH
- 4);
54 fileversion
= get_short_le(buf
+4);
55 if (fileversion
< 3970)
61 if (fileversion
>= 3980)
63 descriptorlength
= get_long_le(buf
+8);
65 header
= buf
+ descriptorlength
;
67 blocksperframe
= get_long_le(header
+4);
68 finalframeblocks
= get_long_le(header
+8);
69 totalframes
= get_long_le(header
+12);
70 id3
->frequency
= get_long_le(header
+20);
74 /* v3.95 and later files all have a fixed framesize */
75 blocksperframe
= 73728 * 4;
77 finalframeblocks
= get_long_le(buf
+28);
78 totalframes
= get_long_le(buf
+24);
79 id3
->frequency
= get_long_le(buf
+12);
82 id3
->vbr
= true; /* All APE files are VBR */
83 id3
->filesize
= filesize(fd
);
85 totalsamples
= finalframeblocks
;
87 totalsamples
+= blocksperframe
* (totalframes
-1);
89 id3
->length
= ((int64_t) totalsamples
* 1000) / id3
->frequency
;
90 id3
->bitrate
= (id3
->filesize
* 8) / id3
->length
;