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/spc.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/spc.c')
-rw-r--r-- | lib/rbcodec/metadata/spc.c | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/lib/rbcodec/metadata/spc.c b/lib/rbcodec/metadata/spc.c new file mode 100644 index 0000000000..1c0206205d --- /dev/null +++ b/lib/rbcodec/metadata/spc.c | |||
@@ -0,0 +1,130 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2005 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 | #include "debug.h" | ||
32 | #include "rbunicode.h" | ||
33 | |||
34 | bool get_spc_metadata(int fd, struct mp3entry* id3) | ||
35 | { | ||
36 | /* Use the trackname part of the id3 structure as a temporary buffer */ | ||
37 | unsigned char * buf = (unsigned char *)id3->path; | ||
38 | char * p; | ||
39 | |||
40 | unsigned long length; | ||
41 | unsigned long fade; | ||
42 | bool isbinary = true; | ||
43 | int i; | ||
44 | |||
45 | /* try to get the ID666 tag */ | ||
46 | if ((lseek(fd, 0x2e, SEEK_SET) < 0) | ||
47 | || (read(fd, buf, 0xD2) < 0xD2)) | ||
48 | { | ||
49 | DEBUGF("lseek or read failed\n"); | ||
50 | return false; | ||
51 | } | ||
52 | |||
53 | p = id3->id3v2buf; | ||
54 | |||
55 | id3->title = p; | ||
56 | buf[31] = 0; | ||
57 | p = iso_decode(buf, p, 0, 32); | ||
58 | buf += 32; | ||
59 | |||
60 | id3->album = p; | ||
61 | buf[31] = 0; | ||
62 | p = iso_decode(buf, p, 0, 32); | ||
63 | buf += 48; | ||
64 | |||
65 | id3->comment = p; | ||
66 | buf[31] = 0; | ||
67 | p = iso_decode(buf, p, 0, 32); | ||
68 | buf += 32; | ||
69 | |||
70 | /* Date check */ | ||
71 | if(buf[2] == '/' && buf[5] == '/') | ||
72 | isbinary = false; | ||
73 | |||
74 | /* Reserved bytes check */ | ||
75 | if(buf[0xD2 - 0x2E - 112] >= '0' && | ||
76 | buf[0xD2 - 0x2E - 112] <= '9' && | ||
77 | buf[0xD3 - 0x2E - 112] == 0x00) | ||
78 | isbinary = false; | ||
79 | |||
80 | /* is length & fade only digits? */ | ||
81 | for (i=0;i<8 && ( | ||
82 | (buf[0xA9 - 0x2E - 112+i]>='0'&&buf[0xA9 - 0x2E - 112+i]<='9') || | ||
83 | buf[0xA9 - 0x2E - 112+i]=='\0'); | ||
84 | i++); | ||
85 | if (i==8) isbinary = false; | ||
86 | |||
87 | if(isbinary) { | ||
88 | id3->year = buf[0] | (buf[1]<<8); | ||
89 | buf += 11; | ||
90 | |||
91 | length = (buf[0] | (buf[1]<<8) | (buf[2]<<16)) * 1000; | ||
92 | buf += 3; | ||
93 | |||
94 | fade = (buf[0] | (buf[1]<<8) | (buf[2]<<16) | (buf[3]<<24)); | ||
95 | buf += 4; | ||
96 | } else { | ||
97 | char tbuf[6]; | ||
98 | |||
99 | buf += 6; | ||
100 | buf[4] = 0; | ||
101 | id3->year = atoi(buf); | ||
102 | buf += 5; | ||
103 | |||
104 | memcpy(tbuf, buf, 3); | ||
105 | tbuf[3] = 0; | ||
106 | length = atoi(tbuf) * 1000; | ||
107 | buf += 3; | ||
108 | |||
109 | memcpy(tbuf, buf, 5); | ||
110 | tbuf[5] = 0; | ||
111 | fade = atoi(tbuf); | ||
112 | buf += 5; | ||
113 | } | ||
114 | |||
115 | id3->artist = p; | ||
116 | buf[31] = 0; | ||
117 | iso_decode(buf, p, 0, 32); | ||
118 | |||
119 | if (length==0) { | ||
120 | length=3*60*1000; /* 3 minutes */ | ||
121 | fade=5*1000; /* 5 seconds */ | ||
122 | } | ||
123 | |||
124 | id3->length = length+fade; | ||
125 | |||
126 | id3->filesize = filesize(fd); | ||
127 | id3->genre_string = id3_get_num_genre(36); | ||
128 | |||
129 | return true; | ||
130 | } | ||