4 #include "modplug-types.h"
6 #include "music-module.h"
15 #define BUF_INIT_SIZE 65536
17 int music_mod_init(void)
19 ModPlug_Settings settings = {
20 .mFlags = MODPLUG_ENABLE_OVERSAMPLING,
23 .mResamplingMode = MODPLUG_RESAMPLE_SPLINE,
27 ModPlug_SetSettings(&settings);
31 void music_mod_exit(void)
35 static struct music_mod *readfile(struct upkg_file *f)
37 struct music_mod *m = malloc(sizeof *m + BUF_INIT_SIZE);
39 *m = (struct music_mod) {
40 .alloc = BUF_INIT_SIZE
44 struct music_mod *tmp;
45 size_t sz = m->alloc - m->len;
47 m->len += upkg_export_read(f, m->buf + m->len, sz);
48 if (m->alloc != m->len) {
50 tmp = realloc(m, sizeof *m + m->len);
57 tmp = realloc(m, sizeof *m + 2*m->alloc);
68 struct music_mod *music_mod_open(struct upkg_file *f)
70 struct music_mod *m = readfile(f);
73 m->f = ModPlug_Load(m->buf, m->len);
82 int music_mod_dump(struct music_mod *m, FILE *of)
84 if (fwrite(m->buf, m->len, 1, of) != 1)
89 void music_mod_close(struct music_mod *m)
95 const char *music_mod_type(struct music_mod *m)
97 int type = ModPlug_GetModuleType(m->f);
99 if (type & MOD_TYPE_MOD)
101 if (type & MOD_TYPE_S3M)
103 if (type & MOD_TYPE_XM)
105 if (type & MOD_TYPE_IT)