/* Read sample information */ static BOOL OKT_doSAMP(int len) { int t; SAMPLE *q; OKTSAMPLE s; of.numins = of.numsmp = (len / 0x20); if (!AllocSamples()) return 0; for (t = 0, q = of.samples; t < of.numins; t++, q++) { _mm_read_UBYTES(s.sampname, 20, modreader); s.len = _mm_read_M_ULONG(modreader); s.loopbeg = _mm_read_M_UWORD(modreader); s.looplen = _mm_read_M_UWORD(modreader); _mm_read_UBYTE(modreader); s.volume = _mm_read_UBYTE(modreader); _mm_read_M_UWORD(modreader); if (_mm_eof(modreader)) { _mm_errno = MMERR_LOADING_SAMPLEINFO; return 0; } if (!s.len) q->seekpos = q->length = q->loopstart = q->loopend = q->flags = 0; else { s.len--; /* sanity checks */ if (s.loopbeg > s.len) s.loopbeg = s.len; if (s.loopbeg + s.looplen > s.len) s.looplen = s.len - s.loopbeg; if (s.looplen < 2) s.looplen = 0; q->length = s.len; q->loopstart = s.loopbeg; q->loopend = s.looplen + q->loopstart; q->volume = s.volume; q->flags = SF_SIGNED; if (s.looplen) q->flags |= SF_LOOP; } q->samplename = DupStr(s.sampname, 20, 1); q->speed = 8363; } return 1; }
SLONG _mm_read_M_SLONG (URL reader) { return ((SLONG) _mm_read_M_ULONG (reader)); }
BOOL OKT_Load(BOOL curious) { UBYTE id[4]; ULONG len; ULONG fp; BOOL seen_cmod = 0, seen_samp = 0, seen_slen = 0, seen_plen = 0, seen_patt = 0, seen_spee = 0; int patnum = 0, insnum = 0; /* skip OKTALYZER header */ _mm_fseek(modreader, 8, SEEK_SET); of.songname = strdup(""); of.modtype = strdup("Amiga Oktalyzer"); of.numpos = of.reppos = 0; /* default values */ of.initspeed = 6; of.inittempo = 125; while (1) { /* read block header */ _mm_read_UBYTES(id, 4, modreader); len = _mm_read_M_ULONG(modreader); if (_mm_eof(modreader)) break; fp = _mm_ftell(modreader); if (!memcmp(id, "CMOD", 4)) { if (!seen_cmod) { OKT_doCMOD(); seen_cmod = 1; } else { _mm_errno = MMERR_LOADING_HEADER; return 0; } } else if (!memcmp(id, "SAMP", 4)) { if (!seen_samp && OKT_doSAMP(len)) seen_samp = 1; else { _mm_errno = MMERR_LOADING_HEADER; return 0; } } else if (!memcmp(id, "SPEE", 4)) { if (!seen_spee) { OKT_doSPEE(); seen_spee = 1; } else { _mm_errno = MMERR_LOADING_HEADER; return 0; } } else if (!memcmp(id, "SLEN", 4)) { if (!seen_slen) { OKT_doSLEN(); seen_slen = 1; } else { _mm_errno = MMERR_LOADING_HEADER; return 0; } } else if (!memcmp(id, "PLEN", 4)) { if (!seen_plen) { OKT_doPLEN(); seen_plen = 1; } else { _mm_errno = MMERR_LOADING_HEADER; return 0; } } else if (!memcmp(id, "PATT", 4)) { if (!seen_plen) { _mm_errno = MMERR_LOADING_HEADER; return 0; } if (!seen_patt && OKT_doPATT()) seen_patt = 1; else { _mm_errno = MMERR_LOADING_HEADER; return 0; } } else if (!memcmp(id,"PBOD", 4)) { /* need to know numpat and numchn */ if (!seen_slen || !seen_cmod || (patnum >= of.numpat)) { _mm_errno = MMERR_LOADING_HEADER; return 0; } if (!OKT_doPBOD(patnum++)) { _mm_errno = MMERR_LOADING_PATTERN; return 0; } } else if (!memcmp(id,"SBOD",4)) { /* need to know numsmp */ if (!seen_samp) { _mm_errno = MMERR_LOADING_HEADER; return 0; } while ((insnum < of.numins) && !of.samples[insnum].length) insnum++; if (insnum >= of.numins) { _mm_errno = MMERR_LOADING_HEADER; return 0; } OKT_doSBOD(insnum++); } /* goto next block start position */ _mm_fseek(modreader, fp + len, SEEK_SET); } if (!seen_cmod || !seen_samp || !seen_patt || !seen_slen || !seen_plen || (patnum != of.numpat)) { _mm_errno = MMERR_LOADING_HEADER; return 0; } return 1; }
static BOOL loadsmp6(void) { int t; SAMPLE *sptr; sptr=of.samples; for(t=0;t<of.numsmp;t++,sptr++) { int flags; flags = _mm_read_M_UWORD(modreader); sptr->flags=0; if(flags&0x0004) sptr->flags|=SF_STEREO; if(flags&0x0002) sptr->flags|=SF_SIGNED; if(flags&0x0001) sptr->flags|=SF_16BITS; /* convert flags */ if(universion>=0x104) { if(flags&0x2000) sptr->flags|=SF_UST_LOOP; if(flags&0x1000) sptr->flags|=SF_OWNPAN; if(flags&0x0800) sptr->flags|=SF_SUSTAIN; if(flags&0x0400) sptr->flags|=SF_REVERSE; if(flags&0x0200) sptr->flags|=SF_BIDI; if(flags&0x0100) sptr->flags|=SF_LOOP; if(flags&0x0020) sptr->flags|=SF_ITPACKED; if(flags&0x0010) sptr->flags|=SF_DELTA; if(flags&0x0008) sptr->flags|=SF_BIG_ENDIAN; } else if(universion>=0x102) { if(flags&0x0800) sptr->flags|=SF_UST_LOOP; if(flags&0x0400) sptr->flags|=SF_OWNPAN; if(flags&0x0200) sptr->flags|=SF_SUSTAIN; if(flags&0x0100) sptr->flags|=SF_REVERSE; if(flags&0x0080) sptr->flags|=SF_BIDI; if(flags&0x0040) sptr->flags|=SF_LOOP; if(flags&0x0020) sptr->flags|=SF_ITPACKED; if(flags&0x0010) sptr->flags|=SF_DELTA; if(flags&0x0008) sptr->flags|=SF_BIG_ENDIAN; } else { if(flags&0x400) sptr->flags|=SF_UST_LOOP; if(flags&0x200) sptr->flags|=SF_OWNPAN; if(flags&0x100) sptr->flags|=SF_REVERSE; if(flags&0x080) sptr->flags|=SF_SUSTAIN; if(flags&0x040) sptr->flags|=SF_BIDI; if(flags&0x020) sptr->flags|=SF_LOOP; if(flags&0x010) sptr->flags|=SF_BIG_ENDIAN; if(flags&0x008) sptr->flags|=SF_DELTA; } sptr->speed = _mm_read_M_ULONG(modreader); sptr->volume = _mm_read_UBYTE(modreader); sptr->panning = _mm_read_M_UWORD(modreader); sptr->length = _mm_read_M_ULONG(modreader); sptr->loopstart = _mm_read_M_ULONG(modreader); sptr->loopend = _mm_read_M_ULONG(modreader); sptr->susbegin = _mm_read_M_ULONG(modreader); sptr->susend = _mm_read_M_ULONG(modreader); sptr->globvol = _mm_read_UBYTE(modreader); sptr->vibflags = _mm_read_UBYTE(modreader); sptr->vibtype = _mm_read_UBYTE(modreader); sptr->vibsweep = _mm_read_UBYTE(modreader); sptr->vibdepth = _mm_read_UBYTE(modreader); sptr->vibrate = _mm_read_UBYTE(modreader); sptr->samplename=readstring(); if(_mm_eof(modreader)) { _mm_errno = MMERR_LOADING_SAMPLEINFO; return 0; } } return 1; }
static GT_CHUNK *loadChunk(void) { GT_CHUNK *new_chunk = (GT_CHUNK *) MikMod_malloc(sizeof(GT_CHUNK)); if (!new_chunk) return NULL; /* the file chunk id only use 3 bytes, others 4 */ _mm_read_UBYTES(new_chunk->id, 3, modreader); if (memcmp(new_chunk, "GT2", 3) != 0) { _mm_read_UBYTES(&new_chunk->id[3], 1, modreader); } else { new_chunk->id[3] = ' '; } #ifdef MIKMOD_DEBUG fprintf(stderr, ">> %c%c%c%c\n", new_chunk->id[0], new_chunk->id[1], new_chunk->id[2], new_chunk->id[3]); #endif if (!memcmp(new_chunk, "GT2", 3)) { _mm_read_UBYTES(&new_chunk->gt2.version, 1, modreader); _mm_read_M_ULONGS(&new_chunk->gt2.chunk_size, 1, modreader); new_chunk->gt2.module_name[32] = 0; _mm_read_UBYTES(&new_chunk->gt2.module_name, 32, modreader); new_chunk->gt2.comments_author[160] = 0; _mm_read_UBYTES(&new_chunk->gt2.comments_author, 160, modreader); _mm_read_UBYTES(&new_chunk->gt2.date_day, 1, modreader); _mm_read_UBYTES(&new_chunk->gt2.date_month, 1, modreader); _mm_read_M_UWORDS(&new_chunk->gt2.date_year, 1, modreader); new_chunk->gt2.tracker_name[24] = 0; _mm_read_UBYTES(&new_chunk->gt2.tracker_name, 24, modreader); if (new_chunk->gt2.version > 5) return new_chunk; _mm_read_M_UWORDS(&new_chunk->gt2.initial_speed, 1, modreader); _mm_read_M_UWORDS(&new_chunk->gt2.initial_tempo, 1, modreader); _mm_read_M_UWORDS(&new_chunk->gt2.initial_master_volume, 1, modreader); _mm_read_M_UWORDS(&new_chunk->gt2.num_voices, 1, modreader); new_chunk->gt2.voice_pannings = (UWORD *) MikMod_malloc(2*new_chunk->gt2.num_voices); if (new_chunk->gt2.voice_pannings == NULL) goto fail; _mm_read_M_UWORDS(new_chunk->gt2.voice_pannings, new_chunk->gt2.num_voices, modreader); return new_chunk; } if (!memcmp(new_chunk, "TVOL", 4)) { new_chunk->tvol.chunk_size = _mm_read_M_ULONG(modreader); new_chunk->tvol.num_tracks = _mm_read_M_UWORD(modreader); new_chunk->tvol.track_volumes = (UWORD *) MikMod_malloc(new_chunk->tvol.num_tracks * 2); if (new_chunk->tvol.track_volumes == NULL) goto fail; _mm_read_M_UWORDS(new_chunk->tvol.track_volumes, new_chunk->tvol.num_tracks, modreader); return new_chunk; } if (!memcmp(new_chunk, "XCOM", 4)) { new_chunk->xcom.chunk_size = _mm_read_M_ULONG(modreader); new_chunk->xcom.comment_len = _mm_read_M_UWORD(modreader); if (!new_chunk->xcom.comment_len) { new_chunk->xcom.comment = NULL; return new_chunk; } new_chunk->xcom.comment = (CHAR *) MikMod_malloc((ULONG)new_chunk->xcom.comment_len + 1); if (new_chunk->xcom.comment == NULL) goto fail; _mm_read_UBYTES(new_chunk->xcom.comment, new_chunk->xcom.comment_len, modreader); return new_chunk; } if (!memcmp(new_chunk, "SONG", 4)) { new_chunk->song.chunk_size = _mm_read_M_ULONG(modreader); new_chunk->song.song_length = _mm_read_M_UWORD(modreader); new_chunk->song.song_repeat_point = _mm_read_M_UWORD(modreader); new_chunk->song.patterns = (UWORD *) MikMod_malloc(2*new_chunk->song.song_length); if (new_chunk->song.patterns == NULL) goto fail; _mm_read_M_UWORDS(new_chunk->song.patterns, new_chunk->song.song_length, modreader); return new_chunk; } if (!memcmp(new_chunk, "PATS", 4)) { new_chunk->pats.chunk_size = _mm_read_M_ULONG(modreader); new_chunk->pats.num_tracks = _mm_read_M_UWORD(modreader); new_chunk->pats.num_patterns = _mm_read_M_UWORD(modreader); return new_chunk; } if (!memcmp(new_chunk, "PATD", 4)) { new_chunk->patd.chunk_size = _mm_read_M_ULONG(modreader); new_chunk->patd.pattern_number = _mm_read_M_UWORD(modreader); new_chunk->patd.pattern_name[16] = 0; _mm_read_UBYTES(new_chunk->patd.pattern_name, 16, modreader); new_chunk->patd.codage_version = _mm_read_M_UWORD(modreader); new_chunk->patd.num_lines = _mm_read_M_UWORD(modreader); new_chunk->patd.num_tracks = _mm_read_M_UWORD(modreader); new_chunk->patd.notes = (GT_NOTE *) MikMod_malloc(5 * new_chunk->patd.num_lines * new_chunk->patd.num_tracks); if (new_chunk->patd.notes == NULL) goto fail; _mm_read_UBYTES(new_chunk->patd.notes, new_chunk->patd.num_lines * new_chunk->patd.num_tracks * 5, modreader); return new_chunk; } if (!memcmp(new_chunk, "ORCH", 4)) { new_chunk->orch.chunk_size = _mm_read_M_ULONG(modreader); new_chunk->orch.num_instruments = _mm_read_M_UWORD(modreader); return new_chunk; } if (!memcmp(new_chunk, "INST", 4)) { return new_chunk; } if (!memcmp(new_chunk, "SAMP", 4)) { return new_chunk; } if (!memcmp(new_chunk, "VENV", 4)) { return new_chunk; } if (!memcmp(new_chunk, "TENV", 4)) { return new_chunk; } if (!memcmp(new_chunk, "PENV", 4)) { return new_chunk; } if (!memcmp(new_chunk, "ENDC", 4)) { return new_chunk; } #ifdef MIKMOD_DEBUG fprintf(stderr, "?? %c%c%c%c\n", new_chunk->id[0], new_chunk->id[1], new_chunk->id[2], new_chunk->id[3]); #endif fail: MikMod_free(new_chunk); return NULL; /* unknown chunk */ }
SLONG _mm_read_M_SLONG() { return((SLONG)_mm_read_M_ULONG()); }