diff options
author | Solomon Peachy <pizza@shaftnet.org> | 2020-08-08 21:56:15 -0400 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2020-08-11 03:29:12 +0000 |
commit | b4e70422a3455e327433a7471c929ef100ef3b10 (patch) | |
tree | e96c5431a1b22af1fcbc628322b79fb8c3162427 /apps/plugins/mikmod/load_imf.c | |
parent | 8c7780bafc9eabac6b92cfe5a5a00831c3d5fd9d (diff) | |
download | rockbox-b4e70422a3455e327433a7471c929ef100ef3b10.tar.gz rockbox-b4e70422a3455e327433a7471c929ef100ef3b10.zip |
mikmod: Upgrade mikmod core from v3.2.0 to v3.3.11
* Get rid of the non-functional GT2 loader
* Add the UMX loader
* Add HQ mixer routines (and make it configurable)
* Allow samplerate to be configured at run/playtime
* Support >64KHz mixing/playback
* Correctly restore non-boost status
(The diff to upstream is much smaller now too!)
Change-Id: Iaa4ac901ba9cd4123bb225656976e78271353a72
Diffstat (limited to 'apps/plugins/mikmod/load_imf.c')
-rw-r--r-- | apps/plugins/mikmod/load_imf.c | 71 |
1 files changed, 52 insertions, 19 deletions
diff --git a/apps/plugins/mikmod/load_imf.c b/apps/plugins/mikmod/load_imf.c index 9c93d97e23..39cdf5464d 100644 --- a/apps/plugins/mikmod/load_imf.c +++ b/apps/plugins/mikmod/load_imf.c | |||
@@ -20,7 +20,7 @@ | |||
20 | 20 | ||
21 | /*============================================================================== | 21 | /*============================================================================== |
22 | 22 | ||
23 | $Id: load_imf.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ | 23 | $Id$ |
24 | 24 | ||
25 | Imago Orpheus (IMF) module loader | 25 | Imago Orpheus (IMF) module loader |
26 | 26 | ||
@@ -127,12 +127,36 @@ static IMFHEADER *mh=NULL; | |||
127 | 127 | ||
128 | static int IMF_Test(void) | 128 | static int IMF_Test(void) |
129 | { | 129 | { |
130 | UBYTE id[4]; | 130 | UBYTE buf[512], *p; |
131 | int t, chn; | ||
131 | 132 | ||
132 | _mm_fseek(modreader,0x3c,SEEK_SET); | 133 | _mm_fseek(modreader,0x3c,SEEK_SET); |
133 | if(!_mm_read_UBYTES(id,4,modreader)) return 0; | 134 | if (!_mm_read_UBYTES(buf,4,modreader)) return 0; |
134 | if(!memcmp(id,"IM10",4)) return 1; | 135 | if (memcmp(buf,"IM10",4) != 0) return 0; /* no magic */ |
135 | return 0; | 136 | |
137 | _mm_fseek(modreader,32,SEEK_SET); | ||
138 | if (_mm_read_I_UWORD(modreader) > 256) return 0;/* bad ordnum */ | ||
139 | if (_mm_read_I_UWORD(modreader) > 256) return 0;/* bad patnum */ | ||
140 | if (_mm_read_I_UWORD(modreader) > 256) return 0;/* bad insnum */ | ||
141 | |||
142 | _mm_fseek(modreader,64,SEEK_SET); | ||
143 | if(!_mm_read_UBYTES(buf,512,modreader)) return 0; | ||
144 | /* verify channel status */ | ||
145 | for (t = 0, chn = 0, p = &buf[15]; t < 512; t += 16, p += 16) { | ||
146 | switch (*p) { | ||
147 | case 0: /* channel enabled */ | ||
148 | case 1: /* channel muted */ | ||
149 | chn++; | ||
150 | break; | ||
151 | case 2: /* channel disabled */ | ||
152 | break; | ||
153 | default: /* bad status value */ | ||
154 | return 0; | ||
155 | } | ||
156 | } | ||
157 | if(!chn) return 0; /* no channels found */ | ||
158 | |||
159 | return 1; | ||
136 | } | 160 | } |
137 | 161 | ||
138 | static int IMF_Init(void) | 162 | static int IMF_Init(void) |
@@ -149,6 +173,8 @@ static void IMF_Cleanup(void) | |||
149 | 173 | ||
150 | MikMod_free(imfpat); | 174 | MikMod_free(imfpat); |
151 | MikMod_free(mh); | 175 | MikMod_free(mh); |
176 | imfpat=NULL; | ||
177 | mh=NULL; | ||
152 | } | 178 | } |
153 | 179 | ||
154 | static int IMF_ReadPattern(SLONG size,UWORD rows) | 180 | static int IMF_ReadPattern(SLONG size,UWORD rows) |
@@ -388,7 +414,7 @@ static int IMF_Load(int curious) | |||
388 | ULONG *nextwav=NULL; | 414 | ULONG *nextwav=NULL; |
389 | UWORD wavcnt=0; | 415 | UWORD wavcnt=0; |
390 | UBYTE id[4]; | 416 | UBYTE id[4]; |
391 | (void)curious; | 417 | (void)curious; |
392 | 418 | ||
393 | /* try to read the module header */ | 419 | /* try to read the module header */ |
394 | _mm_read_string(mh->songname,32,modreader); | 420 | _mm_read_string(mh->songname,32,modreader); |
@@ -410,7 +436,7 @@ static int IMF_Load(int curious) | |||
410 | 436 | ||
411 | /* set module variables */ | 437 | /* set module variables */ |
412 | of.songname=DupStr(mh->songname,31,1); | 438 | of.songname=DupStr(mh->songname,31,1); |
413 | of.modtype=StrDup(IMF_Version); | 439 | of.modtype=MikMod_strdup(IMF_Version); |
414 | of.numpat=mh->patnum; | 440 | of.numpat=mh->patnum; |
415 | of.numins=mh->insnum; | 441 | of.numins=mh->insnum; |
416 | of.reppos=0; | 442 | of.reppos=0; |
@@ -467,6 +493,13 @@ static int IMF_Load(int curious) | |||
467 | if(!AllocPositions(of.numpos)) return 0; | 493 | if(!AllocPositions(of.numpos)) return 0; |
468 | for(t=u=0;t<mh->ordnum;t++) | 494 | for(t=u=0;t<mh->ordnum;t++) |
469 | if(mh->orders[t]!=0xff) of.positions[u++]=mh->orders[t]; | 495 | if(mh->orders[t]!=0xff) of.positions[u++]=mh->orders[t]; |
496 | for(t=0;t<of.numpos;t++) { | ||
497 | if (of.positions[t]>of.numpat) { /* SANITIY CHECK */ | ||
498 | /* fprintf(stderr,"position[%d]=%d > numpat=%d\n",t,of.positions[t],of.numpat);*/ | ||
499 | _mm_errno = MMERR_LOADING_HEADER; | ||
500 | return 0; | ||
501 | } | ||
502 | } | ||
470 | 503 | ||
471 | /* load pattern info */ | 504 | /* load pattern info */ |
472 | of.numtrk=of.numpat*of.numchn; | 505 | of.numtrk=of.numpat*of.numchn; |
@@ -509,16 +542,16 @@ static int IMF_Load(int curious) | |||
509 | _mm_read_I_UWORDS(ih.panenv,IMFENVCNT,modreader); | 542 | _mm_read_I_UWORDS(ih.panenv,IMFENVCNT,modreader); |
510 | _mm_read_I_UWORDS(ih.pitenv,IMFENVCNT,modreader); | 543 | _mm_read_I_UWORDS(ih.pitenv,IMFENVCNT,modreader); |
511 | 544 | ||
512 | #if defined __STDC__ || defined _MSC_VER || defined MPW_C | 545 | #if defined __STDC__ || defined _MSC_VER || defined __WATCOMC__ || defined MPW_C |
513 | #define IMF_FinishLoadingEnvelope(name) \ | 546 | #define IMF_FinishLoadingEnvelope(name) \ |
514 | ih. name##pts=_mm_read_UBYTE(modreader); \ | 547 | ih. name##pts=_mm_read_UBYTE(modreader); \ |
515 | ih. name##sus=_mm_read_UBYTE(modreader); \ | 548 | ih. name##sus=_mm_read_UBYTE(modreader); \ |
516 | ih. name##beg=_mm_read_UBYTE(modreader); \ | 549 | ih. name##beg=_mm_read_UBYTE(modreader); \ |
517 | ih. name##end=_mm_read_UBYTE(modreader); \ | 550 | ih. name##end=_mm_read_UBYTE(modreader); \ |
518 | ih. name##flg=_mm_read_UBYTE(modreader); \ | 551 | ih. name##flg=_mm_read_UBYTE(modreader); \ |
519 | (void)_mm_read_UBYTE(modreader); \ | 552 | _mm_skip_BYTE(modreader); \ |
520 | (void)_mm_read_UBYTE(modreader); \ | 553 | _mm_skip_BYTE(modreader); \ |
521 | (void)_mm_read_UBYTE(modreader) | 554 | _mm_skip_BYTE(modreader) |
522 | #else | 555 | #else |
523 | #define IMF_FinishLoadingEnvelope(name) \ | 556 | #define IMF_FinishLoadingEnvelope(name) \ |
524 | ih. name/**/pts=_mm_read_UBYTE(modreader); \ | 557 | ih. name/**/pts=_mm_read_UBYTE(modreader); \ |
@@ -526,9 +559,9 @@ static int IMF_Load(int curious) | |||
526 | ih. name/**/beg=_mm_read_UBYTE(modreader); \ | 559 | ih. name/**/beg=_mm_read_UBYTE(modreader); \ |
527 | ih. name/**/end=_mm_read_UBYTE(modreader); \ | 560 | ih. name/**/end=_mm_read_UBYTE(modreader); \ |
528 | ih. name/**/flg=_mm_read_UBYTE(modreader); \ | 561 | ih. name/**/flg=_mm_read_UBYTE(modreader); \ |
529 | (void)_mm_read_UBYTE(modreader); \ | 562 | _mm_skip_BYTE(modreader); \ |
530 | (void)_mm_read_UBYTE(modreader); \ | 563 | _mm_skip_BYTE(modreader); \ |
531 | (void)_mm_read_UBYTE(modreader) | 564 | _mm_skip_BYTE(modreader) |
532 | #endif | 565 | #endif |
533 | 566 | ||
534 | IMF_FinishLoadingEnvelope(vol); | 567 | IMF_FinishLoadingEnvelope(vol); |
@@ -541,7 +574,7 @@ static int IMF_Load(int curious) | |||
541 | _mm_read_UBYTES(id,4,modreader); | 574 | _mm_read_UBYTES(id,4,modreader); |
542 | /* Looks like Imago Orpheus forgets the signature for empty | 575 | /* Looks like Imago Orpheus forgets the signature for empty |
543 | instruments following a multi-sample instrument... */ | 576 | instruments following a multi-sample instrument... */ |
544 | if(memcmp(id,"II10",4) && | 577 | if(memcmp(id,"II10",4) && |
545 | (oldnumsmp && memcmp(id,"\x0\x0\x0\x0",4))) { | 578 | (oldnumsmp && memcmp(id,"\x0\x0\x0\x0",4))) { |
546 | if(nextwav) MikMod_free(nextwav); | 579 | if(nextwav) MikMod_free(nextwav); |
547 | if(wh) MikMod_free(wh); | 580 | if(wh) MikMod_free(wh); |
@@ -562,7 +595,7 @@ static int IMF_Load(int curious) | |||
562 | d->samplenumber[u]=ih.what[u]>ih.numsmp?0xffff:ih.what[u]+of.numsmp; | 595 | d->samplenumber[u]=ih.what[u]>ih.numsmp?0xffff:ih.what[u]+of.numsmp; |
563 | d->volfade=ih.volfade; | 596 | d->volfade=ih.volfade; |
564 | 597 | ||
565 | #if defined __STDC__ || defined _MSC_VER || defined MPW_C | 598 | #if defined __STDC__ || defined _MSC_VER || defined __WATCOMC__ || defined MPW_C |
566 | #define IMF_ProcessEnvelope(name) \ | 599 | #define IMF_ProcessEnvelope(name) \ |
567 | for (u = 0; u < (IMFENVCNT >> 1); u++) { \ | 600 | for (u = 0; u < (IMFENVCNT >> 1); u++) { \ |
568 | d-> name##env[u].pos = ih. name##env[u << 1]; \ | 601 | d-> name##env[u].pos = ih. name##env[u << 1]; \ |
@@ -613,12 +646,12 @@ static int IMF_Load(int curious) | |||
613 | /* allocate more room for sample information if necessary */ | 646 | /* allocate more room for sample information if necessary */ |
614 | if(of.numsmp+u==wavcnt) { | 647 | if(of.numsmp+u==wavcnt) { |
615 | wavcnt+=IMF_SMPINCR; | 648 | wavcnt+=IMF_SMPINCR; |
616 | if(!(nextwav=MikMod_realloc(nextwav,wavcnt*sizeof(ULONG)))) { | 649 | if(!(nextwav=(ULONG*)MikMod_realloc(nextwav,wavcnt*sizeof(ULONG)))) { |
617 | if(wh) MikMod_free(wh); | 650 | if(wh) MikMod_free(wh); |
618 | _mm_errno=MMERR_OUT_OF_MEMORY; | 651 | _mm_errno=MMERR_OUT_OF_MEMORY; |
619 | return 0; | 652 | return 0; |
620 | } | 653 | } |
621 | if(!(wh=MikMod_realloc(wh,wavcnt*sizeof(IMFWAVHEADER)))) { | 654 | if(!(wh=(IMFWAVHEADER*)MikMod_realloc(wh,wavcnt*sizeof(IMFWAVHEADER)))) { |
622 | MikMod_free(nextwav); | 655 | MikMod_free(nextwav); |
623 | _mm_errno=MMERR_OUT_OF_MEMORY; | 656 | _mm_errno=MMERR_OUT_OF_MEMORY; |
624 | return 0; | 657 | return 0; |
@@ -627,7 +660,7 @@ static int IMF_Load(int curious) | |||
627 | } | 660 | } |
628 | 661 | ||
629 | _mm_read_string(s->samplename,13,modreader); | 662 | _mm_read_string(s->samplename,13,modreader); |
630 | (void)_mm_read_UBYTE(modreader);(void)_mm_read_UBYTE(modreader);(void)_mm_read_UBYTE(modreader); | 663 | _mm_skip_BYTE(modreader);_mm_skip_BYTE(modreader);_mm_skip_BYTE(modreader); |
631 | s->length =_mm_read_I_ULONG(modreader); | 664 | s->length =_mm_read_I_ULONG(modreader); |
632 | s->loopstart =_mm_read_I_ULONG(modreader); | 665 | s->loopstart =_mm_read_I_ULONG(modreader); |
633 | s->loopend =_mm_read_I_ULONG(modreader); | 666 | s->loopend =_mm_read_I_ULONG(modreader); |