Remove tabs.
[kugel-rb.git] / apps / metadata / mod.c
blobcbc9fc11f60d3960aa7b40ab2214abfe393c7aac
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 <stdlib.h>
23 #include <ctype.h>
24 #include <inttypes.h>
26 #include "system.h"
27 #include "metadata.h"
28 #include <string-extra.h>
29 #include "metadata_common.h"
30 #include "metadata_parsers.h"
31 #include "rbunicode.h"
33 #define MODULEHEADERSIZE 0x438
35 bool get_mod_metadata(int fd, struct mp3entry* id3)
37 /* Use the trackname part of the id3 structure as a temporary buffer */
38 unsigned char buf[MODULEHEADERSIZE];
39 unsigned char id[4];
40 bool is_mod_file = false;
41 char *p;
43 if ((lseek(fd, 0, SEEK_SET) < 0)
44 || (read(fd, buf, sizeof(buf)) < MODULEHEADERSIZE))
46 return false;
49 if (read(fd, id, sizeof(id)) < (ssize_t)sizeof(id))
50 return false;
52 /* Mod type checking based on MikMod */
53 /* Protracker and variants */
54 if ((!memcmp(id, "M.K.", 4)) || (!memcmp(id, "M!K!", 4))) {
55 is_mod_file = true;
58 /* Star Tracker */
59 if (((!memcmp(id, "FLT", 3)) || (!memcmp(id, "EXO", 3))) &&
60 (isdigit(id[3]))) {
61 char numchn = id[3] - '0';
62 if (numchn == 4 || numchn == 8)
63 is_mod_file = true;
66 /* Oktalyzer (Amiga) */
67 if (!memcmp(id, "OKTA", 4)) {
68 is_mod_file = true;
71 /* Oktalyser (Atari) */
72 if (!memcmp(id, "CD81", 4)) {
73 is_mod_file = true;
76 /* Fasttracker */
77 if ((!memcmp(id + 1, "CHN", 3)) && (isdigit(id[0]))) {
78 is_mod_file = true;
80 /* Fasttracker or Taketracker */
81 if (((!memcmp(id + 2, "CH", 2)) || (!memcmp(id + 2, "CN", 2)))
82 && (isdigit(id[0])) && (isdigit(id[1]))) {
83 is_mod_file = true;
86 /* Don't try to play if we can't find a known mod type
87 * (there are mod files which have nothing to do with music) */
88 if (!is_mod_file)
89 return false;
91 p = id3->id3v2buf;
93 /* Copy Title */
94 if (strlcpy(p, buf, sizeof(id3->id3v2buf)) >= sizeof(id3->id3v2buf))
95 return false;
97 id3->title = p;
99 id3->bitrate = filesize(fd)/1024; /* size in kb */
100 id3->frequency = 44100;
101 id3->length = 120*1000;
102 id3->vbr = false;
103 id3->filesize = filesize(fd);
105 return true;