diff options
author | Sean Bartell <wingedtachikoma@gmail.com> | 2011-06-24 01:25:21 -0400 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2012-03-18 12:00:39 +0100 |
commit | b5716df4cb2837bbbc42195cf1aefcf03e21d6a6 (patch) | |
tree | 130cd712e2e00893b6df9959a375a8d9523a1aca /lib/rbcodec/metadata/monkeys.c | |
parent | 24bd9d5393dbe39a5c6194877bc00ede669b1d5d (diff) | |
download | rockbox-b5716df4cb2837bbbc42195cf1aefcf03e21d6a6.tar.gz rockbox-b5716df4cb2837bbbc42195cf1aefcf03e21d6a6.zip |
Build librbcodec with DSP and metadata.
All associated files are moved to /lib/rbcodec.
Change-Id: I572ddd2b8a996aae1e98c081d06b1ed356dce222
Diffstat (limited to 'lib/rbcodec/metadata/monkeys.c')
-rw-r--r-- | lib/rbcodec/metadata/monkeys.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/lib/rbcodec/metadata/monkeys.c b/lib/rbcodec/metadata/monkeys.c new file mode 100644 index 0000000000..4aff1412aa --- /dev/null +++ b/lib/rbcodec/metadata/monkeys.c | |||
@@ -0,0 +1,97 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2007 Dave Chapman | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include <stdio.h> | ||
22 | #include <string.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <ctype.h> | ||
25 | #include <inttypes.h> | ||
26 | |||
27 | #include "system.h" | ||
28 | #include "metadata.h" | ||
29 | #include "metadata_common.h" | ||
30 | #include "metadata_parsers.h" | ||
31 | |||
32 | bool get_monkeys_metadata(int fd, struct mp3entry* id3) | ||
33 | { | ||
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; | ||
37 | bool rc = false; | ||
38 | uint32_t descriptorlength; | ||
39 | uint32_t totalsamples; | ||
40 | uint32_t blocksperframe, finalframeblocks, totalframes; | ||
41 | int fileversion; | ||
42 | |||
43 | lseek(fd, 0, SEEK_SET); | ||
44 | |||
45 | if (read(fd, buf, 4) < 4) | ||
46 | { | ||
47 | return rc; | ||
48 | } | ||
49 | |||
50 | if (memcmp(buf, "MAC ", 4) != 0) | ||
51 | { | ||
52 | return rc; | ||
53 | } | ||
54 | |||
55 | read(fd, buf + 4, MAX_PATH - 4); | ||
56 | |||
57 | fileversion = get_short_le(buf+4); | ||
58 | if (fileversion < 3970) | ||
59 | { | ||
60 | /* Not supported */ | ||
61 | return false; | ||
62 | } | ||
63 | |||
64 | if (fileversion >= 3980) | ||
65 | { | ||
66 | descriptorlength = get_long_le(buf+8); | ||
67 | |||
68 | header = buf + descriptorlength; | ||
69 | |||
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); | ||
74 | } | ||
75 | else | ||
76 | { | ||
77 | /* v3.95 and later files all have a fixed framesize */ | ||
78 | blocksperframe = 73728 * 4; | ||
79 | |||
80 | finalframeblocks = get_long_le(buf+28); | ||
81 | totalframes = get_long_le(buf+24); | ||
82 | id3->frequency = get_long_le(buf+12); | ||
83 | } | ||
84 | |||
85 | id3->vbr = true; /* All APE files are VBR */ | ||
86 | id3->filesize = filesize(fd); | ||
87 | |||
88 | totalsamples = finalframeblocks; | ||
89 | if (totalframes > 1) | ||
90 | totalsamples += blocksperframe * (totalframes-1); | ||
91 | |||
92 | id3->length = ((int64_t) totalsamples * 1000) / id3->frequency; | ||
93 | id3->bitrate = (id3->filesize * 8) / id3->length; | ||
94 | |||
95 | read_ape_tags(fd, id3); | ||
96 | return true; | ||
97 | } | ||