static int mmd3_test(HIO_HANDLE *f, char *t, const int start) { char id[4]; uint32 offset, len; if (hio_read(id, 1, 4, f) < 4) return -1; if (memcmp(id, "MMD2", 4) && memcmp(id, "MMD3", 4)) return -1; hio_seek(f, 28, SEEK_CUR); offset = hio_read32b(f); /* expdata_offset */ if (offset) { hio_seek(f, start + offset + 44, SEEK_SET); offset = hio_read32b(f); len = hio_read32b(f); hio_seek(f, start + offset, SEEK_SET); read_title(f, t, len); } else { read_title(f, t, 0); } return 0; }
static int emod_load(struct module_data *m, HIO_HANDLE * f, const int start) { iff_handle handle; int ret; LOAD_INIT(); hio_read32b(f); /* FORM */ hio_read32b(f); hio_read32b(f); /* EMOD */ handle = iff_new(); if (handle == NULL) return -1; /* IFF chunk IDs */ ret = iff_register(handle, "EMIC", get_emic); ret |= iff_register(handle, "PATT", get_patt); ret |= iff_register(handle, "8SMP", get_8smp); if (ret != 0) return -1; /* Load IFF chunks */ if (iff_load(handle, m, f, NULL) < 0) { iff_release(handle); return -1; } iff_release(handle); return 0; }
int mmd_load_hybrid_instrument(HIO_HANDLE *f, struct module_data *m, int i, int smp_idx, struct SynthInstr *synth, struct InstrExt *exp_smp, struct MMD0sample *sample) { struct xmp_module *mod = &m->mod; struct xmp_instrument *xxi = &mod->xxi[i]; struct xmp_subinstrument *sub; struct xmp_sample *xxs; int length, type; int pos = hio_tell(f); synth->defaultdecay = hio_read8(f); hio_seek(f, 3, SEEK_CUR); synth->rep = hio_read16b(f); synth->replen = hio_read16b(f); synth->voltbllen = hio_read16b(f); synth->wftbllen = hio_read16b(f); synth->volspeed = hio_read8(f); synth->wfspeed = hio_read8(f); synth->wforms = hio_read16b(f); hio_read(synth->voltbl, 1, 128, f);; hio_read(synth->wftbl, 1, 128, f);; hio_seek(f, pos - 6 + hio_read32b(f), SEEK_SET); length = hio_read32b(f); type = hio_read16b(f); if (med_new_instrument_extras(xxi) != 0) return -1; xxi->nsm = 1; if (subinstrument_alloc(mod, i, 1) < 0) return -1; MED_INSTRUMENT_EXTRAS((*xxi))->vts = synth->volspeed; MED_INSTRUMENT_EXTRAS((*xxi))->wts = synth->wfspeed; sub = &xxi->sub[0]; sub->pan = 0x80; sub->vol = sample->svol; sub->xpo = sample->strans; sub->sid = smp_idx; sub->fin = exp_smp->finetune; xxs = &mod->xxs[smp_idx]; xxs->len = length; xxs->lps = 2 * sample->rep; xxs->lpe = xxs->lps + 2 * sample->replen; xxs->flg = sample->replen > 1 ? XMP_SAMPLE_LOOP : 0; if (load_sample(m, f, 0, xxs, NULL) < 0) return -1; return 0; }
static int gdm_test(HIO_HANDLE *f, char *t, const int start) { if (hio_read32b(f) != MAGIC_GDM) return -1; hio_seek(f, start + 0x47, SEEK_SET); if (hio_read32b(f) != MAGIC_GMFS) return -1; hio_seek(f, start + 4, SEEK_SET); libxmp_read_title(f, t, 32); return 0; }
static int sfx_test(HIO_HANDLE *f, char *t, const int start) { uint32 a, b; hio_seek(f, 4 * 15, SEEK_CUR); a = hio_read32b(f); hio_seek(f, 4 * 15, SEEK_CUR); b = hio_read32b(f); if (a != MAGIC_SONG && b != MAGIC_SONG) return -1; read_title(f, t, 0); return 0; }
static int read_abk_song(HIO_HANDLE *f, struct abk_song *song, uint32 songs_section_offset) { int i; uint32 song_section; /* move to the start of the songs data section */ hio_seek(f, songs_section_offset, SEEK_SET); if (hio_read16b(f) != 1) { /* we only support a single song. * in a an abk file for now */ return -1; } song_section = hio_read32b(f); hio_seek(f, songs_section_offset + song_section, SEEK_SET); for (i=0; i<AMOS_ABK_CHANNELS; i++) { song->playlist_offset[i] = hio_read16b(f) + songs_section_offset + song_section; } song->tempo = hio_read16b(f); /* unused. just progress the file pointer forward */ (void) hio_read16b(f); hio_read(song->song_name, 1, AMOS_STRING_LEN, f); return 0; }
static int pt3_load(struct module_data *m, HIO_HANDLE *f, const int start) { iff_handle handle; char buf[20]; int ret; LOAD_INIT(); hio_read32b(f); /* FORM */ hio_read32b(f); /* size */ hio_read32b(f); /* MODL */ hio_read32b(f); /* VERS */ hio_read32b(f); /* VERS size */ hio_read(buf, 1, 10, f); set_type(m, "%-6.6s IFFMODL", buf + 4); handle = iff_new(); if (handle == NULL) return -1; /* IFF chunk IDs */ ret = iff_register(handle, "INFO", get_info); ret |= iff_register(handle, "CMNT", get_cmnt); ret |= iff_register(handle, "PTDT", get_ptdt); if (ret != 0) return -1; iff_set_quirk(handle, IFF_FULL_CHUNK_SIZE); /* Load IFF chunks */ if (iff_load(handle, m, f, NULL) < 0) { iff_release(handle); return -1; } iff_release(handle); /* Sanity check */ if (m->mod.smp <= 0) { return -1; } return 0; }
static int dt_test(HIO_HANDLE *f, char *t, const int start) { if (hio_read32b(f) != MAGIC_D_T_) return -1; hio_read32b(f); /* chunk size */ hio_read16b(f); /* type */ hio_read16b(f); /* 0xff then mono */ hio_read16b(f); /* reserved */ hio_read16b(f); /* tempo */ hio_read16b(f); /* bpm */ hio_read32b(f); /* undocumented */ read_title(f, t, 32); return 0; }
static int pt3_test(HIO_HANDLE *f, char *t, const int start) { if (hio_read32b(f) != MAGIC_FORM) return -1; hio_read32b(f); /* skip size */ if (hio_read32b(f) != MAGIC_MODL) return -1; if (hio_read32b(f) != MAGIC_VERS) return -1; hio_read32b(f); /* skip size */ hio_seek(f, 10, SEEK_CUR); if (hio_read32b(f) == MAGIC_INFO) { hio_read32b(f); /* skip size */ read_title(f, t, 32); } else { read_title(f, t, 0); } return 0; }
static int psm_test(HIO_HANDLE *f, char *t, const int start) { if (hio_read32b(f) != MAGIC_PSM_) return -1; libxmp_read_title(f, t, 60); return 0; }
static int far_test(HIO_HANDLE *f, char *t, const int start) { if (hio_read32b(f) != MAGIC_FAR) return -1; read_title(f, t, 40); return 0; }
static int it_test(HIO_HANDLE *f, char *t, const int start) { if (hio_read32b(f) != MAGIC_IMPM) return -1; read_title(f, t, 26); return 0; }
static int med3_test(HIO_HANDLE *f, char *t, const int start) { if (hio_read32b(f) != MAGIC_MED3) return -1; read_title(f, t, 0); return 0; }
static int mgt_test(HIO_HANDLE *f, char *t, const int start) { int sng_ptr; if (hio_read24b(f) != MAGIC_MGT) return -1; hio_read8(f); if (hio_read32b(f) != MAGIC_MCS) return -1; hio_seek(f, 18, SEEK_CUR); sng_ptr = hio_read32b(f); hio_seek(f, start + sng_ptr, SEEK_SET); read_title(f, t, 32); return 0; }
static int no_test(HIO_HANDLE *f, char *t, const int start) { if (hio_read32b(f) != 0x4e4f0000) /* NO 0x00 0x00 */ return -1; read_title(f, t, hio_read8(f)); return 0; }
static int gal4_test(HIO_HANDLE *f, char *t, const int start) { if (hio_read32b(f) != MAGIC4('R', 'I', 'F', 'F')) return -1; hio_read32b(f); if (hio_read32b(f) != MAGIC4('A', 'M', 'F', 'F')) return -1; if (hio_read32b(f) != MAGIC4('M', 'A', 'I', 'N')) return -1; hio_read32b(f); /* skip size */ read_title(f, t, 64); return 0; }
static int mdl_test(HIO_HANDLE *f, char *t, const int start) { uint16 id; if (hio_read32b(f) != MAGIC_DMDL) return -1; hio_read8(f); /* version */ id = hio_read16b(f); if (id == 0x494e) { /* IN */ hio_read32b(f); read_title(f, t, 32); } else { read_title(f, t, 0); } return 0; }
static int dmf_test(HIO_HANDLE * f, char *t, const int start) { if (hio_read32b(f) != MAGIC_DDMF) return -1; hio_seek(f, 9, SEEK_CUR); read_title(f, t, 30); return 0; }
static int emod_test(HIO_HANDLE * f, char *t, const int start) { if (hio_read32b(f) != MAGIC_FORM) return -1; hio_read32b(f); if (hio_read32b(f) != MAGIC_EMOD) return -1; if (hio_read32b(f) == MAGIC_EMIC) { hio_read32b(f); /* skip size */ hio_read16b(f); /* skip version */ read_title(f, t, 20); } else { read_title(f, t, 0); } return 0; }
static int s3m_test(HIO_HANDLE *f, char *t, const int start) { hio_seek(f, start + 44, SEEK_SET); if (hio_read32b(f) != MAGIC_SCRM) return -1; hio_seek(f, start + 0, SEEK_SET); read_title(f, t, 28); return 0; }
static int stim_test(HIO_HANDLE *f, char *t, const int start) { if (hio_read32b(f) != MAGIC_STIM) return -1; if (hio_read16b(f) > 16) return -1; read_title(f, t, 0); return 0; }
static int get_samp(struct module_data *m, int size, HIO_HANDLE *f, void *parm) { struct xmp_module *mod = &m->mod; struct local_data *data = (struct local_data *)parm; int i, j; int looplen; /* Should be always 36 */ mod->ins = size / 32; /* sizeof(struct okt_instrument_header); */ mod->smp = mod->ins; if (instrument_init(mod) < 0) return -1; for (j = i = 0; i < mod->ins; i++) { struct xmp_instrument *xxi = &mod->xxi[i]; struct xmp_sample *xxs = &mod->xxs[j]; struct xmp_subinstrument *sub; if (subinstrument_alloc(mod, i, 1) < 0) return -1; sub = &xxi->sub[0]; hio_read(xxi->name, 1, 20, f); adjust_string((char *)xxi->name); /* Sample size is always rounded down */ xxs->len = hio_read32b(f) & ~1; xxs->lps = hio_read16b(f); looplen = hio_read16b(f); xxs->lpe = xxs->lps + looplen; xxs->flg = looplen > 2 ? XMP_SAMPLE_LOOP : 0; sub->vol = hio_read16b(f); data->mode[i] = hio_read16b(f); sub->pan = 0x80; sub->sid = j; data->idx[j] = i; if (xxs->len > 0) { xxi->nsm = 1; j++; } } return 0; }
static int get_inst_cnt(struct module_data *m, int size, HIO_HANDLE *f, void *parm) { struct xmp_module *mod = &m->mod; int i; hio_read32b(f); /* 42 01 00 00 */ hio_read8(f); /* 00 */ i = hio_read8(f) + 1; /* instrument number */ if (i > mod->ins) mod->ins = i; return 0; }
static int hmn_test(HIO_HANDLE * f, char *t, const int start) { int magic; hio_seek(f, start + 1080, SEEK_SET); magic = hio_read32b(f); if (magic != MAGIC_FEST && magic != MAGIC_MK) return -1; hio_seek(f, start + 0, SEEK_SET); read_title(f, t, 20); return 0; }
static int get_s_q_(struct module_data *m, int size, HIO_HANDLE *f, void *parm) { struct xmp_module *mod = &m->mod; int i, maxpat; mod->len = hio_read16b(f); mod->rst = hio_read16b(f); hio_read32b(f); /* reserved */ for (maxpat = i = 0; i < 128; i++) { mod->xxo[i] = hio_read8(f); if (mod->xxo[i] > maxpat) maxpat = mod->xxo[i]; } mod->pat = maxpat + 1; return 0; }
static int get_d_t_(struct module_data *m, int size, HIO_HANDLE *f, void *parm) { struct xmp_module *mod = &m->mod; int b; hio_read16b(f); /* type */ hio_read16b(f); /* 0xff then mono */ hio_read16b(f); /* reserved */ mod->spd = hio_read16b(f); if ((b = hio_read16b(f)) > 0) /* RAMBO.DTM has bpm 0 */ mod->bpm = b; hio_read32b(f); /* undocumented */ hio_read(mod->name, 32, 1, f); set_type(m, "Digital Tracker DTM"); MODULE_INFO(); return 0; }
static int no_test(HIO_HANDLE *f, char *t, const int start) { int nsize, pat, chn; int i; hio_seek(f, start, SEEK_CUR); if (hio_read32b(f) != 0x4e4f0000) /* NO 0x00 0x00 */ return -1; nsize = hio_read8(f); if (nsize != 20) return -1; /* test title */ for (i = 0; i < nsize; i++) { if (hio_read8(f) == 0) return -1; } hio_seek(f, 9, SEEK_CUR); /* test number of patterns */ pat = hio_read8(f); if (pat == 0) return -1; hio_read8(f); /* test number of channels */ chn = hio_read8(f); if (chn <= 0 || chn > 16) return -1; hio_seek(f, start + 5, SEEK_SET); libxmp_read_title(f, t, nsize); return 0; }
static int gtk_load(struct module_data *m, HIO_HANDLE *f, const int start) { struct xmp_module *mod = &m->mod; struct xmp_event *event; int i, j, k; uint8 buffer[40]; int rows, bits, c2spd, size; int ver, patmax; LOAD_INIT(); hio_read(buffer, 4, 1, f); ver = buffer[3]; hio_read(mod->name, 32, 1, f); set_type(m, "Graoumf Tracker GTK v%d", ver); hio_seek(f, 160, SEEK_CUR); /* skip comments */ mod->ins = hio_read16b(f); mod->smp = mod->ins; rows = hio_read16b(f); mod->chn = hio_read16b(f); mod->len = hio_read16b(f); mod->rst = hio_read16b(f); m->volbase = 0x100; MODULE_INFO(); D_(D_INFO "Instruments : %d ", mod->ins); if (instrument_init(mod) < 0) return -1; for (i = 0; i < mod->ins; i++) { if (subinstrument_alloc(mod, i, 1) < 0) return -1; hio_read(buffer, 28, 1, f); instrument_name(mod, i, buffer, 28); if (ver == 1) { hio_read32b(f); mod->xxs[i].len = hio_read32b(f); mod->xxs[i].lps = hio_read32b(f); size = hio_read32b(f); mod->xxs[i].lpe = mod->xxs[i].lps + size - 1; hio_read16b(f); hio_read16b(f); mod->xxi[i].sub[0].vol = 0xff; mod->xxi[i].sub[0].pan = 0x80; bits = 1; c2spd = 8363; } else { hio_seek(f, 14, SEEK_CUR); hio_read16b(f); /* autobal */ bits = hio_read16b(f); /* 1 = 8 bits, 2 = 16 bits */ c2spd = hio_read16b(f); c2spd_to_note(c2spd, &mod->xxi[i].sub[0].xpo, &mod->xxi[i].sub[0].fin); mod->xxs[i].len = hio_read32b(f); mod->xxs[i].lps = hio_read32b(f); size = hio_read32b(f); mod->xxs[i].lpe = mod->xxs[i].lps + size - 1; mod->xxi[i].sub[0].vol = hio_read16b(f); hio_read8(f); mod->xxi[i].sub[0].fin = hio_read8s(f); } if (mod->xxs[i].len > 0) mod->xxi[i].nsm = 1; mod->xxi[i].sub[0].sid = i; mod->xxs[i].flg = size > 2 ? XMP_SAMPLE_LOOP : 0; if (bits > 1) { mod->xxs[i].flg |= XMP_SAMPLE_16BIT; mod->xxs[i].len >>= 1; mod->xxs[i].lps >>= 1; mod->xxs[i].lpe >>= 1; } D_(D_INFO "[%2X] %-28.28s %05x%c%05x %05x %c " "V%02x F%+03d %5d", i, mod->xxi[i].name, mod->xxs[i].len, bits > 1 ? '+' : ' ', mod->xxs[i].lps, size, mod->xxs[i].flg & XMP_SAMPLE_LOOP ? 'L' : ' ', mod->xxi[i].sub[0].vol, mod->xxi[i].sub[0].fin, c2spd); }
static int get_emic(struct module_data *m, int size, HIO_HANDLE * f, void *parm) { struct xmp_module *mod = &m->mod; int i, ver; uint8 reorder[256]; ver = hio_read16b(f); hio_read(mod->name, 1, 20, f); hio_seek(f, 20, SEEK_CUR); mod->bpm = hio_read8(f); mod->ins = hio_read8(f); mod->smp = mod->ins; m->quirk |= QUIRK_MODRNG; snprintf(mod->type, XMP_NAME_SIZE, "Quadra Composer EMOD v%d", ver); MODULE_INFO(); if (instrument_init(mod) < 0) return -1; for (i = 0; i < mod->ins; i++) { struct xmp_instrument *xxi = &mod->xxi[i]; struct xmp_sample *xxs = &mod->xxs[i]; struct xmp_subinstrument *sub; if (subinstrument_alloc(mod, i, 1) < 0) return -1; sub = &xxi->sub[0]; hio_read8(f); /* num */ sub->vol = hio_read8(f); xxs->len = 2 * hio_read16b(f); hio_read(xxi->name, 1, 20, f); xxs->flg = hio_read8(f) & 1 ? XMP_SAMPLE_LOOP : 0; sub->fin = hio_read8s(f) << 4; xxs->lps = 2 * hio_read16b(f); xxs->lpe = xxs->lps + 2 * hio_read16b(f); hio_read32b(f); /* ptr */ xxi->nsm = 1; sub->pan = 0x80; sub->sid = i; D_(D_INFO "[%2X] %-20.20s %05x %05x %05x %c V%02x %+d", i, xxi->name, xxs->len, xxs->lps, xxs->lpe, xxs->flg & XMP_SAMPLE_LOOP ? 'L' : ' ', sub->vol, sub->fin >> 4); } hio_read8(f); /* pad */ mod->pat = hio_read8(f); mod->trk = mod->pat * mod->chn; if (pattern_init(mod) < 0) return -1; memset(reorder, 0, 256); for (i = 0; i < mod->pat; i++) { reorder[hio_read8(f)] = i; if (pattern_tracks_alloc(mod, i, hio_read8(f) + 1) < 0) return -1; hio_seek(f, 20, SEEK_CUR); /* skip name */ hio_read32b(f); /* ptr */ } mod->len = hio_read8(f); D_(D_INFO "Module length: %d", mod->len); for (i = 0; i < mod->len; i++) mod->xxo[i] = reorder[hio_read8(f)]; return 0; }
static int depack_pp21(HIO_HANDLE *in, FILE *out) { uint8 ptable[128]; int max = 0; uint8 trk[4][128]; int tptr[512][64]; uint8 numpat; uint8 *tab; uint8 buf[1024]; int i, j; int size; int ssize = 0; int tabsize = 0; /* Reference Table Size */ memset(ptable, 0, 128); memset(trk, 0, 4 * 128); memset(tptr, 0, 512 * 128); pw_write_zero(out, 20); /* title */ for (i = 0; i < 31; i++) { pw_write_zero(out, 22); /* sample name */ write16b(out, size = hio_read16b(in)); ssize += size * 2; write8(out, hio_read8(in)); /* finetune */ write8(out, hio_read8(in)); /* volume */ write16b(out, hio_read16b(in)); /* loop start */ write16b(out, hio_read16b(in)); /* loop size */ } write8(out, numpat = hio_read8(in)); /* number of patterns */ write8(out, hio_read8(in)); /* NoiseTracker restart byte */ max = 0; for (j = 0; j < 4; j++) { for (i = 0; i < 128; i++) { trk[j][i] = hio_read8(in); if (trk[j][i] > max) max = trk[j][i]; } } /* write pattern table without any optimizing ! */ for (i = 0; i < numpat; i++) write8(out, i); pw_write_zero(out, 128 - i); write32b(out, PW_MOD_MAGIC); /* M.K. */ /* PATTERN DATA code starts here */ /*printf ("Highest track number : %d\n", max); */ for (j = 0; j <= max; j++) { for (i = 0; i < 64; i++) tptr[j][i] = hio_read16b(in); } /* read "reference table" size */ tabsize = hio_read32b(in); /* read "reference Table" */ tab = (uint8 *)malloc(tabsize); hio_read(tab, tabsize, 1, in); for (i = 0; i < numpat; i++) { memset(buf, 0, 1024); for (j = 0; j < 64; j++) { uint8 *b = buf + j * 16; memcpy(b, tab + tptr[trk[0][i]][j] * 4, 4); memcpy(b + 4, tab + tptr[trk[1][i]][j] * 4, 4); memcpy(b + 8, tab + tptr[trk[2][i]][j] * 4, 4); memcpy(b + 12, tab + tptr[trk[3][i]][j] * 4, 4); } fwrite (buf, 1024, 1, out); } free (tab); /* Now, it's sample data ... though, VERY quickly handled :) */ pw_move_data(out, in, ssize); return 0; }