add global proxy / cache settings to httpget class. This removes the need of passing...
[Rockbox.git] / apps / metadata / sid.c
blob0dff5f62682ebe1f11e88af0b0d0ea9bb6259eb2
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 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 ****************************************************************************/
19 #include <stdio.h>
20 #include <string.h>
21 #include <stdlib.h>
22 #include <ctype.h>
23 #include <inttypes.h>
25 #include "system.h"
26 #include "id3.h"
27 #include "metadata_common.h"
28 #include "atoi.h"
29 #include "rbunicode.h"
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)
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;
41 if ((lseek(fd, 0, SEEK_SET) < 0)
42 || ((read_bytes = read(fd, buf, 0x80)) < 0x80))
44 return false;
47 if ((memcmp(buf, "PSID",4) != 0))
49 return false;
52 p = id3->id3v2buf;
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);
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);
64 /* Copy Year (assumed max 4 letters + 1 zero byte) */
65 buf[0x56+0x4] = 0;
66 id3->year = atoi(&buf[0x56]);
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);
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
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.
83 id3->length = (buf[0xf]-1)*1000;
84 id3->vbr = false;
85 id3->filesize = filesize(fd);
87 return true;