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_stm.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_stm.c')
-rw-r--r-- | apps/plugins/mikmod/load_stm.c | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/apps/plugins/mikmod/load_stm.c b/apps/plugins/mikmod/load_stm.c index 994b0e5355..c62a6d7f36 100644 --- a/apps/plugins/mikmod/load_stm.c +++ b/apps/plugins/mikmod/load_stm.c | |||
@@ -6,12 +6,12 @@ | |||
6 | it under the terms of the GNU Library General Public License as | 6 | it under the terms of the GNU Library General Public License as |
7 | published by the Free Software Foundation; either version 2 of | 7 | published by the Free Software Foundation; either version 2 of |
8 | the License, or (at your option) any later version. | 8 | the License, or (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU Library General Public License for more details. | 13 | GNU Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public | 15 | You should have received a copy of the GNU Library General Public |
16 | License along with this library; if not, write to the Free Software | 16 | License along with this library; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
@@ -20,7 +20,7 @@ | |||
20 | 20 | ||
21 | /*============================================================================== | 21 | /*============================================================================== |
22 | 22 | ||
23 | $Id: load_stm.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ | 23 | $Id$ |
24 | 24 | ||
25 | Screamtracker 2 (STM) module loader | 25 | Screamtracker 2 (STM) module loader |
26 | 26 | ||
@@ -74,7 +74,7 @@ typedef struct STMHEADER { | |||
74 | UBYTE ver_minor; | 74 | UBYTE ver_minor; |
75 | UBYTE inittempo; /* initspeed= stm inittempo>>4 */ | 75 | UBYTE inittempo; /* initspeed= stm inittempo>>4 */ |
76 | UBYTE numpat; /* number of patterns */ | 76 | UBYTE numpat; /* number of patterns */ |
77 | UBYTE globalvol; | 77 | UBYTE globalvol; |
78 | UBYTE reserved[13]; | 78 | UBYTE reserved[13]; |
79 | STMSAMPLE sample[31]; /* STM sample data */ | 79 | STMSAMPLE sample[31]; /* STM sample data */ |
80 | UBYTE patorder[128]; /* Docs say 64 - actually 128 */ | 80 | UBYTE patorder[128]; /* Docs say 64 - actually 128 */ |
@@ -90,7 +90,7 @@ static STMNOTE *stmbuf = NULL; | |||
90 | static STMHEADER *mh = NULL; | 90 | static STMHEADER *mh = NULL; |
91 | 91 | ||
92 | /* tracker identifiers */ | 92 | /* tracker identifiers */ |
93 | static CHAR* STM_Version[STM_NTRACKERS] = { | 93 | static const CHAR * STM_Version[STM_NTRACKERS] = { |
94 | "Screamtracker 2", | 94 | "Screamtracker 2", |
95 | "Converted by MOD2STM (STM format)", | 95 | "Converted by MOD2STM (STM format)", |
96 | "Wuzamod (STM format)" | 96 | "Wuzamod (STM format)" |
@@ -103,6 +103,7 @@ static int STM_Test(void) | |||
103 | UBYTE str[44]; | 103 | UBYTE str[44]; |
104 | int t; | 104 | int t; |
105 | 105 | ||
106 | memset(str,0,44); | ||
106 | _mm_fseek(modreader,20,SEEK_SET); | 107 | _mm_fseek(modreader,20,SEEK_SET); |
107 | _mm_read_UBYTES(str,44,modreader); | 108 | _mm_read_UBYTES(str,44,modreader); |
108 | if(str[9]!=2) return 0; /* STM Module = filetype 2 */ | 109 | if(str[9]!=2) return 0; /* STM Module = filetype 2 */ |
@@ -110,7 +111,7 @@ static int STM_Test(void) | |||
110 | /* Prevent false positives for S3M files */ | 111 | /* Prevent false positives for S3M files */ |
111 | if(!memcmp(str+40,"SCRM",4)) | 112 | if(!memcmp(str+40,"SCRM",4)) |
112 | return 0; | 113 | return 0; |
113 | 114 | ||
114 | for (t=0;t<STM_NTRACKERS;t++) | 115 | for (t=0;t<STM_NTRACKERS;t++) |
115 | if(!memcmp(str,STM_Signatures[t],8)) | 116 | if(!memcmp(str,STM_Signatures[t],8)) |
116 | return 1; | 117 | return 1; |
@@ -130,6 +131,8 @@ static void STM_Cleanup(void) | |||
130 | { | 131 | { |
131 | MikMod_free(mh); | 132 | MikMod_free(mh); |
132 | MikMod_free(stmbuf); | 133 | MikMod_free(stmbuf); |
134 | mh=NULL; | ||
135 | stmbuf=NULL; | ||
133 | } | 136 | } |
134 | 137 | ||
135 | static void STM_ConvertNote(STMNOTE *n) | 138 | static void STM_ConvertNote(STMNOTE *n) |
@@ -145,7 +148,7 @@ static void STM_ConvertNote(STMNOTE *n) | |||
145 | 148 | ||
146 | if((ins)&&(ins<32)) UniInstrument(ins-1); | 149 | if((ins)&&(ins<32)) UniInstrument(ins-1); |
147 | 150 | ||
148 | /* special values of [SBYTE0] are handled here | 151 | /* special values of [SBYTE0] are handled here |
149 | we have no idea if these strange values will ever be encountered. | 152 | we have no idea if these strange values will ever be encountered. |
150 | but it appears as those stms sound correct. */ | 153 | but it appears as those stms sound correct. */ |
151 | if((note==254)||(note==252)) { | 154 | if((note==254)||(note==252)) { |
@@ -224,8 +227,7 @@ static UBYTE *STM_ConvertTrack(STMNOTE *n) | |||
224 | 227 | ||
225 | static int STM_LoadPatterns(void) | 228 | static int STM_LoadPatterns(void) |
226 | { | 229 | { |
227 | int t,tracks=0; | 230 | unsigned int t,s,tracks=0; |
228 | unsigned int s; | ||
229 | 231 | ||
230 | if(!AllocPatterns()) return 0; | 232 | if(!AllocPatterns()) return 0; |
231 | if(!AllocTracks()) return 0; | 233 | if(!AllocTracks()) return 0; |
@@ -252,10 +254,10 @@ static int STM_LoadPatterns(void) | |||
252 | 254 | ||
253 | static int STM_Load(int curious) | 255 | static int STM_Load(int curious) |
254 | { | 256 | { |
255 | int t; | 257 | int t; |
256 | ULONG MikMod_ISA; /* We must generate our own ISA, it's not stored in stm */ | 258 | ULONG MikMod_ISA; /* We must generate our own ISA, it's not stored in stm */ |
257 | SAMPLE *q; | 259 | SAMPLE *q; |
258 | (void)curious; | 260 | (void)curious; |
259 | 261 | ||
260 | /* try to read stm header */ | 262 | /* try to read stm header */ |
261 | _mm_read_string(mh->songname,20,modreader); | 263 | _mm_read_string(mh->songname,20,modreader); |
@@ -272,6 +274,10 @@ static int STM_Load(int curious) | |||
272 | mh->numpat =_mm_read_UBYTE(modreader); | 274 | mh->numpat =_mm_read_UBYTE(modreader); |
273 | mh->globalvol =_mm_read_UBYTE(modreader); | 275 | mh->globalvol =_mm_read_UBYTE(modreader); |
274 | _mm_read_UBYTES(mh->reserved,13,modreader); | 276 | _mm_read_UBYTES(mh->reserved,13,modreader); |
277 | if(mh->numpat > 128) { | ||
278 | _mm_errno = MMERR_NOT_A_MODULE; | ||
279 | return 0; | ||
280 | } | ||
275 | 281 | ||
276 | for(t=0;t<31;t++) { | 282 | for(t=0;t<31;t++) { |
277 | STMSAMPLE *s=&mh->sample[t]; /* STM sample data */ | 283 | STMSAMPLE *s=&mh->sample[t]; /* STM sample data */ |
@@ -299,9 +305,7 @@ static int STM_Load(int curious) | |||
299 | /* set module variables */ | 305 | /* set module variables */ |
300 | for(t=0;t<STM_NTRACKERS;t++) | 306 | for(t=0;t<STM_NTRACKERS;t++) |
301 | if(!memcmp(mh->trackername,STM_Signatures[t],8)) break; | 307 | if(!memcmp(mh->trackername,STM_Signatures[t],8)) break; |
302 | if(t == STM_NTRACKERS) | 308 | of.modtype = MikMod_strdup(STM_Version[t]); |
303 | return 0; | ||
304 | of.modtype = StrDup(STM_Version[t]); | ||
305 | of.songname = DupStr(mh->songname,20,1); /* make a cstr of songname */ | 309 | of.songname = DupStr(mh->songname,20,1); /* make a cstr of songname */ |
306 | of.numpat = mh->numpat; | 310 | of.numpat = mh->numpat; |
307 | of.inittempo = 125; /* mh->inittempo+0x1c; */ | 311 | of.inittempo = 125; /* mh->inittempo+0x1c; */ |
@@ -316,7 +320,10 @@ static int STM_Load(int curious) | |||
316 | /* 99 terminates the patorder list */ | 320 | /* 99 terminates the patorder list */ |
317 | while((mh->patorder[t]<=99)&&(mh->patorder[t]<mh->numpat)) { | 321 | while((mh->patorder[t]<=99)&&(mh->patorder[t]<mh->numpat)) { |
318 | of.positions[t]=mh->patorder[t]; | 322 | of.positions[t]=mh->patorder[t]; |
319 | t++; | 323 | if(++t == 0x80) { |
324 | _mm_errno = MMERR_NOT_A_MODULE; | ||
325 | return 0; | ||
326 | } | ||
320 | } | 327 | } |
321 | if(mh->patorder[t]<=99) t++; | 328 | if(mh->patorder[t]<=99) t++; |
322 | of.numpos=t; | 329 | of.numpos=t; |
@@ -334,7 +341,7 @@ static int STM_Load(int curious) | |||
334 | q->speed = (mh->sample[t].c2spd * 8363) / 8448; | 341 | q->speed = (mh->sample[t].c2spd * 8363) / 8448; |
335 | q->volume = mh->sample[t].volume; | 342 | q->volume = mh->sample[t].volume; |
336 | q->length = mh->sample[t].length; | 343 | q->length = mh->sample[t].length; |
337 | if (/*(!mh->sample[t].volume)||*/(q->length==1)) q->length=0; | 344 | if (/*!mh->sample[t].volume || */q->length==1) q->length=0; |
338 | q->loopstart = mh->sample[t].loopbeg; | 345 | q->loopstart = mh->sample[t].loopbeg; |
339 | q->loopend = mh->sample[t].loopend; | 346 | q->loopend = mh->sample[t].loopend; |
340 | q->seekpos = MikMod_ISA; | 347 | q->seekpos = MikMod_ISA; |
@@ -374,5 +381,4 @@ MIKMODAPI MLOADER load_stm={ | |||
374 | STM_LoadTitle | 381 | STM_LoadTitle |
375 | }; | 382 | }; |
376 | 383 | ||
377 | |||
378 | /* ex:set ts=4: */ | 384 | /* ex:set ts=4: */ |