forked from len0rd/rockbox
FS#13539: Resync mikmod plugin with upstream
Brings it up to libmikmod 3.3.12, relased 2024-12-31 Also fix a segfault that only happened on simulators when using non-default samplerates. Change-Id: I2ade2d72a00edab5395328fe76a88a88516aac72
This commit is contained in:
parent
08c32cee7c
commit
af7ed73f31
29 changed files with 1860 additions and 706 deletions
|
@ -93,6 +93,7 @@ static FARHEADER2 *mh2 = NULL;
|
|||
static FARNOTE *pat = NULL;
|
||||
|
||||
static const unsigned char FARSIG[4+3]={'F','A','R',0xfe,13,10,26};
|
||||
static const UWORD FAR_MAXPATSIZE=(256*16*4)+2;
|
||||
|
||||
/*========== Loader code */
|
||||
|
||||
|
@ -134,20 +135,36 @@ static UBYTE *FAR_ConvertTrack(FARNOTE* n,int rows)
|
|||
UniInstrument(n->ins);
|
||||
UniNote(n->note+3*OCTAVE-1);
|
||||
}
|
||||
if (n->vol&0xf) UniPTEffect(0xc,(n->vol&0xf)<<2);
|
||||
if (n->vol>=0x01 && n->vol<=0x10) UniPTEffect(0xc,(n->vol - 1)<<2);
|
||||
if (n->eff)
|
||||
switch(n->eff>>4) {
|
||||
case 0x0: /* global effects */
|
||||
switch(n->eff & 0xf) {
|
||||
case 0x3: /* fulfill loop */
|
||||
UniEffect(UNI_KEYFADE, 0);
|
||||
break;
|
||||
case 0x4: /* old tempo mode */
|
||||
case 0x5: /* new tempo mode */
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 0x1: /* pitch adjust up */
|
||||
UniEffect(UNI_FAREFFECT1, n->eff & 0xf);
|
||||
break;
|
||||
case 0x2: /* pitch adjust down */
|
||||
UniEffect(UNI_FAREFFECT2, n->eff & 0xf);
|
||||
break;
|
||||
case 0x3: /* porta to note */
|
||||
UniPTEffect(0x3,(n->eff&0xf)<<4);
|
||||
UniEffect(UNI_FAREFFECT3, n->eff & 0xf);
|
||||
break;
|
||||
case 0x4: /* retrigger */
|
||||
UniPTEffect(0x0e, 0x90 | (n->eff & 0x0f));
|
||||
UniEffect(UNI_FAREFFECT4, n->eff & 0xf);
|
||||
break;
|
||||
case 0x5: /* set vibrato depth */
|
||||
vibdepth=n->eff&0xf;
|
||||
break;
|
||||
case 0x6: /* vibrato */
|
||||
UniPTEffect(0x4,((n->eff&0xf)<<4)|vibdepth);
|
||||
UniEffect(UNI_FAREFFECT6,((n->eff&0xf)<<4)|vibdepth);
|
||||
break;
|
||||
case 0x7: /* volume slide up */
|
||||
UniPTEffect(0xa,(n->eff&0xf)<<4);
|
||||
|
@ -155,11 +172,21 @@ static UBYTE *FAR_ConvertTrack(FARNOTE* n,int rows)
|
|||
case 0x8: /* volume slide down */
|
||||
UniPTEffect(0xa,n->eff&0xf);
|
||||
break;
|
||||
case 0x9: /* sustained vibrato */
|
||||
break;
|
||||
case 0xb: /* panning */
|
||||
UniPTEffect(0xe,0x80|(n->eff&0xf));
|
||||
break;
|
||||
case 0xc: /* note offset */
|
||||
break;
|
||||
case 0xd: /* fine tempo down */
|
||||
UniEffect(UNI_FAREFFECTD, n->eff & 0xf);
|
||||
break;
|
||||
case 0xe: /* fine tempo up */
|
||||
UniEffect(UNI_FAREFFECTE, n->eff & 0xf);
|
||||
break;
|
||||
case 0xf: /* set speed */
|
||||
UniPTEffect(0xf,n->eff&0xf);
|
||||
UniEffect(UNI_FAREFFECTF,n->eff&0xf);
|
||||
break;
|
||||
|
||||
/* others not yet implemented */
|
||||
|
@ -178,11 +205,12 @@ static UBYTE *FAR_ConvertTrack(FARNOTE* n,int rows)
|
|||
|
||||
static int FAR_Load(int curious)
|
||||
{
|
||||
int t,u,tracks=0;
|
||||
int r,t,u,tracks=0;
|
||||
SAMPLE *q;
|
||||
FARSAMPLE s;
|
||||
FARNOTE *crow;
|
||||
UBYTE smap[8];
|
||||
UBYTE addextrapattern;
|
||||
(void)curious;
|
||||
|
||||
/* try to read module header (first part) */
|
||||
|
@ -202,10 +230,9 @@ static int FAR_Load(int curious)
|
|||
of.modtype = MikMod_strdup(FAR_Version);
|
||||
of.songname = DupStr(mh1->songname,40,1);
|
||||
of.numchn = 16;
|
||||
of.initspeed = mh1->speed;
|
||||
of.inittempo = 80;
|
||||
of.reppos = 0;
|
||||
of.flags |= UF_PANNING;
|
||||
of.initspeed = mh1->speed != 0 ? mh1->speed : 4;
|
||||
of.bpmlimit = 5;
|
||||
of.flags |= UF_PANNING | UF_FARTEMPO | UF_HIGHBPM;
|
||||
for(t=0;t<16;t++) of.panning[t]=mh1->panning[t]<<4;
|
||||
|
||||
/* read songtext into comment field */
|
||||
|
@ -225,17 +252,29 @@ static int FAR_Load(int curious)
|
|||
_mm_read_I_UWORDS(mh2->patsiz,256,modreader);
|
||||
|
||||
of.numpos = mh2->snglen;
|
||||
of.reppos = mh2->loopto;
|
||||
|
||||
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;
|
||||
|
||||
addextrapattern = 0;
|
||||
for (t = 0; t < of.numpos; t++) {
|
||||
if (mh2->orders[t] == 0xff) break;
|
||||
of.positions[t] = mh2->orders[t];
|
||||
if (of.positions[t] >= of.numpat) {
|
||||
of.positions[t] = of.numpat;
|
||||
addextrapattern = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (addextrapattern)
|
||||
of.numpat++;
|
||||
|
||||
of.numtrk = of.numpat*of.numchn;
|
||||
|
||||
/* seek across eventual new data */
|
||||
|
@ -246,18 +285,17 @@ static int FAR_Load(int curious)
|
|||
if(!AllocPatterns()) return 0;
|
||||
|
||||
for(t=0;t<of.numpat;t++) {
|
||||
UBYTE rows=0;
|
||||
UBYTE tempo;
|
||||
|
||||
memset(pat,0,256*16*4*sizeof(FARNOTE));
|
||||
if(mh2->patsiz[t]) {
|
||||
rows = _mm_read_UBYTE(modreader);
|
||||
tempo = _mm_read_UBYTE(modreader);
|
||||
(void)tempo; /* unused */
|
||||
/* Break position byte is always 1 less than the final row index,
|
||||
i.e. it is 2 less than the total row count. */
|
||||
UWORD rows = _mm_read_UBYTE(modreader) + 2;
|
||||
_mm_skip_BYTE(modreader); /* tempo */
|
||||
|
||||
crow = pat;
|
||||
/* file often allocates 64 rows even if there are less in pattern */
|
||||
if (mh2->patsiz[t]<2+(rows*16*4)) {
|
||||
/* Also, don't allow more than 256 rows. */
|
||||
if (mh2->patsiz[t]<2+(rows*16*4) || rows>256 || mh2->patsiz[t]>FAR_MAXPATSIZE) {
|
||||
_mm_errno = MMERR_LOADING_PATTERN;
|
||||
return 0;
|
||||
}
|
||||
|
@ -280,8 +318,17 @@ static int FAR_Load(int curious)
|
|||
_mm_errno=MMERR_LOADING_PATTERN;
|
||||
return 0;
|
||||
}
|
||||
} else
|
||||
tracks+=16;
|
||||
} else {
|
||||
// Farandole Composer normally use a 64 rows blank track for patterns with 0 rows
|
||||
for (u = 0; u < 16; u++) {
|
||||
UniReset();
|
||||
for (r = 0; r < 64; r++) {
|
||||
UniNewline();
|
||||
}
|
||||
of.tracks[tracks++] = UniDup();
|
||||
}
|
||||
of.pattrows[t] = 64;
|
||||
}
|
||||
}
|
||||
|
||||
/* read sample map */
|
||||
|
@ -319,11 +366,17 @@ static int FAR_Load(int curious)
|
|||
q->loopend = s.repend;
|
||||
q->volume = s.volume<<2;
|
||||
|
||||
if(s.type&1) q->flags|=SF_16BITS;
|
||||
if(s.type&1) {
|
||||
q->flags|=SF_16BITS;
|
||||
q->length >>= 1;
|
||||
q->loopstart >>= 1;
|
||||
q->loopend >>= 1;
|
||||
}
|
||||
|
||||
if(s.loop&8) q->flags|=SF_LOOP;
|
||||
|
||||
q->seekpos = _mm_ftell(modreader);
|
||||
_mm_fseek(modreader,q->length,SEEK_CUR);
|
||||
_mm_fseek(modreader,s.length,SEEK_CUR);
|
||||
} else
|
||||
q->samplename = MikMod_strdup("");
|
||||
q++;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue