summaryrefslogtreecommitdiff
path: root/lib/rbcodec/metadata/mod.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/metadata/mod.c')
-rw-r--r--lib/rbcodec/metadata/mod.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/lib/rbcodec/metadata/mod.c b/lib/rbcodec/metadata/mod.c
new file mode 100644
index 0000000000..de76823e91
--- /dev/null
+++ b/lib/rbcodec/metadata/mod.c
@@ -0,0 +1,103 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 Dave Chapman
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include <stdio.h>
22#include <stdlib.h>
23#include <ctype.h>
24#include <inttypes.h>
25
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"
32
33#define MODULEHEADERSIZE 0x438
34
35bool get_mod_metadata(int fd, struct mp3entry* id3)
36{
37 /* Use the trackname part of the id3 structure as a temporary buffer */
38 unsigned char *buf = id3->id3v2buf;
39 unsigned char id[4];
40 bool is_mod_file = false;
41
42 /* Seek to file begin */
43 if (lseek(fd, 0, SEEK_SET) < 0)
44 return false;
45 /* Use id3v2buf as buffer for the track name */
46 if (read(fd, buf, sizeof(id3->id3v2buf)) < (ssize_t)sizeof(id3->id3v2buf))
47 return false;
48 /* Seek to MOD ID position */
49 if (lseek(fd, MODULEHEADERSIZE, SEEK_SET) < 0)
50 return false;
51 /* Read MOD ID */
52 if (read(fd, id, sizeof(id)) < (ssize_t)sizeof(id))
53 return false;
54
55 /* Mod type checking based on MikMod */
56 /* Protracker and variants */
57 if ((!memcmp(id, "M.K.", 4)) || (!memcmp(id, "M!K!", 4))) {
58 is_mod_file = true;
59 }
60
61 /* Star Tracker */
62 if (((!memcmp(id, "FLT", 3)) || (!memcmp(id, "EXO", 3))) &&
63 (isdigit(id[3]))) {
64 char numchn = id[3] - '0';
65 if (numchn == 4 || numchn == 8)
66 is_mod_file = true;
67 }
68
69 /* Oktalyzer (Amiga) */
70 if (!memcmp(id, "OKTA", 4)) {
71 is_mod_file = true;
72 }
73
74 /* Oktalyser (Atari) */
75 if (!memcmp(id, "CD81", 4)) {
76 is_mod_file = true;
77 }
78
79 /* Fasttracker */
80 if ((!memcmp(id + 1, "CHN", 3)) && (isdigit(id[0]))) {
81 is_mod_file = true;
82 }
83 /* Fasttracker or Taketracker */
84 if (((!memcmp(id + 2, "CH", 2)) || (!memcmp(id + 2, "CN", 2)))
85 && (isdigit(id[0])) && (isdigit(id[1]))) {
86 is_mod_file = true;
87 }
88
89 /* Don't try to play if we can't find a known mod type
90 * (there are mod files which have nothing to do with music) */
91 if (!is_mod_file)
92 return false;
93
94 id3->title = id3->id3v2buf; /* Point title to previous read ID3 buffer. */
95 id3->bitrate = filesize(fd)/1024; /* size in kb */
96 id3->frequency = 44100;
97 id3->length = 120*1000;
98 id3->vbr = false;
99 id3->filesize = filesize(fd);
100
101 return true;
102}
103