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