1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
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
= id3
->id3v2buf
;
40 bool is_mod_file
= false;
42 /* Seek to file begin */
43 if (lseek(fd
, 0, SEEK_SET
) < 0)
45 /* Use id3v2buf as buffer for the track name */
46 if (read(fd
, buf
, sizeof(id3
->id3v2buf
)) < (ssize_t
)sizeof(id3
->id3v2buf
))
48 /* Seek to MOD ID position */
49 if (lseek(fd
, MODULEHEADERSIZE
, SEEK_SET
) < 0)
52 if (read(fd
, id
, sizeof(id
)) < (ssize_t
)sizeof(id
))
55 /* Mod type checking based on MikMod */
56 /* Protracker and variants */
57 if ((!memcmp(id
, "M.K.", 4)) || (!memcmp(id
, "M!K!", 4))) {
62 if (((!memcmp(id
, "FLT", 3)) || (!memcmp(id
, "EXO", 3))) &&
64 char numchn
= id
[3] - '0';
65 if (numchn
== 4 || numchn
== 8)
69 /* Oktalyzer (Amiga) */
70 if (!memcmp(id
, "OKTA", 4)) {
74 /* Oktalyser (Atari) */
75 if (!memcmp(id
, "CD81", 4)) {
80 if ((!memcmp(id
+ 1, "CHN", 3)) && (isdigit(id
[0]))) {
83 /* Fasttracker or Taketracker */
84 if (((!memcmp(id
+ 2, "CH", 2)) || (!memcmp(id
+ 2, "CN", 2)))
85 && (isdigit(id
[0])) && (isdigit(id
[1]))) {
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) */
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;
99 id3
->filesize
= filesize(fd
);