long _mm_getfsize(MMSTREAM *mmpat) { long fsize; _mm_fseek(mmpat, 0L, SEEK_END); fsize = _mm_ftell(mmpat); _mm_fseek(mmpat, 0L, SEEK_SET); return(fsize); }
static BOOL GetBlockHeader (void) { /* make sure we're at the right position for reading the next riff block, no matter how many bytes read */ _mm_fseek (modreader, blocklp + blockln, SEEK_SET); while (1) { _mm_read_UBYTES (blockid, 4, modreader); blockln = _mm_read_I_ULONG (modreader); if (_mm_eof (modreader)) { _mm_errno = MMERR_LOADING_HEADER; return 0; } if (memcmp (blockid, SONGID, 4) && memcmp (blockid, INSTID, 4) && memcmp (blockid, PATTID, 4)) { #ifdef MIKMOD_DEBUG fprintf (stderr, "\rDSM: Skipping unknown block type %4.4s\n", blockid); #endif _mm_fseek (modreader, blockln, SEEK_CUR); } else break; } blocklp = _mm_ftell (modreader); return 1; }
static CHAR *UNI_LoadTitle(void) { UBYTE ver; int posit[3]={304,306,26}; _mm_fseek(modreader,3,SEEK_SET); ver=_mm_read_UBYTE(modreader); if(ver=='N') ver='6'; _mm_fseek(modreader,posit[ver-'4'],SEEK_SET); return readstring(); }
static void pat_read_waveheader(MMSTREAM *mmpat, WaveHeader *hw, int layer) { long int pos, bestpos=0; LayerHeader hl; ULONG bestfreq, freqdist; int i; // read the very first and maybe only sample pat_read_layerheader(mmpat, &hl); if( hl.samples > 1 ) { if( layer ) { if( layer > hl.samples ) layer = hl.samples; // you don't fool me.... for( i=1; i<layer; i++ ) { _mm_read_UBYTES((BYTE *)hw, sizeof(WaveHeader), mmpat); _mm_fseek(mmpat, hw->wave_size, SEEK_CUR); } } else { bestfreq = C4mHz * 1000; // big enough for( i=0; i<hl.samples; i++ ) { pos = _mm_ftell(mmpat); _mm_read_UBYTES((BYTE *)hw, sizeof(WaveHeader), mmpat); if( hw->root_frequency > C4mHz ) freqdist = hw->root_frequency - C4mHz; else freqdist = 2 * (C4mHz - hw->root_frequency); if( freqdist < bestfreq ) { bestfreq = freqdist; bestpos = pos; } _mm_fseek(mmpat, hw->wave_size, SEEK_CUR); } // if invalid bestpos, assume the start. if( bestpos < 0 ) bestpos = 0; _mm_fseek(mmpat, bestpos, SEEK_SET); } } _mm_read_UBYTES((BYTE *)hw, sizeof(WaveHeader), mmpat); strncpy(hw->reserved, hl.reserved, 32); hw->reserved[31] = 0; if( hw->start_loop >= hw->wave_size ) { hw->start_loop = 0; hw->end_loop = 0; hw->modes &= ~PAT_LOOP; // mask off loop indicator } if( hw->end_loop > hw->wave_size ) hw->end_loop = hw->wave_size; }
/* Loads all patterns of a modfile and converts them into the 3 byte format. */ static BOOL ML_LoadPatterns(void) { int t, s, tracks = 0; if (!AllocPatterns()) { return 0; } if (!AllocTracks()) { return 0; } /* Allocate temporary buffer for loading and converting the patterns */ if (!(patbuf = (MODNOTE *)MikMod_calloc(64U * of.numchn, sizeof(MODNOTE)))) return 0; /* patterns start here */ _mm_fseek(modreader, 0xA66, SEEK_SET); for (t = 0; t < of.numpat; t++) { /* Load the pattern into the temp buffer and convert it */ for (s = 0; s < (64U * of.numchn); s++) { patbuf[s].a = _mm_read_UBYTE(modreader); patbuf[s].b = _mm_read_UBYTE(modreader); patbuf[s].c = _mm_read_UBYTE(modreader); patbuf[s].d = _mm_read_UBYTE(modreader); } for (s = 0; s < of.numchn; s++) { if (!(of.tracks[tracks++] = ConvertTrack(patbuf + s))) { return 0; } } } return 1; }
BOOL S69_Test(void) { UBYTE buf[0x80]; if(!_mm_read_UBYTES(buf,2,modreader)) return 0; /* look for id */ if(!memcmp(buf,"if",2) || !memcmp(buf,"JN",2)) { int i; /* skip song message */ _mm_fseek(modreader,108,SEEK_CUR); /* sanity checks */ if(_mm_read_UBYTE(modreader) > 64) return 0; if(_mm_read_UBYTE(modreader) > 128) return 0; if(_mm_read_UBYTE(modreader) > 127) return 0; /* check order table */ if(!_mm_read_UBYTES(buf,0x80,modreader)) return 0; for(i=0;i<0x80;i++) if((buf[i]>=0x80)&&(buf[i]!=0xff)) return 0; /* check tempos table */ if(!_mm_read_UBYTES(buf,0x80,modreader)) return 0; for(i=0;i<0x80;i++) if((!buf[i])||(buf[i]>32)) return 0; /* check pattern length table */ if(!_mm_read_UBYTES(buf,0x80,modreader)) return 0; for(i=0;i<0x80;i++) if(buf[i]>0x3f) return 0; } else return 0; return 1; }
static BOOL STX_Test(void) { UBYTE id[8]; int t; _mm_fseek(modreader,0x3C,SEEK_SET); if(!_mm_read_UBYTES(id,4,modreader)) return 0; if(memcmp(id,"SCRM",4)) return 0; _mm_fseek(modreader,0x14,SEEK_SET); if(!_mm_read_UBYTES(id,8,modreader)) return 0; for(t=0;t<STM_NTRACKERS;t++) if(!memcmp(id,STM_Signatures[t],8)) return 1; return 0; }
BOOL S3M_Test(void) { char id[4]; _mm_fseek(modfp,0x2c,SEEK_SET); if(!fread(id,4,1,modfp)) return 0; if(!memcmp(id,"SCRM",4)) return 1; return 0; }
static BOOL S3M_Test(void) { char id[4]; _mm_fseek(0x2c,SEEK_SET); if(!_mm_read_str(id,4)) return 0; if(!memcmp(id,"SCRM",4)) return 1; return 0; }
static BOOL IMF_Test(void) { UBYTE id[4]; _mm_fseek(modreader,0x3c,SEEK_SET); if(!_mm_read_UBYTES(id,4,modreader)) return 0; if(!memcmp(id,"IM10",4)) return 1; return 0; }
CHAR *DSM_LoadTitle(void) { CHAR s[28]; _mm_fseek(modreader,12,SEEK_SET); if(!_mm_read_UBYTES(s,28,modreader)) return NULL; return(DupStr(s,28,1)); }
BOOL S3M_Test(void) { UBYTE id[4]; _mm_fseek(modreader,0x2c,SEEK_SET); if(!_mm_read_UBYTES(id,4,modreader)) return 0; if(!memcmp(id,"SCRM",4)) return 1; return 0; }
static CHAR *STX_LoadTitle(void) { CHAR s[28]; _mm_fseek(modreader,0,SEEK_SET); if(!_mm_read_UBYTES(s,20,modreader)) return NULL; return(DupStr(s,28,1)); }
CHAR *DSM_LoadTitle(void) { CHAR s[28]; _mm_fseek(modfp,12,SEEK_SET); if(!_mm_fread(s,28,1,modfp)) return NULL; return(DupStr(s,28)); }
CHAR *S69_LoadTitle(void) { CHAR s[36]; _mm_fseek(modreader,2,SEEK_SET); if(!_mm_read_UBYTES(s,36,modreader)) return NULL; return(DupStr(s,36,1)); }
static BOOL GT2_Test(void) { UBYTE magic[3]; _mm_fseek(modreader, 0, SEEK_SET); if (!_mm_read_UBYTES(magic, 3, modreader)) return 0; if (magic[0] == 'G' && magic[1] == 'T' && magic[2] == '2') { return 1; } return 0; }
static CHAR *GT2_LoadTitle(void) { CHAR title[33]; _mm_fseek(modreader, 8, SEEK_SET); if (!_mm_read_UBYTES(title, 32, modreader)) return NULL; title[32] = 0; return (DupStr(title, 32, 1)); }
static BOOL STM_Test(void) { char str[9],filetype; _mm_fseek(21,SEEK_SET); _mm_read_str(str,9); _mm_read_str(&filetype,1); if(!memcmp(str,"!SCREAM!",8) || (filetype!=2)) /* STM Module = filetype 2 */ return 0; return 1; }
BOOL GetBlockHeader(void) { /* make sure we're at the right position for reading the */ /* next riff block, no matter how many bytes read */ _mm_fseek(modfp, blocklp+blockln, SEEK_SET); while(1) { _mm_read_UBYTES(blockid,4,modfp); blockln = _mm_read_I_ULONG(modfp); if(_mm_feof(modfp)) { _mm_errno = MMERR_LOADING_HEADER; return 0; } if(memcmp(blockid,SONGID,4) && memcmp(blockid,INSTID,4) && memcmp(blockid,PATTID,4)) { /*printf("Skipping unknown block type %4.4s\n",&blockid); */ _mm_fseek(modfp, blockln, SEEK_CUR); } else break; } blocklp = _mm_ftell(modfp); return 1; }
static BOOL GT2_Load(BOOL curious) { GT_CHUNK *tmp; _mm_fseek(modreader, 0, SEEK_SET); while ((tmp = loadChunk()) != NULL) { #ifdef MIKMOD_DEBUG /* FIXME: to be completed */ fprintf(stderr, "%c%c%c%c\n", tmp->id[0], tmp->id[1], tmp->id[2], tmp->id[3]); #endif freeChunk(tmp); } _mm_errno = MMERR_LOADING_HEADER; return 0; }
static BOOL ASY_Test(void) { UBYTE namestring[24], numchn; CHAR *descr; /* Read the magic string */ _mm_fseek(modreader, 0, SEEK_SET); if (!_mm_read_UBYTES(namestring, 24, modreader)) return 0; /* Test if the string is what we expect */ if (ASY_CheckType(namestring, &numchn, &descr)) return 1; return 0; }
/* Load embedded midi information for resonant filters */ static void IT_LoadMidiConfiguration(MREADER* modreader) { int i; memset(filtermacros,0,sizeof(filtermacros)); memset(filtersettings,0,sizeof(filtersettings)); if (modreader) { /* information is embedded in file */ UWORD dat; CHAR midiline[33]; dat=_mm_read_I_UWORD(modreader); _mm_fseek(modreader,8*dat+0x120,SEEK_CUR); /* read midi macros */ for(i=0;i<16;i++) { LoadMidiString(modreader,midiline); if((!strncmp(midiline,"F0F00",5))&& ((midiline[5]=='0')||(midiline[5]=='1'))) filtermacros[i]=(midiline[5]-'0')|0x80; } /* read standalone filters */ for(i=0x80;i<0x100;i++) { LoadMidiString(modreader,midiline); if((!strncmp(midiline,"F0F00",5))&& ((midiline[5]=='0')||(midiline[5]=='1'))) { filtersettings[i].filter=(midiline[5]-'0')|0x80; dat=(midiline[6])?(midiline[6]-'0'):0; if(midiline[7])dat=(dat<<4)|(midiline[7]-'0'); filtersettings[i].inf=(UBYTE)dat; } } } else { /* use default information */ filtermacros[0]=FILT_CUT; for(i=0x80;i<0x90;i++) { filtersettings[i].filter=FILT_RESONANT; filtersettings[i].inf=(i&0x7f)<<3; } } activemacro=0; for(i=0;i<0x80;i++) { filtersettings[i].filter=filtermacros[0]; filtersettings[i].inf=i; } }
static BOOL MOD_Test(void) { int t; char id[4]; _mm_fseek(MODULEHEADERSIZE-4,SEEK_SET); if(!_mm_read_str(id,4)) return 0; /* find out which ID string */ for(t=0;t<10;t++){ if(!memcmp(id,modtypes[t].id,4)) return 1; } return 0; }
static void putheader(void) { ULONG rflen = 36; if (md_mode&DMODE_FLOAT) rflen += 2 + 12; /* FmtExt + "fact" chunk sizes */ rflen += dumpsize; _mm_fseek(wavout,0,SEEK_SET); _mm_write_string("RIFF",wavout); _mm_write_I_ULONG(rflen,wavout); _mm_write_string("WAVEfmt ",wavout); _mm_write_I_ULONG((md_mode&DMODE_FLOAT)?18:16,wavout); /* length of this RIFF block crap */ _mm_write_I_UWORD((md_mode&DMODE_FLOAT)? 3:1,wavout); /* WAVE_FORMAT_PCM :1, WAVE_FORMAT_IEEE_FLOAT :3 */ _mm_write_I_UWORD((md_mode&DMODE_STEREO)?2:1,wavout); _mm_write_I_ULONG(md_mixfreq,wavout); _mm_write_I_ULONG(md_mixfreq * ((md_mode&DMODE_STEREO)?2:1) * ((md_mode&DMODE_FLOAT)? 4: (md_mode&DMODE_16BITS)?2:1), wavout); /* block alignment (8/16 bit) */ _mm_write_I_UWORD(((md_mode&DMODE_FLOAT)?4:(md_mode&DMODE_16BITS)?2:1)* ((md_mode&DMODE_STEREO)?2:1),wavout); _mm_write_I_UWORD((md_mode&DMODE_FLOAT)?32:(md_mode&DMODE_16BITS)?16:8,wavout); if (md_mode&DMODE_FLOAT) { _mm_write_I_UWORD(0,wavout); /* 0 byte of FmtExt */ _mm_write_string("fact",wavout); _mm_write_I_ULONG(4,wavout); _mm_write_I_ULONG(dumpsize / ((md_mode&DMODE_STEREO)?2:1) / /* # of samples written */ ((md_mode&DMODE_FLOAT)? 4: (md_mode&DMODE_16BITS)?2:1), wavout); } _mm_write_string("data",wavout); _mm_write_I_ULONG(dumpsize,wavout); }
BOOL IT_Load(BOOL curious) { int t,u,lp; INSTRUMENT *d; SAMPLE *q; BOOL compressed=0; numtrk=0; filters=0; /* try to read module header */ _mm_read_I_ULONG(modreader); /* kill the 4 byte header */ _mm_read_string(mh->songname,26,modreader); _mm_read_UBYTES(mh->blank01,2,modreader); mh->ordnum =_mm_read_I_UWORD(modreader); mh->insnum =_mm_read_I_UWORD(modreader); mh->smpnum =_mm_read_I_UWORD(modreader); mh->patnum =_mm_read_I_UWORD(modreader); mh->cwt =_mm_read_I_UWORD(modreader); mh->cmwt =_mm_read_I_UWORD(modreader); mh->flags =_mm_read_I_UWORD(modreader); mh->special =_mm_read_I_UWORD(modreader); mh->globvol =_mm_read_UBYTE(modreader); mh->mixvol =_mm_read_UBYTE(modreader); mh->initspeed =_mm_read_UBYTE(modreader); mh->inittempo =_mm_read_UBYTE(modreader); mh->pansep =_mm_read_UBYTE(modreader); mh->zerobyte =_mm_read_UBYTE(modreader); mh->msglength =_mm_read_I_UWORD(modreader); mh->msgoffset =_mm_read_I_ULONG(modreader); _mm_read_UBYTES(mh->blank02,4,modreader); _mm_read_UBYTES(mh->pantable,64,modreader); _mm_read_UBYTES(mh->voltable,64,modreader); if(_mm_eof(modreader)) { _mm_errno=MMERR_LOADING_HEADER; return 0; } /* set module variables */ of.songname = DupStr(mh->songname,26,0); /* make a cstr of songname */ of.reppos = 0; of.numpat = mh->patnum; of.numins = mh->insnum; of.numsmp = mh->smpnum; of.initspeed = mh->initspeed; of.inittempo = mh->inittempo; of.initvolume = mh->globvol; of.flags |= UF_BGSLIDES|UF_ARPMEM; if(mh->songname[25]) { of.numvoices=1+mh->songname[25]; #ifdef MIKMOD_DEBUG fprintf(stderr,"Embedded IT limitation to %d voices\n",of.numvoices); #endif } /* set the module type */ /* 2.17 : IT 2.14p4 */ /* 2.16 : IT 2.14p3 with resonant filters */ /* 2.15 : IT 2.14p3 (improved compression) */ if((mh->cwt<=0x219)&&(mh->cwt>=0x217)) of.modtype=strdup(IT_Version[mh->cmwt<0x214?4:5]); else if (mh->cwt>=0x215) of.modtype=strdup(IT_Version[mh->cmwt<0x214?2:3]); else { of.modtype = strdup(IT_Version[mh->cmwt<0x214?0:1]); of.modtype[mh->cmwt<0x214?15:26] = (mh->cwt>>8)+'0'; of.modtype[mh->cmwt<0x214?17:28] = ((mh->cwt>>4)&0xf)+'0'; of.modtype[mh->cmwt<0x214?18:29] = ((mh->cwt)&0xf)+'0'; } if(mh->flags&8) of.flags|=(UF_XMPERIODS | UF_LINEAR); if((mh->cwt>=0x106)&&(mh->flags&16)) old_effect=1; else old_effect=0; /* set panning positions */ for(t=0;t<64;t++) { mh->pantable[t]&=0x7f; if(mh->pantable[t]<64) of.panning[t]=mh->pantable[t]<<2; else if(mh->pantable[t]==64) of.panning[t]=255; else if(mh->pantable[t]==100) of.panning[t]=PAN_SURROUND; else if(mh->pantable[t]==127) of.panning[t]=PAN_CENTER; else { _mm_errno=MMERR_LOADING_HEADER; return 0; } } /* set channel volumes */ memcpy(of.chanvol,mh->voltable,64); /* read the order data */ if(!AllocPositions(mh->ordnum)) return 0; if(!(origpositions=_mm_calloc(mh->ordnum,sizeof(UWORD)))) return 0; for(t=0;t<mh->ordnum;t++) { origpositions[t]=_mm_read_UBYTE(modreader); if((origpositions[t]>mh->patnum)&&(origpositions[t]<254)) origpositions[t]=255; } if(_mm_eof(modreader)) { _mm_errno = MMERR_LOADING_HEADER; return 0; } poslookupcnt=(UBYTE)mh->ordnum; S3MIT_CreateOrders(curious); if(!(paraptr=(ULONG*)_mm_malloc((mh->insnum+mh->smpnum+of.numpat)* sizeof(ULONG)))) return 0; /* read the instrument, sample, and pattern parapointers */ _mm_read_I_ULONGS(paraptr,mh->insnum+mh->smpnum+of.numpat,modreader); if(_mm_eof(modreader)) { _mm_errno = MMERR_LOADING_HEADER; return 0; } /* Check for and load midi information for resonant filters */ if(mh->cmwt>=0x216) { if(mh->special&8) { IT_LoadMidiConfiguration(modreader); if(_mm_eof(modreader)) { _mm_errno = MMERR_LOADING_HEADER; return 0; } } else IT_LoadMidiConfiguration(NULL); filters=1; } /* Check for and load song comment */ if((mh->special&1)&&(mh->cwt>=0x104)&&(mh->msglength)) { _mm_fseek(modreader,(long)(mh->msgoffset),SEEK_SET); if(!ReadComment(mh->msglength)) return 0; } if(!(mh->flags&4)) of.numins=of.numsmp; if(!AllocSamples()) return 0; if(!AllocLinear()) return 0; /* Load all samples */ q = of.samples; for(t=0;t<mh->smpnum;t++) { ITSAMPLE s; /* seek to sample position */ _mm_fseek(modreader,(long)(paraptr[mh->insnum+t]+4),SEEK_SET); /* load sample info */ _mm_read_string(s.filename,12,modreader); s.zerobyte = _mm_read_UBYTE(modreader); s.globvol = _mm_read_UBYTE(modreader); s.flag = _mm_read_UBYTE(modreader); s.volume = _mm_read_UBYTE(modreader); _mm_read_string(s.sampname,26,modreader); s.convert = _mm_read_UBYTE(modreader); s.panning = _mm_read_UBYTE(modreader); s.length = _mm_read_I_ULONG(modreader); s.loopbeg = _mm_read_I_ULONG(modreader); s.loopend = _mm_read_I_ULONG(modreader); s.c5spd = _mm_read_I_ULONG(modreader); s.susbegin = _mm_read_I_ULONG(modreader); s.susend = _mm_read_I_ULONG(modreader); s.sampoffset = _mm_read_I_ULONG(modreader); s.vibspeed = _mm_read_UBYTE(modreader); s.vibdepth = _mm_read_UBYTE(modreader); s.vibrate = _mm_read_UBYTE(modreader); s.vibwave = _mm_read_UBYTE(modreader); /* Generate an error if c5spd is > 512k, or samplelength > 256 megs (nothing would EVER be that high) */ if(_mm_eof(modreader)||(s.c5spd>0x7ffffL)||(s.length>0xfffffffUL)|| (s.loopbeg>0xfffffffUL)||(s.loopend>0xfffffffUL)) { _mm_errno = MMERR_LOADING_SAMPLEINFO; return 0; } q->samplename = DupStr(s.sampname,26,0); q->speed = s.c5spd / 2; q->panning = ((s.panning&127)==64)?255:(s.panning&127)<<2; q->length = s.length; q->loopstart = s.loopbeg; q->loopend = s.loopend; q->volume = s.volume; q->globvol = s.globvol; q->seekpos = s.sampoffset; /* Convert speed to XM linear finetune */ if(of.flags&UF_LINEAR) q->speed=speed_to_finetune(s.c5spd,t); if(s.panning&128) q->flags|=SF_OWNPAN; if(s.vibrate) { q->vibflags |= AV_IT; q->vibtype = s.vibwave; q->vibsweep = s.vibrate * 2; q->vibdepth = s.vibdepth; q->vibrate = s.vibspeed; } if(s.flag&2) q->flags|=SF_16BITS; if((s.flag&8)&&(mh->cwt>=0x214)) { q->flags|=SF_ITPACKED; compressed=1; } if(s.flag&16) q->flags|=SF_LOOP; if(s.flag&64) q->flags|=SF_BIDI; if(mh->cwt>=0x200) { if(s.convert&1) q->flags|=SF_SIGNED; if(s.convert&4) q->flags|=SF_DELTA; } q++; } /* Load instruments if instrument mode flag enabled */ if(mh->flags&4) { if(!AllocInstruments()) return 0; d=of.instruments; of.flags|=UF_NNA|UF_INST; for(t=0;t<mh->insnum;t++) { ITINSTHEADER ih; /* seek to instrument position */ _mm_fseek(modreader,paraptr[t]+4,SEEK_SET); /* load instrument info */ _mm_read_string(ih.filename,12,modreader); ih.zerobyte = _mm_read_UBYTE(modreader); if(mh->cwt<0x200) { /* load IT 1.xx inst header */ ih.volflg = _mm_read_UBYTE(modreader); ih.volbeg = _mm_read_UBYTE(modreader); ih.volend = _mm_read_UBYTE(modreader); ih.volsusbeg = _mm_read_UBYTE(modreader); ih.volsusend = _mm_read_UBYTE(modreader); _mm_read_I_UWORD(modreader); ih.fadeout = _mm_read_I_UWORD(modreader); ih.nna = _mm_read_UBYTE(modreader); ih.dnc = _mm_read_UBYTE(modreader); } else { /* Read IT200+ header */ ih.nna = _mm_read_UBYTE(modreader); ih.dct = _mm_read_UBYTE(modreader); ih.dca = _mm_read_UBYTE(modreader); ih.fadeout = _mm_read_I_UWORD(modreader); ih.ppsep = _mm_read_UBYTE(modreader); ih.ppcenter = _mm_read_UBYTE(modreader); ih.globvol = _mm_read_UBYTE(modreader); ih.chanpan = _mm_read_UBYTE(modreader); ih.rvolvar = _mm_read_UBYTE(modreader); ih.rpanvar = _mm_read_UBYTE(modreader); } ih.trkvers = _mm_read_I_UWORD(modreader); ih.numsmp = _mm_read_UBYTE(modreader); _mm_read_UBYTE(modreader); _mm_read_string(ih.name,26,modreader); _mm_read_UBYTES(ih.blank01,6,modreader); _mm_read_I_UWORDS(ih.samptable,ITNOTECNT,modreader); if(mh->cwt<0x200) { /* load IT 1xx volume envelope */ _mm_read_UBYTES(ih.volenv,200,modreader); for(lp=0;lp<ITENVCNT;lp++) { ih.oldvoltick[lp] = _mm_read_UBYTE(modreader); ih.volnode[lp] = _mm_read_UBYTE(modreader); } } else { /* load IT 2xx volume, pan and pitch envelopes */ ih.volflg =_mm_read_UBYTE(modreader); ih.volpts =_mm_read_UBYTE(modreader); ih.volbeg =_mm_read_UBYTE(modreader); ih.volend =_mm_read_UBYTE(modreader); ih.volsusbeg=_mm_read_UBYTE(modreader); ih.volsusend=_mm_read_UBYTE(modreader); for(lp=0;lp<ITENVCNT;lp++) { ih.volnode[lp]=_mm_read_UBYTE(modreader); ih.voltick[lp]=_mm_read_I_UWORD(modreader); } _mm_read_UBYTE(modreader); ih.panflg =_mm_read_UBYTE(modreader); ih.panpts =_mm_read_UBYTE(modreader); ih.panbeg =_mm_read_UBYTE(modreader); ih.panend =_mm_read_UBYTE(modreader); ih.pansusbeg=_mm_read_UBYTE(modreader); ih.pansusend=_mm_read_UBYTE(modreader); for(lp=0;lp<ITENVCNT;lp++) { ih.pannode[lp]=_mm_read_SBYTE(modreader); ih.pantick[lp]=_mm_read_I_UWORD(modreader); } _mm_read_UBYTE(modreader); ih.pitflg =_mm_read_UBYTE(modreader); ih.pitpts =_mm_read_UBYTE(modreader); ih.pitbeg =_mm_read_UBYTE(modreader); ih.pitend =_mm_read_UBYTE(modreader); ih.pitsusbeg=_mm_read_UBYTE(modreader); ih.pitsusend=_mm_read_UBYTE(modreader); for(lp=0;lp < ITENVCNT; lp++) { ih.pitnode[lp]=_mm_read_SBYTE(modreader); ih.pittick[lp]=_mm_read_I_UWORD(modreader); } _mm_read_UBYTE(modreader); } if(_mm_eof(modreader)) { _mm_errno = MMERR_LOADING_SAMPLEINFO; return 0; } d->volflg|=EF_VOLENV; d->insname = DupStr(ih.name,26,0); d->nnatype = ih.nna & NNA_MASK; if(mh->cwt<0x200) { d->volfade=ih.fadeout<< 6; if(ih.dnc) { d->dct=DCT_NOTE; d->dca=DCA_CUT; } if(ih.volflg&1) d->volflg|=EF_ON; if(ih.volflg&2) d->volflg|=EF_LOOP; if(ih.volflg&4) d->volflg|=EF_SUSTAIN; /* XM conversion of IT envelope Array */ d->volbeg = ih.volbeg; d->volend = ih.volend; d->volsusbeg = ih.volsusbeg; d->volsusend = ih.volsusend; if(ih.volflg&1) { for(u=0;u<ITENVCNT;u++) if(ih.oldvoltick[d->volpts]!=0xff) { d->volenv[d->volpts].val=(ih.volnode[d->volpts]<<2); d->volenv[d->volpts].pos=ih.oldvoltick[d->volpts]; d->volpts++; } else break; } } else { d->panning=((ih.chanpan&127)==64)?255:(ih.chanpan&127)<<2; if(!(ih.chanpan&128)) d->flags|=IF_OWNPAN; if(!(ih.ppsep & 128)) { d->pitpansep=ih.ppsep<<2; d->pitpancenter=ih.ppcenter; d->flags|=IF_PITCHPAN; } d->globvol=ih.globvol>>1; d->volfade=ih.fadeout<<5; d->dct =ih.dct; d->dca =ih.dca; if(mh->cwt>=0x204) { d->rvolvar = ih.rvolvar; d->rpanvar = ih.rpanvar; } if(ih.volflg&1) d->volflg|=EF_ON; if(ih.volflg&2) d->volflg|=EF_LOOP; if(ih.volflg&4) d->volflg|=EF_SUSTAIN; d->volpts=ih.volpts; d->volbeg=ih.volbeg; d->volend=ih.volend; d->volsusbeg=ih.volsusbeg; d->volsusend=ih.volsusend; for(u=0;u<ih.volpts;u++) d->volenv[u].pos=ih.voltick[u]; if((d->volflg&EF_ON)&&(d->volpts<2)) d->volflg&=~EF_ON; for(u=0;u<ih.volpts;u++) d->volenv[u].val=(ih.volnode[u]<<2); if(ih.panflg&1) d->panflg|=EF_ON; if(ih.panflg&2) d->panflg|=EF_LOOP; if(ih.panflg&4) d->panflg|=EF_SUSTAIN; d->panpts=ih.panpts; d->panbeg=ih.panbeg; d->panend=ih.panend; d->pansusbeg=ih.pansusbeg; d->pansusend=ih.pansusend; for(u=0;u<ih.panpts;u++) d->panenv[u].pos=ih.pantick[u]; if((d->panflg&EF_ON)&&(d->panpts<2)) d->panflg&=~EF_ON; for(u=0;u<ih.panpts;u++) d->panenv[u].val=ih.pannode[u]==32?255:(ih.pannode[u]+32)<<2; if(ih.pitflg&1) d->pitflg|=EF_ON; if(ih.pitflg&2) d->pitflg|=EF_LOOP; if(ih.pitflg&4) d->pitflg|=EF_SUSTAIN; d->pitpts=ih.pitpts; d->pitbeg=ih.pitbeg; d->pitend=ih.pitend; d->pitsusbeg=ih.pitsusbeg; d->pitsusend=ih.pitsusend; for(u=0;u<ih.pitpts;u++) d->pitenv[u].pos=ih.pittick[u]; if((d->pitflg&EF_ON)&&(d->pitpts<2)) d->pitflg&=~EF_ON; for(u=0;u<ih.pitpts;u++) d->pitenv[u].val=ih.pitnode[u]+32; if(ih.pitflg&0x80) { /* filter envelopes not supported yet */ d->pitflg&=~EF_ON; ih.pitpts=ih.pitbeg=ih.pitend=0; #ifdef MIKMOD_DEBUG { static int warn=0; if(!warn) fputs("\rFilter envelopes not supported yet\n",stderr); warn=1; } #endif } } for(u=0;u<ITNOTECNT;u++) { d->samplenote[u]=(ih.samptable[u]&255); d->samplenumber[u]= (ih.samptable[u]>>8)?((ih.samptable[u]>>8)-1):0xffff; if(d->samplenumber[u]>=of.numsmp) d->samplenote[u]=255; else if (of.flags&UF_LINEAR) { int note=(int)d->samplenote[u]+noteindex[d->samplenumber[u]]; d->samplenote[u]=(note<0)?0:(note>255?255:note); } } d++; } } else if(of.flags & UF_LINEAR) {
BOOL S3M_Load(BOOL curious) { int t,u,track = 0; SAMPLE *q; UBYTE pan[32]; /* try to read module header */ _mm_read_string(mh->songname,28,modreader); mh->t1a =_mm_read_UBYTE(modreader); mh->type =_mm_read_UBYTE(modreader); _mm_read_UBYTES(mh->unused1,2,modreader); mh->ordnum =_mm_read_I_UWORD(modreader); mh->insnum =_mm_read_I_UWORD(modreader); mh->patnum =_mm_read_I_UWORD(modreader); mh->flags =_mm_read_I_UWORD(modreader); mh->tracker =_mm_read_I_UWORD(modreader); mh->fileformat =_mm_read_I_UWORD(modreader); _mm_read_string(mh->scrm,4,modreader); mh->mastervol =_mm_read_UBYTE(modreader); mh->initspeed =_mm_read_UBYTE(modreader); mh->inittempo =_mm_read_UBYTE(modreader); mh->mastermult =_mm_read_UBYTE(modreader); mh->ultraclick =_mm_read_UBYTE(modreader); mh->pantable =_mm_read_UBYTE(modreader); _mm_read_UBYTES(mh->unused2,8,modreader); mh->special =_mm_read_I_UWORD(modreader); _mm_read_UBYTES(mh->channels,32,modreader); if(_mm_eof(modreader)) { _mm_errno = MMERR_LOADING_HEADER; return 0; } /* set module variables */ of.songname = DupStr(mh->songname,28,0); of.numpat = mh->patnum; of.reppos = 0; of.numins = of.numsmp = mh->insnum; of.initspeed = mh->initspeed; of.inittempo = mh->inittempo; of.initvolume = mh->mastervol<<1; of.flags |= UF_ARPMEM; if((mh->tracker==0x1300)||(mh->flags&64)) of.flags|=UF_S3MSLIDES; /* read the order data */ if(!AllocPositions(mh->ordnum)) return 0; if(!(origpositions=_mm_calloc(mh->ordnum,sizeof(UWORD)))) return 0; for(t=0;t<mh->ordnum;t++) { origpositions[t]=_mm_read_UBYTE(modreader); if((origpositions[t]>=mh->patnum)&&(origpositions[t]<254)) origpositions[t]=255/*mh->patnum-1*/; } if(_mm_eof(modreader)) { _mm_errno = MMERR_LOADING_HEADER; return 0; } poslookupcnt=(UBYTE)mh->ordnum; S3MIT_CreateOrders(curious); if(!(paraptr=(UWORD*)_mm_malloc((of.numins+of.numpat)*sizeof(UWORD)))) return 0; /* read the instrument+pattern parapointers */ _mm_read_I_UWORDS(paraptr,of.numins+of.numpat,modreader); if(mh->pantable==252) { /* read the panning table (ST 3.2 addition. See below for further portions of channel panning [past reampper]). */ _mm_read_UBYTES(pan,32,modreader); } if(_mm_eof(modreader)) { _mm_errno = MMERR_LOADING_HEADER; return 0; } /* load samples */ if(!AllocSamples()) return 0; q = of.samples; for(t=0;t<of.numins;t++) { S3MSAMPLE s; /* seek to instrument position */ _mm_fseek(modreader,((long)paraptr[t])<<4,SEEK_SET); /* and load sample info */ s.type =_mm_read_UBYTE(modreader); _mm_read_string(s.filename,12,modreader); s.memsegh =_mm_read_UBYTE(modreader); s.memsegl =_mm_read_I_UWORD(modreader); s.length =_mm_read_I_ULONG(modreader); s.loopbeg =_mm_read_I_ULONG(modreader); s.loopend =_mm_read_I_ULONG(modreader); s.volume =_mm_read_UBYTE(modreader); s.dsk =_mm_read_UBYTE(modreader); s.pack =_mm_read_UBYTE(modreader); s.flags =_mm_read_UBYTE(modreader); s.c2spd =_mm_read_I_ULONG(modreader); _mm_read_UBYTES(s.unused,12,modreader); _mm_read_string(s.sampname,28,modreader); _mm_read_string(s.scrs,4,modreader); if(_mm_eof(modreader)) { _mm_errno = MMERR_LOADING_SAMPLEINFO; return 0; } q->samplename = DupStr(s.sampname,28,0); q->speed = s.c2spd; q->length = s.length; q->loopstart = s.loopbeg>s.length?s.length:s.loopbeg; q->loopend = s.loopend>s.length?s.length:s.loopend; q->volume = s.volume; q->seekpos = (((long)s.memsegh)<<16|s.memsegl)<<4; if(s.flags&1) q->flags |= SF_LOOP; if(s.flags&4) q->flags |= SF_16BITS; if(mh->fileformat==1) q->flags |= SF_SIGNED; /* don't load sample if it doesn't have the SCRS tag */ if(memcmp(s.scrs,"SCRS",4)) q->length = 0; q++; } /* determine the number of channels actually used. */ of.numchn = 0; memset(remap,-1,32*sizeof(UBYTE)); for(t=0;t<of.numpat;t++) { /* seek to pattern position (+2 skip pattern length) */ _mm_fseek(modreader,(long)((paraptr[of.numins+t])<<4)+2,SEEK_SET); if(S3M_GetNumChannels()) return 0; } /* then we can decide the module type */ t=mh->tracker>>12; if((!t)||(t>3)) t=NUMTRACKERS-1; /* unknown tracker */ else { if(mh->tracker>=0x3217) t=NUMTRACKERS+1; /* IT 2.14p4 */ else if(mh->tracker>=0x3216) t=NUMTRACKERS; /* IT 2.14p3 */ else t--; } of.modtype = strdup(S3M_Version[t]); if(t<NUMTRACKERS) { of.modtype[numeric[t]] = ((mh->tracker>>8) &0xf)+'0'; of.modtype[numeric[t]+2] = ((mh->tracker>>4)&0xf)+'0'; of.modtype[numeric[t]+3] = ((mh->tracker)&0xf)+'0'; }
BOOL FAR_Load (BOOL curious) { int t, u, tracks = 0; SAMPLE *q; FARSAMPLE s; FARNOTE *crow; UBYTE smap[8]; /* try to read module header (first part) */ _mm_read_UBYTES (mh1->id, 4, modreader); _mm_read_SBYTES (mh1->songname, 40, modreader); _mm_read_SBYTES (mh1->blah, 3, modreader); mh1->headerlen = _mm_read_I_UWORD (modreader); mh1->version = _mm_read_UBYTE (modreader); _mm_read_UBYTES (mh1->onoff, 16, modreader); _mm_read_UBYTES (mh1->edit1, 9, modreader); mh1->speed = _mm_read_UBYTE (modreader); _mm_read_UBYTES (mh1->panning, 16, modreader); _mm_read_UBYTES (mh1->edit2, 4, modreader); mh1->stlen = _mm_read_I_UWORD (modreader); /* init modfile data */ of.modtype = strdup (FAR_Version); of.songname = DupStr (mh1->songname, 40, 1); of.numchn = 16; of.initspeed = mh1->speed; of.inittempo = 80; of.reppos = 0; for (t = 0; t < 16; t++) of.panning[t] = mh1->panning[t] << 4; /* read songtext into comment field */ if (mh1->stlen) if (!ReadComment (mh1->stlen)) return 0; /* try to read module header (second part) */ _mm_read_UBYTES (mh2->orders, 256, modreader); mh2->numpat = _mm_read_UBYTE (modreader); mh2->snglen = _mm_read_UBYTE (modreader); mh2->loopto = _mm_read_UBYTE (modreader); _mm_read_I_UWORDS (mh2->patsiz, 256, modreader); of.numpos = mh2->snglen; if (!AllocPositions (of.numpos)) return 0; for (t = 0; t < of.numpos; t++) { if (mh2->orders[t] == 0xff) break; of.positions[t] = mh2->orders[t]; } /* count number of patterns stored in file */ of.numpat = 0; for (t = 0; t < 256; t++) if (mh2->patsiz[t]) if ((t + 1) > of.numpat) of.numpat = t + 1; of.numtrk = of.numpat * of.numchn; /* seek across eventual new data */ _mm_fseek (modreader, mh1->headerlen - (869 + mh1->stlen), SEEK_CUR); /* alloc track and pattern structures */ if (!AllocTracks ()) return 0; if (!AllocPatterns ()) return 0; for (t = 0; t < of.numpat; t++) { UBYTE rows = 0; memset (pat, 0, 256 * 16 * 4 * sizeof (FARNOTE)); if (mh2->patsiz[t]) { rows = _mm_read_UBYTE (modreader); /* tempo = */ _mm_read_UBYTE (modreader); crow = pat; /* file often allocates 64 rows even if there are less in pattern */ if (mh2->patsiz[t] < 2 + (rows * 16 * 4)) { _mm_errno = MMERR_LOADING_PATTERN; return 0; } for (u = (mh2->patsiz[t] - 2) / 4; u; u--, crow++) { crow->note = _mm_read_UBYTE (modreader); crow->ins = _mm_read_UBYTE (modreader); crow->vol = _mm_read_UBYTE (modreader); crow->eff = _mm_read_UBYTE (modreader); } if (_mm_eof (modreader)) { _mm_errno = MMERR_LOADING_PATTERN; return 0; } crow = pat; of.pattrows[t] = rows; for (u = 16; u; u--, crow++) if (!(of.tracks[tracks++] = FAR_ConvertTrack (crow, rows))) { _mm_errno = MMERR_LOADING_PATTERN; return 0; } } else tracks += 16; } /* read sample map */ if (!_mm_read_UBYTES (smap, 8, modreader)) { _mm_errno = MMERR_LOADING_HEADER; return 0; } /* count number of samples used */ of.numins = 0; for (t = 0; t < 64; t++) if (smap[t >> 3] & (1 << (t & 7))) of.numins = t + 1; of.numsmp = of.numins; /* alloc sample structs */ if (!AllocSamples ()) return 0; q = of.samples; for (t = 0; t < of.numsmp; t++) { q->speed = 8363; q->flags = SF_SIGNED; if (smap[t >> 3] & (1 << (t & 7))) { _mm_read_SBYTES (s.samplename, 32, modreader); s.length = _mm_read_I_ULONG (modreader); s.finetune = _mm_read_UBYTE (modreader); s.volume = _mm_read_UBYTE (modreader); s.reppos = _mm_read_I_ULONG (modreader); s.repend = _mm_read_I_ULONG (modreader); s.type = _mm_read_UBYTE (modreader); s.loop = _mm_read_UBYTE (modreader); q->samplename = DupStr (s.samplename, 32, 1); q->length = s.length; q->loopstart = s.reppos; q->loopend = s.repend; q->volume = s.volume << 2; if (s.type & 1) q->flags |= SF_16BITS; if (s.loop & 8) q->flags |= SF_LOOP; q->seekpos = _mm_ftell (modreader); _mm_fseek (modreader, q->length, SEEK_CUR); } else q->samplename = DupStr (NULL, 0, 0); q++; }
static BOOL ASY_Load(BOOL curious) { int t; SAMPLE *q; MSAMPINFO *s; CHAR *descr=asylum; ULONG seekpos; // no title in asylum amf files :( strcpy(mh->songname, ""); _mm_fseek(modreader, 0x23, SEEK_SET); mh->num_patterns = _mm_read_UBYTE(modreader); mh->num_orders = _mm_read_UBYTE(modreader); // skip unknown byte _mm_skip_BYTE(modreader); _mm_read_UBYTES(mh->positions, 256, modreader); /* read samples headers*/ for (t = 0; t < 64; t++) { s = &mh->samples[t]; _mm_fseek(modreader, 0x126 + (t*37), SEEK_SET); _mm_read_string(s->samplename, 22, modreader); s->samplename[21] = 0; /* just in case */ s->finetune = _mm_read_UBYTE(modreader); s->volume = _mm_read_UBYTE(modreader); _mm_skip_BYTE(modreader); // skip unknown byte s->length = _mm_read_I_ULONG(modreader); s->reppos = _mm_read_I_ULONG(modreader); s->replen = _mm_read_I_ULONG(modreader); } if (_mm_eof(modreader)) { _mm_errno = MMERR_LOADING_HEADER; return 0; } /* set module variables */ of.initspeed = 6; of.inittempo = 125; of.numchn = 8; modtype = 0; of.songname = DupStr(mh->songname, 21, 1); of.numpos = mh->num_orders; of.reppos = 0; of.numpat = mh->num_patterns; of.numtrk = of.numpat * of.numchn; /* Copy positions (orders) */ if (!AllocPositions(of.numpos)) return 0; for (t = 0; t < of.numpos; t++) { of.positions[t] = mh->positions[t]; } /* Finally, init the sampleinfo structures */ of.numins = 31; of.numsmp = 31; if (!AllocSamples()) return 0; s = mh->samples; q = of.samples; seekpos = 2662+(2048*(of.numpat)); for (t = 0; t < of.numins; t++) { /* convert the samplename */ q->samplename = DupStr(s->samplename, 23, 1); /* init the sampleinfo variables */ q->speed = finetune[s->finetune & 0xf]; q->volume = s->volume & 0x7f; q->loopstart = (ULONG)s->reppos; q->loopend = (ULONG)q->loopstart + (s->replen); q->length = (ULONG)s->length; q->flags = SF_SIGNED; q->seekpos = seekpos; seekpos += q->length; if ((s->replen) > 2) { q->flags |= SF_LOOP; } /* fix replen if repend > length */ if (q->loopend > q->length) q->loopend = q->length; s++; q++; } of.modtype = StrDup(descr); if (!ML_LoadPatterns()) return 0; return 1; }
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 S3M_Load(void) { int t,u,track=0; INSTRUMENT *d; SAMPLE *q; UBYTE isused[16]; UBYTE pan[32]; /* try to read module header */ _mm_read_str(mh_s3m->songname,28); mh_s3m->t1a =_mm_read_UBYTE(); mh_s3m->type =_mm_read_UBYTE(); _mm_read_UBYTES(mh_s3m->unused1,2); mh_s3m->ordnum =_mm_read_I_UWORD(); mh_s3m->insnum =_mm_read_I_UWORD(); mh_s3m->patnum =_mm_read_I_UWORD(); mh_s3m->flags =_mm_read_I_UWORD(); mh_s3m->tracker =_mm_read_I_UWORD(); mh_s3m->fileformat =_mm_read_I_UWORD(); _mm_read_str(mh_s3m->scrm,4); mh_s3m->mastervol =_mm_read_UBYTE(); mh_s3m->initspeed =_mm_read_UBYTE(); mh_s3m->inittempo =_mm_read_UBYTE(); mh_s3m->mastermult =_mm_read_UBYTE(); mh_s3m->ultraclick =_mm_read_UBYTE(); mh_s3m->pantable =_mm_read_UBYTE(); _mm_read_UBYTES(mh_s3m->unused2,8); mh_s3m->special =_mm_read_I_UWORD(); _mm_read_UBYTES(mh_s3m->channels,32); if(modpos > modsize){ gModPlayerErrorMessage=ERROR_LOADING_HEADER; return 0; } /* set module variables */ of.modtype=strdup(S3M_Version); of.songname=DupStr(mh_s3m->songname,28); /* make a cstr of songname */ of.numpat=mh_s3m->patnum; of.numins=mh_s3m->insnum; of.initspeed=mh_s3m->initspeed; of.inittempo=mh_s3m->inittempo; /* count the number of channels used */ of.numchn=0; /* for(t=0;t<32;t++) printf("%2.2x ",mh_s3m->channels[t]); */ for(t=0;t<32;t++) remap[t]=0; for(t=0;t<16;t++) isused[t]=0; /* set a flag for each channel (1 out of of 16) thats being used: */ for(t=0;t<32;t++){ if(mh_s3m->channels[t]<16){ isused[mh_s3m->channels[t]]=1; } } /* give each of them a different number */ for(t=0;t<16;t++){ if(isused[t]){ isused[t]=of.numchn; of.numchn++; } } /* build the remap array */ for(t=0;t<32;t++){ if(mh_s3m->channels[t]<16){ remap[t]=isused[mh_s3m->channels[t]]; } } /* set panning positions */ for(t=0;t<32;t++){ if(mh_s3m->channels[t]<16){ if(mh_s3m->channels[t]<8){ of.panning[remap[t]]=0x30; } else{ of.panning[remap[t]]=0xc0; } } } of.numtrk=of.numpat*of.numchn; /* printf("Uses %d channels\n",of.numchn); */ /* read the order data */ _mm_read_UBYTES(of.positions,mh_s3m->ordnum); of.numpos=0; for(t=0;t<mh_s3m->ordnum;t++){ of.positions[of.numpos]=of.positions[t]; if(of.positions[t]<254) of.numpos++; } if((paraptr=(UWORD *)MyMalloc((of.numins+of.numpat)*sizeof(UWORD)))==NULL) return 0; /* read the instrument+pattern parapointers */ _mm_read_I_UWORDS(paraptr,of.numins+of.numpat); /* printf("pantab %d\n",mh_s3m->pantable); */ if(mh_s3m->pantable==252){ /* read the panning table */ _mm_read_UBYTES(pan,32); /* set panning positions according to panning table (new for st3.2) */ for(t=0;t<32;t++){ if((pan[t]&0x20) && mh_s3m->channels[t]<16){ of.panning[remap[t]]=(pan[t]&0xf)<<4; } } } /* now is a good time to check if the header was too short :) */ if(modpos > modsize){ gModPlayerErrorMessage=ERROR_LOADING_HEADER; return 0; } if(!AllocInstruments()) return 0; d=of.instruments; for(t=0;t<of.numins;t++){ S3MSAMPLE s; d->numsmp=1; if(!AllocSamples(d)) return 0; q=d->samples; /* seek to instrument position */ _mm_fseek(((long)paraptr[t])<<4,SEEK_SET); /* and load sample info */ s.type =_mm_read_UBYTE(); _mm_read_str(s.filename,12); s.memsegh =_mm_read_UBYTE(); s.memsegl =_mm_read_I_UWORD(); s.length =_mm_read_I_ULONG(); s.loopbeg =_mm_read_I_ULONG(); s.loopend =_mm_read_I_ULONG(); s.volume =_mm_read_UBYTE(); s.dsk =_mm_read_UBYTE(); s.pack =_mm_read_UBYTE(); s.flags =_mm_read_UBYTE(); s.c2spd =_mm_read_I_ULONG(); _mm_read_UBYTES(s.unused,12); _mm_read_str(s.sampname,28); _mm_read_str(s.scrs,4); if(modpos > modsize){ gModPlayerErrorMessage=ERROR_LOADING_HEADER; return 0; } d->insname=DupStr(s.sampname,28); q->c2spd= (unsigned short)s.c2spd; q->length=s.length; q->loopstart=s.loopbeg; q->loopend=s.loopend; q->volume=s.volume; q->seekpos=(((long)s.memsegh)<<16|s.memsegl)<<4; q->flags=0; if(s.flags&1) q->flags|=SF_LOOP; if(s.flags&4) q->flags|=SF_16BITS; if(mh_s3m->fileformat==1) q->flags|=SF_SIGNED; /* DON'T load sample if it doesn't have the SCRS tag */ if(memcmp(s.scrs,"SCRS",4)!=0) q->length=0; /* printf("%s\n",d->insname); */ d++; } if(!AllocTracks()) { gModPlayerErrorMessage=ERROR_ALLOC_STRUCT; return 0; } if(!AllocPatterns()) { gModPlayerErrorMessage=ERROR_ALLOC_STRUCT; return 0; } for(t=0;t<of.numpat;t++) { /* seek to pattern position ( + 2 skip pattern length ) */ _mm_fseek((((long)paraptr[of.numins+t])<<4)+2,SEEK_SET); if(!S3M_ReadPattern()) { gModPlayerErrorMessage = ERROR_LOADING_PATTERN; return 0; } for(u=0;u<of.numchn;u++) { if(!(of.tracks[track++]=S3M_ConvertTrack(&s3mbuf[u*64]))) { gModPlayerErrorMessage = ERROR_LOADING_TRACK; return 0; } } } return 1; }