Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
static BOOL MOD_Load(void)
{
    int t,modtype;
    INSTRUMENT *d;          /* new sampleinfo structure */
    SAMPLE *q;
    MSAMPINFO *s;           /* old module sampleinfo */

    /* try to read module header */

    _mm_read_str((char *)mh_mod->songname,20);

    for(t=0;t<31;t++){
	s=&mh_mod->samples[t];
	_mm_read_str(s->samplename,22);
	s->length	=_mm_read_M_UWORD();
	s->finetune	=_mm_read_UBYTE();
	s->volume	=_mm_read_UBYTE();
	s->reppos	=_mm_read_M_UWORD();
	s->replen	=_mm_read_M_UWORD();
    }

    mh_mod->songlength	=_mm_read_UBYTE();
    mh_mod->magic1		=_mm_read_UBYTE();

    _mm_read_UBYTES(mh_mod->positions,128);
    _mm_read_UBYTES(mh_mod->magic2,4);

    if(modpos > modsize){
	gModPlayerErrorMessage=ERROR_LOADING_HEADER;
	return 0;
    }

    /* find out which ID string */

    for(modtype=0;modtype<10;modtype++){
	if(!memcmp(mh_mod->magic2,modtypes[modtype].id,4)) break;
    }

    if(modtype==10){

	/* unknown modtype */
	gModPlayerErrorMessage=ERROR_NOT_A_MODULE;
	return 0;
    }

    /* set module variables */

    of.initspeed=6;
    of.inittempo=125;
    of.numchn=modtypes[modtype].channels;      /* get number of channels */
    of.modtype=strdup(modtypes[modtype].name);      /* get ascii type of mod */
    of.songname=DupStr(mh_mod->songname,20);            /* make a cstr of songname */
    of.numpos=mh_mod->songlength;               /* copy the songlength */
    memcpy(of.positions,mh_mod->positions,128);         /* copy the position array */

    /* Count the number of patterns */

    of.numpat=0;

    for(t=0;t<128;t++){             /* <-- BUGFIX... have to check ALL positions */
	if(of.positions[t] > of.numpat){
	    of.numpat=of.positions[t];
	}
    }
    of.numpat++;
    of.numtrk=of.numpat*of.numchn;

    /* Finally, init the sampleinfo structures */

    of.numins=31;

    if(!AllocInstruments()) return 0;

    s=mh_mod->samples;   /* init source pointer */
    d=of.instruments;  /* init dest pointer */

    for(t=0;t<of.numins;t++){

	d->numsmp=1;
	if(!AllocSamples(d)) return 0;

	q=d->samples;

	/* convert the samplename */

	d->insname=DupStr(s->samplename,22);

	/* init the sampleinfo variables and
	   convert the size pointers to longword format */

	q->c2spd=finetune[s->finetune&0xf];
	q->volume=s->volume;
	q->loopstart=(ULONG)s->reppos<<1;
	q->loopend=q->loopstart+((ULONG)s->replen<<1);
	q->length=(ULONG)s->length<<1;
	q->seekpos=0;

	q->flags=SF_SIGNED;
	if(s->replen>1) q->flags|=SF_LOOP;

	/* fix replen if repend>length */

	if(q->loopend>q->length) q->loopend=q->length;

	s++;    /* point to next source sampleinfo */
	d++;    /* point to next destiny sampleinfo */
    }

    if(!ML_LoadPatterns()) return 0;
    return 1;
}