diff options
Diffstat (limited to 'apps/metadata/sid.c')
-rw-r--r-- | apps/metadata/sid.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/apps/metadata/sid.c b/apps/metadata/sid.c new file mode 100644 index 0000000000..0dff5f6268 --- /dev/null +++ b/apps/metadata/sid.c | |||
@@ -0,0 +1,88 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2005 Dave Chapman | ||
11 | * | ||
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. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include <stdio.h> | ||
20 | #include <string.h> | ||
21 | #include <stdlib.h> | ||
22 | #include <ctype.h> | ||
23 | #include <inttypes.h> | ||
24 | |||
25 | #include "system.h" | ||
26 | #include "id3.h" | ||
27 | #include "metadata_common.h" | ||
28 | #include "atoi.h" | ||
29 | #include "rbunicode.h" | ||
30 | |||
31 | /* PSID metadata info is available here: | ||
32 | http://www.unusedino.de/ec64/technical/formats/sidplay.html */ | ||
33 | bool get_sid_metadata(int fd, struct mp3entry* id3) | ||
34 | { | ||
35 | /* Use the trackname part of the id3 structure as a temporary buffer */ | ||
36 | unsigned char* buf = (unsigned char *)id3->path; | ||
37 | int read_bytes; | ||
38 | char *p; | ||
39 | |||
40 | |||
41 | if ((lseek(fd, 0, SEEK_SET) < 0) | ||
42 | || ((read_bytes = read(fd, buf, 0x80)) < 0x80)) | ||
43 | { | ||
44 | return false; | ||
45 | } | ||
46 | |||
47 | if ((memcmp(buf, "PSID",4) != 0)) | ||
48 | { | ||
49 | return false; | ||
50 | } | ||
51 | |||
52 | p = id3->id3v2buf; | ||
53 | |||
54 | /* Copy Title (assumed max 0x1f letters + 1 zero byte) */ | ||
55 | id3->title = p; | ||
56 | buf[0x16+0x1f] = 0; | ||
57 | p = iso_decode(&buf[0x16], p, 0, strlen(&buf[0x16])+1); | ||
58 | |||
59 | /* Copy Artist (assumed max 0x1f letters + 1 zero byte) */ | ||
60 | id3->artist = p; | ||
61 | buf[0x36+0x1f] = 0; | ||
62 | p = iso_decode(&buf[0x36], p, 0, strlen(&buf[0x36])+1); | ||
63 | |||
64 | /* Copy Year (assumed max 4 letters + 1 zero byte) */ | ||
65 | buf[0x56+0x4] = 0; | ||
66 | id3->year = atoi(&buf[0x56]); | ||
67 | |||
68 | /* Copy Album (assumed max 0x1f-0x05 letters + 1 zero byte) */ | ||
69 | id3->album = p; | ||
70 | buf[0x56+0x1f] = 0; | ||
71 | p = iso_decode(&buf[0x5b], p, 0, strlen(&buf[0x5b])+1); | ||
72 | |||
73 | id3->bitrate = 706; | ||
74 | id3->frequency = 44100; | ||
75 | /* New idea as posted by Marco Alanen (ravon): | ||
76 | * Set the songlength in seconds to the number of subsongs | ||
77 | * so every second represents a subsong. | ||
78 | * Users can then skip the current subsong by seeking | ||
79 | * | ||
80 | * Note: the number of songs is a 16bit value at 0xE, so this code only | ||
81 | * uses the lower 8 bits of the counter. | ||
82 | */ | ||
83 | id3->length = (buf[0xf]-1)*1000; | ||
84 | id3->vbr = false; | ||
85 | id3->filesize = filesize(fd); | ||
86 | |||
87 | return true; | ||
88 | } | ||