2 * upkg: tool for manipulating Unreal Tournament packages.
3 * Copyright © 2009-2011 Nick Bowler
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "modplug-types.h"
24 #include "music-module.h"
33 #define BUF_INIT_SIZE 65536
35 int music_mod_init(void)
37 ModPlug_Settings settings = {
38 .mFlags = MODPLUG_ENABLE_OVERSAMPLING,
41 .mResamplingMode = MODPLUG_RESAMPLE_SPLINE,
45 ModPlug_SetSettings(&settings);
49 void music_mod_exit(void)
53 static struct music_mod *readfile(struct upkg_file *f)
55 struct music_mod *m = malloc(sizeof *m + BUF_INIT_SIZE);
57 *m = (struct music_mod) {
58 .alloc = BUF_INIT_SIZE
62 struct music_mod *tmp;
63 size_t sz = m->alloc - m->len;
65 m->len += upkg_export_read(f, m->buf + m->len, sz);
66 if (m->alloc != m->len) {
68 tmp = realloc(m, sizeof *m + m->len);
75 tmp = realloc(m, sizeof *m + 2*m->alloc);
86 struct music_mod *music_mod_open(struct upkg_file *f)
88 struct music_mod *m = readfile(f);
91 m->f = ModPlug_Load(m->buf, m->len);
100 int music_mod_dump(struct music_mod *m, FILE *of)
102 if (fwrite(m->buf, m->len, 1, of) != 1)
107 void music_mod_close(struct music_mod *m)
109 ModPlug_Unload(m->f);
113 const char *music_mod_type(struct music_mod *m)
115 int type = ModPlug_GetModuleType(m->f);
117 if (type & MOD_TYPE_MOD)
119 if (type & MOD_TYPE_S3M)
121 if (type & MOD_TYPE_XM)
123 if (type & MOD_TYPE_IT)