Fix Gigabeat S configure string.
[maemo-rb.git] / apps / metadata / sid.c
blob50b879b56db52d34f1a84b5622a5ef0ff8eb0b2e
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 char *p;
42 if ((lseek(fd, 0, SEEK_SET) < 0)
43 || (read(fd, buf, 0x80) < 0x80))
45 return false;
48 if ((memcmp(buf, "PSID", 4) != 0))
50 return false;
53 p = id3->id3v2buf;
55 /* Copy Title (assumed max 0x1f letters + 1 zero byte) */
56 id3->title = p;
57 buf[0x16+0x1f] = 0;
58 p = iso_decode(&buf[0x16], p, 0, strlen(&buf[0x16])+1);
60 /* Copy Artist (assumed max 0x1f letters + 1 zero byte) */
61 id3->artist = p;
62 buf[0x36+0x1f] = 0;
63 p = iso_decode(&buf[0x36], p, 0, strlen(&buf[0x36])+1);
65 /* Copy Year (assumed max 4 letters + 1 zero byte) */
66 buf[0x56+0x4] = 0;
67 id3->year = atoi(&buf[0x56]);
69 /* Copy Album (assumed max 0x1f-0x05 letters + 1 zero byte) */
70 id3->album = p;
71 buf[0x56+0x1f] = 0;
72 iso_decode(&buf[0x5b], p, 0, strlen(&buf[0x5b])+1);
74 id3->bitrate = 706;
75 id3->frequency = 44100;
76 /* New idea as posted by Marco Alanen (ravon):
77 * Set the songlength in seconds to the number of subsongs
78 * so every second represents a subsong.
79 * Users can then skip the current subsong by seeking
81 * Note: the number of songs is a 16bit value at 0xE, so this code only
82 * uses the lower 8 bits of the counter.
84 id3->length = (buf[0xf]-1)*1000;
85 id3->vbr = false;
86 id3->filesize = filesize(fd);
88 return true;