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
[MODULEHEADERSIZE
];
40 bool is_mod_file
= false;
43 if ((lseek(fd
, 0, SEEK_SET
) < 0)
44 || (read(fd
, buf
, sizeof(buf
)) < MODULEHEADERSIZE
))
49 if (read(fd
, id
, sizeof(id
)) < (ssize_t
)sizeof(id
))
52 /* Mod type checking based on MikMod */
53 /* Protracker and variants */
54 if ((!memcmp(id
, "M.K.", 4)) || (!memcmp(id
, "M!K!", 4))) {
59 if (((!memcmp(id
, "FLT", 3)) || (!memcmp(id
, "EXO", 3))) &&
61 char numchn
= id
[3] - '0';
62 if (numchn
== 4 || numchn
== 8)
66 /* Oktalyzer (Amiga) */
67 if (!memcmp(id
, "OKTA", 4)) {
71 /* Oktalyser (Atari) */
72 if (!memcmp(id
, "CD81", 4)) {
77 if ((!memcmp(id
+ 1, "CHN", 3)) && (isdigit(id
[0]))) {
80 /* Fasttracker or Taketracker */
81 if (((!memcmp(id
+ 2, "CH", 2)) || (!memcmp(id
+ 2, "CN", 2)))
82 && (isdigit(id
[0])) && (isdigit(id
[1]))) {
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) */
94 if (strlcpy(p
, buf
, sizeof(id3
->id3v2buf
)) >= sizeof(id3
->id3v2buf
))
99 id3
->bitrate
= filesize(fd
)/1024; /* size in kb */
100 id3
->frequency
= 44100;
101 id3
->length
= 120*1000;
103 id3
->filesize
= filesize(fd
);