Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+5060 -2790
+40
apps/lang/english.lang
··· 15352 15352 </voice> 15353 15353 </phrase> 15354 15354 <phrase> 15355 + id: LANG_MIKMOD_HQMIXER 15356 + desc: in mikmod settings menu 15357 + user: core 15358 + <source> 15359 + *: none 15360 + lowmem: none 15361 + swcodec: "HQ Mixer" 15362 + </source> 15363 + <dest> 15364 + *: none 15365 + lowmem: none 15366 + swcodec: "HQ Mixer" 15367 + </dest> 15368 + <voice> 15369 + *: none 15370 + lowmem: none 15371 + swcodec: "High Quality Mixer" 15372 + </voice> 15373 + </phrase> 15374 + <phrase> 15375 + id: LANG_MIKMOD_SAMPLERATE 15376 + desc: in mikmod settings menu 15377 + user: core 15378 + <source> 15379 + *: none 15380 + lowmem: none 15381 + swcodec: "Sample Rate" 15382 + </source> 15383 + <dest> 15384 + *: none 15385 + lowmem: none 15386 + swcodec: "Sample Rate" 15387 + </dest> 15388 + <voice> 15389 + *: none 15390 + lowmem: none 15391 + swcodec: "Sample Rate" 15392 + </voice> 15393 + </phrase> 15394 + <phrase> 15355 15395 id: LANG_CPU_BOOST 15356 15396 desc: in mikmod settings menu 15357 15397 user: core
+2 -1
apps/plugins/mikmod/SOURCES
··· 5 5 load_dsm.c 6 6 load_far.c 7 7 load_gdm.c 8 - load_gt2.c 9 8 load_imf.c 10 9 load_it.c 11 10 load_m15.c ··· 17 16 load_stm.c 18 17 load_stx.c 19 18 load_ult.c 19 + load_umx.c 20 20 load_uni.c 21 21 load_xm.c 22 22 mdreg.c ··· 34 34 strdup.c 35 35 strstr.c 36 36 virtch.c 37 + virtch2.c 37 38 virtch_common.c 38 39 mikmod.c 39 40
+16 -14
apps/plugins/mikmod/load_669.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: load_669.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ 23 + $Id: $ 24 24 25 25 Composer 669 module loader 26 26 ··· 49 49 /*========== Module structure */ 50 50 51 51 /* header */ 52 - typedef struct S69HEADER { 52 + typedef struct S69HEADER { 53 53 UBYTE marker[2]; 54 54 CHAR message[108]; 55 55 UBYTE nos; 56 - UBYTE rbnop; 56 + UBYTE RBnop; 57 57 UBYTE looporder; 58 58 UBYTE orders[0x80]; 59 59 UBYTE tempos[0x80]; ··· 81 81 static S69HEADER* mh=NULL; 82 82 83 83 /* file type identification */ 84 - static CHAR* S69_Version[]={ 84 + static const CHAR* S69_Version[]={ 85 85 "Composer 669", 86 86 "Extended 669" 87 87 }; ··· 134 134 { 135 135 MikMod_free(s69pat); 136 136 MikMod_free(mh); 137 + mh=NULL; 138 + s69pat=NULL; 137 139 } 138 140 139 141 static int S69_LoadPatterns(void) ··· 142 144 UBYTE note,inst,vol,effect,lastfx,lastval; 143 145 S69NOTE *cur; 144 146 int tracks=0; 145 - 147 + 146 148 if(!AllocPatterns()) return 0; 147 149 if(!AllocTracks()) return 0; 148 150 ··· 226 228 case 5: /* set speed */ 227 229 if (effect) 228 230 UniPTEffect(0xf,effect); 229 - else 231 + else 230 232 if(mh->marker[0]!=0x69) { 231 233 #ifdef MIKMOD_DEBUG 232 234 fprintf(stderr,"\r669: unsupported super fast tempo at pat=%d row=%d chan=%d\n", ··· 250 252 int i; 251 253 SAMPLE *current; 252 254 S69SAMPLE sample; 253 - (void)curious; 255 + (void)curious; 254 256 255 257 /* module header */ 256 258 _mm_read_UBYTES(mh->marker,2,modreader); 257 259 _mm_read_UBYTES(mh->message,108,modreader); 258 260 mh->nos=_mm_read_UBYTE(modreader); 259 - mh->rbnop=_mm_read_UBYTE(modreader); 261 + mh->RBnop=_mm_read_UBYTE(modreader); 260 262 mh->looporder=_mm_read_UBYTE(modreader); 261 263 _mm_read_UBYTES(mh->orders,0x80,modreader); 262 264 for(i=0;i<0x80;i++) ··· 281 283 of.initspeed=4; 282 284 of.inittempo=78; 283 285 of.songname=DupStr(mh->message,36,1); 284 - of.modtype=StrDup(S69_Version[memcmp(mh->marker,"JN",2)==0]); 286 + of.modtype=MikMod_strdup(S69_Version[memcmp(mh->marker,"JN",2)==0]); 285 287 of.numchn=8; 286 - of.numpat=mh->rbnop; 288 + of.numpat=mh->RBnop; 287 289 of.numins=of.numsmp=mh->nos; 288 290 of.numtrk=of.numchn*of.numpat; 289 291 of.flags=UF_XMPERIODS|UF_LINEAR; ··· 292 294 for(i=36+35;(i>=36+0)&&(mh->message[i]==' ');i--) mh->message[i]=0; 293 295 for(i=72+35;(i>=72+0)&&(mh->message[i]==' ');i--) mh->message[i]=0; 294 296 if((mh->message[0])||(mh->message[36])||(mh->message[72])) 295 - if((of.comment=(CHAR*)MikMod_malloc(3*(36+1)+1))) { 297 + if((of.comment=(CHAR*)MikMod_malloc(3*(36+1)+1)) != NULL) { 296 298 strncpy(of.comment,mh->message,36); 297 299 strcat(of.comment,"\r"); 298 300 if (mh->message[36]) strncat(of.comment,mh->message+36,36); ··· 304 306 305 307 if(!AllocPositions(0x80)) return 0; 306 308 for(i=0;i<0x80;i++) { 307 - if(mh->orders[i]>=mh->rbnop) break; 309 + if(mh->orders[i]>=mh->RBnop) break; 308 310 of.positions[i]=mh->orders[i]; 309 311 } 310 312 of.numpos=i;
+47 -25
apps/plugins/mikmod/load_amf.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 19 19 */ 20 20 21 21 /*============================================================================== 22 - 23 - $Id: load_amf.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ 24 22 25 23 DMP Advanced Module Format loader 26 24 ··· 112 110 { 113 111 MikMod_free(mh); 114 112 MikMod_free(track); 113 + mh=NULL; 114 + track=NULL; 115 115 } 116 116 117 - static int AMF_UnpackTrack(MREADER* modreader) 117 + static int AMF_UnpackTrack(MREADER* r) 118 118 { 119 119 ULONG tracksize; 120 120 UBYTE row,cmd; ··· 124 124 memset(track,0,64*sizeof(AMFNOTE)); 125 125 126 126 /* read packed track */ 127 - if (modreader) { 128 - tracksize=_mm_read_I_UWORD(modreader); 129 - tracksize+=((ULONG)_mm_read_UBYTE(modreader))<<16; 127 + if (r) { 128 + tracksize=_mm_read_I_UWORD(r); 129 + tracksize+=((ULONG)_mm_read_UBYTE(r))<<16; 130 130 if (tracksize) 131 131 while(tracksize--) { 132 - row=_mm_read_UBYTE(modreader); 133 - cmd=_mm_read_UBYTE(modreader); 134 - arg=_mm_read_SBYTE(modreader); 132 + row=_mm_read_UBYTE(r); 133 + cmd=_mm_read_UBYTE(r); 134 + arg=_mm_read_SBYTE(r); 135 135 /* unexpected end of track */ 136 136 if(!tracksize) { 137 137 if((row==0xff)&&(cmd==0xff)&&(arg==-1)) 138 138 break; 139 139 /* the last triplet should be FF FF FF, but this is not 140 - always the case... maybe a bug in m2amf ? 140 + always the case... maybe a bug in m2amf ? 141 141 else 142 142 return 0; 143 143 */ ··· 164 164 if (cmd==0x83) { 165 165 /* volume without note */ 166 166 track[row].volume=(UBYTE)arg+1; 167 - } else 167 + } else 168 168 if (cmd==0xff) { 169 169 /* apparently, some M2AMF version fail to estimate the 170 170 size of the compressed patterns correctly, and end ··· 322 322 of.flags |= UF_PANNING; 323 323 break; 324 324 } 325 - 325 + 326 326 } 327 327 if (track[row].volume) UniVolEffect(VOL_VOLUME,track[row].volume-1); 328 328 UniNewline(); ··· 333 333 static int AMF_Load(int curious) 334 334 { 335 335 int u,defaultpanning; 336 - unsigned int t,realtrackcnt,realsmpcnt; 336 + unsigned int t,realtrackcnt,realsmpcnt; 337 337 AMFSAMPLE s; 338 338 SAMPLE *q; 339 339 UWORD *track_remap; 340 - ULONG samplepos; 340 + ULONG samplepos, fileend; 341 341 int channel_remap[16]; 342 - (void)curious; 342 + (void)curious; 343 343 344 344 /* try to read module header */ 345 345 _mm_read_UBYTES(mh->id,3,modreader); ··· 386 386 of.inittempo = mh->songbpm; 387 387 AMF_Version[AMFTEXTLEN-3]='0'+(mh->version/10); 388 388 AMF_Version[AMFTEXTLEN-1]='0'+(mh->version%10); 389 - of.modtype = StrDup(AMF_Version); 389 + of.modtype = MikMod_strdup(AMF_Version); 390 390 of.numchn = mh->numchannels; 391 391 of.numtrk = mh->numorders*mh->numchannels; 392 392 if (mh->numtracks>of.numtrk) ··· 400 400 /* XXX whenever possible, we should try to determine the original format. 401 401 Here we assume it was S3M-style wrt bpmlimit... */ 402 402 of.bpmlimit = 32; 403 - 403 + 404 404 /* 405 405 * Play with the panning table. Although the AMF format embeds a 406 406 * panning table, if the module was a MOD or an S3M with default ··· 466 466 s.c2spd =_mm_read_I_UWORD(modreader); 467 467 if(s.c2spd==8368) s.c2spd=8363; 468 468 s.volume =_mm_read_UBYTE(modreader); 469 - if(mh->version>=11) { 469 + /* "the tribal zone.amf" and "the way its gonna b.amf" by Maelcum 470 + * are the only version 10 files I can find, and they have 32 bit 471 + * reppos and repend, not 16. */ 472 + if(mh->version>=10) {/* was 11 */ 470 473 s.reppos =_mm_read_I_ULONG(modreader); 471 474 s.repend =_mm_read_I_ULONG(modreader); 472 475 } else { ··· 475 478 } 476 479 477 480 if(_mm_eof(modreader)) { 478 - _mm_errno = MMERR_LOADING_SAMPLEINFO; 481 + _mm_errno = MMERR_LOADING_SAMPLEINFO; 479 482 return 0; 480 483 } 481 484 ··· 493 496 } 494 497 495 498 /* read track table */ 496 - if(!(track_remap=MikMod_calloc(mh->numtracks+1,sizeof(UWORD)))) 499 + if(!(track_remap=(UWORD*)MikMod_calloc(mh->numtracks+1,sizeof(UWORD)))) 497 500 return 0; 498 501 _mm_read_I_UWORDS(track_remap+1,mh->numtracks,modreader); 499 502 if(_mm_eof(modreader)) { ··· 505 508 for(realtrackcnt=t=0;t<=mh->numtracks;t++) 506 509 if (realtrackcnt<track_remap[t]) 507 510 realtrackcnt=track_remap[t]; 511 + if (realtrackcnt > (int)mh->numtracks) { 512 + MikMod_free(track_remap); 513 + _mm_errno=MMERR_NOT_A_MODULE; 514 + return 0; 515 + } 508 516 for(t=0;t<of.numpat*of.numchn;t++) 509 517 of.patterns[t]=(of.patterns[t]<=mh->numtracks)? 510 - track_remap[of.patterns[t]]-1:(int)realtrackcnt; 518 + track_remap[of.patterns[t]]-1:(int)realtrackcnt; 511 519 512 520 MikMod_free(track_remap); 513 521 ··· 531 539 for(t=realtrackcnt;t<of.numtrk;t++) of.tracks[t]=NULL; 532 540 533 541 /* compute sample offsets */ 542 + if(_mm_eof(modreader)) goto fail; 534 543 samplepos=_mm_ftell(modreader); 544 + _mm_fseek(modreader,0,SEEK_END); 545 + fileend=_mm_ftell(modreader); 546 + _mm_fseek(modreader,samplepos,SEEK_SET); 535 547 for(realsmpcnt=t=0;t<of.numsmp;t++) 536 548 if(realsmpcnt<of.samples[t].seekpos) 537 549 realsmpcnt=of.samples[t].seekpos; 538 550 for(t=1;t<=realsmpcnt;t++) { 539 551 q=of.samples; 540 - while(q->seekpos!=t) q++; 552 + u=0; 553 + while(q->seekpos!=t) { 554 + if(++u==of.numsmp) 555 + goto fail; 556 + q++; 557 + } 541 558 q->seekpos=samplepos; 542 559 samplepos+=q->length; 543 560 } 544 - 561 + if(samplepos>fileend) 562 + goto fail; 563 + 545 564 return 1; 565 + fail: 566 + _mm_errno = MMERR_LOADING_SAMPLEINFO; 567 + return 0; 546 568 } 547 569 548 570 static CHAR *AMF_LoadTitle(void)
+52 -39
apps/plugins/mikmod/load_asy.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: load_asy.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ 23 + $Id$ 24 24 25 25 ASYLUM Music Format v1.0 (.amf) loader 26 26 adapted from load_mod.c by Raphael Assenat <raph@raphnet.net>, 27 27 with the help of the AMF2MOD utility sourcecode, 28 28 written to convert crusader's amf files into 8 29 29 channels mod file in 1995 by Mr. P / Powersource 30 - mrp@fish.share.net, ac054@sfn.saskatoon.sk.ca 31 - 30 + mrp@fish.share.net, ac054@sfn.saskatoon.sk.ca 31 + 32 32 33 33 ==============================================================================*/ 34 34 ··· 76 76 77 77 /* This table is taken from AMF2MOD.C 78 78 * written in 1995 by Mr. P / Powersource 79 - * mrp@fish.share.net, ac054@sfn.saskatoon.sk.ca */ 80 - UWORD periodtable[]={6848,6464,6096,5760,5424,5120,4832,4560,4304, 79 + * mrp@fish.share.net, ac054@sfn.saskatoon.sk.ca */ 80 + static const UWORD periodtable[] = { 81 + 6848,6464,6096,5760,5424,5120,4832,4560,4304, 81 82 4064,3840,3628,3424,3232,3048,2880,2712,2560, 82 83 2416,2280,2152,2032,1920,1814,1712,1616,1524, 83 84 1440,1356,1280,1208,1140,1076,1016, 960, 907, ··· 108 109 modtype = 1; 109 110 return 1; 110 111 } 111 - 112 + 112 113 return 0; 113 114 } 114 115 ··· 140 141 { 141 142 MikMod_free(mh); 142 143 MikMod_free(patbuf); 144 + mh = NULL; 145 + patbuf = NULL; 143 146 } 144 147 145 - static void ConvertNote(MODNOTE *n) 148 + static int ConvertNote(MODNOTE *n) 146 149 { 147 150 UBYTE instrument, effect, effdat, note; 148 151 UWORD period; 149 152 UBYTE lastnote = 0; 150 - 153 + 151 154 instrument = n->b&0x1f; 152 155 effect = n->c; 153 156 effdat = n->d; ··· 158 161 } else { 159 162 period = 0; 160 163 } 161 - 164 + 162 165 /* Convert the period to a note number */ 163 166 note = 0; 164 - if (period) 167 + if (period) 165 168 { 166 169 for (note = 0; note < 7 * OCTAVE; note++) 167 170 if (period >= npertab[note]) ··· 186 189 UniInstrument(instrument - 1); 187 190 /* ...otherwise, only adjust volume... */ 188 191 else { 189 - /* ...unless an effect was specified, 190 - * which forces a new note to be 192 + /* ...unless an effect was specified, 193 + * which forces a new note to be 191 194 * played */ 192 195 if (effect || effdat) { 193 196 UniInstrument(instrument - 1); ··· 218 221 if ((effect == 0xa) && (effdat & 0xf) && (effdat & 0xf0)) 219 222 effdat &= 0xf0; 220 223 224 + if (effect == 0x1b) { 225 + return 0; /* UniEffect(UNI_S3MEFFECTQ,dat) ? */ 226 + } 227 + if (effect > 0xf) { 228 + return 0; /* return -1 to fail? */ 229 + } 230 + 221 231 UniPTEffect(effect, effdat); 232 + return 0; 222 233 } 223 234 224 235 static UBYTE *ConvertTrack(MODNOTE *n) ··· 227 238 228 239 UniReset(); 229 240 for (t = 0; t < 64; t++) { 230 - ConvertNote(n); 241 + if (ConvertNote(n) < 0) 242 + return NULL; 231 243 UniNewline(); 232 244 n += of.numchn; 233 245 } ··· 237 249 /* Loads all patterns of a modfile and converts them into the 3 byte format. */ 238 250 static int ML_LoadPatterns(void) 239 251 { 240 - int t, tracks = 0; 241 - unsigned int s; 252 + unsigned int t, s, tracks = 0; 242 253 243 254 if (!AllocPatterns()) { 244 255 return 0; ··· 246 257 if (!AllocTracks()) { 247 258 return 0; 248 259 } 249 - 260 + 250 261 /* Allocate temporary buffer for loading and converting the patterns */ 251 262 if (!(patbuf = (MODNOTE *)MikMod_calloc(64U * of.numchn, sizeof(MODNOTE)))) 252 263 return 0; ··· 278 289 MSAMPINFO *s; 279 290 CHAR *descr=asylum; 280 291 ULONG seekpos; 281 - (void)curious; 292 + (void)curious; 282 293 283 - // no title in asylum amf files :( 284 - strcpy(mh->songname, ""); 294 + /* no title in asylum amf files :( */ 295 + mh->songname[0] = '\0'; 285 296 286 297 _mm_fseek(modreader, 0x23, SEEK_SET); 287 298 mh->num_patterns = _mm_read_UBYTE(modreader); 288 299 mh->num_orders = _mm_read_UBYTE(modreader); 289 - 290 - // skip unknown byte 291 - (void)_mm_read_UBYTE(modreader); 300 + 301 + /* skip unknown byte */ 302 + _mm_skip_BYTE(modreader); 292 303 _mm_read_UBYTES(mh->positions, 256, modreader); 293 - 304 + 294 305 /* read samples headers*/ 295 306 for (t = 0; t < 64; t++) { 296 307 s = &mh->samples[t]; 297 - 308 + 298 309 _mm_fseek(modreader, 0x126 + (t*37), SEEK_SET); 299 - 310 + 300 311 _mm_read_string(s->samplename, 22, modreader); 301 312 s->samplename[21] = 0; /* just in case */ 302 - 313 + 303 314 s->finetune = _mm_read_UBYTE(modreader); 304 315 s->volume = _mm_read_UBYTE(modreader); 305 - (void)_mm_read_UBYTE(modreader); // skip unknown byte 316 + _mm_skip_BYTE(modreader);/* skip unknown byte */ 306 317 s->length = _mm_read_I_ULONG(modreader); 307 318 s->reppos = _mm_read_I_ULONG(modreader); 308 319 s->replen = _mm_read_I_ULONG(modreader); ··· 324 335 of.numpat = mh->num_patterns; 325 336 of.numtrk = of.numpat * of.numchn; 326 337 327 - 328 338 /* Copy positions (orders) */ 329 339 if (!AllocPositions(of.numpos)) 330 340 return 0; 331 341 for (t = 0; t < of.numpos; t++) { 332 342 of.positions[t] = mh->positions[t]; 343 + if (of.positions[t]>of.numpat) { /* SANITIY CHECK */ 344 + /* fprintf(stderr,"positions[%d]=%d > numpat=%d\n",t,of.positions[t],of.numpat);*/ 345 + _mm_errno = MMERR_LOADING_HEADER; 346 + return 0; 347 + } 333 348 } 334 349 335 350 /* Finally, init the sampleinfo structures */ ··· 343 358 for (t = 0; t < of.numins; t++) { 344 359 /* convert the samplename */ 345 360 q->samplename = DupStr(s->samplename, 23, 1); 346 - 361 + 347 362 /* init the sampleinfo variables */ 348 363 q->speed = finetune[s->finetune & 0xf]; 349 364 q->volume = s->volume & 0x7f; ··· 351 366 q->loopstart = (ULONG)s->reppos; 352 367 q->loopend = (ULONG)q->loopstart + (s->replen); 353 368 q->length = (ULONG)s->length; 354 - 369 + 355 370 q->flags = SF_SIGNED; 356 - 371 + 357 372 q->seekpos = seekpos; 358 373 seekpos += q->length; 359 - 374 + 360 375 if ((s->replen) > 2) { 361 376 q->flags |= SF_LOOP; 362 377 } 363 - 378 + 364 379 /* fix replen if repend > length */ 365 380 if (q->loopend > q->length) 366 381 q->loopend = q->length; ··· 369 384 q++; 370 385 } 371 386 372 - of.modtype = StrDup(descr); 387 + of.modtype = MikMod_strdup(descr); 373 388 374 389 if (!ML_LoadPatterns()) 375 390 return 0; ··· 379 394 380 395 static CHAR *ASY_LoadTitle(void) 381 396 { 382 - CHAR *s = ""; // no titles 383 - 384 - return (DupStr(s, 21, 1)); 397 + return MikMod_strdup(""); 385 398 } 386 399 387 400 /*========== Loader information */
+18 -11
apps/plugins/mikmod/load_dsm.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: load_dsm.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ 23 + $Id$ 24 24 25 25 DSIK internal format (DSM) module loader 26 26 ··· 89 89 90 90 /*========== Loader variables */ 91 91 92 - static CHAR* SONGID="SONG"; 93 - static CHAR* INSTID="INST"; 94 - static CHAR* PATTID="PATT"; 92 + static const CHAR* SONGID="SONG"; 93 + static const CHAR* INSTID="INST"; 94 + static const CHAR* PATTID="PATT"; 95 95 96 96 static UBYTE blockid[4]; 97 97 static ULONG blockln; ··· 101 101 102 102 static CHAR DSM_Version[]="DSIK DSM-format"; 103 103 104 - static unsigned char DSMSIG[4+4]={'R','I','F','F','D','S','M','F'}; 104 + static const unsigned char DSMSIG[4+4]={'R','I','F','F','D','S','M','F'}; 105 105 106 106 /*========== Loader code */ 107 107 ··· 126 126 { 127 127 MikMod_free(dsmbuf); 128 128 MikMod_free(mh); 129 + dsmbuf = NULL; 130 + mh = NULL; 129 131 } 130 132 131 133 static int GetBlockHeader(void) ··· 133 135 /* make sure we're at the right position for reading the 134 136 next riff block, no matter how many bytes read */ 135 137 _mm_fseek(modreader, blocklp+blockln, SEEK_SET); 136 - 138 + 137 139 while(1) { 138 140 _mm_read_UBYTES(blockid,4,modreader); 139 141 blockln=_mm_read_I_ULONG(modreader); ··· 237 239 DSMINST s; 238 240 SAMPLE *q; 239 241 int cursmp=0,curpat=0,track=0; 240 - (void)curious; 242 + (void)curious; 241 243 242 244 blocklp=0; 243 245 blockln=12; ··· 266 268 /* set module variables */ 267 269 of.initspeed=mh->speed; 268 270 of.inittempo=mh->bpm; 269 - of.modtype=StrDup(DSM_Version); 271 + of.modtype=MikMod_strdup(DSM_Version); 270 272 of.numchn=mh->numtrk; 271 273 of.numpat=mh->numpat; 272 274 of.numtrk=of.numchn*of.numpat; ··· 286 288 for(t=0;t<mh->numord;t++) { 287 289 int order=mh->orders[t]; 288 290 if(order==255) order=LAST_PATTERN; 291 + else if (of.positions[t]>of.numpat) { /* SANITIY CHECK */ 292 + /* fprintf(stderr,"positions[%d]=%d > numpat=%d\n",t,of.positions[t],of.numpat);*/ 293 + _mm_errno = MMERR_LOADING_HEADER; 294 + return 0; 295 + } 289 296 of.positions[of.numpos]=order; 290 297 if(mh->orders[t]<254) of.numpos++; 291 298 } ··· 344 351 345 352 _mm_fseek(modreader,12,SEEK_SET); 346 353 if(!_mm_read_UBYTES(s,28,modreader)) return NULL; 347 - 354 + 348 355 return(DupStr(s,28,1)); 349 356 } 350 357
+24 -14
apps/plugins/mikmod/load_far.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: load_far.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ 23 + $Id$ 24 24 25 25 Farandole (FAR) module loader 26 26 ··· 92 92 static FARHEADER2 *mh2 = NULL; 93 93 static FARNOTE *pat = NULL; 94 94 95 - static unsigned char FARSIG[4+3]={'F','A','R',0xfe,13,10,26}; 95 + static const unsigned char FARSIG[4+3]={'F','A','R',0xfe,13,10,26}; 96 96 97 97 /*========== Loader code */ 98 98 ··· 119 119 MikMod_free(mh1); 120 120 MikMod_free(mh2); 121 121 MikMod_free(pat); 122 + mh1 = NULL; 123 + mh2 = NULL; 124 + pat = NULL; 122 125 } 123 126 124 127 static UBYTE *FAR_ConvertTrack(FARNOTE* n,int rows) ··· 180 183 FARSAMPLE s; 181 184 FARNOTE *crow; 182 185 UBYTE smap[8]; 183 - (void)curious; 186 + (void)curious; 184 187 185 188 /* try to read module header (first part) */ 186 189 _mm_read_UBYTES(mh1->id,4,modreader); ··· 196 199 mh1->stlen = _mm_read_I_UWORD (modreader); 197 200 198 201 /* init modfile data */ 199 - of.modtype = StrDup(FAR_Version); 202 + of.modtype = MikMod_strdup(FAR_Version); 200 203 of.songname = DupStr(mh1->songname,40,1); 201 204 of.numchn = 16; 202 205 of.initspeed = mh1->speed; ··· 207 210 208 211 /* read songtext into comment field */ 209 212 if(mh1->stlen) 210 - if (!ReadLinedComment(mh1->stlen, 66)) return 0; 213 + if (!ReadLinedComment(mh1->stlen, 132)) return 0; 214 + 215 + if(_mm_eof(modreader)) { 216 + _mm_errno = MMERR_LOADING_HEADER; 217 + return 0; 218 + } 211 219 212 220 /* try to read module header (second part) */ 213 221 _mm_read_UBYTES(mh2->orders,256,modreader); ··· 238 246 if(!AllocPatterns()) return 0; 239 247 240 248 for(t=0;t<of.numpat;t++) { 241 - UBYTE rows=0/* ,tempo */; 249 + UBYTE rows=0; 250 + UBYTE tempo; 242 251 243 252 memset(pat,0,256*16*4*sizeof(FARNOTE)); 244 253 if(mh2->patsiz[t]) { 245 254 rows = _mm_read_UBYTE(modreader); 246 - /* tempo = */ (void)_mm_read_UBYTE(modreader); 255 + tempo = _mm_read_UBYTE(modreader); 256 + (void)tempo; /* unused */ 247 257 248 258 crow = pat; 249 259 /* file often allocates 64 rows even if there are less in pattern */ ··· 284 294 of.numins = 0; 285 295 for(t=0;t<64;t++) 286 296 if(smap[t>>3]&(1<<(t&7))) of.numins=t+1; 287 - of.numsmp = of.numins; 297 + of.numsmp = of.numins; 288 298 289 299 /* alloc sample structs */ 290 300 if(!AllocSamples()) return 0; ··· 314 324 315 325 q->seekpos = _mm_ftell(modreader); 316 326 _mm_fseek(modreader,q->length,SEEK_CUR); 317 - } else 318 - q->samplename = DupStr(NULL,0,0); 327 + } else 328 + q->samplename = MikMod_strdup(""); 319 329 q++; 320 330 } 321 331 return 1; ··· 327 337 328 338 _mm_fseek(modreader,4,SEEK_SET); 329 339 if(!_mm_read_UBYTES(s,40,modreader)) return NULL; 330 - 331 - return(DupStr(s,40,1)); 340 + 341 + return (DupStr(s,40,1)); 332 342 } 333 343 334 344 /*========== Loader information */
+21 -12
apps/plugins/mikmod/load_gdm.c
··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: load_gdm.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ 23 + $Id$ 24 24 25 25 General DigiMusic (GDM) module loader 26 26 ··· 114 114 static GDMHEADER *mh=NULL; /* pointer to GDM header */ 115 115 static GDMNOTE *gdmbuf=NULL; /* pointer to a complete GDM pattern */ 116 116 117 - CHAR GDM_Version[]="General DigiMusic 1.xx"; 117 + static CHAR GDM_Version[]="General DigiMusic 1.xx"; 118 118 119 119 static int GDM_Test(void) 120 120 { ··· 146 146 { 147 147 MikMod_free(mh); 148 148 MikMod_free(gdmbuf); 149 + mh=NULL; 150 + gdmbuf=NULL; 149 151 } 150 152 151 153 static int GDM_ReadPattern(void) 152 154 { 153 - int pos,flag,ch,i,maxch; 155 + int pos,flag,ch,i; 154 156 GDMNOTE n; 155 - UWORD length,x=0; 157 + SLONG length,x=0; 156 158 157 159 /* get pattern length */ 158 - length=_mm_read_I_UWORD(modreader)-2; 160 + length=(SLONG)_mm_read_I_UWORD(modreader); 161 + length-=2; 159 162 160 163 /* clear pattern data */ 161 164 memset(gdmbuf,255,32*64*sizeof(GDMNOTE)); 162 165 pos=0; 163 - maxch=0; 164 166 165 167 while (x<length) { 166 168 memset(&n,255,sizeof(GDMNOTE)); 167 169 flag=_mm_read_UBYTE(modreader); 168 170 x++; 169 171 170 - if (_mm_eof(modreader)) { 171 - _mm_errno=MMERR_LOADING_PATTERN; 172 + if (_mm_eof(modreader)) 172 173 return 0; 173 - } 174 174 175 175 ch=flag&31; 176 - if (ch>maxch) maxch=ch; 176 + if (ch > of.numchn) 177 + return 0; 178 + 177 179 if (!flag) { 178 180 pos++; 181 + if (x==length) { 182 + if (pos > 64) 183 + return 0; 184 + } else { 185 + if (pos >= 64) 186 + return 0; 187 + } 179 188 continue; 180 189 } 181 190 if (flag&0x60) { ··· 343 352 SAMPLE *q; 344 353 GDMSAMPLE s; 345 354 ULONG position; 346 - (void)curious; 355 + (void)curious; 347 356 348 357 /* read header */ 349 358 _mm_read_string(mh->id1,4,modreader); ··· 390 399 } 391 400 392 401 /* now we fill */ 393 - of.modtype=StrDup(GDM_Version); 402 + of.modtype=MikMod_strdup(GDM_Version); 394 403 of.modtype[18]=mh->majorver+'0'; 395 404 of.modtype[20]=mh->minorver/10+'0'; 396 405 of.modtype[21]=mh->minorver%10+'0';
-375
apps/plugins/mikmod/load_gt2.c
··· 1 - /* MikMod sound library 2 - (c) 2003-2004 Raphael Assenat and others - see file 3 - AUTHORS for complete list. 4 - 5 - This library is free software; you can redistribute it and/or modify 6 - it under the terms of the GNU Library General Public License as 7 - published by the Free Software Foundation; either version 2 of 8 - the License, or (at your option) any later version. 9 - 10 - This program is distributed in the hope that it will be useful, 11 - but WITHOUT ANY WARRANTY; without even the implied warranty of 12 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 - GNU Library General Public License for more details. 14 - 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 17 - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 18 - 02111-1307, USA. 19 - */ 20 - 21 - /*============================================================================== 22 - 23 - $Id: load_gt2.c,v 1.2 2005/03/30 19:09:35 realtech Exp $ 24 - 25 - Graoumf tracker format (.GT2) 26 - 27 - ==============================================================================*/ 28 - 29 - #ifdef HAVE_CONFIG_H 30 - #include "config.h" 31 - #endif 32 - 33 - #ifdef HAVE_UNISTD_H 34 - #include <unistd.h> 35 - #endif 36 - 37 - #include <ctype.h> 38 - #include <stdio.h> 39 - #ifdef HAVE_MEMORY_H 40 - #include <memory.h> 41 - #endif 42 - #include <string.h> 43 - 44 - #include "mikmod_internals.h" 45 - 46 - typedef struct GT_NOTE { 47 - UBYTE note; /* 24-127, 48 is middle C-2. 0 for no note */ 48 - UBYTE inst; /* instrument, 1-255, 0 for none */ 49 - UWORD effect; /* 0 for no FX */ 50 - UBYTE vv; /* volume, 1-255, 0 for no volume */ 51 - } GT_NOTE; 52 - 53 - /* general info chunk */ 54 - typedef struct GT2_CHUNK { 55 - UBYTE magic[4]; /* must be 'GT2' */ 56 - UBYTE version; /* 01 = v0.7, 02=v0.726, 03=v0.731 */ 57 - ULONG chunk_size; 58 - CHAR module_name[33]; /* 32 bytes in file */ 59 - CHAR comments_author[161]; /* 160 bytes in file */ 60 - UBYTE date_day; 61 - UBYTE date_month; 62 - UWORD date_year; 63 - CHAR tracker_name[25]; /* 24 in file */ 64 - UWORD initial_speed; 65 - UWORD initial_tempo; 66 - UWORD initial_master_volume; /* 000 - fff */ 67 - UWORD num_voices; /* for the following panning section */ 68 - UWORD *voice_pannings; /* 000 - 800 - fff */ 69 - } GT2_CHUNK; 70 - 71 - /* track volume chunk */ 72 - typedef struct TVOL_CHUNK { 73 - UBYTE id[4]; /* must be TVOL */ 74 - ULONG chunk_size; 75 - UWORD num_tracks; /* for the following array */ 76 - UWORD *track_volumes; /* 0000 - 1000 - FFFF */ 77 - } TVOL_CHUNK; 78 - 79 - /* extra-comment chunk */ 80 - typedef struct XCOM_CHUNK { 81 - UBYTE id[4]; /* must be XCOM */ 82 - ULONG chunk_size; 83 - ULONG comment_len; 84 - CHAR *comment; /* comment_len + 1 allocated */ 85 - } XCOM_CHUNK; 86 - 87 - /* song chunk */ 88 - typedef struct SONG_CHUNK { 89 - UBYTE id[4]; /* must be SONG */ 90 - ULONG chunk_size; 91 - UWORD song_length; 92 - UWORD song_repeat_point; 93 - UWORD *patterns; /* pattern numbers */ 94 - } SONG_CHUNK; 95 - 96 - /* pattern set chunk */ 97 - typedef struct PATS_CHUNK { 98 - UBYTE id[4]; /* must be PATS */ 99 - ULONG chunk_size; 100 - UWORD num_tracks; /* total number of tracks for the song */ 101 - UWORD num_patterns; /* number of patterns saved */ 102 - } PATS_CHUNK; 103 - 104 - /* pattern chunk */ 105 - typedef struct PATD_CHUNK { 106 - UBYTE id[4]; /* must be PATD */ 107 - ULONG chunk_size; 108 - UWORD pattern_number; 109 - CHAR pattern_name[17]; /* 16 in file */ 110 - UWORD codage_version; /* only 0 expected for now */ 111 - /* version 0 (full pattern) */ 112 - UWORD num_lines; 113 - UWORD num_tracks; 114 - GT_NOTE *notes; /* sizeof(GT_NOTE) * num_lines * num_tracks */ 115 - } PATD_CHUNK; 116 - 117 - /* instrument set chunk */ 118 - typedef struct ORCH_CHUNK { 119 - UBYTE id[4]; /* must be ORCH */ 120 - ULONG chunk_size; 121 - UWORD num_instruments; /* number of instruments saved */ 122 - } ORCH_CHUNK; 123 - 124 - typedef struct INST_NOTE { 125 - UBYTE samp_number;/* sample number for midi note */ 126 - CHAR tranp; /* transposition for note */ 127 - } INST_NOTE; 128 - 129 - /* instrument chunk */ 130 - typedef struct INST_CHUNK { 131 - UBYTE id[4]; /* must be INST */ 132 - ULONG chunk_size; 133 - UWORD instrument_number; 134 - CHAR name[29]; /* 28 in file */ 135 - UWORD type; /* 0 = sample */ 136 - UWORD volume; /* volume, 0-255 */ 137 - UWORD auto_panning; /* autopanning, 000 - 800 - fff, -1 no autopanning */ 138 - UWORD volume_enveloppe_number; 139 - UWORD tone_enveloppe_number; 140 - UWORD pan_enveloppe_number; 141 - UBYTE reserved[10]; 142 - INST_NOTE note[128]; 143 - } INST_CHUNK; 144 - 145 - typedef struct SAMP_CHUNK { 146 - UBYTE id[4]; /* must be SAMP */ 147 - ULONG chunk_size; 148 - UWORD sample_number; 149 - CHAR name[29]; /* 28 in file */ 150 - UWORD flags; /* bit0: 0 = mono, 1 = stereo bit1: 0 normal loop, bit2: ping pong loop */ 151 - UWORD autopanning; /* 000 - 800 - fff */ 152 - UWORD num_bits; /* 8 or 16 */ 153 - UWORD rate; /* between 2000 and 65000 */ 154 - ULONG length; /* bytes */ 155 - ULONG loop_start; /* bytes */ 156 - ULONG loop_len; /* bytes */ 157 - UWORD volume; /* 0 - 255 */ 158 - UWORD finetune; /* (-8..+7 -> -1..+7/8 halftone) */ 159 - UWORD codage; /* 0 */ 160 - UBYTE *data; 161 - } SAMP_CHUNK; 162 - 163 - typedef struct xENV_CHUNK { 164 - UBYTE id[4]; /* must be VENV, TENV or PENV */ 165 - ULONG chunk_size; 166 - UWORD envelope_number; 167 - CHAR name[21]; /* 20 in file */ 168 - UWORD keyoff_offset; 169 - UBYTE *data; 170 - } xENV_CHUNK; 171 - 172 - typedef struct ENDC_CHUNK { 173 - UBYTE id[4]; /* must be ENDC */ 174 - ULONG chunk_size; 175 - ULONG total_module_size; 176 - } ENDC_CHUNK; 177 - 178 - 179 - typedef union GT_CHUNK 180 - { 181 - UBYTE id[4]; /* must be TVOL */ 182 - GT2_CHUNK gt2; 183 - TVOL_CHUNK tvol; 184 - XCOM_CHUNK xcom; 185 - SONG_CHUNK song; 186 - PATS_CHUNK pats; 187 - PATD_CHUNK patd; 188 - ORCH_CHUNK orch; 189 - INST_CHUNK inst; 190 - SAMP_CHUNK samp; 191 - xENV_CHUNK xenv; 192 - ENDC_CHUNK endc; 193 - } GT_CHUNK; 194 - 195 - static GT_CHUNK *loadChunk(void) 196 - { 197 - GT_CHUNK *new_chunk = MikMod_malloc(sizeof(GT_CHUNK)); 198 - 199 - /* the file chunk id only use 3 bytes, others 4 */ 200 - _mm_read_UBYTES(new_chunk->id, 3, modreader); 201 - if (! (new_chunk->id[0]=='G' && 202 - new_chunk->id[1]=='T' && 203 - new_chunk->id[2]=='2') 204 - ) 205 - { 206 - _mm_read_UBYTES(&new_chunk->id[3], 1, modreader); 207 - } 208 - else 209 - { 210 - new_chunk->id[3] = ' '; 211 - } 212 - 213 - printf(">> %c%c%c%c\n", new_chunk->id[0], new_chunk->id[1], new_chunk->id[2], new_chunk->id[3]); 214 - 215 - if (!memcmp(new_chunk, "GT2", 3)) { 216 - _mm_read_UBYTES(&new_chunk->gt2.version, 1, modreader); 217 - _mm_read_M_ULONGS(&new_chunk->gt2.chunk_size, 1, modreader); 218 - new_chunk->gt2.module_name[32] = 0; 219 - _mm_read_UBYTES(&new_chunk->gt2.module_name, 32, modreader); 220 - new_chunk->gt2.comments_author[160] = 0; 221 - _mm_read_UBYTES(&new_chunk->gt2.comments_author, 160, modreader); 222 - _mm_read_UBYTES(&new_chunk->gt2.date_day, 1, modreader); 223 - _mm_read_UBYTES(&new_chunk->gt2.date_month, 1, modreader); 224 - _mm_read_M_UWORDS(&new_chunk->gt2.date_year, 1, modreader); 225 - new_chunk->gt2.tracker_name[24] = 0; 226 - _mm_read_UBYTES(&new_chunk->gt2.tracker_name, 24, modreader); 227 - _mm_read_M_UWORDS(&new_chunk->gt2.initial_speed, 1, modreader); 228 - _mm_read_M_UWORDS(&new_chunk->gt2.initial_tempo, 1, modreader); 229 - _mm_read_M_UWORDS(&new_chunk->gt2.initial_master_volume, 1, modreader); 230 - _mm_read_M_UWORDS(&new_chunk->gt2.num_voices, 1, modreader); 231 - new_chunk->gt2.voice_pannings = MikMod_malloc(2*new_chunk->gt2.num_voices); 232 - _mm_read_M_UWORDS(new_chunk->gt2.voice_pannings, new_chunk->gt2.num_voices, modreader); 233 - return new_chunk; 234 - } 235 - 236 - if (!memcmp(new_chunk, "TVOL", 4)) { 237 - new_chunk->tvol.chunk_size = _mm_read_M_ULONG(modreader); 238 - new_chunk->tvol.num_tracks = _mm_read_M_UWORD(modreader); 239 - new_chunk->tvol.track_volumes = MikMod_malloc(new_chunk->tvol.num_tracks * 2); 240 - _mm_read_M_UWORDS(new_chunk->tvol.track_volumes, new_chunk->tvol.num_tracks, modreader); 241 - return new_chunk; 242 - } 243 - 244 - if (!memcmp(new_chunk, "XCOM", 4)) { 245 - new_chunk->xcom.chunk_size = _mm_read_M_ULONG(modreader); 246 - new_chunk->xcom.comment_len = _mm_read_M_ULONG(modreader); 247 - new_chunk->xcom.comment = MikMod_malloc(new_chunk->xcom.comment_len + 1); 248 - _mm_read_UBYTES(new_chunk->xcom.comment, new_chunk->xcom.comment_len, modreader); 249 - return new_chunk; 250 - } 251 - 252 - if (!memcmp(new_chunk, "SONG", 4)) { 253 - new_chunk->song.chunk_size = _mm_read_M_ULONG(modreader); 254 - new_chunk->song.song_length = _mm_read_M_UWORD(modreader); 255 - new_chunk->song.song_repeat_point = _mm_read_M_UWORD(modreader); 256 - new_chunk->song.patterns = MikMod_malloc(2*new_chunk->song.song_length); 257 - _mm_read_M_UWORDS(new_chunk->song.patterns, new_chunk->song.song_length, modreader); 258 - return new_chunk; 259 - } 260 - 261 - if (!memcmp(new_chunk, "PATS", 4)) { 262 - new_chunk->pats.chunk_size = _mm_read_M_ULONG(modreader); 263 - new_chunk->pats.num_tracks = _mm_read_M_UWORD(modreader); 264 - new_chunk->pats.num_patterns = _mm_read_M_UWORD(modreader); 265 - return new_chunk; 266 - } 267 - 268 - if (!memcmp(new_chunk, "PATD", 4)) { 269 - new_chunk->patd.chunk_size = _mm_read_M_ULONG(modreader); 270 - new_chunk->patd.pattern_number = _mm_read_M_UWORD(modreader); 271 - new_chunk->patd.pattern_name[16] = 0; 272 - _mm_read_UBYTES(new_chunk->patd.pattern_name, 16, modreader); 273 - new_chunk->patd.codage_version = _mm_read_M_UWORD(modreader); 274 - new_chunk->patd.num_lines = _mm_read_M_UWORD(modreader); 275 - new_chunk->patd.num_tracks = _mm_read_M_UWORD(modreader); 276 - new_chunk->patd.notes = MikMod_malloc(5 * 277 - new_chunk->patd.num_lines * 278 - new_chunk->patd.num_tracks); 279 - _mm_read_UBYTES(new_chunk->patd.notes, 280 - new_chunk->patd.num_lines * new_chunk->patd.num_tracks * 5, 281 - modreader); 282 - return new_chunk; 283 - } 284 - 285 - if (!memcmp(new_chunk, "ORCH", 4)) { 286 - new_chunk->orch.chunk_size = _mm_read_M_ULONG(modreader); 287 - new_chunk->orch.num_instruments = _mm_read_M_UWORD(modreader); 288 - return new_chunk; 289 - } 290 - if (!memcmp(new_chunk, "INST", 4)) { 291 - return new_chunk; 292 - } 293 - if (!memcmp(new_chunk, "SAMP", 4)) { 294 - return new_chunk; 295 - } 296 - if (!memcmp(new_chunk, "VENV", 4)) { 297 - return new_chunk; 298 - } 299 - if (!memcmp(new_chunk, "TENV", 4)) { 300 - return new_chunk; 301 - } 302 - if (!memcmp(new_chunk, "PENV", 4)) { 303 - return new_chunk; 304 - } 305 - if (!memcmp(new_chunk, "ENDC", 4)) { 306 - return new_chunk; 307 - } 308 - 309 - printf("?? %c%c%c%c\n", new_chunk->id[0], new_chunk->id[1], new_chunk->id[2], new_chunk->id[3]); 310 - 311 - MikMod_free(new_chunk); 312 - return NULL; // unknown chunk 313 - } 314 - 315 - static int GT2_Init(void) 316 - { 317 - return 1; 318 - } 319 - 320 - static int GT2_Test(void) 321 - { 322 - UBYTE magic[3]; 323 - _mm_fseek(modreader, 0, SEEK_SET); 324 - 325 - _mm_read_UBYTES(magic, 3, modreader); 326 - 327 - if (magic[0] == 'G' && magic[1] == 'T' && magic[2] == '2') { return 1; } 328 - 329 - return 0; 330 - } 331 - 332 - static int GT2_Load(int curious) 333 - { 334 - GT_CHUNK *tmp; 335 - (void)curious; 336 - 337 - _mm_fseek(modreader, 0, SEEK_SET); 338 - while ( (tmp = loadChunk() )) 339 - { 340 - printf("%c%c%c%c\n", tmp->id[0], tmp->id[1], tmp->id[2], tmp->id[3]); 341 - 342 - } 343 - 344 - return 0; 345 - } 346 - 347 - static void GT2_Cleanup(void) 348 - { 349 - } 350 - 351 - static CHAR *GT2_LoadTitle(void) 352 - { 353 - CHAR title[33]; 354 - _mm_fseek(modreader, 8, SEEK_SET); 355 - 356 - _mm_read_UBYTES(title, 32, modreader); 357 - title[32]=0; 358 - 359 - return (DupStr(title, 32, 1)); 360 - } 361 - 362 - 363 - MIKMODAPI MLOADER load_gt2 = { 364 - NULL, 365 - "Graoumf Tracker 2 module", 366 - "Graoumf Tracker 2", 367 - GT2_Init, 368 - GT2_Test, 369 - GT2_Load, 370 - GT2_Cleanup, 371 - GT2_LoadTitle 372 - }; 373 - 374 - 375 -
+52 -19
apps/plugins/mikmod/load_imf.c
··· 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 25 Imago Orpheus (IMF) module loader 26 26 ··· 127 127 128 128 static int IMF_Test(void) 129 129 { 130 - UBYTE id[4]; 130 + UBYTE buf[512], *p; 131 + int t, chn; 131 132 132 133 _mm_fseek(modreader,0x3c,SEEK_SET); 133 - if(!_mm_read_UBYTES(id,4,modreader)) return 0; 134 - if(!memcmp(id,"IM10",4)) return 1; 135 - return 0; 134 + if (!_mm_read_UBYTES(buf,4,modreader)) return 0; 135 + if (memcmp(buf,"IM10",4) != 0) return 0; /* no magic */ 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 162 static int IMF_Init(void) ··· 149 173 150 174 MikMod_free(imfpat); 151 175 MikMod_free(mh); 176 + imfpat=NULL; 177 + mh=NULL; 152 178 } 153 179 154 180 static int IMF_ReadPattern(SLONG size,UWORD rows) ··· 388 414 ULONG *nextwav=NULL; 389 415 UWORD wavcnt=0; 390 416 UBYTE id[4]; 391 - (void)curious; 417 + (void)curious; 392 418 393 419 /* try to read the module header */ 394 420 _mm_read_string(mh->songname,32,modreader); ··· 410 436 411 437 /* set module variables */ 412 438 of.songname=DupStr(mh->songname,31,1); 413 - of.modtype=StrDup(IMF_Version); 439 + of.modtype=MikMod_strdup(IMF_Version); 414 440 of.numpat=mh->patnum; 415 441 of.numins=mh->insnum; 416 442 of.reppos=0; ··· 467 493 if(!AllocPositions(of.numpos)) return 0; 468 494 for(t=u=0;t<mh->ordnum;t++) 469 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 504 /* load pattern info */ 472 505 of.numtrk=of.numpat*of.numchn; ··· 509 542 _mm_read_I_UWORDS(ih.panenv,IMFENVCNT,modreader); 510 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 546 #define IMF_FinishLoadingEnvelope(name) \ 514 547 ih. name##pts=_mm_read_UBYTE(modreader); \ 515 548 ih. name##sus=_mm_read_UBYTE(modreader); \ 516 549 ih. name##beg=_mm_read_UBYTE(modreader); \ 517 550 ih. name##end=_mm_read_UBYTE(modreader); \ 518 551 ih. name##flg=_mm_read_UBYTE(modreader); \ 519 - (void)_mm_read_UBYTE(modreader); \ 520 - (void)_mm_read_UBYTE(modreader); \ 521 - (void)_mm_read_UBYTE(modreader) 552 + _mm_skip_BYTE(modreader); \ 553 + _mm_skip_BYTE(modreader); \ 554 + _mm_skip_BYTE(modreader) 522 555 #else 523 556 #define IMF_FinishLoadingEnvelope(name) \ 524 557 ih. name/**/pts=_mm_read_UBYTE(modreader); \ ··· 526 559 ih. name/**/beg=_mm_read_UBYTE(modreader); \ 527 560 ih. name/**/end=_mm_read_UBYTE(modreader); \ 528 561 ih. name/**/flg=_mm_read_UBYTE(modreader); \ 529 - (void)_mm_read_UBYTE(modreader); \ 530 - (void)_mm_read_UBYTE(modreader); \ 531 - (void)_mm_read_UBYTE(modreader) 562 + _mm_skip_BYTE(modreader); \ 563 + _mm_skip_BYTE(modreader); \ 564 + _mm_skip_BYTE(modreader) 532 565 #endif 533 566 534 567 IMF_FinishLoadingEnvelope(vol); ··· 541 574 _mm_read_UBYTES(id,4,modreader); 542 575 /* Looks like Imago Orpheus forgets the signature for empty 543 576 instruments following a multi-sample instrument... */ 544 - if(memcmp(id,"II10",4) && 577 + if(memcmp(id,"II10",4) && 545 578 (oldnumsmp && memcmp(id,"\x0\x0\x0\x0",4))) { 546 579 if(nextwav) MikMod_free(nextwav); 547 580 if(wh) MikMod_free(wh); ··· 562 595 d->samplenumber[u]=ih.what[u]>ih.numsmp?0xffff:ih.what[u]+of.numsmp; 563 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 599 #define IMF_ProcessEnvelope(name) \ 567 600 for (u = 0; u < (IMFENVCNT >> 1); u++) { \ 568 601 d-> name##env[u].pos = ih. name##env[u << 1]; \ ··· 613 646 /* allocate more room for sample information if necessary */ 614 647 if(of.numsmp+u==wavcnt) { 615 648 wavcnt+=IMF_SMPINCR; 616 - if(!(nextwav=MikMod_realloc(nextwav,wavcnt*sizeof(ULONG)))) { 649 + if(!(nextwav=(ULONG*)MikMod_realloc(nextwav,wavcnt*sizeof(ULONG)))) { 617 650 if(wh) MikMod_free(wh); 618 651 _mm_errno=MMERR_OUT_OF_MEMORY; 619 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 655 MikMod_free(nextwav); 623 656 _mm_errno=MMERR_OUT_OF_MEMORY; 624 657 return 0; ··· 627 660 } 628 661 629 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 664 s->length =_mm_read_I_ULONG(modreader); 632 665 s->loopstart =_mm_read_I_ULONG(modreader); 633 666 s->loopend =_mm_read_I_ULONG(modreader);
+106 -78
apps/plugins/mikmod/load_it.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: load_it.c,v 1.4 2010/01/12 03:30:32 realtech Exp $ 23 + $Id$ 24 24 25 25 Impulse tracker (IT) module loader 26 26 ··· 45 45 46 46 #ifdef SUNOS 47 47 extern int fprintf(FILE *, const char *, ...); 48 - extern int toupper(int); 49 48 #endif 50 49 51 50 /*========== Module structure */ ··· 67 66 UBYTE initspeed; 68 67 UBYTE inittempo; 69 68 UBYTE pansep; /* panning separation between channels */ 70 - UBYTE zerobyte; 69 + UBYTE zerobyte; 71 70 UWORD msglength; 72 71 ULONG msgoffset; 73 72 UBYTE blank02[4]; ··· 107 106 CHAR filename[12]; /* (char) Instrument filename */ 108 107 UBYTE zerobyte; /* (byte) Instrument type (always 0) */ 109 108 UBYTE volflg; 110 - UBYTE volpts; 109 + UBYTE volpts; 111 110 UBYTE volbeg; /* (byte) Volume loop start (node) */ 112 111 UBYTE volend; /* (byte) Volume loop end (node) */ 113 112 UBYTE volsusbeg; /* (byte) Volume sustain begin (node) */ 114 113 UBYTE volsusend; /* (byte) Volume Sustain end (node) */ 115 114 UBYTE panflg; 116 - UBYTE panpts; 115 + UBYTE panpts; 117 116 UBYTE panbeg; /* (byte) channel loop start (node) */ 118 117 UBYTE panend; /* (byte) channel loop end (node) */ 119 118 UBYTE pansusbeg; /* (byte) channel sustain begin (node) */ 120 119 UBYTE pansusend; /* (byte) channel Sustain end (node) */ 121 120 UBYTE pitflg; 122 - UBYTE pitpts; 121 + UBYTE pitpts; 123 122 UBYTE pitbeg; /* (byte) pitch loop start (node) */ 124 123 UBYTE pitend; /* (byte) pitch loop end (node) */ 125 124 UBYTE pitsusbeg; /* (byte) pitch sustain begin (node) */ ··· 149 148 UWORD pantick[ITENVCNT]; /* tick value of panning nodes */ 150 149 SBYTE pitnode[ITENVCNT]; /* pitchenv - node points */ 151 150 UWORD pittick[ITENVCNT]; /* tick value of pitch nodes */ 152 - } ITINSTHEADER; 151 + } ITINSTHEADER; 153 152 154 153 /* unpacked note */ 155 154 ··· 166 165 static ITNOTE *last=NULL; /* uncompressing IT's pattern information */ 167 166 static int numtrk=0; 168 167 static unsigned int old_effect; /* if set, use S3M old-effects stuffs */ 169 - 170 - static CHAR* IT_Version[]={ 168 + 169 + static const CHAR* IT_Version[]={ 171 170 "ImpulseTracker . ", 172 171 "Compressed ImpulseTracker . ", 173 172 "ImpulseTracker 2.14p3", ··· 177 176 }; 178 177 179 178 /* table for porta-to-note command within volume/panning column */ 180 - static UBYTE portatable[10]= {0,1,4,8,16,32,64,96,128,255}; 179 + static const UBYTE portatable[10]= {0,1,4,8,16,32,64,96,128,255}; 181 180 182 181 /*========== Loader code */ 183 182 ··· 212 211 MikMod_free(last); 213 212 MikMod_free(paraptr); 214 213 MikMod_free(origpositions); 214 + mh=NULL; 215 + poslookup=NULL; 216 + itpat=NULL; 217 + mask=NULL; 218 + last=NULL; 219 + paraptr=NULL; 220 + origpositions=NULL; 215 221 } 216 222 217 223 /* Because so many IT files have 64 channels as the set number used, but really 218 224 only use far less (usually from 8 to 24 still), I had to make this function, 219 225 which determines the number of channels that are actually USED by a pattern. 220 - 226 + 221 227 NOTE: You must first seek to the file location of the pattern before calling 222 - this procedure. 228 + this procedure. 223 229 224 - Returns 1 on error 230 + Returns 0 on error 225 231 */ 226 232 static int IT_GetNumChannels(UWORD patrows) 227 233 { 228 234 int row=0,flag,ch; 229 235 230 236 do { 231 - if((flag=_mm_read_UBYTE(modreader))==EOF) { 237 + if(_mm_eof(modreader)) { 232 238 _mm_errno=MMERR_LOADING_PATTERN; 233 - return 1; 239 + return 0; 234 240 } 241 + flag=_mm_read_UBYTE(modreader); 235 242 if(!flag) 236 243 row++; 237 244 else { 238 245 ch=(flag-1)&63; 239 246 remap[ch]=0; 240 247 if(flag & 128) mask[ch]=_mm_read_UBYTE(modreader); 241 - if(mask[ch]&1) (void)_mm_read_UBYTE(modreader); 242 - if(mask[ch]&2) (void)_mm_read_UBYTE(modreader); 243 - if(mask[ch]&4) (void)_mm_read_UBYTE(modreader); 244 - if(mask[ch]&8) { (void)_mm_read_UBYTE(modreader);(void)_mm_read_UBYTE(modreader); } 248 + if(mask[ch]&1) _mm_skip_BYTE(modreader); 249 + if(mask[ch]&2) _mm_skip_BYTE(modreader); 250 + if(mask[ch]&4) _mm_skip_BYTE(modreader); 251 + if(mask[ch]&8) { _mm_skip_BYTE(modreader);_mm_skip_BYTE(modreader); } 245 252 } 246 253 } while(row<patrows); 247 254 248 - return 0; 255 + return 1; 249 256 } 250 257 251 258 static UBYTE* IT_ConvertTrack(ITNOTE* tr,UWORD numrows) ··· 282 289 /* process volume / panning column 283 290 volume / panning effects do NOT all share the same memory address 284 291 yet. */ 285 - if(volpan<=64) 292 + if(volpan<=64) 286 293 UniVolEffect(VOL_VOLUME,volpan); 287 294 else if(volpan==65) /* fine volume slide up (65-74) - A0 case */ 288 295 UniVolEffect(VOL_VOLSLIDE,0); ··· 324 331 325 332 static int IT_ReadPattern(UWORD patrows) 326 333 { 327 - int row=0,flag,ch,blah; 334 + int row=0,flag,ch; 335 + unsigned int blah; 328 336 ITNOTE *itt=itpat,dummy,*n,*l; 337 + ITNOTE *ite=&itpat[200*64 -1]; 338 + UBYTE *m; 329 339 330 340 memset(itt,255,200*64*sizeof(ITNOTE)); 331 341 332 342 do { 333 - if((flag=_mm_read_UBYTE(modreader))==EOF) { 343 + if(_mm_eof(modreader)) { 334 344 _mm_errno = MMERR_LOADING_PATTERN; 335 345 return 0; 336 346 } 347 + flag=_mm_read_UBYTE(modreader); 337 348 if(!flag) { 338 349 itt=&itt[of.numchn]; 339 350 row++; ··· 342 353 if(ch!=-1) { 343 354 n=&itt[ch]; 344 355 l=&last[ch]; 345 - } else 356 + m=&mask[ch]; 357 + if(n > ite) { /* malformed file */ 358 + _mm_errno = MMERR_NOT_A_MODULE; 359 + return 0; 360 + } 361 + } else 362 + { 346 363 n=l=&dummy; 364 + blah = 0; 365 + m=(UBYTE*)&blah; 366 + } 347 367 348 - if(flag&128) mask[ch]=_mm_read_UBYTE(modreader); 349 - if(mask[ch]&1) 368 + if(flag&128) *m=_mm_read_UBYTE(modreader); 369 + if(*m&1) 350 370 /* convert IT note off to internal note off */ 351 - if((l->note=n->note=_mm_read_UBYTE(modreader))==255) 371 + if((l->note=n->note=_mm_read_UBYTE(modreader))==255) 352 372 l->note=n->note=253; 353 - if(mask[ch]&2) 373 + if(*m&2) 354 374 l->ins=n->ins=_mm_read_UBYTE(modreader); 355 - if(mask[ch]&4) 375 + if(*m&4) 356 376 l->volpan=n->volpan=_mm_read_UBYTE(modreader); 357 - if(mask[ch]&8) { 377 + if(*m&8) { 358 378 l->cmd=n->cmd=_mm_read_UBYTE(modreader); 359 379 l->inf=n->inf=_mm_read_UBYTE(modreader); 360 380 } 361 - if(mask[ch]&16) 381 + if(*m&16) 362 382 n->note=l->note; 363 - if(mask[ch]&32) 383 + if(*m&32) 364 384 n->ins=l->ins; 365 - if(mask[ch]&64) 385 + if(*m&64) 366 386 n->volpan=l->volpan; 367 - if(mask[ch]&128) { 387 + if(*m&128) { 368 388 n->cmd=l->cmd; 369 389 n->inf=l->inf; 370 390 } ··· 379 399 return 1; 380 400 } 381 401 382 - static void LoadMidiString(MREADER* modreader,CHAR* dest) 402 + static void LoadMidiString(MREADER* r,CHAR* dest) 383 403 { 384 - CHAR *cur,*last; 404 + CHAR *curp,*lastp; 385 405 386 - _mm_read_UBYTES(dest,32,modreader); 387 - cur=last=dest; 406 + memset(dest,0,33*sizeof(CHAR));/* caller sends midiline[33] */ 407 + _mm_read_UBYTES(dest,32,r); 408 + curp=lastp=dest; 388 409 /* remove blanks and uppercase all */ 389 - while(*last) { 390 - if(isalnum((int)*last)) *(cur++)=toupper((int)*last); 391 - last++; 410 + while(*lastp) { 411 + if(isalnum((int)*lastp)) *(curp++)=toupper((int)*lastp); 412 + lastp++; 392 413 } 393 - *cur=0; 414 + *curp=0; 394 415 } 395 416 396 417 /* Load embedded midi information for resonant filters */ 397 - static void IT_LoadMidiConfiguration(MREADER* modreader) 418 + static void IT_LoadMidiConfiguration(MREADER* r) 398 419 { 399 420 int i; 400 421 401 422 memset(filtermacros,0,sizeof(filtermacros)); 402 423 memset(filtersettings,0,sizeof(filtersettings)); 403 424 404 - if (modreader) { /* information is embedded in file */ 425 + if (r) { /* information is embedded in file */ 405 426 UWORD dat; 406 427 CHAR midiline[33]; 407 428 408 - dat=_mm_read_I_UWORD(modreader); 409 - _mm_fseek(modreader,8*dat+0x120,SEEK_CUR); 429 + dat=_mm_read_I_UWORD(r); 430 + _mm_fseek(r,8*dat+0x120,SEEK_CUR); 410 431 411 432 /* read midi macros */ 412 433 for(i=0;i<UF_MAXMACRO;i++) { 413 - LoadMidiString(modreader,midiline); 434 + LoadMidiString(r,midiline); 414 435 if((!strncmp(midiline,"F0F00",5))&& 415 436 ((midiline[5]=='0')||(midiline[5]=='1'))) 416 437 filtermacros[i]=(midiline[5]-'0')|0x80; ··· 418 439 419 440 /* read standalone filters */ 420 441 for(i=0x80;i<0x100;i++) { 421 - LoadMidiString(modreader,midiline); 442 + LoadMidiString(r,midiline); 422 443 if((!strncmp(midiline,"F0F00",5))&& 423 444 ((midiline[5]=='0')||(midiline[5]=='1'))) { 424 445 filtersettings[i].filter=(midiline[5]-'0')|0x80; ··· 446 467 int t,u,lp; 447 468 INSTRUMENT *d; 448 469 SAMPLE *q; 449 - /* int compressed=0; */ 470 + /*int compressed=0;*/ 450 471 451 472 numtrk=0; 452 473 filters=0; ··· 477 498 478 499 if(_mm_eof(modreader)) { 479 500 _mm_errno=MMERR_LOADING_HEADER; 501 + return 0; 502 + } 503 + if(mh->ordnum > 256 || mh->insnum > 255 || mh->smpnum > 255 || mh->patnum > 255) { 504 + _mm_errno=MMERR_NOT_A_MODULE; 480 505 return 0; 481 506 } 482 507 ··· 506 531 /* 2.16 : IT 2.14p3 with resonant filters */ 507 532 /* 2.15 : IT 2.14p3 (improved compression) */ 508 533 if((mh->cwt<=0x219)&&(mh->cwt>=0x217)) 509 - of.modtype=StrDup(IT_Version[mh->cmwt<0x214?4:5]); 534 + of.modtype=MikMod_strdup(IT_Version[mh->cmwt<0x214?4:5]); 510 535 else if (mh->cwt>=0x215) 511 - of.modtype=StrDup(IT_Version[mh->cmwt<0x214?2:3]); 536 + of.modtype=MikMod_strdup(IT_Version[mh->cmwt<0x214?2:3]); 512 537 else { 513 - of.modtype = StrDup(IT_Version[mh->cmwt<0x214?0:1]); 538 + of.modtype = MikMod_strdup(IT_Version[mh->cmwt<0x214?0:1]); 514 539 of.modtype[mh->cmwt<0x214?15:26] = (mh->cwt>>8)+'0'; 515 540 of.modtype[mh->cmwt<0x214?17:28] = ((mh->cwt>>4)&0xf)+'0'; 516 541 of.modtype[mh->cmwt<0x214?18:29] = ((mh->cwt)&0xf)+'0'; ··· 550 575 551 576 /* read the order data */ 552 577 if(!AllocPositions(mh->ordnum)) return 0; 553 - if(!(origpositions=MikMod_calloc(mh->ordnum,sizeof(UWORD)))) return 0; 578 + if(!(origpositions=(UWORD*)MikMod_calloc(mh->ordnum,sizeof(UWORD)))) return 0; 554 579 555 580 for(t=0;t<mh->ordnum;t++) { 556 581 origpositions[t]=_mm_read_UBYTE(modreader); ··· 672 697 if(s.flag&2) q->flags|=SF_16BITS; 673 698 if((s.flag&8)&&(mh->cwt>=0x214)) { 674 699 q->flags|=SF_ITPACKED; 675 - /* compressed=1; */ 700 + /*compressed=1;*/ 676 701 } 677 702 if(s.flag&16) q->flags|=SF_LOOP; 678 703 if(s.flag&64) q->flags|=SF_BIDI; 679 704 680 705 if(mh->cwt>=0x200) { 681 706 if(s.convert&1) q->flags|=SF_SIGNED; 682 - if(s.convert&4) q->flags|=SF_DELTA; 707 + if(s.convert&4) q->flags|=SF_DELTA; 683 708 } 684 709 q++; 685 710 } ··· 726 751 727 752 ih.trkvers = _mm_read_I_UWORD(modreader); 728 753 ih.numsmp = _mm_read_UBYTE(modreader); 729 - (void)_mm_read_UBYTE(modreader); 754 + _mm_skip_BYTE(modreader); 730 755 _mm_read_string(ih.name,26,modreader); 731 756 _mm_read_UBYTES(ih.blank01,6,modreader); 732 757 _mm_read_I_UWORDS(ih.samptable,ITNOTECNT,modreader); ··· 736 761 for(lp=0;lp<ITENVCNT;lp++) { 737 762 ih.oldvoltick[lp] = _mm_read_UBYTE(modreader); 738 763 ih.volnode[lp] = _mm_read_UBYTE(modreader); 739 - } 764 + } 740 765 } else { 741 766 /* load IT 2xx volume, pan and pitch envelopes */ 742 - #if defined __STDC__ || defined _MSC_VER || defined MPW_C 767 + #if defined __STDC__ || defined _MSC_VER || defined __WATCOMC__ || defined MPW_C 743 768 #define IT_LoadEnvelope(name,type) \ 744 769 ih. name##flg =_mm_read_UBYTE(modreader); \ 745 770 ih. name##pts =_mm_read_UBYTE(modreader); \ 771 + if (ih. name##pts > ITENVCNT) \ 772 + ih. name##pts = ITENVCNT; \ 746 773 ih. name##beg =_mm_read_UBYTE(modreader); \ 747 774 ih. name##end =_mm_read_UBYTE(modreader); \ 748 775 ih. name##susbeg=_mm_read_UBYTE(modreader); \ ··· 751 778 ih. name##node[lp]=_mm_read_##type (modreader); \ 752 779 ih. name##tick[lp]=_mm_read_I_UWORD(modreader); \ 753 780 } \ 754 - (void)_mm_read_UBYTE(modreader) 781 + _mm_skip_BYTE(modreader) 755 782 #else 756 783 #define IT_LoadEnvelope(name,type) \ 757 784 ih. name/**/flg =_mm_read_UBYTE(modreader); \ 758 785 ih. name/**/pts =_mm_read_UBYTE(modreader); \ 786 + if (ih. name/**/pts > ITENVCNT) \ 787 + ih. name/**/pts = ITENVCNT; \ 759 788 ih. name/**/beg =_mm_read_UBYTE(modreader); \ 760 789 ih. name/**/end =_mm_read_UBYTE(modreader); \ 761 790 ih. name/**/susbeg=_mm_read_UBYTE(modreader); \ ··· 764 793 ih. name/**/node[lp]=_mm_read_/**/type (modreader); \ 765 794 ih. name/**/tick[lp]=_mm_read_I_UWORD(modreader); \ 766 795 } \ 767 - (void)_mm_read_UBYTE(modreader) 796 + _mm_skip_BYTE(modreader) 768 797 #endif 769 798 770 799 IT_LoadEnvelope(vol,UBYTE); ··· 772 801 IT_LoadEnvelope(pit,SBYTE); 773 802 #undef IT_LoadEnvelope 774 803 } 775 - 804 + 776 805 if(_mm_eof(modreader)) { 777 806 _mm_errno = MMERR_LOADING_SAMPLEINFO; 778 807 return 0; ··· 791 820 792 821 if(ih.volflg&1) d->volflg|=EF_ON; 793 822 if(ih.volflg&2) d->volflg|=EF_LOOP; 794 - if(ih.volflg&4) d->volflg|=EF_SUSTAIN; 823 + if(ih.volflg&4) d->volflg|=EF_SUSTAIN; 795 824 796 825 /* XM conversion of IT envelope Array */ 797 - d->volbeg = ih.volbeg; 826 + d->volbeg = ih.volbeg; 798 827 d->volend = ih.volend; 799 828 d->volsusbeg = ih.volsusbeg; 800 829 d->volsusend = ih.volsusend; ··· 807 836 d->volpts++; 808 837 } else 809 838 break; 810 - } 839 + } 811 840 } else { 812 841 d->panning=((ih.chanpan&127)==64)?255:(ih.chanpan&127)<<2; 813 842 if(!(ih.chanpan&128)) d->flags|=IF_OWNPAN; ··· 827 856 d->rpanvar = ih.rpanvar; 828 857 } 829 858 830 - #if defined __STDC__ || defined _MSC_VER || defined MPW_C 859 + #if defined __STDC__ || defined _MSC_VER || defined __WATCOMC__ || defined MPW_C 831 860 #define IT_ProcessEnvelope(name) \ 832 861 if(ih. name##flg&1) d-> name##flg|=EF_ON; \ 833 862 if(ih. name##flg&2) d-> name##flg|=EF_LOOP; \ ··· 862 891 #endif 863 892 864 893 IT_ProcessEnvelope(vol); 865 - 866 - // Secunia SA37775 867 - if (ih.volpts>= ENVPOINTS) 868 - ih.volpts = ENVPOINTS-1; 869 - 894 + 870 895 for(u=0;u<ih.volpts;u++) 871 896 d->volenv[u].val=(ih.volnode[u]<<2); 872 897 ··· 887 912 #ifdef MIKMOD_DEBUG 888 913 { 889 914 static int warn=0; 890 - 915 + 891 916 if(!warn) 892 917 fprintf(stderr, "\rFilter envelopes not supported yet\n"); 893 918 warn=1; ··· 908 933 } 909 934 } 910 935 911 - d++; 936 + d++; 912 937 } 913 938 } else if(of.flags & UF_LINEAR) { 914 939 if(!AllocInstruments()) return 0; ··· 946 971 return 0; 947 972 } 948 973 _mm_read_I_ULONG(modreader); 949 - if(IT_GetNumChannels(packlen)) return 0; 974 + if(!IT_GetNumChannels(packlen)) return 0; 950 975 } 951 976 } 952 977 953 978 /* give each of them a different number */ 954 - for(t=0;t<UF_MAXCHAN;t++) 979 + for(t=0;t<UF_MAXCHAN;t++) 955 980 if(!remap[t]) 956 981 remap[t]=of.numchn++; 957 982 ··· 963 988 if(!AllocTracks()) return 0; 964 989 965 990 for(t=0;t<of.numpat;t++) { 991 + UWORD packlen; 992 + 966 993 /* seek to pattern position */ 967 994 if(!paraptr[mh->insnum+mh->smpnum+t]) { /* 0 -> empty 64 row pattern */ 968 995 of.pattrows[t]=64; ··· 975 1002 } 976 1003 } else { 977 1004 _mm_fseek(modreader,((long)paraptr[mh->insnum+mh->smpnum+t]),SEEK_SET); 978 - (void)_mm_read_I_UWORD(modreader); 1005 + packlen=_mm_read_I_UWORD(modreader); 1006 + (void)packlen; /* unused */ 979 1007 of.pattrows[t]=_mm_read_I_UWORD(modreader); 980 1008 _mm_read_I_ULONG(modreader); 981 1009 if(!IT_ReadPattern(of.pattrows[t])) return 0; ··· 991 1019 992 1020 _mm_fseek(modreader,4,SEEK_SET); 993 1021 if(!_mm_read_UBYTES(s,26,modreader)) return NULL; 994 - 1022 + 995 1023 return(DupStr(s,26,0)); 996 1024 } 997 1025
+54 -53
apps/plugins/mikmod/load_m15.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: load_m15.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ 23 + $Id$ 24 24 25 25 15 instrument MOD loader 26 26 Also supports Ultimate Sound Tracker (old M15 format) ··· 79 79 80 80 /* known file formats which can confuse the loader */ 81 81 #define REJECT 2 82 - static char *signatures[REJECT]={ 82 + static const char *signatures[REJECT]={ 83 83 "CAKEWALK", /* cakewalk midi files */ 84 84 "SZDD" /* Microsoft compressed files */ 85 85 }; 86 - static int siglen[REJECT]={8,4}; 86 + static const int siglen[REJECT]={8,4}; 87 87 88 88 /*========== Loader code */ 89 89 90 - static int LoadModuleHeader(MODULEHEADER *mh) 90 + static int LoadModuleHeader(MODULEHEADER *h) 91 91 { 92 92 int t,u; 93 93 94 - _mm_read_string(mh->songname,20,modreader); 95 - mh->songname[20]=0; /* just in case */ 94 + _mm_read_string(h->songname,20,modreader); 96 95 97 96 /* sanity check : title should contain printable characters and a bunch 98 97 of null chars */ 99 98 for(t=0;t<20;t++) 100 - if((mh->songname[t])&&(mh->songname[t]<32)) return 0; 101 - for(t=0;(mh->songname[t])&&(t<20);t++); 102 - if(t<20) for(;t<20;t++) if(mh->songname[t]) return 0; 99 + if((h->songname[t])&&(h->songname[t]<32)) return 0; 100 + for(t=0;(h->songname[t])&&(t<20);t++); 101 + if(t<20) for(;t<20;t++) if(h->songname[t]) return 0; 103 102 104 103 for(t=0;t<15;t++) { 105 - MSAMPINFO *s=&mh->samples[t]; 104 + MSAMPINFO *s=&h->samples[t]; 106 105 107 106 _mm_read_string(s->samplename,22,modreader); 108 - s->samplename[22]=0; /* just in case */ 109 107 s->length =_mm_read_M_UWORD(modreader); 110 108 s->finetune =_mm_read_UBYTE(modreader); 111 109 s->volume =_mm_read_UBYTE(modreader); ··· 123 121 if(s->finetune>>4) return 0; 124 122 } 125 123 126 - mh->songlength =_mm_read_UBYTE(modreader); 127 - mh->magic1 =_mm_read_UBYTE(modreader); /* should be 127 */ 124 + h->songlength =_mm_read_UBYTE(modreader); 125 + h->magic1 =_mm_read_UBYTE(modreader); /* should be 127 */ 128 126 129 127 /* sanity check : no more than 128 positions, restart position in range */ 130 - if((!mh->songlength)||(mh->songlength>128)) return 0; 128 + if((!h->songlength)||(h->songlength>128)) return 0; 131 129 /* values encountered so far are 0x6a and 0x78 */ 132 - if(((mh->magic1&0xf8)!=0x78)&&(mh->magic1!=0x6a)&&(mh->magic1>mh->songlength)) return 0; 130 + if(((h->magic1&0xf8)!=0x78)&&(h->magic1!=0x6a)&&(h->magic1>h->songlength)) return 0; 133 131 134 - _mm_read_UBYTES(mh->positions,128,modreader); 132 + _mm_read_UBYTES(h->positions,128,modreader); 135 133 136 134 /* sanity check : pattern range is 0..63 */ 137 135 for(t=0;t<128;t++) 138 - if(mh->positions[t]>63) return 0; 136 + if(h->positions[t]>63) return 0; 139 137 140 138 return(!_mm_eof(modreader)); 141 139 } 142 140 143 141 /* Checks the patterns in the modfile for UST / 15-inst indications. 144 - For example, if an effect 3xx is found, it is assumed that the song 145 - is 15-inst. If a 1xx effect has dat greater than 0x20, it is UST. 142 + For example, if an effect 3xx is found, it is assumed that the song 143 + is 15-inst. If a 1xx effect has dat greater than 0x20, it is UST. 146 144 147 145 Returns: 0 indecisive; 1 = UST; 2 = 15-inst */ 148 146 static int CheckPatternType(int numpat) ··· 152 150 153 151 for(t=0;t<numpat*(64U*4);t++) { 154 152 /* Load the pattern into the temp buffer and scan it */ 155 - (void)_mm_read_UBYTE(modreader);(void)_mm_read_UBYTE(modreader); 153 + _mm_skip_BYTE(modreader);_mm_skip_BYTE(modreader); 156 154 eff = _mm_read_UBYTE(modreader); 157 155 dat = _mm_read_UBYTE(modreader); 158 156 ··· 177 175 static int M15_Test(void) 178 176 { 179 177 int t, numpat; 180 - MODULEHEADER mh; 178 + MODULEHEADER h; 181 179 182 180 ust_loader = 0; 183 - if(!LoadModuleHeader(&mh)) return 0; 181 + memset(&h, 0, sizeof(MODULEHEADER)); 182 + if(!LoadModuleHeader(&h)) return 0; 184 183 185 184 /* reject other file types */ 186 185 for(t=0;t<REJECT;t++) 187 - if(!memcmp(mh.songname,signatures[t],siglen[t])) return 0; 186 + if(!memcmp(h.songname,signatures[t],siglen[t])) return 0; 188 187 189 - if(mh.magic1>127) return 0; 190 - if((!mh.songlength)||(mh.songlength>mh.magic1)) return 0; 188 + if(h.magic1>127) return 0; 189 + if((!h.songlength)||(h.songlength>h.magic1)) return 0; 191 190 192 191 for(t=0;t<15;t++) { 193 192 /* all finetunes should be zero */ 194 - if(mh.samples[t].finetune) return 0; 193 + if(h.samples[t].finetune) return 0; 195 194 196 195 /* all volumes should be <= 64 */ 197 - if(mh.samples[t].volume>64) return 0; 196 + if(h.samples[t].volume>64) return 0; 198 197 199 198 /* all instrument names should begin with s, st-, or a number */ 200 - if((mh.samples[t].samplename[0]=='s')|| 201 - (mh.samples[t].samplename[0]=='S')) { 202 - if((memcmp(mh.samples[t].samplename,"st-",3)) && 203 - (memcmp(mh.samples[t].samplename,"ST-",3)) && 204 - (*mh.samples[t].samplename)) 199 + if((h.samples[t].samplename[0]=='s')|| 200 + (h.samples[t].samplename[0]=='S')) { 201 + if((memcmp(h.samples[t].samplename,"st-",3)) && 202 + (memcmp(h.samples[t].samplename,"ST-",3)) && 203 + (*h.samples[t].samplename)) 205 204 ust_loader = 1; 206 205 } else 207 - if(!isdigit((int)mh.samples[t].samplename[0])) 206 + if(!isdigit((int)h.samples[t].samplename[0])) 208 207 ust_loader = 1; 209 208 210 - if(mh.samples[t].length>4999||mh.samples[t].reppos>9999) { 209 + if(h.samples[t].length>4999||h.samples[t].reppos>9999) { 211 210 ust_loader = 0; 212 - if(mh.samples[t].length>32768) return 0; 211 + if(h.samples[t].length>32768) return 0; 213 212 } 214 213 215 214 /* if loop information is incorrect as words, but correct as bytes, 216 215 this is likely to be an ust-style module */ 217 - if((mh.samples[t].reppos+mh.samples[t].replen>mh.samples[t].length)&& 218 - (mh.samples[t].reppos+mh.samples[t].replen<(mh.samples[t].length<<1))){ 216 + if((h.samples[t].reppos+h.samples[t].replen>h.samples[t].length)&& 217 + (h.samples[t].reppos+h.samples[t].replen<(h.samples[t].length<<1))) { 219 218 ust_loader = 1; 220 219 return 1; 221 220 } 222 221 223 - if(!ust_loader) return 1; 222 + if(!ust_loader) return 1; 224 223 } 225 224 226 - for(numpat=0,t=0;t<mh.songlength;t++) 227 - if(mh.positions[t]>numpat) 228 - numpat = mh.positions[t]; 225 + for(numpat=0,t=0;t<h.songlength;t++) 226 + if(h.positions[t]>numpat) 227 + numpat = h.positions[t]; 229 228 numpat++; 230 229 switch(CheckPatternType(numpat)) { 231 230 case 0: /* indecisive, so check more clues... */ ··· 242 241 243 242 static int M15_Init(void) 244 243 { 245 - if(!(mh=(MODULEHEADER*)MikMod_malloc(sizeof(MODULEHEADER)))) return 0; 244 + if(!(mh=(MODULEHEADER*)MikMod_calloc(1,sizeof(MODULEHEADER)))) return 0; 246 245 return 1; 247 246 } 248 247 ··· 250 249 { 251 250 MikMod_free(mh); 252 251 MikMod_free(patbuf); 252 + mh=NULL; 253 + patbuf=NULL; 253 254 } 254 255 255 256 /* ··· 331 332 case 1: 332 333 UniPTEffect(0,effdat); 333 334 break; 334 - case 2: 335 + case 2: 335 336 if(effdat&0xf) UniPTEffect(1,effdat&0xf); 336 337 else if(effdat>>2) UniPTEffect(2,effdat>>2); 337 338 break; ··· 351 352 } 352 353 if (effect == 8) 353 354 of.flags |= UF_PANNING; 354 - 355 + 355 356 return effect; 356 357 } 357 358 ··· 372 373 /* Loads all patterns of a modfile and converts them into the 3 byte format. */ 373 374 static int M15_LoadPatterns(void) 374 375 { 375 - int t,tracks=0; 376 - unsigned int s; 376 + unsigned int t,s,tracks=0; 377 377 378 378 if(!AllocPatterns()) return 0; 379 379 if(!AllocTracks()) return 0; ··· 398 398 399 399 static int M15_Load(int curious) 400 400 { 401 - int t,scan; 401 + unsigned int t,scan; 402 402 SAMPLE *q; 403 403 MSAMPINFO *s; 404 + (void)curious; 404 405 405 406 /* try to read module header */ 406 407 if(!LoadModuleHeader(mh)) { ··· 409 410 } 410 411 411 412 if(ust_loader) 412 - of.modtype = StrDup("Ultimate Soundtracker"); 413 + of.modtype = MikMod_strdup("Ultimate Soundtracker"); 413 414 else 414 - of.modtype = StrDup("Soundtracker"); 415 + of.modtype = MikMod_strdup("Soundtracker"); 415 416 416 417 /* set module variables */ 417 418 of.initspeed = 6; 418 419 of.inittempo = 125; 419 - of.numchn = 4; 420 + of.numchn = 4; 420 421 of.songname = DupStr(mh->songname,21,1); 421 422 of.numpos = mh->songlength; 422 423 of.reppos = 0; ··· 467 468 q->length = s->length<<1; 468 469 469 470 q->flags = SF_SIGNED; 470 - if(ust_loader) q->flags |= SF_UST_LOOP; 471 + if(ust_loader) q->flags |= SF_UST_LOOP; 471 472 if(s->replen>2) q->flags |= SF_LOOP; 472 473 473 474 s++;
+57 -17
apps/plugins/mikmod/load_med.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: load_med.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ 23 + $Id$ 24 24 25 25 Amiga MED module loader 26 26 ··· 189 189 MikMod_free(ba); 190 190 MikMod_free(mmd0pat); 191 191 MikMod_free(mmd1pat); 192 + me = NULL; 193 + mh = NULL; 194 + ms = NULL; 195 + ba = NULL; 196 + mmd0pat = NULL; 197 + mmd1pat = NULL; 192 198 } 193 199 194 200 static void EffectCvt(UBYTE eff, UBYTE dat) ··· 338 344 of.numchn = numtracks; 339 345 if (numlines > maxlines) 340 346 maxlines = numlines; 347 + /* sanity check */ 348 + if (numtracks > 64) 349 + return 0; 341 350 } 351 + /* sanity check */ 352 + if (! of.numchn) /* docs say 4, 8, 12 or 16 */ 353 + return 0; 342 354 343 355 of.numtrk = of.numpat * of.numchn; 344 356 if (!AllocTracks()) ··· 346 358 if (!AllocPatterns()) 347 359 return 0; 348 360 349 - if (! 350 - (mmd0pat = 351 - (MMD0NOTE *)MikMod_calloc(of.numchn * (maxlines + 1), 352 - sizeof(MMD0NOTE)))) return 0; 361 + if (!(mmd0pat = (MMD0NOTE *)MikMod_calloc(of.numchn * (maxlines + 1), sizeof(MMD0NOTE)))) 362 + return 0; 353 363 354 364 /* second read: read and convert patterns */ 355 365 for (t = 0; t < of.numpat; t++) { ··· 388 398 of.numchn = numtracks; 389 399 if (numlines > maxlines) 390 400 maxlines = numlines; 401 + /* sanity check */ 402 + if (numtracks > 64) 403 + return 0; 404 + if (numlines >= 3200) /* per docs */ 405 + return 0; 391 406 } 407 + /* sanity check */ 408 + if (! of.numchn) /* docs say 4, 8, 12 or 16 */ 409 + return 0; 392 410 393 411 of.numtrk = of.numpat * of.numchn; 394 412 if (!AllocTracks()) ··· 396 414 if (!AllocPatterns()) 397 415 return 0; 398 416 399 - if (! 400 - (mmd1pat = 401 - (MMD1NOTE *)MikMod_calloc(of.numchn * (maxlines + 1), 402 - sizeof(MMD1NOTE)))) return 0; 417 + if (!(mmd1pat = (MMD1NOTE *)MikMod_calloc(of.numchn * (maxlines + 1), sizeof(MMD1NOTE)))) 418 + return 0; 403 419 404 420 /* second read: really read and convert patterns */ 405 421 for (t = 0; t < of.numpat; t++) { ··· 471 487 ms->numblocks = _mm_read_M_UWORD(modreader); 472 488 ms->songlen = _mm_read_M_UWORD(modreader); 473 489 _mm_read_UBYTES(ms->playseq, 256, modreader); 490 + /* sanity check */ 491 + if (ms->numblocks > 255 || ms->songlen > 256) { 492 + _mm_errno = MMERR_NOT_A_MODULE; 493 + return 0; 494 + } 474 495 ms->deftempo = _mm_read_M_UWORD(modreader); 475 496 ms->playtransp = _mm_read_SBYTE(modreader); 476 497 ms->flags = _mm_read_UBYTE(modreader); ··· 479 500 _mm_read_UBYTES(ms->trkvol, 16, modreader); 480 501 ms->mastervol = _mm_read_UBYTE(modreader); 481 502 ms->numsamples = _mm_read_UBYTE(modreader); 503 + /* sanity check */ 504 + if (ms->numsamples > 64) { 505 + _mm_errno = MMERR_NOT_A_MODULE; 506 + return 0; 507 + } 482 508 483 509 /* check for a bad header */ 484 510 if (_mm_eof(modreader)) { ··· 505 531 me->songname = _mm_read_M_ULONG(modreader); 506 532 me->songnamelen = _mm_read_M_ULONG(modreader); 507 533 me->dumps = _mm_read_M_ULONG(modreader); 534 + /* sanity check */ 535 + if (me->annolen > 0xffff) { 536 + _mm_errno = MMERR_NOT_A_MODULE; 537 + return 0; 538 + } 539 + /* truncate insane songnamelen (fail instead??) */ 540 + if (me->songnamelen > 256) 541 + me->songnamelen = 256; 508 542 } 509 543 510 544 /* seek to and read the samplepointer array */ ··· 526 560 /* copy song positions */ 527 561 if (!AllocPositions(ms->songlen)) 528 562 return 0; 529 - for (t = 0; t < ms->songlen; t++) 563 + for (t = 0; t < ms->songlen; t++) { 530 564 of.positions[t] = ms->playseq[t]; 565 + if (of.positions[t]>ms->numblocks) { /* SANITIY CHECK */ 566 + /* fprintf(stderr,"positions[%d]=%d > numpat=%d\n",t,of.positions[t],ms->numblocks);*/ 567 + _mm_errno = MMERR_LOADING_HEADER; 568 + return 0; 569 + } 570 + } 531 571 532 572 decimalvolumes = (ms->flags & 0x10) ? 0 : 1; 533 573 bpmtempos = (ms->flags2 & 0x20) ? 1 : 0; ··· 571 611 of.flags |= UF_HIGHBPM; 572 612 } 573 613 MED_Version[12] = mh->id; 574 - of.modtype = StrDup(MED_Version); 614 + of.modtype = MikMod_strdup(MED_Version); 575 615 of.numchn = 0; /* will be counted later */ 576 616 of.numpat = ms->numblocks; 577 617 of.numpos = ms->songlen; ··· 582 622 char *name; 583 623 584 624 _mm_fseek(modreader, me->songname, SEEK_SET); 585 - name = MikMod_malloc(me->songnamelen); 625 + name = (char *) MikMod_malloc(me->songnamelen); 586 626 _mm_read_UBYTES(name, me->songnamelen, modreader); 587 627 of.songname = DupStr(name, me->songnamelen, 1); 588 628 MikMod_free(name); ··· 684 724 { 685 725 ULONG posit, namelen; 686 726 CHAR *name, *retvalue = NULL; 687 - 727 + 688 728 _mm_fseek(modreader, 0x20, SEEK_SET); 689 729 posit = _mm_read_M_ULONG(modreader); 690 - 730 + 691 731 if (posit) { 692 732 _mm_fseek(modreader, posit + 0x2C, SEEK_SET); 693 733 posit = _mm_read_M_ULONG(modreader); 694 734 namelen = _mm_read_M_ULONG(modreader); 695 735 696 736 _mm_fseek(modreader, posit, SEEK_SET); 697 - name = MikMod_malloc(namelen); 737 + name = (CHAR*) MikMod_malloc(namelen); 698 738 _mm_read_UBYTES(name, namelen, modreader); 699 739 retvalue = DupStr(name, namelen, 1); 700 740 MikMod_free(name);
+14 -13
apps/plugins/mikmod/load_mod.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: load_mod.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ 23 + $Id$ 24 24 25 25 Generic MOD loader (Protracker, StarTracker, FastTracker, etc) 26 26 ··· 108 108 *numchn = 4; 109 109 return 1; 110 110 } 111 - 111 + 112 112 /* Star Tracker */ 113 113 if (((!memcmp(id, "FLT", 3)) || (!memcmp(id, "EXO", 3))) && 114 114 (isdigit(id[3]))) { ··· 190 190 { 191 191 MikMod_free(mh); 192 192 MikMod_free(patbuf); 193 + mh=NULL; 194 + patbuf=NULL; 193 195 } 194 196 195 197 /* ··· 277 279 /* Handle ``heavy'' volumes correctly */ 278 280 if ((effect == 0xc) && (effdat > 0x40)) 279 281 effdat = 0x40; 280 - 282 + 281 283 /* An isolated 100, 200 or 300 effect should be ignored (no 282 284 "standalone" porta memory in mod files). However, a sequence such 283 285 as 1XX, 100, 100, 100 is fine. */ ··· 288 290 UniPTEffect(effect, effdat); 289 291 if (effect == 8) 290 292 of.flags |= UF_PANNING; 291 - 293 + 292 294 return effect; 293 295 } 294 296 ··· 309 311 /* Loads all patterns of a modfile and converts them into the 3 byte format. */ 310 312 static int ML_LoadPatterns(void) 311 313 { 312 - int t, tracks = 0; 313 - unsigned int s; 314 + unsigned int t, s, tracks = 0; 314 315 315 316 if (!AllocPatterns()) 316 317 return 0; 317 318 if (!AllocTracks()) 318 319 return 0; 319 - 320 + 320 321 /* Allocate temporary buffer for loading and converting the patterns */ 321 322 if (!(patbuf = (MODNOTE *)MikMod_calloc(64U * of.numchn, sizeof(MODNOTE)))) 322 323 return 0; ··· 385 386 386 387 mh->songlength = _mm_read_UBYTE(modreader); 387 388 388 - /* this fixes mods which declare more than 128 positions. 389 + /* this fixes mods which declare more than 128 positions. 389 390 * eg: beatwave.mod */ 390 391 if (mh->songlength > 128) { mh->songlength = 128; } 391 - 392 + 392 393 mh->magic1 = _mm_read_UBYTE(modreader); 393 394 _mm_read_UBYTES(mh->positions, 128, modreader); 394 395 _mm_read_UBYTES(mh->magic2, 4, modreader); ··· 477 478 q++; 478 479 } 479 480 480 - of.modtype = StrDup(descr); 481 + of.modtype = MikMod_strdup(descr); 481 482 482 483 if (!ML_LoadPatterns()) 483 484 return 0; 484 - 485 + 485 486 return 1; 486 487 } 487 488
+21 -13
apps/plugins/mikmod/load_mtm.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: load_mtm.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ 23 + $Id$ 24 24 25 25 MTM module loader 26 26 ··· 108 108 { 109 109 MikMod_free(mtmtrk); 110 110 MikMod_free(mh); 111 + mtmtrk=NULL; 112 + mh=NULL; 111 113 } 112 114 113 115 static UBYTE* MTM_Convert(void) ··· 145 147 int t,u; 146 148 MTMSAMPLE s; 147 149 SAMPLE *q; 148 - (void)curious; 150 + (void)curious; 149 151 150 152 /* try to read module header */ 151 153 _mm_read_UBYTES(mh->id,3,modreader); ··· 169 171 /* set module variables */ 170 172 of.initspeed = 6; 171 173 of.inittempo = 125; 172 - of.modtype = StrDup(MTM_Version); 174 + of.modtype = MikMod_strdup(MTM_Version); 173 175 of.numchn = mh->numchannels; 174 176 of.numtrk = mh->numtracks+1; /* get number of channels */ 175 177 of.songname = DupStr(mh->songname,20,1); /* make a cstr of songname */ ··· 193 195 s.attribute =_mm_read_UBYTE(modreader); 194 196 195 197 if(_mm_eof(modreader)) { 196 - _mm_errno = MMERR_LOADING_SAMPLEINFO; 198 + _mm_errno = MMERR_LOADING_SAMPLEINFO; 197 199 return 0; 198 200 } 199 201 ··· 218 220 } 219 221 220 222 if(!AllocPositions(of.numpos)) return 0; 221 - for(t=0;t<of.numpos;t++) 223 + for(t=0;t<of.numpos;t++) { 222 224 of.positions[t]=_mm_read_UBYTE(modreader); 223 - for(;t<128;t++) (void)_mm_read_UBYTE(modreader); 225 + if (of.positions[t]>of.numpat) { /* SANITIY CHECK */ 226 + /* fprintf(stderr,"positions[%d]=%d > numpat=%d\n",t,of.positions[t],of.numpat);*/ 227 + _mm_errno = MMERR_LOADING_HEADER; 228 + return 0; 229 + } 230 + } 231 + for(;t<128;t++) _mm_skip_BYTE(modreader); 224 232 if(_mm_eof(modreader)) { 225 233 _mm_errno = MMERR_LOADING_HEADER; 226 234 return 0; ··· 231 239 232 240 of.tracks[0]=MTM_Convert(); /* track 0 is empty */ 233 241 for(t=1;t<of.numtrk;t++) { 234 - int s; 242 + int s_idx; 235 243 236 - for(s=0;s<64;s++) { 237 - mtmtrk[s].a=_mm_read_UBYTE(modreader); 238 - mtmtrk[s].b=_mm_read_UBYTE(modreader); 239 - mtmtrk[s].c=_mm_read_UBYTE(modreader); 244 + for(s_idx=0;s_idx<64;s_idx++) { 245 + mtmtrk[s_idx].a=_mm_read_UBYTE(modreader); 246 + mtmtrk[s_idx].b=_mm_read_UBYTE(modreader); 247 + mtmtrk[s_idx].c=_mm_read_UBYTE(modreader); 240 248 } 241 249 242 250 if(_mm_eof(modreader)) {
+11 -10
apps/plugins/mikmod/load_okt.c
··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: load_okt.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ 23 + $Id$ 24 24 25 25 Oktalyzer (OKT) module loader 26 26 ··· 203 203 s.len = _mm_read_M_ULONG(modreader); 204 204 s.loopbeg = _mm_read_M_UWORD(modreader) * 2; 205 205 s.looplen = _mm_read_M_UWORD(modreader) * 2; 206 - (void)_mm_read_UBYTE(modreader); 206 + _mm_skip_BYTE(modreader); 207 207 s.volume = _mm_read_UBYTE(modreader); 208 208 _mm_read_M_UWORD(modreader); 209 209 ··· 314 314 } 315 315 MikMod_free(patbuf); 316 316 MikMod_free(okttrk); 317 + okttrk = NULL; 317 318 return 1; 318 319 } 319 320 ··· 330 331 int seen_cmod = 0, seen_samp = 0, seen_slen = 0, seen_plen = 0, seen_patt 331 332 = 0, seen_spee = 0; 332 333 int patnum = 0, insnum = 0; 333 - (void)curious; 334 + (void)curious; 334 335 335 336 /* skip OKTALYZER header */ 336 337 _mm_fseek(modreader, 8, SEEK_SET); 337 - of.songname = StrDup(""); 338 + of.songname = MikMod_strdup(""); 338 339 339 - of.modtype = StrDup("Amiga Oktalyzer"); 340 + of.modtype = MikMod_strdup("Amiga Oktalyzer"); 340 341 of.numpos = of.reppos = 0; 341 - 342 + 342 343 /* default values */ 343 344 of.initspeed = 6; 344 345 of.inittempo = 125; 345 - 346 + 346 347 while (1) { 347 348 /* read block header */ 348 349 _mm_read_UBYTES(id, 4, modreader); 349 350 len = _mm_read_M_ULONG(modreader); 350 - 351 + 351 352 if (_mm_eof(modreader)) 352 353 break; 353 354 fp = _mm_ftell(modreader); 354 - 355 + 355 356 if (!memcmp(id, "CMOD", 4)) { 356 357 if (!seen_cmod) { 357 358 OKT_doCMOD(); ··· 442 443 443 444 static CHAR *OKT_LoadTitle(void) 444 445 { 445 - return StrDup(""); 446 + return MikMod_strdup(""); 446 447 } 447 448 448 449 /*========== Loader information */
+30 -20
apps/plugins/mikmod/load_s3m.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: load_s3m.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ 23 + $Id$ 24 24 25 25 Screamtracker (S3M) module loader 26 26 ··· 104 104 105 105 /* tracker identifiers */ 106 106 #define NUMTRACKERS 4 107 - static CHAR* S3M_Version[] = { 107 + static const CHAR * S3M_Version[] = { 108 108 "Screamtracker x.xx", 109 109 "Imago Orpheus x.xx (S3M format)", 110 110 "Impulse Tracker x.xx (S3M format)", ··· 113 113 "Impulse Tracker 2.14p4 (S3M format)" 114 114 }; 115 115 /* version number position in above array */ 116 - static int numeric[NUMTRACKERS]={14,14,16,16}; 116 + static const int numeric[NUMTRACKERS]={14,14,16,16}; 117 117 118 118 /*========== Loader code */ 119 119 ··· 144 144 MikMod_free(poslookup); 145 145 MikMod_free(mh); 146 146 MikMod_free(origpositions); 147 + s3mbuf=NULL; 148 + paraptr=NULL; 149 + poslookup=NULL; 150 + mh=NULL; 151 + origpositions=NULL; 147 152 } 148 153 149 154 /* Because so many s3m files have 16 channels as the set number used, but really ··· 154 159 global variable 'remap' 155 160 156 161 NOTE: You must first seek to the file location of the pattern before calling 157 - this procedure. 162 + this procedure. 158 163 159 - Returns 1 on fail. */ 164 + Returns 0 on fail. */ 160 165 static int S3M_GetNumChannels(void) 161 166 { 162 167 int row=0,flag,ch; ··· 166 171 167 172 if(_mm_eof(modreader)) { 168 173 _mm_errno = MMERR_LOADING_PATTERN; 169 - return 1; 174 + return 0; 170 175 } 171 176 172 177 if(flag) { 173 178 ch=flag&31; 174 179 if(mh->channels[ch]<32) remap[ch] = 0; 175 - if(flag&32) {(void)_mm_read_UBYTE(modreader);(void)_mm_read_UBYTE(modreader);} 176 - if(flag&64) (void)_mm_read_UBYTE(modreader); 177 - if(flag&128){(void)_mm_read_UBYTE(modreader);(void)_mm_read_UBYTE(modreader);} 180 + if(flag&32) {_mm_skip_BYTE(modreader);_mm_skip_BYTE(modreader);} 181 + if(flag&64) _mm_skip_BYTE(modreader); 182 + if(flag&128){_mm_skip_BYTE(modreader);_mm_skip_BYTE(modreader);} 178 183 } else row++; 179 184 } 180 - return 0; 181 - } 185 + return 1; 186 + } 182 187 183 188 static int S3M_ReadPattern(void) 184 189 { ··· 282 287 _mm_errno = MMERR_LOADING_HEADER; 283 288 return 0; 284 289 } 290 + if(mh->ordnum > 255 || mh->insnum > 255 || mh->patnum > 255) { 291 + _mm_errno = MMERR_NOT_A_MODULE; 292 + return 0; 293 + } 285 294 286 295 /* then we can decide the module type */ 287 296 tracker=mh->tracker>>12; ··· 294 303 tracker=NUMTRACKERS; /* IT 2.14p3 */ 295 304 else tracker--; 296 305 } 297 - of.modtype = StrDup(S3M_Version[tracker]); 306 + of.modtype = MikMod_strdup(S3M_Version[tracker]); 298 307 if(tracker<NUMTRACKERS) { 299 308 of.modtype[numeric[tracker]] = ((mh->tracker>>8) &0xf)+'0'; 300 309 of.modtype[numeric[tracker]+2] = ((mh->tracker>>4)&0xf)+'0'; ··· 315 324 316 325 /* read the order data */ 317 326 if(!AllocPositions(mh->ordnum)) return 0; 318 - if(!(origpositions=MikMod_calloc(mh->ordnum,sizeof(UWORD)))) return 0; 327 + if(!(origpositions=(UWORD*)MikMod_calloc(mh->ordnum,sizeof(UWORD)))) return 0; 319 328 320 329 for(t=0;t<mh->ordnum;t++) { 321 330 origpositions[t]=_mm_read_UBYTE(modreader); ··· 374 383 _mm_read_string(s.scrs,4,modreader); 375 384 376 385 /* ScreamTracker imposes a 64000 bytes (not 64k !) limit */ 377 - if (s.length > 64000) 386 + /* enforce it, if we'll use S3MIT_SCREAM in S3M_ConvertTrack() */ 387 + if (s.length > 64000 && tracker == 1) 378 388 s.length = 64000; 379 389 380 390 if(_mm_eof(modreader)) { ··· 388 398 q->loopstart = s.loopbeg; 389 399 q->loopend = s.loopend; 390 400 q->volume = s.volume; 391 - q->seekpos = (((long)s.memsegh)<<16|s.memsegl)<<4; 401 + q->seekpos = (((ULONG)s.memsegh)<<16|s.memsegl)<<4; 392 402 393 403 if(s.flags&1) q->flags |= SF_LOOP; 394 404 if(s.flags&4) q->flags |= SF_16BITS; ··· 406 416 for(t=0;t<of.numpat;t++) { 407 417 /* seek to pattern position (+2 skip pattern length) */ 408 418 _mm_fseek(modreader,(long)((paraptr[of.numins+t])<<4)+2,SEEK_SET); 409 - if(S3M_GetNumChannels()) return 0; 419 + if(!S3M_GetNumChannels()) return 0; 410 420 } 411 421 412 422 /* build the remap array */ 413 423 for(t=0;t<32;t++) 414 - if(!remap[t]) 424 + if(!remap[t]) 415 425 remap[t]=of.numchn++; 416 426 417 427 /* set panning positions after building remap chart! */ 418 - for(t=0;t<32;t++) 428 + for(t=0;t<32;t++) 419 429 if((mh->channels[t]<32)&&(remap[t]!=-1)) { 420 430 if(mh->channels[t]<8) 421 431 of.panning[remap[t]]=0x30;
+23 -17
apps/plugins/mikmod/load_stm.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 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 25 Screamtracker 2 (STM) module loader 26 26 ··· 74 74 UBYTE ver_minor; 75 75 UBYTE inittempo; /* initspeed= stm inittempo>>4 */ 76 76 UBYTE numpat; /* number of patterns */ 77 - UBYTE globalvol; 77 + UBYTE globalvol; 78 78 UBYTE reserved[13]; 79 79 STMSAMPLE sample[31]; /* STM sample data */ 80 80 UBYTE patorder[128]; /* Docs say 64 - actually 128 */ ··· 90 90 static STMHEADER *mh = NULL; 91 91 92 92 /* tracker identifiers */ 93 - static CHAR* STM_Version[STM_NTRACKERS] = { 93 + static const CHAR * STM_Version[STM_NTRACKERS] = { 94 94 "Screamtracker 2", 95 95 "Converted by MOD2STM (STM format)", 96 96 "Wuzamod (STM format)" ··· 103 103 UBYTE str[44]; 104 104 int t; 105 105 106 + memset(str,0,44); 106 107 _mm_fseek(modreader,20,SEEK_SET); 107 108 _mm_read_UBYTES(str,44,modreader); 108 109 if(str[9]!=2) return 0; /* STM Module = filetype 2 */ ··· 110 111 /* Prevent false positives for S3M files */ 111 112 if(!memcmp(str+40,"SCRM",4)) 112 113 return 0; 113 - 114 + 114 115 for (t=0;t<STM_NTRACKERS;t++) 115 116 if(!memcmp(str,STM_Signatures[t],8)) 116 117 return 1; ··· 130 131 { 131 132 MikMod_free(mh); 132 133 MikMod_free(stmbuf); 134 + mh=NULL; 135 + stmbuf=NULL; 133 136 } 134 137 135 138 static void STM_ConvertNote(STMNOTE *n) ··· 145 148 146 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 152 we have no idea if these strange values will ever be encountered. 150 153 but it appears as those stms sound correct. */ 151 154 if((note==254)||(note==252)) { ··· 224 227 225 228 static int STM_LoadPatterns(void) 226 229 { 227 - int t,tracks=0; 228 - unsigned int s; 230 + unsigned int t,s,tracks=0; 229 231 230 232 if(!AllocPatterns()) return 0; 231 233 if(!AllocTracks()) return 0; ··· 252 254 253 255 static int STM_Load(int curious) 254 256 { 255 - int t; 257 + int t; 256 258 ULONG MikMod_ISA; /* We must generate our own ISA, it's not stored in stm */ 257 259 SAMPLE *q; 258 - (void)curious; 260 + (void)curious; 259 261 260 262 /* try to read stm header */ 261 263 _mm_read_string(mh->songname,20,modreader); ··· 272 274 mh->numpat =_mm_read_UBYTE(modreader); 273 275 mh->globalvol =_mm_read_UBYTE(modreader); 274 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 282 for(t=0;t<31;t++) { 277 283 STMSAMPLE *s=&mh->sample[t]; /* STM sample data */ ··· 299 305 /* set module variables */ 300 306 for(t=0;t<STM_NTRACKERS;t++) 301 307 if(!memcmp(mh->trackername,STM_Signatures[t],8)) break; 302 - if(t == STM_NTRACKERS) 303 - return 0; 304 - of.modtype = StrDup(STM_Version[t]); 308 + of.modtype = MikMod_strdup(STM_Version[t]); 305 309 of.songname = DupStr(mh->songname,20,1); /* make a cstr of songname */ 306 310 of.numpat = mh->numpat; 307 311 of.inittempo = 125; /* mh->inittempo+0x1c; */ ··· 316 320 /* 99 terminates the patorder list */ 317 321 while((mh->patorder[t]<=99)&&(mh->patorder[t]<mh->numpat)) { 318 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 328 if(mh->patorder[t]<=99) t++; 322 329 of.numpos=t; ··· 334 341 q->speed = (mh->sample[t].c2spd * 8363) / 8448; 335 342 q->volume = mh->sample[t].volume; 336 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 345 q->loopstart = mh->sample[t].loopbeg; 339 346 q->loopend = mh->sample[t].loopend; 340 347 q->seekpos = MikMod_ISA; ··· 373 380 STM_Cleanup, 374 381 STM_LoadTitle 375 382 }; 376 - 377 383 378 384 /* ex:set ts=4: */
+18 -8
apps/plugins/mikmod/load_stx.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: load_stx.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ 23 + $Id$ 24 24 25 25 STMIK 0.2 (STX) module loader 26 26 ··· 114 114 UBYTE id[8]; 115 115 int t; 116 116 117 + memset(id,0,8); 117 118 _mm_fseek(modreader,0x3C,SEEK_SET); 118 119 if(!_mm_read_UBYTES(id,4,modreader)) return 0; 119 120 if(memcmp(id,"SCRM",4)) return 0; 120 121 121 122 _mm_fseek(modreader,0x14,SEEK_SET); 122 123 if(!_mm_read_UBYTES(id,8,modreader)) return 0; 123 - 124 + 124 125 for(t=0;t<STM_NTRACKERS;t++) 125 126 if(!memcmp(id,STM_Signatures[t],8)) return 1; 126 127 ··· 143 144 MikMod_free(paraptr); 144 145 MikMod_free(poslookup); 145 146 MikMod_free(mh); 147 + stxbuf=NULL; 148 + paraptr=NULL; 149 + poslookup=NULL; 150 + mh=NULL; 146 151 } 147 152 148 153 static int STX_ReadPattern(void) ··· 297 302 _mm_errno = MMERR_LOADING_HEADER; 298 303 return 0; 299 304 } 305 + if(mh->ordnum > 256 || !mh->insnum || mh->insnum > 256 || 306 + mh->patnum > 254 || !mh->patnum) { 307 + _mm_errno = MMERR_NOT_A_MODULE; 308 + return 0; 309 + } 300 310 301 311 /* set module variables */ 302 312 of.songname = DupStr(mh->songname,20,1); ··· 323 333 version=_mm_read_I_UWORD(modreader); 324 334 if(version==mh->patsize) { 325 335 version = 0x10; 326 - of.modtype = StrDup("STMIK 0.2 (STM2STX 1.0)"); 336 + of.modtype = MikMod_strdup("STMIK 0.2 (STM2STX 1.0)"); 327 337 } else { 328 338 version = 0x11; 329 - of.modtype = StrDup("STMIK 0.2 (STM2STX 1.1)"); 339 + of.modtype = MikMod_strdup("STMIK 0.2 (STM2STX 1.1)"); 330 340 } 331 341 332 342 /* read the order data */ ··· 343 353 if(order==255) order=LAST_PATTERN; 344 354 of.positions[of.numpos]=order; 345 355 poslookup[t]=of.numpos; /* bug fix for freaky S3Ms */ 346 - if(of.positions[t]<254) of.numpos++; 356 + if(of.positions[t]<254) of.numpos++; 347 357 else 348 358 /* special end of song pattern */ 349 359 if((order==LAST_PATTERN)&&(!curious)) break; ··· 389 399 q->loopstart = s.loopbeg; 390 400 q->loopend = s.loopend; 391 401 q->volume = s.volume; 392 - q->seekpos = (((long)s.memsegh)<<16|s.memsegl)<<4; 402 + q->seekpos = (((ULONG)s.memsegh)<<16|s.memsegl)<<4; 393 403 q->flags |= SF_SIGNED; 394 404 395 405 if(s.flags&1) q->flags |= SF_LOOP;
+24 -16
apps/plugins/mikmod/load_ult.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: load_ult.c,v 1.3 2010/01/12 03:30:32 realtech Exp $ 23 + $Id$ 24 24 25 25 Ultratracker (ULT) module loader 26 26 ··· 80 80 #define ULTS_REVERSE 16 81 81 82 82 #define ULT_VERSION_LEN 18 83 - static CHAR ULT_Version[ULT_VERSION_LEN]="Ultra Tracker v1.x"; 83 + static CHAR ULT_Version[ULT_VERSION_LEN+1]="Ultra Tracker v1.x"; 84 84 85 85 static ULTEVENT ev; 86 86 ··· 130 130 SAMPLE *q; 131 131 ULTSAMPLE s; 132 132 ULTHEADER mh; 133 - UBYTE nos,noc,rbnop; 134 - (void)curious; 133 + UBYTE nos,noc,RBnop; 134 + (void)curious; 135 135 136 136 /* try to read module header */ 137 137 _mm_read_string(mh.id,15,modreader); ··· 207 207 if(!AllocPositions(256)) return 0; 208 208 for(t=0;t<256;t++) 209 209 of.positions[t]=_mm_read_UBYTE(modreader); 210 - for(t=0;t<256;t++) 210 + 211 + noc=_mm_read_UBYTE(modreader); 212 + RBnop=_mm_read_UBYTE(modreader); 213 + 214 + of.numchn=++noc; 215 + of.numpat=++RBnop; 216 + of.numtrk=of.numchn*of.numpat; 217 + 218 + for(t=0;t<256;t++) { 211 219 if(of.positions[t]==255) { 212 220 of.positions[t]=LAST_PATTERN; 213 221 break; 214 222 } 223 + if (of.positions[t]>of.numpat) { /* SANITIY CHECK */ 224 + /* fprintf(stderr,"positions[%d]=%d > numpat=%d\n",t,of.positions[t],of.numpat);*/ 225 + _mm_errno = MMERR_LOADING_HEADER; 226 + return 0; 227 + } 228 + } 215 229 of.numpos=t; 216 230 217 - noc=_mm_read_UBYTE(modreader); 218 - rbnop=_mm_read_UBYTE(modreader); 219 - 220 - of.numchn=++noc; 221 - of.numpat=++rbnop; 222 - of.numtrk=of.numchn*of.numpat; 223 231 if(!AllocTracks()) return 0; 224 232 if(!AllocPatterns()) return 0; 225 233 for(u=0;u<of.numchn;u++) 226 234 for(t=0;t<of.numpat;t++) 227 235 of.patterns[(t*of.numchn)+u]=tracks++; 228 236 229 - // SA37775 237 + /* Secunia SA37775 / CVE-2009-3996 */ 230 238 if (of.numchn>=UF_MAXCHAN) 231 239 of.numchn=UF_MAXCHAN - 1; 232 - 240 + 233 241 /* read pan position table for v1.5 and higher */ 234 242 if(mh.id[14]>='3') { 235 243 for(t=0;t<of.numchn;t++) of.panning[t]=_mm_read_UBYTE(modreader)<<4; ··· 313 321 return 1; 314 322 } 315 323 316 - static CHAR *ULT_LoadTitle(void) 324 + static CHAR * ULT_LoadTitle(void) 317 325 { 318 326 CHAR s[32]; 319 327
+476
apps/plugins/mikmod/load_umx.c
··· 1 + /* MikMod sound library 2 + * (c) 2003-2004 Raphael Assenat and others - see file 3 + * AUTHORS for complete list. 4 + * 5 + * This library is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU Library General Public License as 7 + * published by the Free Software Foundation; either version 2 of 8 + * the License, or (at your option) any later version. 9 + * 10 + * This program is distributed in the hope that it will be useful, 11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 + * GNU Library General Public License for more details. 14 + * 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 17 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 18 + * 02111-1307, USA. 19 + */ 20 + 21 + /* Epic Games Unreal UMX container loading for libmikmod 22 + * Written by O. Sezer <sezero@users.sourceforge.net> 23 + * 24 + * Records data type/offset info in its Test() function, then acts 25 + * as a middle-man, forwarding calls to the real loader units. It 26 + * requires that the MREADER implementation in use always respects 27 + * its iobase fields. Like all other libmikmod loaders, this code 28 + * is not reentrant yet. 29 + * 30 + * UPKG parsing partially based on Unreal Media Ripper (UMR) v0.3 31 + * by Andy Ward <wardwh@swbell.net>, with additional updates 32 + * by O. Sezer - see git repo at https://github.com/sezero/umr/ 33 + * 34 + * The cheaper way, i.e. linear search of music object like libxmp 35 + * and libmodplug does, is possible. With this however we're using 36 + * the embedded offset, size and object type directly from the umx 37 + * file, and I feel safer with it. 38 + */ 39 + 40 + #ifdef HAVE_CONFIG_H 41 + #include "config.h" 42 + #endif 43 + 44 + #include <stddef.h> 45 + #include <stdio.h> 46 + #include <string.h> 47 + 48 + #include "mikmod_internals.h" 49 + 50 + 51 + /*========== upkg defs */ 52 + 53 + typedef SLONG fci_t; /* FCompactIndex */ 54 + 55 + #define UPKG_HDR_TAG 0x9e2a83c1 56 + 57 + struct _genhist { /* for upkg versions >= 68 */ 58 + SLONG export_count; 59 + SLONG name_count; 60 + }; 61 + 62 + struct upkg_hdr { 63 + ULONG tag; /* UPKG_HDR_TAG */ 64 + SLONG file_version; 65 + ULONG pkg_flags; 66 + SLONG name_count; /* number of names in name table (>= 0) */ 67 + SLONG name_offset; /* offset to name table (>= 0) */ 68 + SLONG export_count; /* num. exports in export table (>= 0) */ 69 + SLONG export_offset; /* offset to export table (>= 0) */ 70 + SLONG import_count; /* num. imports in export table (>= 0) */ 71 + SLONG import_offset; /* offset to import table (>= 0) */ 72 + 73 + /* number of GUIDs in heritage table (>= 1) and table's offset: 74 + * only with versions < 68. */ 75 + SLONG heritage_count; 76 + SLONG heritage_offset; 77 + /* with versions >= 68: a GUID, a dword for generation count 78 + * and export_count and name_count dwords for each generation: */ 79 + ULONG guid[4]; 80 + SLONG generation_count; 81 + #define UPKG_HDR_SIZE 64 /* 64 bytes up until here */ 82 + /*struct _genhist *gen;*/ 83 + }; 84 + /* compile time assert for upkg_hdr size */ 85 + /*typedef int _check_hdrsize[2 * (offsetof(struct upkg_hdr, gen) == UPKG_HDR_SIZE) - 1];*/ 86 + typedef int _check_hdrsize[2 * (sizeof(struct upkg_hdr) == UPKG_HDR_SIZE) - 1]; 87 + 88 + /*========== Supported content types */ 89 + 90 + #define UMUSIC_IT 0 91 + #define UMUSIC_S3M 1 92 + #define UMUSIC_XM 2 93 + #define UMUSIC_MOD 3 94 + 95 + static const char *mustype[] = { 96 + "IT", "S3M", "XM", "MOD", 97 + NULL 98 + }; 99 + 100 + /*========== UPKG parsing */ 101 + 102 + /* decode an FCompactIndex. 103 + * original documentation by Tim Sweeney was at 104 + * http://unreal.epicgames.com/Packages.htm 105 + * also see Unreal Wiki: 106 + * http://wiki.beyondunreal.com/Legacy:Package_File_Format/Data_Details 107 + */ 108 + static fci_t get_fci (const char *in, int *pos) 109 + { 110 + SLONG a; 111 + int size; 112 + 113 + size = 1; 114 + a = in[0] & 0x3f; 115 + 116 + if (in[0] & 0x40) { 117 + size++; 118 + a |= (in[1] & 0x7f) << 6; 119 + 120 + if (in[1] & 0x80) { 121 + size++; 122 + a |= (in[2] & 0x7f) << 13; 123 + 124 + if (in[2] & 0x80) { 125 + size++; 126 + a |= (in[3] & 0x7f) << 20; 127 + 128 + if (in[3] & 0x80) { 129 + size++; 130 + a |= (in[4] & 0x3f) << 27; 131 + } 132 + } 133 + } 134 + } 135 + 136 + if (in[0] & 0x80) 137 + a = -a; 138 + 139 + *pos += size; 140 + 141 + return a; 142 + } 143 + 144 + static int get_objtype (SLONG ofs, int type) 145 + { 146 + char sig[16]; 147 + _retry: 148 + _mm_fseek(modreader, ofs, SEEK_SET); 149 + _mm_read_UBYTES(sig, 16, modreader); 150 + if (type == UMUSIC_IT) { 151 + if (memcmp(sig, "IMPM", 4) == 0) 152 + return UMUSIC_IT; 153 + return -1; 154 + } 155 + if (type == UMUSIC_XM) { 156 + if (memcmp(sig, "Extended Module:", 16) != 0) 157 + return -1; 158 + _mm_read_UBYTES(sig, 16, modreader); 159 + if (sig[0] != ' ') return -1; 160 + _mm_read_UBYTES(sig, 16, modreader); 161 + if (sig[5] != 0x1a) return -1; 162 + return UMUSIC_XM; 163 + } 164 + 165 + _mm_fseek(modreader, ofs + 44, SEEK_SET); 166 + _mm_read_UBYTES(sig, 4, modreader); 167 + if (type == UMUSIC_S3M) { 168 + if (memcmp(sig, "SCRM", 4) == 0) 169 + return UMUSIC_S3M; 170 + /*return -1;*/ 171 + /* SpaceMarines.umx and Starseek.umx from Return to NaPali 172 + * report as "s3m" whereas the actual music format is "it" */ 173 + type = UMUSIC_IT; 174 + goto _retry; 175 + } 176 + 177 + _mm_fseek(modreader, ofs + 1080, SEEK_SET); 178 + _mm_read_UBYTES(sig, 4, modreader); 179 + if (type == UMUSIC_MOD) { 180 + if (memcmp(sig, "M.K.", 4) == 0 || memcmp(sig, "M!K!", 4) == 0) 181 + return UMUSIC_MOD; 182 + return -1; 183 + } 184 + 185 + return -1; 186 + } 187 + 188 + static int read_export (const struct upkg_hdr *hdr, 189 + SLONG *ofs, SLONG *objsize) 190 + { 191 + char buf[40]; 192 + int idx = 0, t; 193 + 194 + _mm_fseek(modreader, *ofs, SEEK_SET); 195 + if (!_mm_read_UBYTES(buf, 40, modreader)) 196 + return -1; 197 + 198 + if (hdr->file_version < 40) idx += 8; /* 00 00 00 00 00 00 00 00 */ 199 + if (hdr->file_version < 60) idx += 16; /* 81 00 00 00 00 00 FF FF FF FF FF FF FF FF 00 00 */ 200 + get_fci(&buf[idx], &idx); /* skip junk */ 201 + t = get_fci(&buf[idx], &idx); /* type_name */ 202 + if (hdr->file_version > 61) idx += 4; /* skip export size */ 203 + *objsize = get_fci(&buf[idx], &idx); 204 + *ofs += idx; /* offset for real data */ 205 + 206 + return t; /* return type_name index */ 207 + } 208 + 209 + static int read_typname(const struct upkg_hdr *hdr, 210 + int idx, char *out) 211 + { 212 + int i, s; 213 + long l; 214 + char buf[64]; 215 + 216 + if (idx >= hdr->name_count) return -1; 217 + buf[63] = '\0'; 218 + for (i = 0, l = 0; i <= idx; i++) { 219 + _mm_fseek(modreader, hdr->name_offset + l, SEEK_SET); 220 + _mm_read_UBYTES(buf, 63, modreader); 221 + if (hdr->file_version >= 64) { 222 + s = *(signed char *)buf; /* numchars *including* terminator */ 223 + if (s <= 0 || s > 64) return -1; 224 + l += s + 5; /* 1 for buf[0], 4 for int32_t name_flags */ 225 + } else { 226 + l += (long)strlen(buf); 227 + l += 5; /* 1 for terminator, 4 for int32_t name_flags */ 228 + } 229 + } 230 + 231 + strcpy(out, (hdr->file_version >= 64)? &buf[1] : buf); 232 + return 0; 233 + } 234 + 235 + static int probe_umx (const struct upkg_hdr *hdr, 236 + SLONG *ofs, SLONG *objsize) 237 + { 238 + int i, idx, t; 239 + SLONG s, pos; 240 + long fsiz; 241 + char buf[64]; 242 + 243 + idx = 0; 244 + _mm_fseek(modreader, 0, SEEK_END); 245 + fsiz = _mm_ftell(modreader); 246 + 247 + /* Find the offset and size of the first IT, S3M or XM 248 + * by parsing the exports table. The umx files should 249 + * have only one export. Kran32.umx from Unreal has two, 250 + * but both pointing to the same music. */ 251 + if (hdr->export_offset >= fsiz) return -1; 252 + memset(buf, 0, 64); 253 + _mm_fseek(modreader, hdr->export_offset, SEEK_SET); 254 + _mm_read_UBYTES(buf, 64, modreader); 255 + 256 + get_fci(&buf[idx], &idx); /* skip class_index */ 257 + get_fci(&buf[idx], &idx); /* skip super_index */ 258 + if (hdr->file_version >= 60) idx += 4; /* skip int32 package_index */ 259 + get_fci(&buf[idx], &idx); /* skip object_name */ 260 + idx += 4; /* skip int32 object_flags */ 261 + 262 + s = get_fci(&buf[idx], &idx); /* get serial_size */ 263 + if (s <= 0) return -1; 264 + pos = get_fci(&buf[idx],&idx); /* get serial_offset */ 265 + if (pos < 0 || pos > fsiz - 40) return -1; 266 + 267 + if ((t = read_export(hdr, &pos, &s)) < 0) return -1; 268 + if (s <= 0 || s > fsiz - pos) return -1; 269 + 270 + if (read_typname(hdr, t, buf) < 0) return -1; 271 + for (i = 0; mustype[i] != NULL; i++) { 272 + if (!strcasecmp(buf, mustype[i])) { 273 + t = i; 274 + break; 275 + } 276 + } 277 + if (mustype[i] == NULL) return -1; 278 + if ((t = get_objtype(pos, t)) < 0) return -1; 279 + 280 + *ofs = pos; 281 + *objsize = s; 282 + return t; 283 + } 284 + 285 + static SLONG probe_header (void *header) 286 + { 287 + struct upkg_hdr *hdr; 288 + unsigned char *p; 289 + ULONG *swp; 290 + int i; 291 + 292 + /* byte swap the header - all members are 32 bit LE values */ 293 + p = (unsigned char *) header; 294 + swp = (ULONG *) header; 295 + for (i = 0; i < UPKG_HDR_SIZE/4; i++, p += 4) { 296 + swp[i] = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); 297 + } 298 + 299 + hdr = (struct upkg_hdr *) header; 300 + if (hdr->tag != UPKG_HDR_TAG) { 301 + return -1; 302 + } 303 + if (hdr->name_count < 0 || 304 + hdr->name_offset < 0 || 305 + hdr->export_count < 0 || 306 + hdr->export_offset < 0 || 307 + hdr->import_count < 0 || 308 + hdr->import_offset < 0 ) { 309 + return -1; 310 + } 311 + 312 + switch (hdr->file_version) { 313 + case 35: case 37: /* Unreal beta - */ 314 + case 40: case 41: /* 1998 */ 315 + case 61:/* Unreal */ 316 + case 62:/* Unreal Tournament */ 317 + case 63:/* Return to NaPali */ 318 + case 64:/* Unreal Tournament */ 319 + case 66:/* Unreal Tournament */ 320 + case 68:/* Unreal Tournament */ 321 + case 69:/* Tactical Ops */ 322 + case 83:/* Mobile Forces */ 323 + return 0; 324 + } 325 + 326 + return -1; 327 + } 328 + 329 + static int process_upkg (SLONG *ofs, SLONG *objsize) 330 + { 331 + char header[UPKG_HDR_SIZE]; 332 + 333 + if (!_mm_read_UBYTES(header, UPKG_HDR_SIZE, modreader)) 334 + return -1; 335 + if (probe_header(header) < 0) 336 + return -1; 337 + 338 + return probe_umx((struct upkg_hdr *)header, ofs, objsize); 339 + } 340 + 341 + /*========== Loader vars */ 342 + 343 + typedef struct _umx_info { 344 + int type; 345 + SLONG ofs, size; 346 + MLOADER* loader; 347 + } umx_info; 348 + 349 + static umx_info *umx_data = NULL; 350 + 351 + /*========== Loader code */ 352 + 353 + /* Without Test() being called first, Load[Title] is never called. 354 + * A Test() is always followed by either a Load() or a LoadTitle(). 355 + * A Load() is always followed by Cleanup() regardless of success. 356 + * 357 + * Therefore, in between Test() and LoadTitle() or Load()/Cleanup(), 358 + * we must remember the type and the offset of the umx music data, 359 + * and always clear it when returning from LoadTitle() or Cleanup(). 360 + */ 361 + 362 + static int UMX_Test(void) 363 + { 364 + int type; 365 + SLONG ofs = 0, size = 0; 366 + 367 + if (umx_data) { 368 + #ifdef MIKMOD_DEBUG 369 + fprintf(stderr, "UMX_Test called while a previous instance is active\n"); 370 + #endif 371 + MikMod_free(umx_data); 372 + umx_data = NULL; 373 + } 374 + 375 + _mm_fseek(modreader, 0, SEEK_SET); 376 + type = process_upkg(&ofs, &size); 377 + if (type < 0 || type > UMUSIC_MOD) 378 + return 0; 379 + 380 + umx_data = (umx_info*) MikMod_calloc(1, sizeof(umx_info)); 381 + if (!umx_data) return 0; 382 + 383 + umx_data->type = type; 384 + umx_data->ofs = ofs; 385 + umx_data->size = size; 386 + switch (type) { 387 + case UMUSIC_IT: 388 + umx_data->loader = &load_it; 389 + break; 390 + case UMUSIC_S3M: 391 + umx_data->loader = &load_s3m; 392 + break; 393 + case UMUSIC_XM: 394 + umx_data->loader = &load_xm; 395 + break; 396 + case UMUSIC_MOD: 397 + umx_data->loader = &load_mod; 398 + break; 399 + } 400 + 401 + return 1; 402 + } 403 + 404 + static int UMX_Init(void) 405 + { 406 + if (!umx_data || !umx_data->loader) 407 + return 0; 408 + 409 + if (umx_data->loader->Init) 410 + return umx_data->loader->Init(); 411 + 412 + return 1; 413 + } 414 + 415 + static void UMX_Cleanup(void) 416 + { 417 + if (!umx_data) return; 418 + 419 + if (umx_data->loader && umx_data->loader->Cleanup) 420 + umx_data->loader->Cleanup(); 421 + 422 + MikMod_free(umx_data); 423 + umx_data = NULL; 424 + } 425 + 426 + static int UMX_Load(int curious) 427 + { 428 + if (!umx_data || !umx_data->loader) 429 + return 0; 430 + 431 + _mm_fseek(modreader, umx_data->ofs, SEEK_SET); 432 + /* set reader iobase to the umx object offset */ 433 + _mm_iobase_revert(modreader); 434 + _mm_iobase_setcur(modreader); 435 + 436 + return umx_data->loader->Load(curious); 437 + } 438 + 439 + static CHAR *UMX_LoadTitle(void) 440 + { 441 + CHAR *title; 442 + 443 + if (!umx_data) return NULL; 444 + 445 + if (!umx_data->loader) { 446 + title = NULL; 447 + } 448 + else { 449 + _mm_fseek(modreader, umx_data->ofs, SEEK_SET); 450 + /* set reader iobase to the umx object offset */ 451 + _mm_iobase_revert(modreader); 452 + _mm_iobase_setcur(modreader); 453 + 454 + title = umx_data->loader->LoadTitle(); 455 + } 456 + 457 + MikMod_free(umx_data); 458 + umx_data = NULL; 459 + 460 + return title; 461 + } 462 + 463 + /*========== Loader information */ 464 + 465 + MIKMODAPI MLOADER load_umx = { 466 + NULL, 467 + "UMX", 468 + "UMX (Unreal UMX container)", 469 + UMX_Init, 470 + UMX_Test, 471 + UMX_Load, 472 + UMX_Cleanup, 473 + UMX_LoadTitle 474 + }; 475 + 476 + /* ex:set ts=8: */
+83 -78
apps/plugins/mikmod/load_uni.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: load_uni.c,v 1.3 2005/04/07 19:57:38 realtech Exp $ 23 + $Id$ 24 24 25 25 UNIMOD (libmikmod's and APlayer's internal module format) loader 26 26 ··· 94 94 95 95 /*========== Loader code */ 96 96 97 - static char* readstring(void) 97 + static char * readstring(void) 98 98 { 99 - char *s=NULL; 99 + char *str=NULL; 100 100 UWORD len; 101 - 101 + 102 102 len=_mm_read_I_UWORD(modreader); 103 103 if(len) { 104 - s=MikMod_malloc(len+1); 105 - _mm_read_UBYTES(s,len,modreader); 106 - s[len]=0; 104 + str=(char *) MikMod_malloc(len+1); 105 + _mm_read_UBYTES(str,len,modreader); 106 + str[len]=0; 107 107 } 108 - return s; 108 + return str; 109 109 } 110 110 111 111 static int UNI_Test(void) ··· 133 133 static void UNI_Cleanup(void) 134 134 { 135 135 MikMod_free(wh); 136 - s=NULL; 136 + wh = s = NULL; 137 137 } 138 138 139 139 static UBYTE* readtrack(void) ··· 148 148 len=_mm_read_I_UWORD(modreader); 149 149 150 150 if(!len) return NULL; 151 - if(!(t=MikMod_malloc(len))) return NULL; 151 + if(!(t=(UBYTE*)MikMod_malloc(len))) return NULL; 152 152 _mm_read_UBYTES(t,len,modreader); 153 153 154 154 /* Check if the track is correct */ ··· 221 221 static int loadsmp6(void) 222 222 { 223 223 int t; 224 - SAMPLE *s; 224 + SAMPLE *sptr; 225 225 226 - s=of.samples; 227 - for(t=0;t<of.numsmp;t++,s++) { 226 + sptr=of.samples; 227 + for(t=0;t<of.numsmp;t++,sptr++) { 228 228 int flags; 229 229 230 230 flags = _mm_read_M_UWORD(modreader); 231 - s->flags=0; 232 - if(flags&0x0004) s->flags|=SF_STEREO; 233 - if(flags&0x0002) s->flags|=SF_SIGNED; 234 - if(flags&0x0001) s->flags|=SF_16BITS; 231 + sptr->flags=0; 232 + if(flags&0x0004) sptr->flags|=SF_STEREO; 233 + if(flags&0x0002) sptr->flags|=SF_SIGNED; 234 + if(flags&0x0001) sptr->flags|=SF_16BITS; 235 235 /* convert flags */ 236 236 if(universion>=0x104) { 237 - if(flags&0x2000) s->flags|=SF_UST_LOOP; 238 - if(flags&0x1000) s->flags|=SF_OWNPAN; 239 - if(flags&0x0800) s->flags|=SF_SUSTAIN; 240 - if(flags&0x0400) s->flags|=SF_REVERSE; 241 - if(flags&0x0200) s->flags|=SF_BIDI; 242 - if(flags&0x0100) s->flags|=SF_LOOP; 243 - if(flags&0x0020) s->flags|=SF_ITPACKED; 244 - if(flags&0x0010) s->flags|=SF_DELTA; 245 - if(flags&0x0008) s->flags|=SF_BIG_ENDIAN; 237 + if(flags&0x2000) sptr->flags|=SF_UST_LOOP; 238 + if(flags&0x1000) sptr->flags|=SF_OWNPAN; 239 + if(flags&0x0800) sptr->flags|=SF_SUSTAIN; 240 + if(flags&0x0400) sptr->flags|=SF_REVERSE; 241 + if(flags&0x0200) sptr->flags|=SF_BIDI; 242 + if(flags&0x0100) sptr->flags|=SF_LOOP; 243 + if(flags&0x0020) sptr->flags|=SF_ITPACKED; 244 + if(flags&0x0010) sptr->flags|=SF_DELTA; 245 + if(flags&0x0008) sptr->flags|=SF_BIG_ENDIAN; 246 246 } else if(universion>=0x102) { 247 - if(flags&0x0800) s->flags|=SF_UST_LOOP; 248 - if(flags&0x0400) s->flags|=SF_OWNPAN; 249 - if(flags&0x0200) s->flags|=SF_SUSTAIN; 250 - if(flags&0x0100) s->flags|=SF_REVERSE; 251 - if(flags&0x0080) s->flags|=SF_BIDI; 252 - if(flags&0x0040) s->flags|=SF_LOOP; 253 - if(flags&0x0020) s->flags|=SF_ITPACKED; 254 - if(flags&0x0010) s->flags|=SF_DELTA; 255 - if(flags&0x0008) s->flags|=SF_BIG_ENDIAN; 247 + if(flags&0x0800) sptr->flags|=SF_UST_LOOP; 248 + if(flags&0x0400) sptr->flags|=SF_OWNPAN; 249 + if(flags&0x0200) sptr->flags|=SF_SUSTAIN; 250 + if(flags&0x0100) sptr->flags|=SF_REVERSE; 251 + if(flags&0x0080) sptr->flags|=SF_BIDI; 252 + if(flags&0x0040) sptr->flags|=SF_LOOP; 253 + if(flags&0x0020) sptr->flags|=SF_ITPACKED; 254 + if(flags&0x0010) sptr->flags|=SF_DELTA; 255 + if(flags&0x0008) sptr->flags|=SF_BIG_ENDIAN; 256 256 } else { 257 - if(flags&0x400) s->flags|=SF_UST_LOOP; 258 - if(flags&0x200) s->flags|=SF_OWNPAN; 259 - if(flags&0x100) s->flags|=SF_REVERSE; 260 - if(flags&0x080) s->flags|=SF_SUSTAIN; 261 - if(flags&0x040) s->flags|=SF_BIDI; 262 - if(flags&0x020) s->flags|=SF_LOOP; 263 - if(flags&0x010) s->flags|=SF_BIG_ENDIAN; 264 - if(flags&0x008) s->flags|=SF_DELTA; 257 + if(flags&0x400) sptr->flags|=SF_UST_LOOP; 258 + if(flags&0x200) sptr->flags|=SF_OWNPAN; 259 + if(flags&0x100) sptr->flags|=SF_REVERSE; 260 + if(flags&0x080) sptr->flags|=SF_SUSTAIN; 261 + if(flags&0x040) sptr->flags|=SF_BIDI; 262 + if(flags&0x020) sptr->flags|=SF_LOOP; 263 + if(flags&0x010) sptr->flags|=SF_BIG_ENDIAN; 264 + if(flags&0x008) sptr->flags|=SF_DELTA; 265 265 } 266 266 267 - s->speed = _mm_read_M_ULONG(modreader); 268 - s->volume = _mm_read_UBYTE(modreader); 269 - s->panning = _mm_read_M_UWORD(modreader); 270 - s->length = _mm_read_M_ULONG(modreader); 271 - s->loopstart = _mm_read_M_ULONG(modreader); 272 - s->loopend = _mm_read_M_ULONG(modreader); 273 - s->susbegin = _mm_read_M_ULONG(modreader); 274 - s->susend = _mm_read_M_ULONG(modreader); 275 - s->globvol = _mm_read_UBYTE(modreader); 276 - s->vibflags = _mm_read_UBYTE(modreader); 277 - s->vibtype = _mm_read_UBYTE(modreader); 278 - s->vibsweep = _mm_read_UBYTE(modreader); 279 - s->vibdepth = _mm_read_UBYTE(modreader); 280 - s->vibrate = _mm_read_UBYTE(modreader); 267 + sptr->speed = _mm_read_M_ULONG(modreader); 268 + sptr->volume = _mm_read_UBYTE(modreader); 269 + sptr->panning = _mm_read_M_UWORD(modreader); 270 + sptr->length = _mm_read_M_ULONG(modreader); 271 + sptr->loopstart = _mm_read_M_ULONG(modreader); 272 + sptr->loopend = _mm_read_M_ULONG(modreader); 273 + sptr->susbegin = _mm_read_M_ULONG(modreader); 274 + sptr->susend = _mm_read_M_ULONG(modreader); 275 + sptr->globvol = _mm_read_UBYTE(modreader); 276 + sptr->vibflags = _mm_read_UBYTE(modreader); 277 + sptr->vibtype = _mm_read_UBYTE(modreader); 278 + sptr->vibsweep = _mm_read_UBYTE(modreader); 279 + sptr->vibdepth = _mm_read_UBYTE(modreader); 280 + sptr->vibrate = _mm_read_UBYTE(modreader); 281 281 282 - s->samplename=readstring(); 282 + sptr->samplename=readstring(); 283 283 284 284 if(_mm_eof(modreader)) { 285 285 _mm_errno = MMERR_LOADING_SAMPLEINFO; ··· 308 308 i->rpanvar = _mm_read_UBYTE(modreader); 309 309 i->volfade = _mm_read_M_UWORD(modreader); 310 310 311 - #if defined __STDC__ || defined _MSC_VER || defined MPW_C 311 + #if defined __STDC__ || defined _MSC_VER || defined __WATCOMC__ || defined MPW_C 312 312 #define UNI_LoadEnvelope6(name) \ 313 313 i-> name##flg=_mm_read_UBYTE(modreader); \ 314 314 i-> name##pts=_mm_read_UBYTE(modreader); \ ··· 373 373 for(u=0;u<96;u++) 374 374 i->samplenumber[u]=of.numsmp+_mm_read_UBYTE(modreader); 375 375 376 - #if defined __STDC__ || defined _MSC_VER || defined MPW_C 376 + #if defined __STDC__ || defined _MSC_VER || defined __WATCOMC__ || defined MPW_C 377 377 #define UNI_LoadEnvelope5(name) \ 378 378 i-> name##flg=_mm_read_UBYTE(modreader); \ 379 379 i-> name##pts=_mm_read_UBYTE(modreader); \ ··· 415 415 /* Allocate more room for sample information if necessary */ 416 416 if(of.numsmp+u==wavcnt) { 417 417 wavcnt+=UNI_SMPINCR; 418 - if(!(wh=MikMod_realloc(wh,wavcnt*sizeof(UNISMP05)))) { 418 + if(!(wh=(UNISMP05*)MikMod_realloc(wh,wavcnt*sizeof(UNISMP05)))) { 419 419 _mm_errno=MMERR_OUT_OF_MEMORY; 420 420 return 0; 421 421 } ··· 447 447 448 448 /* sanity check */ 449 449 if(!of.numsmp) { 450 - if(wh) { MikMod_free(wh);wh=NULL; } 450 + MikMod_free(wh);wh=NULL; 451 451 _mm_errno=MMERR_LOADING_SAMPLEINFO; 452 452 return 0; 453 453 } ··· 504 504 char *modtype,*oldtype=NULL; 505 505 INSTRUMENT *d; 506 506 SAMPLE *q; 507 - (void)curious; 508 - 507 + (void)curious; 508 + 509 509 /* read module header */ 510 510 _mm_read_UBYTES(mh.id,4,modreader); 511 511 if(mh.id[3]!='N') ··· 514 514 universion=0x100; 515 515 516 516 if(universion>=6) { 517 - if (universion==6) 518 - (void)_mm_read_UBYTE(modreader); 519 - else 517 + if (universion==6) { 518 + _mm_skip_BYTE(modreader); 519 + } else { 520 520 universion=_mm_read_M_UWORD(modreader); 521 - 521 + } 522 522 mh.flags =_mm_read_M_UWORD(modreader); 523 523 mh.numchn =_mm_read_UBYTE(modreader); 524 524 mh.numvoices =_mm_read_UBYTE(modreader); ··· 556 556 mh.flags &= UF_XMPERIODS | UF_LINEAR; 557 557 mh.flags |= UF_INST | UF_NOWRAP | UF_PANNING; 558 558 } 559 - 559 + 560 560 /* set module parameters */ 561 561 of.flags =mh.flags; 562 562 of.numchn =mh.numchn; ··· 578 578 oldtype=readstring(); 579 579 if(oldtype) { 580 580 size_t len=strlen(oldtype)+20; 581 - if(!(modtype=MikMod_malloc(len))) return 0; 581 + if(!(modtype=(char*)MikMod_malloc(len))) return 0; 582 582 #ifdef HAVE_SNPRINTF 583 583 snprintf(modtype,len,"%s (was %s)",(universion>=0x100)?"APlayer":"MikCvt2",oldtype); 584 584 #else 585 585 sprintf(modtype,"%s (was %s)",(universion>=0x100)?"APlayer":"MikCvt2",oldtype); 586 586 #endif 587 587 } else { 588 - if(!(modtype=MikMod_malloc(10))) return 0; 588 + if(!(modtype=(char*)MikMod_malloc(10))) return 0; 589 589 #ifdef HAVE_SNPRINTF 590 590 snprintf(modtype,10,"%s",(universion>=0x100)?"APlayer":"MikCvt3"); 591 591 #else 592 592 sprintf(modtype,"%s",(universion>=0x100)?"APlayer":"MikCvt3"); 593 593 #endif 594 594 } 595 - of.modtype=StrDup(modtype); 595 + of.modtype=MikMod_strdup(modtype); 596 596 MikMod_free(modtype);MikMod_free(oldtype); 597 597 of.comment=readstring(); 598 598 ··· 624 624 for(t=0;t<of.numchn;t++) of.panning[t]=mh.panning[t]; 625 625 } 626 626 /* convert the ``end of song'' pattern code if necessary */ 627 - if(universion<0x106) 628 - for(t=0;t<of.numpos;t++) 629 - if(of.positions[t]==255) of.positions[t]=LAST_PATTERN; 627 + for(t=0;t<of.numpos;t++) { 628 + if(universion<0x106 && of.positions[t]==255) of.positions[t]=LAST_PATTERN; 629 + else if (of.positions[t]>of.numpat) { /* SANITIY CHECK */ 630 + /* fprintf(stderr,"position[%d]=%d > numpat=%d\n",t,of.positions[t],of.numpat);*/ 631 + _mm_errno = MMERR_LOADING_HEADER; 632 + return 0; 633 + } 634 + } 630 635 631 636 /* instruments and samples */ 632 637 if(universion>=6) { ··· 642 647 if(!AllocInstruments()) return 0; 643 648 if(!loadinstr5()) return 0; 644 649 if(!AllocSamples()) { 645 - if(wh) { MikMod_free(wh);wh=NULL; } 650 + MikMod_free(wh);wh=NULL; 646 651 return 0; 647 652 } 648 653 if(!loadsmp5()) return 0;
+70 -59
apps/plugins/mikmod/load_xm.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: load_xm.c,v 1.5 2008/02/29 18:49:03 denis111 Exp $ 23 + $Id$ 24 24 25 25 Fasttracker (XM) module loader 26 26 ··· 59 59 UWORD numchn; /* Number of channels (2,4,6,8,10,...,32) */ 60 60 UWORD numpat; /* Number of patterns (max 256) */ 61 61 UWORD numins; /* Number of instruments (max 128) */ 62 - UWORD flags; 62 + UWORD flags; 63 63 UWORD tempo; /* Default tempo */ 64 64 UWORD bpm; /* Default BPM */ 65 65 UBYTE orders[256]; /* Pattern order table */ ··· 129 129 static XMNOTE *xmpat=NULL; 130 130 static XMHEADER *mh=NULL; 131 131 132 - /* increment unit for sample array MikMod_reallocation */ 132 + /* increment unit for sample array reallocation */ 133 133 #define XM_SMPINCR 64 134 134 static ULONG *nextwav=NULL; 135 135 static XMWAVHEADER *wh=NULL,*s=NULL; ··· 155 155 static void XM_Cleanup(void) 156 156 { 157 157 MikMod_free(mh); 158 + mh=NULL; 158 159 } 159 160 160 161 static int XM_ReadNote(XMNOTE* n) ··· 359 360 return 0; 360 361 361 362 /* when packsize is 0, don't try to load a pattern.. it's empty. */ 362 - if(ph.packsize) 363 - for(u=0;u<ph.numrows;u++) 363 + if(ph.packsize) 364 + for(u=0;u<ph.numrows;u++) 364 365 for(v=0;v<of.numchn;v++) { 365 366 if(!ph.packsize) break; 366 367 ··· 443 444 444 445 static int LoadInstruments(void) 445 446 { 446 - int t,u, ck; 447 + long filend,ck; 448 + int t,u; 447 449 INSTRUMENT *d; 448 450 ULONG next=0; 449 451 UWORD wavcnt=0; 452 + 453 + ck = _mm_ftell(modreader); 454 + _mm_fseek(modreader,0,SEEK_END); 455 + filend = _mm_ftell(modreader); 456 + _mm_fseek(modreader,ck,SEEK_SET); 450 457 451 458 if(!AllocInstruments()) return 0; 452 459 d=of.instruments; ··· 461 468 ih.size = _mm_read_I_ULONG(modreader); 462 469 headend += ih.size; 463 470 ck = _mm_ftell(modreader); 464 - _mm_fseek(modreader,0,SEEK_END); 465 - if ((headend<0) || (_mm_ftell(modreader)<headend) || (headend<ck)) { 466 - _mm_fseek(modreader,ck,SEEK_SET); 471 + if ((headend<0) || (filend<headend) || (headend<ck)) { 467 472 break; 468 473 } 469 - _mm_fseek(modreader,ck,SEEK_SET); 470 474 _mm_read_string(ih.name, 22, modreader); 471 475 ih.type = _mm_read_UBYTE(modreader); 472 476 ih.numsmp = _mm_read_I_UWORD(modreader); ··· 500 504 501 505 /* read the remainder of the header 502 506 (2 bytes for 1.03, 22 for 1.04) */ 503 - if (headend>=_mm_ftell(modreader)) for(u=headend-_mm_ftell(modreader);u;u--) (void)_mm_read_UBYTE(modreader); 507 + if (headend>=_mm_ftell(modreader)) { 508 + for(u=headend-_mm_ftell(modreader);u;u--) { 509 + _mm_skip_BYTE(modreader); 510 + } 511 + } 504 512 505 513 /* we can't trust the envelope point count here, as some 506 514 modules have incorrect values (K_OSPACE.XM reports 32 volume ··· 509 517 if(pth.panpts>XMENVCNT/2) pth.panpts=XMENVCNT/2; 510 518 511 519 if((_mm_eof(modreader))||(pth.volpts>XMENVCNT/2)||(pth.panpts>XMENVCNT/2)) { 512 - if(nextwav) { MikMod_free(nextwav);nextwav=NULL; } 513 - if(wh) { MikMod_free(wh);wh=NULL; } 520 + MikMod_free(nextwav);nextwav=NULL; 521 + MikMod_free(wh);wh=NULL; 514 522 _mm_errno = MMERR_LOADING_SAMPLEINFO; 515 523 return 0; 516 524 } ··· 519 527 d->samplenumber[u]=pth.what[u]+of.numsmp; 520 528 d->volfade = pth.volfade; 521 529 522 - #if defined __STDC__ || defined _MSC_VER || defined MPW_C 530 + #if defined __STDC__ || defined _MSC_VER || defined __WATCOMC__ || defined MPW_C 523 531 #define XM_ProcessEnvelope(name) \ 524 532 for (u = 0; u < (XMENVCNT >> 1); u++) { \ 525 533 d-> name##env[u].pos = pth. name##env[u << 1]; \ ··· 560 568 \ 561 569 if ((d-> name/**/flg&EF_ON)&&(d-> name/**/pts<2)) \ 562 570 d-> name/**/flg&=~EF_ON 563 - #endif 571 + #endif 564 572 565 573 XM_ProcessEnvelope(vol); 566 574 XM_ProcessEnvelope(pan); ··· 577 585 everything over */ 578 586 if(mh->version>0x0103) next = 0; 579 587 for(u=0;u<ih.numsmp;u++,s++) { 588 + /* XM sample header is 40 bytes: make sure we won't hit EOF */ 589 + /* Note: last instrument is at the end of file in version 0x0104 */ 590 + if(_mm_ftell(modreader)+40>filend) { 591 + MikMod_free(nextwav);MikMod_free(wh); 592 + nextwav=NULL;wh=NULL; 593 + _mm_errno = MMERR_LOADING_SAMPLEINFO; 594 + return 0; 595 + } 580 596 /* Allocate more room for sample information if necessary */ 581 597 if(of.numsmp+u==wavcnt) { 582 598 wavcnt+=XM_SMPINCR; 583 - if(!(nextwav=MikMod_realloc(nextwav,wavcnt*sizeof(ULONG)))){ 584 - if(wh) { MikMod_free(wh);wh=NULL; } 599 + if(!(nextwav=(ULONG*)MikMod_realloc(nextwav,wavcnt*sizeof(ULONG)))){ 600 + MikMod_free(wh);wh=NULL; 585 601 _mm_errno = MMERR_OUT_OF_MEMORY; 586 602 return 0; 587 603 } 588 - if(!(wh=MikMod_realloc(wh,wavcnt*sizeof(XMWAVHEADER)))) { 604 + if(!(wh=(XMWAVHEADER*)MikMod_realloc(wh,wavcnt*sizeof(XMWAVHEADER)))) { 589 605 MikMod_free(nextwav);nextwav=NULL; 590 606 _mm_errno = MMERR_OUT_OF_MEMORY; 591 607 return 0; ··· 610 626 611 627 nextwav[of.numsmp+u]=next; 612 628 next+=s->length; 613 - 614 - if(_mm_eof(modreader)) { 615 - MikMod_free(nextwav);MikMod_free(wh); 616 - nextwav=NULL;wh=NULL; 617 - _mm_errno = MMERR_LOADING_SAMPLEINFO; 618 - return 0; 619 - } 620 629 } 621 630 622 631 if(mh->version>0x0103) { ··· 628 637 } else { 629 638 /* read the remainder of the header */ 630 639 ck = _mm_ftell(modreader); 631 - _mm_fseek(modreader,0,SEEK_END); 632 - if ((headend<0) || (_mm_ftell(modreader)<headend) || (headend<ck)) { 633 - _mm_fseek(modreader,ck,SEEK_SET); 640 + if ((headend<0) || (filend<headend) || (headend<ck)) { 634 641 break; 635 642 } 636 - _mm_fseek(modreader,ck,SEEK_SET); 637 - for(u=headend-_mm_ftell(modreader);u;u--) (void)_mm_read_UBYTE(modreader); 643 + for(u=headend-_mm_ftell(modreader);u;u--) { 644 + _mm_skip_BYTE(modreader); 645 + } 638 646 639 - if(_mm_eof(modreader)) { 647 + /* last instrument is at the end of file in version 0x0104 */ 648 + if(_mm_eof(modreader) && (mh->version<0x0104 || t<of.numins-1)) { 640 649 MikMod_free(nextwav);MikMod_free(wh); 641 650 nextwav=NULL;wh=NULL; 642 651 _mm_errno = MMERR_LOADING_SAMPLEINFO; ··· 648 657 649 658 /* sanity check */ 650 659 if(!of.numsmp) { 651 - if(nextwav) { MikMod_free(nextwav);nextwav=NULL; } 652 - if(wh) { MikMod_free(wh);wh=NULL; } 660 + MikMod_free(nextwav);nextwav=NULL; 661 + MikMod_free(wh);wh=NULL; 653 662 _mm_errno = MMERR_LOADING_SAMPLEINFO; 654 663 return 0; 655 664 } ··· 664 673 int t,u; 665 674 int dummypat=0; 666 675 char tracker[21],modtype[60]; 667 - (void)curious; 676 + (void)curious; 668 677 669 678 /* try to read module header */ 670 679 _mm_read_string(mh->id,17,modreader); 671 680 _mm_read_string(mh->songname,21,modreader); 672 681 _mm_read_string(mh->trackername,20,modreader); 673 682 mh->version =_mm_read_I_UWORD(modreader); 674 - if((mh->version<0x102)||(mh->version>0x104)) { 675 - _mm_errno=MMERR_NOT_A_MODULE; 676 - return 0; 677 - } 683 + if(mh->version < 0x102 || mh->version > 0x104) 684 + goto bad_xm; 678 685 mh->headersize =_mm_read_I_ULONG(modreader); 679 686 mh->songlength =_mm_read_I_UWORD(modreader); 680 687 mh->restart =_mm_read_I_UWORD(modreader); ··· 684 691 mh->flags =_mm_read_I_UWORD(modreader); 685 692 mh->tempo =_mm_read_I_UWORD(modreader); 686 693 mh->bpm =_mm_read_I_UWORD(modreader); 687 - if(!mh->bpm) { 688 - _mm_errno=MMERR_NOT_A_MODULE; 689 - return 0; 690 - } 691 - _mm_read_UBYTES(mh->orders,mh->headersize-20,modreader); 692 - 693 - if(_mm_eof(modreader)) { 694 - _mm_errno = MMERR_LOADING_HEADER; 695 - return 0; 696 - } 694 + if(mh->numchn > 64) goto bad_xm; 695 + if(mh->tempo > 32 || mh->bpm < 32 || mh->bpm > 255) 696 + goto bad_xm; 697 + if(mh->songlength > 256 || mh->headersize < 20 || mh->headersize > 20+256) 698 + goto bad_xm; 699 + if(mh->numpat > 256 || mh->numins > 255 || mh->restart > 255) 700 + goto bad_xm; 701 + /* _mm_read_UBYTES(mh->orders,256,modreader);*/ 702 + /* _mm_read_UBYTES(mh->orders,mh->headersize-20,modreader);*/ 703 + _mm_read_UBYTES(mh->orders,mh->songlength,modreader); 704 + if(_mm_fseek(modreader, mh->headersize+60, SEEK_SET) || _mm_eof(modreader)) 705 + goto bad_hdr; 697 706 698 707 /* set module variables */ 699 - of.initspeed = mh->tempo; 708 + of.initspeed = mh->tempo; 700 709 of.inittempo = mh->bpm; 701 710 strncpy(tracker,mh->trackername,20);tracker[20]=0; 702 - for(t=20;(tracker[t]<=' ')&&(t>=0);t--) tracker[t]=0; 703 - 711 + for(t=20;(t>=0)&&(tracker[t]<=' ');t--) tracker[t]=0; 712 + 704 713 /* some modules have the tracker name empty */ 705 714 if (!tracker[0]) 706 715 strcpy(tracker,"Unknown tracker"); ··· 712 721 sprintf(modtype,"%s (XM format %d.%02d)", 713 722 tracker,mh->version>>8,mh->version&0xff); 714 723 #endif 715 - of.modtype = StrDup(modtype); 724 + of.modtype = MikMod_strdup(modtype); 716 725 of.numchn = mh->numchn; 717 726 of.numpat = mh->numpat; 718 727 of.numtrk = (UWORD)of.numpat*of.numchn; /* get number of channels */ ··· 720 729 of.numpos = mh->songlength; /* copy the songlength */ 721 730 of.reppos = mh->restart<mh->songlength?mh->restart:0; 722 731 of.numins = mh->numins; 723 - of.flags |= UF_XMPERIODS | UF_INST | UF_NOWRAP | UF_FT2QUIRKS | 724 - UF_PANNING; 732 + of.flags |= UF_XMPERIODS | UF_INST | UF_NOWRAP | UF_FT2QUIRKS | UF_PANNING; 725 733 if(mh->flags&1) of.flags |= UF_LINEAR; 726 734 of.bpmlimit = 32; 727 735 ··· 802 810 MikMod_free(wh);MikMod_free(nextwav); 803 811 wh=NULL;nextwav=NULL; 804 812 return 1; 813 + 814 + bad_hdr: _mm_errno = MMERR_LOADING_HEADER; return 0; 815 + bad_xm: _mm_errno = MMERR_NOT_A_MODULE; return 0; 805 816 } 806 817 807 818 static CHAR *XM_LoadTitle(void) 808 819 { 809 - CHAR s[21]; 820 + CHAR str[21]; 810 821 811 822 _mm_fseek(modreader,17,SEEK_SET); 812 - if(!_mm_read_UBYTES(s,21,modreader)) return NULL; 823 + if(!_mm_read_UBYTES(str, 21, modreader)) return NULL; 813 824 814 - return(DupStr(s,21,1)); 825 + return(DupStr(str,21,1)); 815 826 } 816 827 817 828 /*========== Loader information */
+50 -16
apps/plugins/mikmod/mdreg.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: mdreg.c,v 1.2 2005/03/30 19:11:13 realtech Exp $ 24 - 25 23 Routine for registering all drivers in libmikmod for the current platform. 26 24 27 25 ==============================================================================*/ ··· 34 32 35 33 static void _mm_registeralldrivers(void) 36 34 { 37 - #if 0 38 - 39 35 /* Register network drivers */ 40 36 #ifdef DRV_AF 41 37 _mm_registerdriver(&drv_AF); 42 38 #endif 39 + #ifdef DRV_PULSEAUDIO 40 + _mm_registerdriver(&drv_pulseaudio); 41 + #endif 43 42 #ifdef DRV_ESD 44 43 _mm_registerdriver(&drv_esd); 45 44 #endif ··· 51 50 #ifdef DRV_ULTRA 52 51 _mm_registerdriver(&drv_ultra); 53 52 #endif 53 + #ifdef DRV_SAM9407 54 + _mm_registerdriver(&drv_sam9407); 55 + #endif 54 56 55 - /* Register hardware drivers - software mixing */ 57 + /* Register multi-platform drivers -- software mixing */ 58 + #ifdef DRV_SDL 59 + _mm_registerdriver(&drv_sdl); 60 + #endif 61 + #ifdef DRV_OPENAL 62 + _mm_registerdriver(&drv_openal); 63 + #endif 64 + 65 + /* Register OS-specific hardware drivers - software mixing */ 66 + #ifdef DRV_AHI 67 + _mm_registerdriver(&drv_ahi); 68 + #endif 56 69 #ifdef DRV_AIX 57 70 _mm_registerdriver(&drv_aix); 58 71 #endif ··· 62 75 #ifdef DRV_HP 63 76 _mm_registerdriver(&drv_hp); 64 77 #endif 78 + #ifdef DRV_SNDIO 79 + _mm_registerdriver(&drv_sndio); 80 + #endif 65 81 #ifdef DRV_OSS 66 82 _mm_registerdriver(&drv_oss); 67 83 #endif ··· 76 92 #endif 77 93 #ifdef DRV_OS2 78 94 _mm_registerdriver(&drv_os2); 95 + #endif 96 + #ifdef DRV_XAUDIO2 97 + _mm_registerdriver(&drv_xaudio2); 79 98 #endif 80 99 #ifdef DRV_DS 81 100 _mm_registerdriver(&drv_ds); ··· 89 108 #ifdef DRV_OSX 90 109 _mm_registerdriver(&drv_osx); 91 110 #endif 111 + #ifdef DRV_DC 112 + _mm_registerdriver(&drv_dc); 113 + #endif 92 114 #ifdef DRV_GP32 93 115 _mm_registerdriver(&drv_gp32); 94 116 #endif 95 - 96 - /* dos drivers */ 117 + #ifdef DRV_PSP 118 + _mm_registerdriver(&drv_psp); 119 + #endif 120 + #ifdef DRV_OSLES 121 + _mm_registerdriver(&drv_osles); 122 + #endif 123 + #ifdef DRV_N64 124 + _mm_registerdriver(&drv_n64); 125 + #endif 126 + 127 + /* dos drivers - wss first, since some cards emulate sb */ 97 128 #ifdef DRV_WSS 98 - /* wss first, since some cards emulate sb */ 99 129 _mm_registerdriver(&drv_wss); 100 130 #endif 101 131 #ifdef DRV_SB 102 132 _mm_registerdriver(&drv_sb); 103 133 #endif 104 - 134 + 105 135 /* Register disk writers */ 106 - _mm_registerdriver(&drv_raw); 136 + #ifdef DRV_WAV 107 137 _mm_registerdriver(&drv_wav); 138 + #endif 108 139 #ifdef DRV_AIFF 109 140 _mm_registerdriver(&drv_aiff); 110 141 #endif 111 - 142 + #ifdef DRV_RAW 143 + _mm_registerdriver(&drv_raw); 144 + #endif 145 + 112 146 /* Register other drivers */ 113 147 #ifdef DRV_PIPE 114 148 _mm_registerdriver(&drv_pipe); 115 149 #endif 116 - #ifndef macintosh 150 + #if defined(DRV_STDOUT) && !defined(macintosh) 117 151 _mm_registerdriver(&drv_stdout); 118 152 #endif 119 153 120 - #endif 154 + /* Register 'nosound' driver */ 121 155 _mm_registerdriver(&drv_nos); 122 156 } 123 157 124 - void MikMod_RegisterAllDrivers(void) 158 + MIKMODAPI void MikMod_RegisterAllDrivers(void) 125 159 { 126 160 MUTEX_LOCK(lists); 127 161 _mm_registeralldrivers();
+93 -90
apps/plugins/mikmod/mdriver.c
··· 1 1 /* MikMod sound library 2 - (c) 1998, 1999, 2000, 2001 Miodrag Vallat and others - see file AUTHORS 3 - for complete list. 2 + (c) 1998-2014 Miodrag Vallat and others - see file AUTHORS 3 + for a complete list. 4 4 5 5 This library is free software; you can redistribute it and/or modify 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 19 19 */ 20 20 21 21 /*============================================================================== 22 - 23 - $Id: mdriver.c,v 1.4 2007/12/03 20:59:05 denis111 Exp $ 24 22 25 23 These routines are used to access the available soundcard drivers. 26 24 ··· 34 32 #include <unistd.h> 35 33 #endif 36 34 37 - #if 0 38 - #if defined unix || (defined __APPLE__ && defined __MACH__) 39 - #include <pwd.h> 40 - #include <sys/stat.h> 41 - #endif 42 - #endif 43 - 44 35 #include <string.h> 45 - #ifdef HAVE_STRINGS_H 46 - #include <strings.h> 47 - #endif 48 36 49 37 #include "mikmod_internals.h" 50 38 39 + #if (MIKMOD_UNIX) 40 + #include <pwd.h> 41 + #include <sys/stat.h> 42 + #endif 43 + 51 44 #ifdef SUNOS 52 45 extern int fprintf(FILE *, const char *, ...); 53 46 #endif 54 47 55 - static MDRIVER *firstdriver=NULL; 56 - MIKMODAPI MDRIVER *md_driver=NULL; 57 48 extern MODULE *pf; /* modfile being played */ 49 + 50 + /* EXPORTED GLOBALS */ 51 + MIKMODAPI MDRIVER *md_driver = NULL; 58 52 59 53 /* Initial global settings */ 60 - MIKMODAPI UWORD md_device = 0; /* autodetect */ 61 - MIKMODAPI UWORD md_mixfreq = 44100; 62 - MIKMODAPI UWORD md_mode = DMODE_STEREO | DMODE_16BITS | 63 - DMODE_SURROUND |DMODE_SOFT_MUSIC | 64 - DMODE_SOFT_SNDFX; 65 - MIKMODAPI UBYTE md_pansep = 128; /* 128 == 100% (full left/right) */ 66 - MIKMODAPI UBYTE md_reverb = 0; /* no reverb */ 67 - MIKMODAPI UBYTE md_volume = 128; /* global sound volume (0-128) */ 68 - MIKMODAPI UBYTE md_musicvolume = 128; /* volume of song */ 69 - MIKMODAPI UBYTE md_sndfxvolume = 128; /* volume of sound effects */ 70 - UWORD md_bpm = 125; /* tempo */ 54 + MIKMODAPI UWORD md_device = 0; /* autodetect */ 55 + MIKMODAPI ULONG md_mixfreq = 44100; 56 + MIKMODAPI UWORD md_mode = DMODE_STEREO | DMODE_16BITS | 57 + DMODE_SURROUND | 58 + DMODE_SOFT_MUSIC | DMODE_SOFT_SNDFX; 59 + MIKMODAPI UBYTE md_pansep = 128; /* 128 == 100% (full left/right) */ 60 + MIKMODAPI UBYTE md_reverb = 0; /* no reverb */ 61 + MIKMODAPI UBYTE md_volume = 128; /* global sound volume (0-128) */ 62 + MIKMODAPI UBYTE md_musicvolume = 128; /* volume of song */ 63 + MIKMODAPI UBYTE md_sndfxvolume = 128; /* volume of sound effects */ 64 + 65 + /* INTERNAL GLOBALS */ 66 + UWORD md_bpm = 125; /* tempo */ 67 + 68 + /* Do not modify the numchn variables yourself! use MikMod_SetNumVoices() */ 69 + UBYTE md_numchn = 0, md_sngchn = 0, md_sfxchn = 0; 70 + UBYTE md_hardchn = 0, md_softchn= 0; 71 + 72 + MikMod_player_t md_player = Player_HandleTick; 73 + 74 + MikMod_callback_t vc_callback = NULL; 75 + 76 + /* PRIVATE VARS */ 77 + static MDRIVER *firstdriver = NULL; 71 78 72 - /* Do not modify the numchn variables yourself! use MD_SetVoices() */ 73 - UBYTE md_numchn=0,md_sngchn=0,md_sfxchn=0; 74 - UBYTE md_hardchn=0,md_softchn=0; 79 + static volatile int isplaying = 0, initialized = 0; 75 80 76 - void (*md_player)(void) = Player_HandleTick; 77 - static volatile int isplaying=0, initialized = 0; 78 - static UBYTE *sfxinfo; 79 - static int sfxpool; 81 + static UBYTE *sfxinfo; 82 + static int sfxpool; 80 83 81 - static SAMPLE **md_sample = NULL; 84 + static SAMPLE **md_sample = NULL; 82 85 83 86 /* Previous driver in use */ 84 - static SWORD olddevice = -1; 87 + static SWORD olddevice = -1; 85 88 86 89 /* Limits the number of hardware voices to the specified amount. 87 90 This function should only be used by the low-level drivers. */ ··· 183 186 184 187 MUTEX_LOCK(lists); 185 188 /* compute size of buffer */ 186 - for(l=firstdriver;l;l=l->next) 187 - len+=4+(l->next?1:0)+strlen(l->Version); 189 + for(l = firstdriver; l; l = l->next) 190 + len += 4 + (l->next ? 1 : 0) + strlen(l->Version); 188 191 189 192 if(len) 190 - if((list=MikMod_malloc(len*sizeof(CHAR)))) { 191 - list[0]=0; 192 - /* list all registered device drivers : */ 193 - for(t=1,l=firstdriver;l;l=l->next,t++) 194 - sprintf(list,(l->next)?"%s%2d %s\n":"%s%2d %s", 195 - list,t,l->Version); 193 + if((list=(CHAR*)MikMod_malloc(len*sizeof(CHAR))) != NULL) { 194 + CHAR *list_end = list; 195 + list[0] = 0; 196 + /* list all registered device drivers : */ 197 + for(t = 1, l = firstdriver; l; l = l->next, t++) { 198 + list_end += sprintf(list_end, "%2d %s%s", t, l->Version, (l->next)? "\n" : ""); 196 199 } 200 + } 197 201 MUTEX_UNLOCK(lists); 198 202 return list; 199 203 } ··· 214 218 } 215 219 cruise->next = drv; 216 220 } else 217 - firstdriver = drv; 221 + firstdriver = drv; 218 222 } 219 223 } 220 224 ··· 230 234 MUTEX_UNLOCK(lists); 231 235 } 232 236 233 - MIKMODAPI int MikMod_DriverFromAlias(CHAR *alias) 237 + MIKMODAPI int MikMod_DriverFromAlias(const CHAR *alias) 234 238 { 235 239 int rank=1; 236 240 MDRIVER *cruise; ··· 252 256 253 257 MIKMODAPI MDRIVER *MikMod_DriverByOrdinal(int ordinal) 254 258 { 255 - MDRIVER *cruise; 259 + MDRIVER *cruise; 256 260 257 - /* Allow only driver ordinals > 0 */ 258 - if (!ordinal) 259 - return 0; 261 + /* Allow only driver ordinals > 0 */ 262 + if (!ordinal) return NULL; 260 263 261 - MUTEX_LOCK(lists); 262 - cruise = firstdriver; 263 - while (cruise && --ordinal) 264 - cruise = cruise->next; 265 - MUTEX_UNLOCK(lists); 266 - return cruise; 264 + MUTEX_LOCK(lists); 265 + cruise = firstdriver; 266 + while (cruise && --ordinal) 267 + cruise = cruise->next; 268 + MUTEX_UNLOCK(lists); 269 + return cruise; 267 270 } 268 271 269 272 SWORD MD_SampleLoad(SAMPLOAD* s, int type) ··· 496 499 return result; 497 500 } 498 501 499 - extern MikMod_callback_t vc_callback; 500 - 501 502 MIKMODAPI void VC_SetCallback(MikMod_callback_t callback) 502 503 { 503 504 vc_callback = callback; 504 505 } 505 506 506 - static int _mm_init(CHAR *cmdline) 507 + static int _mm_init(const CHAR *cmdline) 507 508 { 508 509 UWORD t; 509 510 ··· 561 562 return 0; 562 563 } 563 564 564 - MIKMODAPI int MikMod_Init(CHAR *cmdline) 565 + MIKMODAPI int MikMod_Init(const CHAR *cmdline) 565 566 { 566 567 int result; 567 568 ··· 581 582 md_numchn = md_sfxchn = md_sngchn = 0; 582 583 md_driver = &drv_nos; 583 584 584 - if(sfxinfo) MikMod_free(sfxinfo); 585 - if(md_sample) MikMod_free(md_sample); 585 + MikMod_free(sfxinfo); 586 + MikMod_free(md_sample); 586 587 md_sample = NULL; 587 588 sfxinfo = NULL; 588 589 ··· 598 599 MUTEX_UNLOCK(vars); 599 600 } 600 601 601 - /* Reset the driver using the new global variable settings. 602 + /* Reset the driver using the new global variable settings. 602 603 If the driver has not been initialized, it will be now. */ 603 - static int _mm_reset(CHAR *cmdline) 604 + static int _mm_reset(const CHAR *cmdline) 604 605 { 605 606 int wasplaying = 0; 606 607 607 608 if(!initialized) return _mm_init(cmdline); 608 - 609 + 609 610 if (isplaying) { 610 611 wasplaying = 1; 611 612 md_driver->PlayStop(); ··· 629 630 return 1; 630 631 } 631 632 } 632 - 633 - if (wasplaying) md_driver->PlayStart(); 633 + 634 + if (wasplaying) return md_driver->PlayStart(); 634 635 return 0; 635 636 } 636 637 637 - MIKMODAPI int MikMod_Reset(CHAR *cmdline) 638 + MIKMODAPI int MikMod_Reset(const CHAR *cmdline) 638 639 { 639 640 int result; 640 641 ··· 661 662 resume = 1; 662 663 } 663 664 664 - if(sfxinfo) MikMod_free(sfxinfo); 665 - if(md_sample) MikMod_free(md_sample); 665 + MikMod_free(sfxinfo); 666 + MikMod_free(md_sample); 666 667 md_sample = NULL; 667 668 sfxinfo = NULL; 668 669 ··· 764 765 allocated for use as sound effects (loops through voices, skipping all active 765 766 criticals). 766 767 767 - Returns the voice that the sound is being played on. */ 768 + Returns the voice that the sound is being played on. */ 768 769 static SBYTE Sample_Play_internal(SAMPLE *s,ULONG start,UBYTE flags) 769 770 { 770 771 int orig=sfxpool;/* for cases where all channels are critical */ ··· 825 826 #ifdef HAVE_PTHREAD 826 827 #define INIT_MUTEX(name) \ 827 828 pthread_mutex_t _mm_mutex_##name=PTHREAD_MUTEX_INITIALIZER 829 + 828 830 #elif defined(__OS2__)||defined(__EMX__) 829 831 #define INIT_MUTEX(name) \ 830 832 HMTX _mm_mutex_##name 831 - #elif defined(WIN32) 833 + 834 + #elif defined(_WIN32) 832 835 #define INIT_MUTEX(name) \ 833 836 HANDLE _mm_mutex_##name 837 + 834 838 #else 835 839 #define INIT_MUTEX(name) \ 836 840 void *_mm_mutex_##name = NULL ··· 842 846 MIKMODAPI int MikMod_InitThreads(void) 843 847 { 844 848 static int firstcall=1; 845 - static int result=0; 846 - 849 + static int result = 0; 850 + 847 851 if (firstcall) { 848 852 firstcall=0; 849 853 #ifdef HAVE_PTHREAD ··· 855 859 result=0; 856 860 } else 857 861 result=1; 858 - #elif defined(WIN32) 859 - if((!(_mm_mutex_lists=CreateMutex(NULL,FALSE,"libmikmod(lists)")))|| 860 - (!(_mm_mutex_vars=CreateMutex(NULL,FALSE,"libmikmod(vars)")))) 862 + #elif defined(_WIN32) 863 + if((!(_mm_mutex_lists=CreateMutex(NULL,FALSE,TEXT("libmikmod(lists)"))))|| 864 + (!(_mm_mutex_vars=CreateMutex(NULL,FALSE,TEXT("libmikmod(vars)"))))) 861 865 result=0; 862 866 else 863 867 result=1; ··· 880 884 881 885 /*========== Parameter extraction helper */ 882 886 883 - CHAR *MD_GetAtom(CHAR *atomname,CHAR *cmdline,int implicit) 887 + CHAR *MD_GetAtom(const CHAR *atomname, const CHAR *cmdline, int implicit) 884 888 { 885 889 CHAR *ret=NULL; 886 890 887 891 if(cmdline) { 888 - CHAR *buf=strstr(cmdline,atomname); 892 + const CHAR *buf=strstr(cmdline,atomname); 889 893 890 894 if((buf)&&((buf==cmdline)||(*(buf-1)==','))) { 891 - CHAR *ptr=buf+strlen(atomname); 895 + const CHAR *ptr=buf+strlen(atomname); 892 896 893 897 if(*ptr=='=') { 894 898 for(buf=++ptr;(*ptr)&&((*ptr)!=',');ptr++); 895 - ret=MikMod_malloc((1+ptr-buf)*sizeof(CHAR)); 899 + ret=(CHAR *)MikMod_malloc((1+ptr-buf)*sizeof(CHAR)); 896 900 if(ret) 897 901 strncpy(ret,buf,ptr-buf); 898 902 } else if((*ptr==',')||(!*ptr)) { 899 903 if(implicit) { 900 - ret=MikMod_malloc((1+ptr-buf)*sizeof(CHAR)); 904 + ret=(CHAR *)MikMod_malloc((1+ptr-buf)*sizeof(CHAR)); 901 905 if(ret) 902 906 strncpy(ret,buf,ptr-buf); 903 907 } ··· 907 911 return ret; 908 912 } 909 913 910 - #if 0 911 - #if defined unix || (defined __APPLE__ && defined __MACH__) 914 + #if (MIKMOD_UNIX) 912 915 913 916 /*========== Posix helper functions */ 914 917 ··· 917 920 reasonable. Returns 1 if it is safe to rewrite the file, 0 otherwise. 918 921 The goal is to prevent a setuid root libmikmod application from overriding 919 922 files like /etc/passwd with digital sound... */ 920 - int MD_Access(CHAR *filename) 923 + int MD_Access(const CHAR * filename) 921 924 { 922 925 struct stat buf; 923 926 ··· 934 937 } else 935 938 if(!(buf.st_mode&S_IWOTH)) return 0; 936 939 } 937 - 940 + 938 941 return 1; 939 942 } 940 943 ··· 961 964 } 962 965 963 966 #endif 964 - #endif 965 - /* ex:set ts=4: */ 967 + 968 + /* ex:set ts=8: */
+100 -33
apps/plugins/mikmod/mikmod.c
··· 25 25 /* Persistent configuration */ 26 26 #define MIKMOD_CONFIGFILE "mikmod.cfg" 27 27 #define MIKMOD_SETTINGS_MINVERSION 1 28 - #define MIKMOD_SETTINGS_VERSION 1 28 + #define MIKMOD_SETTINGS_VERSION 2 29 29 30 30 #ifdef USETHREADS 31 31 #define EV_EXIT 9999 ··· 161 161 !rb->strcasecmp(ext,".dsm") || 162 162 !rb->strcasecmp(ext,".far") || 163 163 !rb->strcasecmp(ext,".gdm") || 164 - !rb->strcasecmp(ext,".gt2") || 165 164 !rb->strcasecmp(ext,".imf") || 166 165 !rb->strcasecmp(ext,".it") || 167 166 !rb->strcasecmp(ext,".m15") || ··· 174 173 !rb->strcasecmp(ext,".stx") || 175 174 !rb->strcasecmp(ext,".ult") || 176 175 !rb->strcasecmp(ext,".uni") || 176 + !rb->strcasecmp(ext,".umx") || 177 177 !rb->strcasecmp(ext,".xm") ) 178 178 return true; 179 179 else ··· 305 305 rb->lcd_putsxy(1, 1, statustext); 306 306 sprintf(statustext, "Type: %s", module->modtype); 307 307 rb->lcd_putsxy(1, 11, statustext); 308 - 308 + 309 309 sprintf(statustext, "Samples: %d", module->numsmp); 310 310 rb->lcd_putsxy(1, 21, statustext); 311 311 ··· 315 315 rb->lcd_putsxy(1, 31, statustext); 316 316 } 317 317 318 - sprintf(statustext, "pat: %03d/%03d %2.2X", 318 + sprintf(statustext, "pat: %03d/%03d %2.2X", 319 319 module->sngpos, module->numpos - 1, module->patpos); 320 320 rb->lcd_putsxy(1, 51, statustext); 321 321 322 - sprintf(statustext, "spd: %d/%d", 322 + sprintf(statustext, "spd: %d/%d", 323 323 module->sngspd, module->bpm); 324 324 rb->lcd_putsxy(1, 61, statustext); 325 325 326 326 sprintf(statustext, "vol: %ddB", rb->global_settings->volume); 327 327 rb->lcd_putsxy(1, 71, statustext); 328 328 329 - sprintf(statustext, "time: %d:%02d", 329 + sprintf(statustext, "time: %d:%02d", 330 330 (playingtime / 60) % 60, playingtime % 60); 331 331 rb->lcd_putsxy(1, 81, statustext); 332 332 333 333 if (module->flags & UF_NNA) 334 334 { 335 335 sprintf(statustext, "chn: %d/%d+%d->%d", 336 - module->realchn, module->numchn, 336 + module->realchn, module->numchn, 337 337 module->totalchn - module->realchn, 338 338 module->totalchn); 339 339 } ··· 465 465 { 466 466 int pansep; 467 467 int reverb; 468 + int sample_rate; 468 469 bool interp; 469 470 bool reverse; 470 471 bool surround; 472 + bool hqmixer; 473 + #ifdef HAVE_ADJUSTABLE_CPU_FREQ 471 474 bool boost; 475 + #endif 472 476 }; 473 477 474 478 static struct mikmod_settings settings = 475 479 { 476 - 128, 477 - 0, 478 - 0, 479 - 0, 480 - 1, 481 - 1 480 + .pansep = 128, 481 + .reverb = 0, 482 + .sample_rate = -1, 483 + .interp = 0, 484 + .reverse = 0, 485 + .surround = 1, 486 + .hqmixer = 0, 487 + #ifdef HAVE_ADJUSTABLE_CPU_FREQ 488 + .boost = 1, 489 + #endif 482 490 }; 483 491 484 492 static struct mikmod_settings old_settings; 485 493 486 - static struct configdata config[] = 494 + static const struct configdata config[] = 487 495 { 488 496 { TYPE_INT, 0, 128, { .int_p = &settings.pansep }, "Panning Separation", NULL}, 489 497 { TYPE_INT, 0, 15, { .int_p = &settings.reverb }, "Reverberation", NULL}, 490 498 { TYPE_BOOL, 0, 1, { .bool_p = &settings.interp }, "Interpolation", NULL}, 491 499 { TYPE_BOOL, 0, 1, { .bool_p = &settings.reverse }, "Reverse Channels", NULL}, 492 500 { TYPE_BOOL, 0, 1, { .bool_p = &settings.surround }, "Surround", NULL}, 501 + { TYPE_BOOL, 0, 1, { .bool_p = &settings.hqmixer }, "HQ Mixer", NULL}, 502 + { TYPE_INT, 0, HW_NUM_FREQ-1, { .int_p = &settings.sample_rate }, "Sample Rate", NULL}, 503 + #ifdef HAVE_ADJUSTABLE_CPU_FREQ 493 504 { TYPE_BOOL, 0, 1, { .bool_p = &settings.boost }, "CPU Boost", NULL}, 505 + #endif 494 506 }; 495 507 496 508 static void applysettings(void) ··· 498 510 md_pansep = settings.pansep; 499 511 md_reverb = settings.reverb; 500 512 md_mode = DMODE_STEREO | DMODE_16BITS | DMODE_SOFT_MUSIC | DMODE_SOFT_SNDFX; 513 + 501 514 if ( settings.interp ) 502 515 { 503 516 md_mode |= DMODE_INTERP; ··· 510 523 { 511 524 md_mode |= DMODE_SURROUND; 512 525 } 526 + #ifndef NO_HQMIXER 527 + if ( settings.hqmixer ) 528 + { 529 + md_mode |= DMODE_HQMIXER; 530 + } 531 + #endif 532 + 533 + if (md_mixfreq != rb->hw_freq_sampr[settings.sample_rate]) { 534 + md_mixfreq = rb->hw_freq_sampr[settings.sample_rate]; 535 + // MikMod_Reset(""); BROKEN! 536 + rb->pcm_play_stop(); 537 + rb->mixer_set_frequency(md_mixfreq); 538 + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0); 539 + } 540 + 513 541 #ifdef HAVE_ADJUSTABLE_CPU_FREQ 514 542 if ( Player_Active() ) 515 543 { ··· 518 546 #endif 519 547 } 520 548 549 + static const struct opt_items sr_names[HW_NUM_FREQ] = { 550 + HW_HAVE_96_([HW_FREQ_96] = { "96kHz", TALK_ID(96, UNIT_KHZ) },) 551 + HW_HAVE_88_([HW_FREQ_88] = { "88.2kHz", TALK_ID(88, UNIT_KHZ) },) 552 + HW_HAVE_64_([HW_FREQ_64] = { "64kHz", TALK_ID(64, UNIT_KHZ) },) 553 + HW_HAVE_48_([HW_FREQ_48] = { "48kHz", TALK_ID(48, UNIT_KHZ) },) 554 + HW_HAVE_44_([HW_FREQ_44] = { "44.1kHz", TALK_ID(44, UNIT_KHZ) },) 555 + HW_HAVE_32_([HW_FREQ_32] = { "32kHz", TALK_ID(32, UNIT_KHZ) },) 556 + HW_HAVE_24_([HW_FREQ_24] = { "24kHz", TALK_ID(24, UNIT_KHZ) },) 557 + HW_HAVE_22_([HW_FREQ_22] = { "22.05kHz", TALK_ID(22, UNIT_KHZ) },) 558 + HW_HAVE_16_([HW_FREQ_16] = { "16kHz", TALK_ID(16, UNIT_KHZ) },) 559 + HW_HAVE_12_([HW_FREQ_12] = { "12kHz", TALK_ID(12, UNIT_KHZ) },) 560 + HW_HAVE_11_([HW_FREQ_11] = { "11.025kHz", TALK_ID(11, UNIT_KHZ) },) 561 + HW_HAVE_8_( [HW_FREQ_8 ] = { "8kHz", TALK_ID( 8, UNIT_KHZ) },) 562 + }; 563 + 521 564 /** 522 565 Shows the settings menu 523 566 */ ··· 531 574 ID2P(LANG_INTERPOLATION), 532 575 ID2P(LANG_SWAP_CHANNELS), 533 576 ID2P(LANG_MIKMOD_SURROUND), 577 + ID2P(LANG_MIKMOD_HQMIXER), 578 + ID2P(LANG_MIKMOD_SAMPLERATE), 534 579 #ifdef HAVE_ADJUSTABLE_CPU_FREQ 535 580 ID2P(LANG_CPU_BOOST) 536 581 #endif ··· 571 616 break; 572 617 573 618 case 5: 619 + rb->set_bool(rb->str(LANG_MIKMOD_HQMIXER), &(settings.hqmixer)); 620 + applysettings(); 621 + break; 622 + 623 + case 6: 624 + rb->set_option(rb->str(LANG_MIKMOD_SAMPLERATE), &(settings.sample_rate), INT, sr_names, 625 + HW_NUM_FREQ, NULL); 626 + applysettings(); 627 + break; 628 + 629 + #ifdef HAVE_ADJUSTABLE_CPU_FREQ 630 + case 7: 574 631 rb->set_bool(rb->str(LANG_CPU_BOOST), &(settings.boost)); 575 632 applysettings(); 576 633 break; 634 + #endif 577 635 578 636 case MENU_ATTACHED_USB: 579 637 return PLUGIN_USB_CONNECTED; ··· 675 733 } 676 734 677 735 #ifdef HAVE_ADJUSTABLE_CPU_FREQ 678 - if ( settings.boost ) 679 - rb->cpu_boost(true); 736 + rb->cpu_boost(settings.boost); 680 737 #endif 681 738 #ifdef USETHREADS 682 739 rb->queue_init(&thread_q, true); 683 740 if ((thread_id = rb->create_thread(thread, thread_stack, 684 - sizeof(thread_stack), 0, "render buffering thread" 741 + sizeof(thread_stack), 0, "render buffering thread" 685 742 IF_PRIO(, PRIORITY_PLAYBACK) 686 743 IF_COP(, CPU))) == 0) 687 744 { ··· 830 887 rb->lcd_setfont(FONT_SYSFIXED); 831 888 screenupdated = false; 832 889 break; 833 - 890 + 834 891 case ACTION_WPS_STOP: 835 892 quit = true; 836 893 break; 837 - 894 + 838 895 default: 839 896 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) 840 897 { ··· 850 907 rb->queue_delete(&thread_q); 851 908 #endif 852 909 #ifdef HAVE_ADJUSTABLE_CPU_FREQ 853 - if ( settings.boost ) 854 - rb->cpu_boost(false); 910 + rb->cpu_boost(false); 855 911 #endif 856 912 857 913 Player_Stop(); 858 914 Player_Free(module); 859 - 915 + 860 916 memset(gmbuf, '\0', sizeof(gmbuf)); 861 - 917 + 862 918 if ( retval == PLUGIN_OK && entries > 1 && !quit ) 863 919 { 864 920 retval = change_filename(DIR_NEXT); 865 921 } 866 - 922 + 867 923 return retval; 868 924 } 869 925 ··· 891 947 rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK); 892 948 rb->audio_set_output_source(AUDIO_SRC_PLAYBACK); 893 949 #endif 894 - rb->mixer_set_frequency(SAMPLE_RATE); 895 950 896 951 audio_buffer = rb->plugin_get_audio_buffer((size_t *)&audio_buffer_free); 897 - 952 + 898 953 rb->strcpy(np_file, parameter); 899 954 get_mod_list(); 900 955 if(!entries) { ··· 903 958 904 959 //add_pool(audio_buffer, audio_buffer_free); 905 960 init_memory_pool(audio_buffer_free, audio_buffer); 906 - 961 + 907 962 MikMod_RegisterDriver(&drv_nos); 908 963 MikMod_RegisterAllLoaders(); 909 964 MikMod_RegisterErrorHandler(mm_errorhandler); 910 965 911 - md_mixfreq = SAMPLE_RATE; 912 - 913 966 configfile_load(MIKMOD_CONFIGFILE, config, 914 967 ARRAYLEN(config), MIKMOD_SETTINGS_MINVERSION); 915 968 rb->memcpy(&old_settings, &settings, sizeof (settings)); 969 + 970 + /* If there's no configured rate, use the default */ 971 + if (settings.sample_rate == -1) { 972 + int i; 973 + for (i = 0 ; i < HW_NUM_FREQ ; i++) { 974 + if (rb->hw_freq_sampr[i] == SAMPLE_RATE) { 975 + settings.sample_rate = i; 976 + break; 977 + } 978 + } 979 + if (settings.sample_rate == -1) { 980 + settings.sample_rate = HW_NUM_FREQ -1; 981 + } 982 + } 983 + 916 984 applysettings(); 917 985 918 986 if (MikMod_Init("")) ··· 934 1002 935 1003 if (retval == PLUGIN_OK) 936 1004 { 937 - rb->splash(0, "Saving Settings"); 938 1005 if (rb->memcmp(&settings, &old_settings, sizeof (settings))) 939 1006 { 940 - configfile_save(MIKMOD_CONFIGFILE, config, 941 - ARRAYLEN(config), MIKMOD_SETTINGS_MINVERSION); 1007 + configfile_save(MIKMOD_CONFIGFILE, config, 1008 + ARRAYLEN(config), MIKMOD_SETTINGS_MINVERSION); 942 1009 } 943 1010 } 944 - 1011 + 945 1012 destroy_memory_pool(audio_buffer); 946 1013 947 1014 return retval;
+462 -363
apps/plugins/mikmod/mikmod.h
··· 1 - /* MikMod sound library 2 - (c) 1998, 1999, 2000 Miodrag Vallat and others - see file AUTHORS 3 - for complete list. 1 + /* MikMod sound library 2 + (c) 1998-2014 Miodrag Vallat and others - see the AUTHORS file 3 + for complete list. 4 4 5 - This library is free software; you can redistribute it and/or modify 6 - it under the terms of the GNU Library General Public License as 7 - published by the Free Software Foundation; either version 2 of 8 - the License, or (at your option) any later version. 9 - 10 - This program is distributed in the hope that it will be useful, 11 - but WITHOUT ANY WARRANTY; without even the implied warranty of 12 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 - GNU Library General Public License for more details. 14 - 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 17 - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 18 - 02111-1307, USA. 5 + This library is free software; you can redistribute it and/or modify 6 + it under the terms of the GNU Library General Public License as 7 + published by the Free Software Foundation; either version 2 of 8 + the License, or (at your option) any later version. 9 + 10 + This program is distributed in the hope that it will be useful, 11 + but WITHOUT ANY WARRANTY; without even the implied warranty of 12 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 + GNU Library General Public License for more details. 14 + 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 17 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 18 + 02111-1307, USA. 19 19 */ 20 20 21 21 /*============================================================================== 22 - 23 - $Id: mikmod.h.in,v 1.3 2005/03/30 19:09:21 realtech Exp $ 24 22 25 23 MikMod sound library include file 26 24 27 - ==============================================================================*/ 25 + ==============================================================================*/ 28 26 29 27 #ifndef _MIKMOD_H_ 30 28 #define _MIKMOD_H_ ··· 40 38 41 39 /* 42 40 * ========== Compiler magic for shared libraries 41 + * 42 + * ========== NOTE TO WINDOWS DEVELOPERS: 43 + * If you are compiling for Windows and will link to the static library 44 + * (libmikmod.a with MinGW, or mikmod_static.lib with MSVC or LCC, etc), 45 + * you must define MIKMOD_STATIC in your project. Otherwise, dllimport 46 + * will be assumed. 43 47 */ 44 - 45 - #if defined WIN32 && defined _DLL 46 - #ifdef DLL_EXPORTS 47 - #define MIKMODAPI __declspec(dllexport) 48 - #else 49 - #define MIKMODAPI __declspec(dllimport) 50 - #endif 48 + #if defined(_WIN32) || defined(__CYGWIN__) 49 + # if defined(MIKMOD_BUILD) && defined(DLL_EXPORT) /* building libmikmod as a dll for windows */ 50 + # define MIKMODAPI __declspec(dllexport) 51 + # elif defined(MIKMOD_BUILD) || defined(MIKMOD_STATIC) /* building or using static libmikmod for windows */ 52 + # define MIKMODAPI 53 + # else 54 + # define MIKMODAPI __declspec(dllimport) /* using libmikmod dll for windows */ 55 + # endif 56 + #elif defined(__OS2__) && defined(__WATCOMC__) 57 + # if defined(MIKMOD_BUILD) && defined(__SW_BD) /* building libmikmod as a dll for os/2 */ 58 + # define MIKMODAPI __declspec(dllexport) 59 + # else 60 + # define MIKMODAPI /* using dll or static libmikmod for os/2 */ 61 + # endif 62 + /* SYM_VISIBILITY should be defined if both the compiler 63 + * and the target support the visibility attributes. the 64 + * configury does that automatically. for the standalone 65 + * makefiles, etc, the developer should add the required 66 + * flags, i.e.: -DSYM_VISIBILITY -fvisibility=hidden */ 67 + #elif defined(MIKMOD_BUILD) && defined(SYM_VISIBILITY) 68 + # define MIKMODAPI __attribute__((visibility("default"))) 51 69 #else 52 - #define MIKMODAPI 70 + # define MIKMODAPI 53 71 #endif 54 72 55 73 /* 56 - * ========== Library version 74 + * ========== Library version 57 75 */ 58 76 59 77 #define LIBMIKMOD_VERSION_MAJOR 3L 60 - #define LIBMIKMOD_VERSION_MINOR 2L 61 - #define LIBMIKMOD_REVISION 0L 78 + #define LIBMIKMOD_VERSION_MINOR 3L 79 + #define LIBMIKMOD_REVISION 11L 62 80 63 81 #define LIBMIKMOD_VERSION \ 64 - ((LIBMIKMOD_VERSION_MAJOR<<16)| \ 65 - (LIBMIKMOD_VERSION_MINOR<< 8)| \ 66 - (LIBMIKMOD_REVISION)) 82 + ((LIBMIKMOD_VERSION_MAJOR<<16)| \ 83 + (LIBMIKMOD_VERSION_MINOR<< 8)| \ 84 + (LIBMIKMOD_REVISION)) 67 85 68 86 MIKMODAPI extern long MikMod_GetVersion(void); 69 87 70 88 /* 71 - * ========== Platform independent-type definitions 89 + * ========== Dependency platform headers 72 90 */ 73 - #if 0 74 - #ifdef WIN32 91 + 92 + #ifdef _WIN32 93 + #ifndef WIN32_LEAN_AND_MEAN 75 94 #define WIN32_LEAN_AND_MEAN 95 + #endif 76 96 #include <windows.h> 77 97 #include <io.h> 78 98 #include <mmsystem.h> 99 + #define _MIKMOD_WIN32 79 100 #endif 80 101 81 - #if defined(__OS2__)||defined(__EMX__) 102 + #if defined(__DJGPP__) || defined(MSDOS) || defined(__MSDOS__) || defined(__DOS__) 103 + #define _MIKMOD_DOS 104 + #endif 105 + 106 + #if defined(__OS2__) || defined(__EMX__) 82 107 #define INCL_DOSSEMAPHORES 83 108 #include <os2.h> 84 - #else 85 - typedef char CHAR; 109 + #include <io.h> 110 + #define _MIKMOD_OS2 86 111 #endif 112 + 113 + #if defined(__MORPHOS__) || defined(__AROS__) || defined(_AMIGA) || defined(__AMIGA__) || defined(__amigaos__) || defined(AMIGAOS) 114 + #include <exec/types.h> 115 + #define _MIKMOD_AMIGA 87 116 #endif 88 117 89 - typedef char CHAR; 118 + /* 119 + * ========== Platform independent-type definitions 120 + * (pain when it comes to cross-platform maintenance..) 121 + */ 90 122 123 + #if !(defined(_MIKMOD_OS2) || defined(_MIKMOD_WIN32)) 124 + typedef char CHAR; 125 + #endif 91 126 92 - #if defined(__arch64__) || defined(__alpha) || defined(__x86_64) || defined(__powerpc64__) 93 - /* 64 bit architectures */ 127 + /* int: 0=false, <>0 true -- 16 bits on Amiga, int-wide on others. */ 128 + #if !(defined(_MIKMOD_OS2) || defined(_MIKMOD_WIN32) || defined(_MIKMOD_AMIGA)) 129 + //typedef int int; 130 + #endif 94 131 95 - typedef signed char SBYTE; /* 1 byte, signed */ 96 - typedef unsigned char UBYTE; /* 1 byte, unsigned */ 97 - typedef signed short SWORD; /* 2 bytes, signed */ 98 - typedef unsigned short UWORD; /* 2 bytes, unsigned */ 99 - typedef signed int SLONG; /* 4 bytes, signed */ 100 - typedef unsigned int ULONG; /* 4 bytes, unsigned */ 101 - //typedef int BOOL; /* 0=false, <>0 true */ 132 + /* 1 byte, signed and unsigned: */ 133 + typedef signed char SBYTE; 134 + #ifndef _MIKMOD_AMIGA 135 + typedef unsigned char UBYTE; 136 + #endif 102 137 103 - #else 104 - /* 32 bit architectures */ 138 + /* 2 bytes, signed and unsigned: */ 139 + #if !(defined __LCC__ && defined _WIN32) 140 + typedef signed short int SWORD; 141 + #endif 142 + #if !((defined __LCC__ && defined _WIN32) || defined(_MIKMOD_AMIGA)) 143 + typedef unsigned short int UWORD; 144 + #endif 105 145 106 - typedef signed char SBYTE; /* 1 byte, signed */ 107 - typedef unsigned char UBYTE; /* 1 byte, unsigned */ 108 - typedef signed short SWORD; /* 2 bytes, signed */ 109 - typedef unsigned short UWORD; /* 2 bytes, unsigned */ 110 - typedef signed long SLONG; /* 4 bytes, signed */ 111 - #if !defined(__OS2__)&&!defined(__EMX__)&&!defined(WIN32) 112 - typedef unsigned long ULONG; /* 4 bytes, unsigned */ 113 - //typedef int BOOL; /* 0=false, <>0 true */ 146 + /* 4 bytes, signed and unsigned: */ 147 + #if defined(_LP64) || defined(__LP64__) || defined(__arch64__) || defined(__alpha) || defined(__x86_64) || defined(__powerpc64__) 148 + /* 64 bit architectures: */ 149 + typedef signed int SLONG; 150 + #if !(defined(_WIN32) || defined(_MIKMOD_AMIGA)) 151 + typedef unsigned int ULONG; 152 + #endif 153 + 154 + #else /* 32 bit architectures: */ 155 + typedef signed long int SLONG; 156 + #if !(defined(_MIKMOD_OS2) || defined(_MIKMOD_WIN32) || defined(_MIKMOD_AMIGA)) 157 + typedef unsigned long int ULONG; 114 158 #endif 115 159 #endif 116 160 161 + /* make sure types are of correct sizes: */ 162 + typedef int __mikmod_typetest [ 163 + ( 164 + (sizeof(SBYTE)==1) && (sizeof(UBYTE)==1) 165 + && (sizeof(SWORD)==2) && (sizeof(UWORD)==2) 166 + && (sizeof(SLONG)==4) && (sizeof(ULONG)==4) 167 + #ifndef _MIKMOD_AMIGA 168 + && (sizeof(int) == sizeof(int)) 169 + #endif 170 + && (sizeof(CHAR) == sizeof(char)) 171 + ) * 2 - 1 ]; 172 + 117 173 /* 118 - * ========== Error codes 174 + * ========== Error codes 119 175 */ 120 176 121 177 enum { 122 - MMERR_OPENING_FILE = 1, 123 - MMERR_OUT_OF_MEMORY, 124 - MMERR_DYNAMIC_LINKING, 178 + MMERR_OPENING_FILE = 1, 179 + MMERR_OUT_OF_MEMORY, 180 + MMERR_DYNAMIC_LINKING, 125 181 126 - MMERR_SAMPLE_TOO_BIG, 127 - MMERR_OUT_OF_HANDLES, 128 - MMERR_UNKNOWN_WAVE_TYPE, 182 + MMERR_SAMPLE_TOO_BIG, 183 + MMERR_OUT_OF_HANDLES, 184 + MMERR_UNKNOWN_WAVE_TYPE, 129 185 130 - MMERR_LOADING_PATTERN, 131 - MMERR_LOADING_TRACK, 132 - MMERR_LOADING_HEADER, 133 - MMERR_LOADING_SAMPLEINFO, 134 - MMERR_NOT_A_MODULE, 135 - MMERR_NOT_A_STREAM, 136 - MMERR_MED_SYNTHSAMPLES, 137 - MMERR_ITPACK_INVALID_DATA, 186 + MMERR_LOADING_PATTERN, 187 + MMERR_LOADING_TRACK, 188 + MMERR_LOADING_HEADER, 189 + MMERR_LOADING_SAMPLEINFO, 190 + MMERR_NOT_A_MODULE, 191 + MMERR_NOT_A_STREAM, 192 + MMERR_MED_SYNTHSAMPLES, 193 + MMERR_ITPACK_INVALID_DATA, 138 194 139 - MMERR_DETECTING_DEVICE, 140 - MMERR_INVALID_DEVICE, 141 - MMERR_INITIALIZING_MIXER, 142 - MMERR_OPENING_AUDIO, 143 - MMERR_8BIT_ONLY, 144 - MMERR_16BIT_ONLY, 145 - MMERR_STEREO_ONLY, 146 - MMERR_ULAW, 147 - MMERR_NON_BLOCK, 195 + MMERR_DETECTING_DEVICE, 196 + MMERR_INVALID_DEVICE, 197 + MMERR_INITIALIZING_MIXER, 198 + MMERR_OPENING_AUDIO, 199 + MMERR_8BIT_ONLY, 200 + MMERR_16BIT_ONLY, 201 + MMERR_STEREO_ONLY, 202 + MMERR_ULAW, 203 + MMERR_NON_BLOCK, 148 204 149 - MMERR_AF_AUDIO_PORT, 205 + MMERR_AF_AUDIO_PORT, 150 206 151 - MMERR_AIX_CONFIG_INIT, 152 - MMERR_AIX_CONFIG_CONTROL, 153 - MMERR_AIX_CONFIG_START, 207 + MMERR_AIX_CONFIG_INIT, 208 + MMERR_AIX_CONFIG_CONTROL, 209 + MMERR_AIX_CONFIG_START, 154 210 155 - MMERR_GUS_SETTINGS, 156 - MMERR_GUS_RESET, 157 - MMERR_GUS_TIMER, 211 + MMERR_GUS_SETTINGS, 212 + MMERR_GUS_RESET, 213 + MMERR_GUS_TIMER, 158 214 159 - MMERR_HP_SETSAMPLESIZE, 160 - MMERR_HP_SETSPEED, 161 - MMERR_HP_CHANNELS, 162 - MMERR_HP_AUDIO_OUTPUT, 163 - MMERR_HP_AUDIO_DESC, 164 - MMERR_HP_BUFFERSIZE, 215 + MMERR_HP_SETSAMPLESIZE, 216 + MMERR_HP_SETSPEED, 217 + MMERR_HP_CHANNELS, 218 + MMERR_HP_AUDIO_OUTPUT, 219 + MMERR_HP_AUDIO_DESC, 220 + MMERR_HP_BUFFERSIZE, 165 221 166 - MMERR_OSS_SETFRAGMENT, 167 - MMERR_OSS_SETSAMPLESIZE, 168 - MMERR_OSS_SETSTEREO, 169 - MMERR_OSS_SETSPEED, 222 + MMERR_OSS_SETFRAGMENT, 223 + MMERR_OSS_SETSAMPLESIZE, 224 + MMERR_OSS_SETSTEREO, 225 + MMERR_OSS_SETSPEED, 170 226 171 - MMERR_SGI_SPEED, 172 - MMERR_SGI_16BIT, 173 - MMERR_SGI_8BIT, 174 - MMERR_SGI_STEREO, 175 - MMERR_SGI_MONO, 227 + MMERR_SGI_SPEED, 228 + MMERR_SGI_16BIT, 229 + MMERR_SGI_8BIT, 230 + MMERR_SGI_STEREO, 231 + MMERR_SGI_MONO, 176 232 177 - MMERR_SUN_INIT, 233 + MMERR_SUN_INIT, 178 234 179 - MMERR_OS2_MIXSETUP, 180 - MMERR_OS2_SEMAPHORE, 181 - MMERR_OS2_TIMER, 182 - MMERR_OS2_THREAD, 235 + MMERR_OS2_MIXSETUP, 236 + MMERR_OS2_SEMAPHORE, 237 + MMERR_OS2_TIMER, 238 + MMERR_OS2_THREAD, 183 239 184 - MMERR_DS_PRIORITY, 185 - MMERR_DS_BUFFER, 186 - MMERR_DS_FORMAT, 187 - MMERR_DS_NOTIFY, 188 - MMERR_DS_EVENT, 189 - MMERR_DS_THREAD, 190 - MMERR_DS_UPDATE, 240 + MMERR_DS_PRIORITY, 241 + MMERR_DS_BUFFER, 242 + MMERR_DS_FORMAT, 243 + MMERR_DS_NOTIFY, 244 + MMERR_DS_EVENT, 245 + MMERR_DS_THREAD, 246 + MMERR_DS_UPDATE, 191 247 192 - MMERR_WINMM_HANDLE, 193 - MMERR_WINMM_ALLOCATED, 194 - MMERR_WINMM_DEVICEID, 195 - MMERR_WINMM_FORMAT, 196 - MMERR_WINMM_UNKNOWN, 248 + MMERR_WINMM_HANDLE, 249 + MMERR_WINMM_ALLOCATED, 250 + MMERR_WINMM_DEVICEID, 251 + MMERR_WINMM_FORMAT, 252 + MMERR_WINMM_UNKNOWN, 197 253 198 - MMERR_MAC_SPEED, 199 - MMERR_MAC_START, 254 + MMERR_MAC_SPEED, 255 + MMERR_MAC_START, 200 256 201 257 MMERR_OSX_UNKNOWN_DEVICE, 202 258 MMERR_OSX_BAD_PROPERTY, ··· 205 261 MMERR_OSX_BUFFER_ALLOC, 206 262 MMERR_OSX_ADD_IO_PROC, 207 263 MMERR_OSX_DEVICE_START, 208 - MMERR_OSX_PTHREAD, 264 + MMERR_OSX_PTHREAD, 209 265 210 - MMERR_DOSWSS_STARTDMA, 211 - MMERR_DOSSB_STARTDMA, 212 - 213 - MMERR_MAX 266 + MMERR_DOSWSS_STARTDMA, 267 + MMERR_DOSSB_STARTDMA, 268 + 269 + MMERR_NO_FLOAT32,/* should actually be after MMERR_ULAW or something */ 270 + 271 + MMERR_OPENAL_CREATECTX, 272 + MMERR_OPENAL_CTXCURRENT, 273 + MMERR_OPENAL_GENBUFFERS, 274 + MMERR_OPENAL_GENSOURCES, 275 + MMERR_OPENAL_SOURCE, 276 + MMERR_OPENAL_QUEUEBUFFERS, 277 + MMERR_OPENAL_UNQUEUEBUFFERS, 278 + MMERR_OPENAL_BUFFERDATA, 279 + MMERR_OPENAL_GETSOURCE, 280 + MMERR_OPENAL_SOURCEPLAY, 281 + MMERR_OPENAL_SOURCESTOP, 282 + 283 + MMERR_ALSA_NOCONFIG, 284 + MMERR_ALSA_SETPARAMS, 285 + MMERR_ALSA_SETFORMAT, 286 + MMERR_ALSA_SETRATE, 287 + MMERR_ALSA_SETCHANNELS, 288 + MMERR_ALSA_BUFFERSIZE, 289 + MMERR_ALSA_PCM_START, 290 + MMERR_ALSA_PCM_WRITE, 291 + MMERR_ALSA_PCM_RECOVER, 292 + 293 + MMERR_SNDIO_SETPARAMS, 294 + MMERR_SNDIO_BADPARAMS, 295 + 296 + MMERR_MAX 214 297 }; 215 298 216 299 /* 217 - * ========== Error handling 300 + * ========== Error handling 218 301 */ 219 302 220 303 typedef void (MikMod_handler)(void); ··· 222 305 223 306 MIKMODAPI extern int MikMod_errno; 224 307 MIKMODAPI extern int MikMod_critical; 225 - MIKMODAPI extern char *MikMod_strerror(int); 308 + MIKMODAPI extern const char *MikMod_strerror(int); 226 309 227 310 MIKMODAPI extern MikMod_handler_t MikMod_RegisterErrorHandler(MikMod_handler_t); 228 311 229 312 /* 230 - * ========== Library initialization and core functions 313 + * ========== Library initialization and core functions 231 314 */ 232 315 233 316 struct MDRIVER; ··· 236 319 237 320 MIKMODAPI extern CHAR* MikMod_InfoDriver(void); 238 321 MIKMODAPI extern void MikMod_RegisterDriver(struct MDRIVER*); 239 - MIKMODAPI extern int MikMod_DriverFromAlias(CHAR*); 322 + MIKMODAPI extern int MikMod_DriverFromAlias(const CHAR*); 240 323 MIKMODAPI extern struct MDRIVER *MikMod_DriverByOrdinal(int); 241 324 242 - MIKMODAPI extern int MikMod_Init(CHAR*); 325 + MIKMODAPI extern int MikMod_Init(const CHAR*); 243 326 MIKMODAPI extern void MikMod_Exit(void); 244 - MIKMODAPI extern int MikMod_Reset(CHAR*); 245 - MIKMODAPI extern int MikMod_SetNumVoices(int,int); 327 + MIKMODAPI extern int MikMod_Reset(const CHAR*); 328 + MIKMODAPI extern int MikMod_SetNumVoices(int,int); 246 329 MIKMODAPI extern int MikMod_Active(void); 247 - MIKMODAPI extern int MikMod_EnableOutput(void); 330 + MIKMODAPI extern int MikMod_EnableOutput(void); 248 331 MIKMODAPI extern void MikMod_DisableOutput(void); 249 332 MIKMODAPI extern void MikMod_Update(void); 250 333 ··· 253 336 MIKMODAPI extern void MikMod_Unlock(void); 254 337 255 338 MIKMODAPI extern void* MikMod_malloc(size_t); 256 - MIKMODAPI extern void* MikMod_realloc(void *, size_t); 257 339 MIKMODAPI extern void* MikMod_calloc(size_t,size_t); 258 - MIKMODAPI extern void MikMod_free(void*); 340 + MIKMODAPI extern void* MikMod_realloc(void*,size_t); 341 + MIKMODAPI extern CHAR* MikMod_strdup(const CHAR*); 342 + MIKMODAPI extern void MikMod_free(void*); /* frees if ptr != NULL */ 259 343 260 344 /* 261 - * ========== Reader, Writer 345 + * ========== Reader, Writer 262 346 */ 263 347 264 348 typedef struct MREADER { 265 - int (*Seek)(struct MREADER*,long,int); 266 - long (*Tell)(struct MREADER*); 267 - int (*Read)(struct MREADER*,void*,size_t); 268 - int (*Get)(struct MREADER*); 269 - int (*Eof)(struct MREADER*); 270 - long iobase; 271 - long prev_iobase; 349 + int (*Seek)(struct MREADER*,long,int); 350 + long (*Tell)(struct MREADER*); 351 + int (*Read)(struct MREADER*,void*,size_t); 352 + int (*Get)(struct MREADER*); 353 + int (*Eof)(struct MREADER*); 354 + long iobase; 355 + long prev_iobase; 272 356 } MREADER; 273 357 274 358 typedef struct MWRITER { 275 - int (*Seek)(struct MWRITER*,long,int); 276 - long (*Tell)(struct MWRITER*); 277 - int (*Write)(struct MWRITER*,void*,size_t); 278 - int (*Put)(struct MWRITER*,int); 359 + int (*Seek)(struct MWRITER*, long, int); 360 + long (*Tell)(struct MWRITER*); 361 + int (*Write)(struct MWRITER*, const void*, size_t); 362 + int (*Put)(struct MWRITER*, int); 279 363 } MWRITER; 280 364 281 365 /* 282 - * ========== Samples 366 + * ========== Samples 283 367 */ 284 368 285 369 /* Sample playback should not be interrupted */ ··· 291 375 #define SF_SIGNED 0x0004 292 376 #define SF_BIG_ENDIAN 0x0008 293 377 #define SF_DELTA 0x0010 294 - #define SF_ITPACKED 0x0020 378 + #define SF_ITPACKED 0x0020 295 379 296 - #define SF_FORMATMASK 0x003F 380 + #define SF_FORMATMASK 0x003F 297 381 298 382 /* General Playback flags */ 299 383 ··· 302 386 #define SF_REVERSE 0x0400 303 387 #define SF_SUSTAIN 0x0800 304 388 305 - #define SF_PLAYBACKMASK 0x0C00 389 + #define SF_PLAYBACKMASK 0x0C00 306 390 307 391 /* Module-only Playback Flags */ 308 392 309 - #define SF_OWNPAN 0x1000 393 + #define SF_OWNPAN 0x1000 310 394 #define SF_UST_LOOP 0x2000 311 395 312 - #define SF_EXTRAPLAYBACKMASK 0x3000 396 + #define SF_EXTRAPLAYBACKMASK 0x3000 313 397 314 398 /* Panning constants */ 315 - #define PAN_LEFT 0 316 - #define PAN_HALFLEFT 64 317 - #define PAN_CENTER 128 318 - #define PAN_HALFRIGHT 192 319 - #define PAN_RIGHT 255 320 - #define PAN_SURROUND 512 /* panning value for Dolby Surround */ 399 + #define PAN_LEFT 0 400 + #define PAN_HALFLEFT 64 401 + #define PAN_CENTER 128 402 + #define PAN_HALFRIGHT 192 403 + #define PAN_RIGHT 255 404 + #define PAN_SURROUND 512 /* panning value for Dolby Surround */ 321 405 322 406 typedef struct SAMPLE { 323 - SWORD panning; /* panning (0-255 or PAN_SURROUND) */ 324 - ULONG speed; /* Base playing speed/frequency of note */ 325 - UBYTE volume; /* volume 0-64 */ 326 - UWORD inflags; /* sample format on disk */ 327 - UWORD flags; /* sample format in memory */ 328 - ULONG length; /* length of sample (in samples!) */ 329 - ULONG loopstart; /* repeat position (relative to start, in samples) */ 330 - ULONG loopend; /* repeat end */ 331 - ULONG susbegin; /* sustain loop begin (in samples) \ Not Supported */ 332 - ULONG susend; /* sustain loop end / Yet! */ 407 + SWORD panning; /* panning (0-255 or PAN_SURROUND) */ 408 + ULONG speed; /* Base playing speed/frequency of note */ 409 + UBYTE volume; /* volume 0-64 */ 410 + UWORD inflags; /* sample format on disk */ 411 + UWORD flags; /* sample format in memory */ 412 + ULONG length; /* length of sample (in samples!) */ 413 + ULONG loopstart; /* repeat position (relative to start, in samples) */ 414 + ULONG loopend; /* repeat end */ 415 + ULONG susbegin; /* sustain loop begin (in samples) \ Not Supported */ 416 + ULONG susend; /* sustain loop end / Yet! */ 333 417 334 - /* Variables used by the module player only! (ignored for sound effects) */ 335 - UBYTE globvol; /* global volume */ 336 - UBYTE vibflags; /* autovibrato flag stuffs */ 337 - UBYTE vibtype; /* Vibratos moved from INSTRUMENT to SAMPLE */ 338 - UBYTE vibsweep; 339 - UBYTE vibdepth; 340 - UBYTE vibrate; 341 - CHAR* samplename; /* name of the sample */ 418 + /* Variables used by the module player only! (ignored for sound effects) */ 419 + UBYTE globvol; /* global volume */ 420 + UBYTE vibflags; /* autovibrato flag stuffs */ 421 + UBYTE vibtype; /* Vibratos moved from INSTRUMENT to SAMPLE */ 422 + UBYTE vibsweep; 423 + UBYTE vibdepth; 424 + UBYTE vibrate; 425 + CHAR* samplename; /* name of the sample */ 342 426 343 - /* Values used internally only */ 344 - UWORD avibpos; /* autovibrato pos [player use] */ 345 - UBYTE divfactor; /* for sample scaling, maintains proper period slides */ 346 - ULONG seekpos; /* seek position in file */ 347 - SWORD handle; /* sample handle used by individual drivers */ 348 - void (*onfree)(void *ctx); /* called from Sample_Free if not NULL */ 349 - void *ctx; /* context passed to previous function*/ 427 + /* Values used internally only */ 428 + UWORD avibpos; /* autovibrato pos [player use] */ 429 + UBYTE divfactor; /* for sample scaling, maintains proper period slides */ 430 + ULONG seekpos; /* seek position in file */ 431 + SWORD handle; /* sample handle used by individual drivers */ 432 + void (*onfree)(void *ctx); /* called from Sample_Free if not NULL */ 433 + void *ctx; /* context passed to previous function*/ 350 434 } SAMPLE; 351 435 352 436 /* Sample functions */ 353 437 354 - MIKMODAPI extern SAMPLE *Sample_LoadRaw(CHAR *,ULONG rate, ULONG channel, ULONG flags); 438 + MIKMODAPI extern SAMPLE *Sample_LoadRaw(const CHAR *,ULONG rate, ULONG channel, ULONG flags); 355 439 MIKMODAPI extern SAMPLE *Sample_LoadRawFP(int fp,ULONG rate,ULONG channel, ULONG flags); 356 440 MIKMODAPI extern SAMPLE *Sample_LoadRawMem(const char *buf, int len, ULONG rate, ULONG channel, ULONG flags); 357 441 MIKMODAPI extern SAMPLE *Sample_LoadRawGeneric(MREADER*reader,ULONG rate, ULONG channel, ULONG flags); 358 442 359 - MIKMODAPI extern SAMPLE *Sample_Load(CHAR*); 443 + MIKMODAPI extern SAMPLE *Sample_Load(const CHAR*); 360 444 MIKMODAPI extern SAMPLE *Sample_LoadFP(int); 361 445 MIKMODAPI extern SAMPLE *Sample_LoadMem(const char *buf, int len); 362 446 MIKMODAPI extern SAMPLE *Sample_LoadGeneric(MREADER*); ··· 376 460 MIKMODAPI extern ULONG Voice_RealVolume(SBYTE); 377 461 378 462 /* 379 - * ========== Internal module representation (UniMod) 463 + * ========== Internal module representation (UniMod) 380 464 */ 381 465 382 466 /* 383 - Instrument definition - for information only, the only field which may be 384 - of use in user programs is the name field 467 + Instrument definition - for information only, the only field which may be 468 + of use in user programs is the name field 385 469 */ 386 470 387 471 /* Instrument note count */ ··· 389 473 390 474 /* Envelope point */ 391 475 typedef struct ENVPT { 392 - SWORD pos; 393 - SWORD val; 476 + SWORD pos; 477 + SWORD val; 394 478 } ENVPT; 395 479 396 480 /* Envelope point count */ ··· 398 482 399 483 /* Instrument structure */ 400 484 typedef struct INSTRUMENT { 401 - CHAR* insname; 485 + CHAR* insname; 402 486 403 - UBYTE flags; 404 - UWORD samplenumber[INSTNOTES]; 405 - UBYTE samplenote[INSTNOTES]; 487 + UBYTE flags; 488 + UWORD samplenumber[INSTNOTES]; 489 + UBYTE samplenote[INSTNOTES]; 406 490 407 - UBYTE nnatype; 408 - UBYTE dca; /* duplicate check action */ 409 - UBYTE dct; /* duplicate check type */ 410 - UBYTE globvol; 411 - UWORD volfade; 412 - SWORD panning; /* instrument-based panning var */ 491 + UBYTE nnatype; 492 + UBYTE dca; /* duplicate check action */ 493 + UBYTE dct; /* duplicate check type */ 494 + UBYTE globvol; 495 + UWORD volfade; 496 + SWORD panning; /* instrument-based panning var */ 413 497 414 - UBYTE pitpansep; /* pitch pan separation (0 to 255) */ 415 - UBYTE pitpancenter; /* pitch pan center (0 to 119) */ 416 - UBYTE rvolvar; /* random volume varations (0 - 100%) */ 417 - UBYTE rpanvar; /* random panning varations (0 - 100%) */ 498 + UBYTE pitpansep; /* pitch pan separation (0 to 255) */ 499 + UBYTE pitpancenter; /* pitch pan center (0 to 119) */ 500 + UBYTE rvolvar; /* random volume varations (0 - 100%) */ 501 + UBYTE rpanvar; /* random panning varations (0 - 100%) */ 418 502 419 - /* volume envelope */ 420 - UBYTE volflg; /* bit 0: on 1: sustain 2: loop */ 421 - UBYTE volpts; 422 - UBYTE volsusbeg; 423 - UBYTE volsusend; 424 - UBYTE volbeg; 425 - UBYTE volend; 426 - ENVPT volenv[ENVPOINTS]; 427 - /* panning envelope */ 428 - UBYTE panflg; /* bit 0: on 1: sustain 2: loop */ 429 - UBYTE panpts; 430 - UBYTE pansusbeg; 431 - UBYTE pansusend; 432 - UBYTE panbeg; 433 - UBYTE panend; 434 - ENVPT panenv[ENVPOINTS]; 435 - /* pitch envelope */ 436 - UBYTE pitflg; /* bit 0: on 1: sustain 2: loop */ 437 - UBYTE pitpts; 438 - UBYTE pitsusbeg; 439 - UBYTE pitsusend; 440 - UBYTE pitbeg; 441 - UBYTE pitend; 442 - ENVPT pitenv[ENVPOINTS]; 503 + /* volume envelope */ 504 + UBYTE volflg; /* bit 0: on 1: sustain 2: loop */ 505 + UBYTE volpts; 506 + UBYTE volsusbeg; 507 + UBYTE volsusend; 508 + UBYTE volbeg; 509 + UBYTE volend; 510 + ENVPT volenv[ENVPOINTS]; 511 + /* panning envelope */ 512 + UBYTE panflg; /* bit 0: on 1: sustain 2: loop */ 513 + UBYTE panpts; 514 + UBYTE pansusbeg; 515 + UBYTE pansusend; 516 + UBYTE panbeg; 517 + UBYTE panend; 518 + ENVPT panenv[ENVPOINTS]; 519 + /* pitch envelope */ 520 + UBYTE pitflg; /* bit 0: on 1: sustain 2: loop */ 521 + UBYTE pitpts; 522 + UBYTE pitsusbeg; 523 + UBYTE pitsusend; 524 + UBYTE pitbeg; 525 + UBYTE pitend; 526 + ENVPT pitenv[ENVPOINTS]; 443 527 } INSTRUMENT; 444 528 445 529 struct MP_CONTROL; 446 530 struct MP_VOICE; 447 531 448 532 /* 449 - Module definition 533 + Module definition 450 534 */ 451 535 452 536 /* maximum master channels supported */ 453 - #define UF_MAXCHAN 64 537 + #define UF_MAXCHAN 64 454 538 455 539 /* Module flags */ 456 - #define UF_XMPERIODS 0x0001 /* XM periods / finetuning */ 457 - #define UF_LINEAR 0x0002 /* LINEAR periods (UF_XMPERIODS must be set) */ 458 - #define UF_INST 0x0004 /* Instruments are used */ 459 - #define UF_NNA 0x0008 /* IT: NNA used, set numvoices rather 460 - than numchn */ 461 - #define UF_S3MSLIDES 0x0010 /* uses old S3M volume slides */ 462 - #define UF_BGSLIDES 0x0020 /* continue volume slides in the background */ 463 - #define UF_HIGHBPM 0x0040 /* MED: can use >255 bpm */ 464 - #define UF_NOWRAP 0x0080 /* XM-type (i.e. illogical) pattern break 465 - semantics */ 466 - #define UF_ARPMEM 0x0100 /* IT: need arpeggio memory */ 467 - #define UF_FT2QUIRKS 0x0200 /* emulate some FT2 replay quirks */ 468 - #define UF_PANNING 0x0400 /* module uses panning effects or have 469 - non-tracker default initial panning */ 540 + #define UF_XMPERIODS 0x0001 /* XM periods / finetuning */ 541 + #define UF_LINEAR 0x0002 /* LINEAR periods (UF_XMPERIODS must be set) */ 542 + #define UF_INST 0x0004 /* Instruments are used */ 543 + #define UF_NNA 0x0008 /* IT: NNA used, set numvoices rather 544 + than numchn */ 545 + #define UF_S3MSLIDES 0x0010 /* uses old S3M volume slides */ 546 + #define UF_BGSLIDES 0x0020 /* continue volume slides in the background */ 547 + #define UF_HIGHBPM 0x0040 /* MED: can use >255 bpm */ 548 + #define UF_NOWRAP 0x0080 /* XM-type (i.e. illogical) pattern break 549 + semantics */ 550 + #define UF_ARPMEM 0x0100 /* IT: need arpeggio memory */ 551 + #define UF_FT2QUIRKS 0x0200 /* emulate some FT2 replay quirks */ 552 + #define UF_PANNING 0x0400 /* module uses panning effects or have 553 + non-tracker default initial panning */ 470 554 471 555 typedef struct MODULE { 472 - /* general module information */ 473 - CHAR* songname; /* name of the song */ 474 - CHAR* modtype; /* string type of module loaded */ 475 - CHAR* comment; /* module comments */ 556 + /* general module information */ 557 + CHAR* songname; /* name of the song */ 558 + CHAR* modtype; /* string type of module loaded */ 559 + CHAR* comment; /* module comments */ 476 560 477 - UWORD flags; /* See module flags above */ 478 - UBYTE numchn; /* number of module channels */ 479 - UBYTE numvoices; /* max # voices used for full NNA playback */ 480 - UWORD numpos; /* number of positions in this song */ 481 - UWORD numpat; /* number of patterns in this song */ 482 - UWORD numins; /* number of instruments */ 483 - UWORD numsmp; /* number of samples */ 484 - struct INSTRUMENT* instruments; /* all instruments */ 485 - struct SAMPLE* samples; /* all samples */ 486 - UBYTE realchn; /* real number of channels used */ 487 - UBYTE totalchn; /* total number of channels used (incl NNAs) */ 561 + UWORD flags; /* See module flags above */ 562 + UBYTE numchn; /* number of module channels */ 563 + UBYTE numvoices; /* max # voices used for full NNA playback */ 564 + UWORD numpos; /* number of positions in this song */ 565 + UWORD numpat; /* number of patterns in this song */ 566 + UWORD numins; /* number of instruments */ 567 + UWORD numsmp; /* number of samples */ 488 568 489 - /* playback settings */ 490 - UWORD reppos; /* restart position */ 491 - UBYTE initspeed; /* initial song speed */ 492 - UWORD inittempo; /* initial song tempo */ 493 - UBYTE initvolume; /* initial global volume (0 - 128) */ 494 - UWORD panning[UF_MAXCHAN]; /* panning positions */ 495 - UBYTE chanvol[UF_MAXCHAN]; /* channel positions */ 496 - UWORD bpm; /* current beats-per-minute speed */ 497 - UWORD sngspd; /* current song speed */ 498 - SWORD volume; /* song volume (0-128) (or user volume) */ 569 + struct INSTRUMENT* instruments; /* all instruments */ 570 + struct SAMPLE* samples; /* all samples */ 499 571 500 - int extspd; /* extended speed flag (default enabled) */ 501 - int panflag; /* panning flag (default enabled) */ 502 - int wrap; /* wrap module ? (default disabled) */ 503 - int loop; /* allow module to loop ? (default enabled) */ 504 - int fadeout; /* volume fade out during last pattern */ 572 + UBYTE realchn; /* real number of channels used */ 573 + UBYTE totalchn; /* total number of channels used (incl NNAs) */ 505 574 506 - UWORD patpos; /* current row number */ 507 - SWORD sngpos; /* current song position */ 508 - ULONG sngtime; /* current song time in 2^-10 seconds */ 575 + /* playback settings */ 576 + UWORD reppos; /* restart position */ 577 + UBYTE initspeed; /* initial song speed */ 578 + UWORD inittempo; /* initial song tempo */ 579 + UBYTE initvolume; /* initial global volume (0 - 128) */ 580 + UWORD panning[UF_MAXCHAN]; /* panning positions */ 581 + UBYTE chanvol[UF_MAXCHAN]; /* channel positions */ 582 + UWORD bpm; /* current beats-per-minute speed */ 583 + UWORD sngspd; /* current song speed */ 584 + SWORD volume; /* song volume (0-128) (or user volume) */ 509 585 510 - SWORD relspd; /* relative speed factor */ 586 + int extspd; /* extended speed flag (default enabled) */ 587 + int panflag; /* panning flag (default enabled) */ 588 + int wrap; /* wrap module ? (default disabled) */ 589 + int loop; /* allow module to loop ? (default enabled) */ 590 + int fadeout; /* volume fade out during last pattern */ 511 591 512 - /* internal module representation */ 513 - UWORD numtrk; /* number of tracks */ 514 - UBYTE** tracks; /* array of numtrk pointers to tracks */ 515 - UWORD* patterns; /* array of Patterns */ 516 - UWORD* pattrows; /* array of number of rows for each pattern */ 517 - UWORD* positions; /* all positions */ 592 + UWORD patpos; /* current row number */ 593 + SWORD sngpos; /* current song position */ 594 + ULONG sngtime; /* current song time in 2^-10 seconds */ 518 595 519 - int forbid; /* if true, no player update! */ 520 - UWORD numrow; /* number of rows on current pattern */ 521 - UWORD vbtick; /* tick counter (counts from 0 to sngspd) */ 522 - UWORD sngremainder;/* used for song time computation */ 596 + SWORD relspd; /* relative speed factor */ 597 + 598 + /* internal module representation */ 599 + UWORD numtrk; /* number of tracks */ 600 + UBYTE** tracks; /* array of numtrk pointers to tracks */ 601 + UWORD* patterns; /* array of Patterns */ 602 + UWORD* pattrows; /* array of number of rows for each pattern */ 603 + UWORD* positions; /* all positions */ 604 + 605 + int forbid; /* if true, no player update! */ 606 + UWORD numrow; /* number of rows on current pattern */ 607 + UWORD vbtick; /* tick counter (counts from 0 to sngspd) */ 608 + UWORD sngremainder;/* used for song time computation */ 523 609 524 - struct MP_CONTROL* control; /* Effects Channel info (size pf->numchn) */ 525 - struct MP_VOICE* voice; /* Audio Voice information (size md_numchn) */ 610 + struct MP_CONTROL* control; /* Effects Channel info (size pf->numchn) */ 611 + struct MP_VOICE* voice; /* Audio Voice information (size md_numchn) */ 526 612 527 - UBYTE globalslide; /* global volume slide rate */ 528 - UBYTE pat_repcrazy;/* module has just looped to position -1 */ 529 - UWORD patbrk; /* position where to start a new pattern */ 530 - UBYTE patdly; /* patterndelay counter (command memory) */ 531 - UBYTE patdly2; /* patterndelay counter (real one) */ 532 - SWORD posjmp; /* flag to indicate a jump is needed... */ 533 - UWORD bpmlimit; /* threshold to detect bpm or speed values */ 613 + UBYTE globalslide; /* global volume slide rate */ 614 + UBYTE pat_repcrazy;/* module has just looped to position -1 */ 615 + UWORD patbrk; /* position where to start a new pattern */ 616 + UBYTE patdly; /* patterndelay counter (command memory) */ 617 + UBYTE patdly2; /* patterndelay counter (real one) */ 618 + SWORD posjmp; /* flag to indicate a jump is needed... */ 619 + UWORD bpmlimit; /* threshold to detect bpm or speed values */ 534 620 } MODULE; 535 621 536 622 537 623 /* This structure is used to query current playing voices status */ 538 624 typedef struct VOICEINFO { 539 - INSTRUMENT* i; /* Current channel instrument */ 540 - SAMPLE* s; /* Current channel sample */ 541 - SWORD panning; /* panning position */ 542 - SBYTE volume; /* channel's "global" volume (0..64) */ 543 - UWORD period; /* period to play the sample at */ 544 - UBYTE kick; /* if true = sample has been restarted */ 625 + INSTRUMENT* i; /* Current channel instrument */ 626 + SAMPLE* s; /* Current channel sample */ 627 + SWORD panning; /* panning position */ 628 + SBYTE volume; /* channel's "global" volume (0..64) */ 629 + UWORD period; /* period to play the sample at */ 630 + UBYTE kick; /* if true = sample has been restarted */ 545 631 } VOICEINFO; 546 632 547 633 /* 548 - * ========== Module loaders 634 + * ========== Module loaders 549 635 */ 550 636 551 637 struct MLOADER; ··· 572 658 MIKMODAPI extern struct MLOADER load_stx; /* STMIK 0.2 (by Future Crew) */ 573 659 MIKMODAPI extern struct MLOADER load_s3m; /* ScreamTracker 3 (by Future Crew) */ 574 660 MIKMODAPI extern struct MLOADER load_ult; /* UltraTracker (by MAS) */ 661 + MIKMODAPI extern struct MLOADER load_umx; /* Unreal UMX container of Epic Games */ 575 662 MIKMODAPI extern struct MLOADER load_uni; /* MikMod and APlayer internal module format */ 576 663 MIKMODAPI extern struct MLOADER load_xm; /* FastTracker 2 (by Triton) */ 577 664 578 665 /* 579 - * ========== Module player 666 + * ========== Module player 580 667 */ 581 668 582 - MIKMODAPI extern MODULE* Player_Load(CHAR*,int,int); 669 + MIKMODAPI extern MODULE* Player_Load(const CHAR*,int,int); 583 670 MIKMODAPI extern MODULE* Player_LoadFP(int,int,int); 584 671 MIKMODAPI extern MODULE* Player_LoadMem(const char *buffer,int len,int maxchan,int curious); 585 672 MIKMODAPI extern MODULE* Player_LoadGeneric(MREADER*,int,int); 586 - MIKMODAPI extern CHAR* Player_LoadTitle(CHAR*); 673 + MIKMODAPI extern CHAR* Player_LoadTitle(const CHAR*); 587 674 MIKMODAPI extern CHAR* Player_LoadTitleFP(int); 588 675 MIKMODAPI extern CHAR* Player_LoadTitleMem(const char *buffer,int len); 589 676 MIKMODAPI extern CHAR* Player_LoadTitleGeneric(MREADER*); ··· 607 694 MIKMODAPI extern void Player_ToggleMute(SLONG,...); 608 695 MIKMODAPI extern int Player_GetChannelVoice(UBYTE); 609 696 MIKMODAPI extern UWORD Player_GetChannelPeriod(UBYTE); 610 - MIKMODAPI extern int Player_QueryVoices(UWORD numvoices, VOICEINFO *vinfo); 697 + MIKMODAPI extern int Player_QueryVoices(UWORD numvoices, VOICEINFO *vinfo); 611 698 MIKMODAPI extern int Player_GetRow(void); 612 - MIKMODAPI extern int Player_GetOrder(void); 699 + MIKMODAPI extern int Player_GetOrder(void); 613 700 614 701 typedef void (*MikMod_player_t)(void); 615 702 typedef void (*MikMod_callback_t)(unsigned char *data, size_t len); ··· 620 707 #define MUTE_INCLUSIVE 32001 621 708 622 709 /* 623 - * ========== Drivers 710 + * ========== Drivers 624 711 */ 625 712 626 713 enum { 627 - MD_MUSIC = 0, 628 - MD_SNDFX 714 + MD_MUSIC = 0, 715 + MD_SNDFX 629 716 }; 630 717 631 718 enum { 632 - MD_HARDWARE = 0, 633 - MD_SOFTWARE 719 + MD_HARDWARE = 0, 720 + MD_SOFTWARE 634 721 }; 635 722 636 723 /* Mixing flags */ ··· 646 733 #define DMODE_SURROUND 0x0100 /* enable surround sound */ 647 734 #define DMODE_INTERP 0x0200 /* enable interpolation */ 648 735 #define DMODE_REVERSE 0x0400 /* reverse stereo */ 649 - #define DMODE_SIMDMIXER 0x0800 /* enable SIMD mixing */ 736 + #define DMODE_SIMDMIXER 0x0800 /* enable SIMD mixing */ 650 737 #define DMODE_NOISEREDUCTION 0x1000 /* Low pass filtering */ 651 738 739 + 652 740 struct SAMPLOAD; 741 + 653 742 typedef struct MDRIVER { 654 - struct MDRIVER* next; 655 - CHAR* Name; 656 - CHAR* Version; 743 + struct MDRIVER* next; 744 + const CHAR* Name; 745 + const CHAR* Version; 657 746 658 - UBYTE HardVoiceLimit; /* Limit of hardware mixer voices */ 659 - UBYTE SoftVoiceLimit; /* Limit of software mixer voices */ 747 + UBYTE HardVoiceLimit; /* Limit of hardware mixer voices */ 748 + UBYTE SoftVoiceLimit; /* Limit of software mixer voices */ 660 749 661 - CHAR *Alias; 662 - CHAR *CmdLineHelp; 750 + const CHAR* Alias; 751 + const CHAR* CmdLineHelp; 663 752 664 - void (*CommandLine) (CHAR*); 665 - int (*IsPresent) (void); 666 - SWORD (*SampleLoad) (struct SAMPLOAD*,int); 667 - void (*SampleUnload) (SWORD); 668 - ULONG (*FreeSampleSpace) (int); 669 - ULONG (*RealSampleLength) (int,struct SAMPLE*); 670 - int (*Init) (void); 671 - void (*Exit) (void); 672 - int (*Reset) (void); 673 - int (*SetNumVoices) (void); 674 - int (*PlayStart) (void); 675 - void (*PlayStop) (void); 676 - void (*Update) (void); 677 - void (*Pause) (void); 678 - void (*VoiceSetVolume) (UBYTE,UWORD); 679 - UWORD (*VoiceGetVolume) (UBYTE); 680 - void (*VoiceSetFrequency)(UBYTE,ULONG); 681 - ULONG (*VoiceGetFrequency)(UBYTE); 682 - void (*VoiceSetPanning) (UBYTE,ULONG); 683 - ULONG (*VoiceGetPanning) (UBYTE); 684 - void (*VoicePlay) (UBYTE,SWORD,ULONG,ULONG,ULONG,ULONG,UWORD); 685 - void (*VoiceStop) (UBYTE); 686 - int (*VoiceStopped) (UBYTE); 687 - SLONG (*VoiceGetPosition) (UBYTE); 688 - ULONG (*VoiceRealVolume) (UBYTE); 753 + void (*CommandLine) (const CHAR*); 754 + int (*IsPresent) (void); 755 + SWORD (*SampleLoad) (struct SAMPLOAD*,int); 756 + void (*SampleUnload) (SWORD); 757 + ULONG (*FreeSampleSpace) (int); 758 + ULONG (*RealSampleLength) (int,struct SAMPLE*); 759 + int (*Init) (void); 760 + void (*Exit) (void); 761 + int (*Reset) (void); 762 + int (*SetNumVoices) (void); 763 + int (*PlayStart) (void); 764 + void (*PlayStop) (void); 765 + void (*Update) (void); 766 + void (*Pause) (void); 767 + void (*VoiceSetVolume) (UBYTE,UWORD); 768 + UWORD (*VoiceGetVolume) (UBYTE); 769 + void (*VoiceSetFrequency)(UBYTE,ULONG); 770 + ULONG (*VoiceGetFrequency)(UBYTE); 771 + void (*VoiceSetPanning) (UBYTE,ULONG); 772 + ULONG (*VoiceGetPanning) (UBYTE); 773 + void (*VoicePlay) (UBYTE,SWORD,ULONG,ULONG,ULONG,ULONG,UWORD); 774 + void (*VoiceStop) (UBYTE); 775 + int (*VoiceStopped) (UBYTE); 776 + SLONG (*VoiceGetPosition) (UBYTE); 777 + ULONG (*VoiceRealVolume) (UBYTE); 689 778 } MDRIVER; 690 779 691 780 /* These variables can be changed at ANY time and results will be immediate */ ··· 700 789 in a skip or pop in audio (depending on the soundcard driver and the settings 701 790 changed). */ 702 791 MIKMODAPI extern UWORD md_device; /* device */ 703 - MIKMODAPI extern UWORD md_mixfreq; /* mixing frequency */ 792 + MIKMODAPI extern ULONG md_mixfreq; /* mixing frequency */ 704 793 MIKMODAPI extern UWORD md_mode; /* mode. See DMODE_? flags above */ 705 794 706 795 /* The following variable should not be changed! */ ··· 709 798 /* Known drivers list */ 710 799 711 800 MIKMODAPI extern struct MDRIVER drv_nos; /* no sound */ 712 - #if 0 713 801 MIKMODAPI extern struct MDRIVER drv_pipe; /* piped output */ 714 802 MIKMODAPI extern struct MDRIVER drv_raw; /* raw file disk writer [music.raw] */ 715 803 MIKMODAPI extern struct MDRIVER drv_stdout; /* output to stdout */ ··· 717 805 MIKMODAPI extern struct MDRIVER drv_aiff; /* AIFF file disk writer [music.aiff] */ 718 806 719 807 MIKMODAPI extern struct MDRIVER drv_ultra; /* Linux Ultrasound driver */ 720 - MIKMODAPI extern struct MDRIVER drv_sam9407; /* Linux sam9407 driver */ 808 + MIKMODAPI extern struct MDRIVER drv_sam9407;/* Linux sam9407 driver */ 721 809 722 810 MIKMODAPI extern struct MDRIVER drv_AF; /* Dec Alpha AudioFile */ 811 + MIKMODAPI extern struct MDRIVER drv_ahi; /* Amiga AHI */ 723 812 MIKMODAPI extern struct MDRIVER drv_aix; /* AIX audio device */ 724 813 MIKMODAPI extern struct MDRIVER drv_alsa; /* Advanced Linux Sound Architecture (ALSA) */ 725 814 MIKMODAPI extern struct MDRIVER drv_esd; /* Enlightened sound daemon (EsounD) */ 815 + MIKMODAPI extern struct MDRIVER drv_pulseaudio; /* PulseAudio */ 726 816 MIKMODAPI extern struct MDRIVER drv_hp; /* HP-UX audio device */ 727 - MIKMODAPI extern struct MDRIVER drv_nas; /* Network Audio System (NAS) */ 817 + MIKMODAPI extern struct MDRIVER drv_nas; /* Network Audio System (NAS) */ 728 818 MIKMODAPI extern struct MDRIVER drv_oss; /* OpenSound System (Linux,FreeBSD...) */ 819 + MIKMODAPI extern struct MDRIVER drv_openal; /* OpenAL driver */ 820 + MIKMODAPI extern struct MDRIVER drv_sdl; /* SDL audio driver */ 729 821 MIKMODAPI extern struct MDRIVER drv_sgi; /* SGI audio library */ 822 + MIKMODAPI extern struct MDRIVER drv_sndio; /* OpenBSD sndio */ 730 823 MIKMODAPI extern struct MDRIVER drv_sun; /* Sun/NetBSD/OpenBSD audio device */ 731 824 732 825 MIKMODAPI extern struct MDRIVER drv_dart; /* OS/2 Direct Audio RealTime */ 733 826 MIKMODAPI extern struct MDRIVER drv_os2; /* OS/2 MMPM/2 */ 734 827 735 828 MIKMODAPI extern struct MDRIVER drv_ds; /* Win32 DirectSound driver */ 829 + MIKMODAPI extern struct MDRIVER drv_xaudio2;/* Win32 XAudio2 driver */ 736 830 MIKMODAPI extern struct MDRIVER drv_win; /* Win32 multimedia API driver */ 737 831 738 832 MIKMODAPI extern struct MDRIVER drv_mac; /* Macintosh Sound Manager driver */ 739 - MIKMODAPI extern struct MDRIVER drv_osx; /* MacOS X CoreAudio Driver */ 833 + MIKMODAPI extern struct MDRIVER drv_osx; /* MacOS X CoreAudio Driver */ 740 834 835 + MIKMODAPI extern struct MDRIVER drv_dc; /* Dreamcast driver */ 741 836 MIKMODAPI extern struct MDRIVER drv_gp32; /* GP32 Sound driver */ 837 + MIKMODAPI extern struct MDRIVER drv_psp; /* PlayStation Portable driver */ 838 + MIKMODAPI extern struct MDRIVER drv_n64; /* Nintendo64 driver */ 742 839 743 840 MIKMODAPI extern struct MDRIVER drv_wss; /* DOS WSS driver */ 744 - MIKMODAPI extern struct MDRIVER drv_sb; /* DOS SB driver */ 745 - #endif 841 + MIKMODAPI extern struct MDRIVER drv_sb; /* DOS S/B driver */ 842 + 843 + MIKMODAPI extern struct MDRIVER drv_osles; /* OpenSL ES driver for android */ 844 + 746 845 /*========== Virtual channel mixer interface (for user-supplied drivers only) */ 747 846 748 - MIKMODAPI extern int VC_Init(void); 847 + MIKMODAPI extern int VC_Init(void); 749 848 MIKMODAPI extern void VC_Exit(void); 750 849 MIKMODAPI extern void VC_SetCallback(MikMod_callback_t callback); 751 - MIKMODAPI extern int VC_SetNumVoices(void); 850 + MIKMODAPI extern int VC_SetNumVoices(void); 752 851 MIKMODAPI extern ULONG VC_SampleSpace(int); 753 852 MIKMODAPI extern ULONG VC_SampleLength(int,SAMPLE*); 754 853 755 - MIKMODAPI extern int VC_PlayStart(void); 854 + MIKMODAPI extern int VC_PlayStart(void); 756 855 MIKMODAPI extern void VC_PlayStop(void); 757 856 758 857 MIKMODAPI extern SWORD VC_SampleLoad(struct SAMPLOAD*,int);
+407 -346
apps/plugins/mikmod/mikmod_internals.h
··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: mikmod_internals.h,v 1.7 2010/01/12 03:30:31 realtech Exp $ 24 - 25 23 MikMod sound library internal definitions 26 24 27 - ==============================================================================*/ 25 + ==============================================================================*/ 28 26 29 27 #ifndef _MIKMOD_INTERNALS_H 30 28 #define _MIKMOD_INTERNALS_H ··· 34 32 #endif 35 33 36 34 #include <stdarg.h> 37 - #if 0 38 - #if defined(__OS2__)||defined(__EMX__)||defined(WIN32) 39 - #define strcasecmp(s,t) stricmp(s,t) 40 - #endif 35 + 36 + #if defined(_MSC_VER) && !defined(__cplusplus) && !defined(HAVE_CONFIG_H) 37 + #define inline __inline 41 38 #endif 42 39 43 40 #include "mikmod.h" 44 41 42 + #ifndef MIKMOD_UNIX 43 + #if (defined(unix) || defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) && \ 44 + !(defined(_MIKMOD_WIN32) || defined(_MIKMOD_OS2) || defined(_MIKMOD_DOS) || defined(_MIKMOD_AMIGA) || defined(macintosh)) 45 + #define MIKMOD_UNIX 1 46 + #else 47 + #define MIKMOD_UNIX 0 48 + #endif 49 + #endif /* MIKMOD_UNIX */ 50 + 45 51 /*========== More type definitions */ 46 52 47 53 /* SLONGLONG: 64bit, signed */ 48 - #if defined (__arch64__) || defined(__alpha) || defined (__x64_64) || defined (_LP64) || defined (__powerpc64__) 49 - typedef long SLONGLONG; 54 + #if !defined(_WIN32) && \ 55 + (defined(_LP64) || defined(__LP64__) || defined(__arch64__) || defined(__alpha) || defined(__x64_64) || defined(__powerpc64__)) 56 + typedef long SLONGLONG; 50 57 #define NATIVE_64BIT_INT 51 - #if 0 58 + #elif defined(_WIN64) /* win64 is LLP64, not LP64 */ 59 + #define NATIVE_64BIT_INT 60 + typedef long long SLONGLONG; 52 61 #elif defined(__WATCOMC__) 53 - typedef __int64 SLONGLONG; 54 - #elif defined(WIN32) && !defined(__MWERKS__) 55 - typedef LONGLONG SLONGLONG; 56 - #elif macintosh && !TYPE_LONGLONG 62 + typedef __int64 SLONGLONG; 63 + #elif defined(_WIN32) && !defined(__MWERKS__) 64 + typedef LONGLONG SLONGLONG; 65 + #elif defined(macintosh) && !TYPE_LONGLONG 57 66 #include <Types.h> 58 - typedef SInt64 SLONGLONG; 67 + typedef SInt64 SLONGLONG; 68 + #else 69 + typedef long long SLONGLONG; 59 70 #endif 71 + typedef int __s64_typetest [(sizeof(SLONGLONG)==8) * 2 - 1]; 72 + 73 + /* pointer-sized signed int (ssize_t/intptr_t) : */ 74 + #if defined(_WIN64) /* win64 is LLP64, not LP64 */ 75 + typedef long long SINTPTR_T; 60 76 #else 61 - typedef long long SLONGLONG; 77 + /* long should be pointer-sized for all others : */ 78 + typedef long SINTPTR_T; 62 79 #endif 80 + typedef int __iptr_typetest [(sizeof(SINTPTR_T)==sizeof(void*)) * 2 - 1]; 63 81 64 82 /*========== Error handling */ 65 83 ··· 72 90 #ifdef HAVE_PTHREAD 73 91 #include <pthread.h> 74 92 #define DECLARE_MUTEX(name) \ 75 - extern pthread_mutex_t _mm_mutex_##name 76 - #define MUTEX_LOCK(name) \ 77 - pthread_mutex_lock(&_mm_mutex_##name) 78 - #define MUTEX_UNLOCK(name) \ 79 - pthread_mutex_unlock(&_mm_mutex_##name) 93 + extern pthread_mutex_t _mm_mutex_##name 94 + #define MUTEX_LOCK(name) \ 95 + pthread_mutex_lock(&_mm_mutex_##name) 96 + #define MUTEX_UNLOCK(name) \ 97 + pthread_mutex_unlock(&_mm_mutex_##name) 98 + 80 99 #elif defined(__OS2__)||defined(__EMX__) 81 - #define DECLARE_MUTEX(name) \ 82 - extern HMTX _mm_mutex_##name 83 - #define MUTEX_LOCK(name) \ 84 - if(_mm_mutex_##name) \ 85 - DosRequestMutexSem(_mm_mutex_##name,SEM_INDEFINITE_WAIT) 86 - #define MUTEX_UNLOCK(name) \ 87 - if(_mm_mutex_##name) \ 88 - DosReleaseMutexSem(_mm_mutex_##name) 89 - #elif defined(WIN32) 100 + #define DECLARE_MUTEX(name) \ 101 + extern HMTX _mm_mutex_##name 102 + #define MUTEX_LOCK(name) \ 103 + if(_mm_mutex_##name)\ 104 + DosRequestMutexSem(_mm_mutex_##name,SEM_INDEFINITE_WAIT) 105 + #define MUTEX_UNLOCK(name) \ 106 + if(_mm_mutex_##name)\ 107 + DosReleaseMutexSem(_mm_mutex_##name) 108 + 109 + #elif defined(_WIN32) 90 110 #include <windows.h> 91 - #define DECLARE_MUTEX(name) \ 92 - extern HANDLE _mm_mutex_##name 93 - #define MUTEX_LOCK(name) \ 94 - if(_mm_mutex_##name) \ 95 - WaitForSingleObject(_mm_mutex_##name,INFINITE) 96 - #define MUTEX_UNLOCK(name) \ 97 - if(_mm_mutex_##name) \ 98 - ReleaseMutex(_mm_mutex_##name) 111 + #define DECLARE_MUTEX(name) \ 112 + extern HANDLE _mm_mutex_##name 113 + #define MUTEX_LOCK(name) \ 114 + if(_mm_mutex_##name)\ 115 + WaitForSingleObject(_mm_mutex_##name,INFINITE) 116 + #define MUTEX_UNLOCK(name) \ 117 + if(_mm_mutex_##name)\ 118 + ReleaseMutex(_mm_mutex_##name) 119 + 99 120 #else 100 - #define DECLARE_MUTEX(name) \ 101 - extern void *_mm_mutex_##name 121 + #define DECLARE_MUTEX(name) \ 122 + extern void *_mm_mutex_##name 102 123 #define MUTEX_LOCK(name) 103 124 #define MUTEX_UNLOCK(name) 104 125 #endif ··· 106 127 DECLARE_MUTEX(lists); 107 128 DECLARE_MUTEX(vars); 108 129 130 + /*========== Replacement funcs */ 131 + 132 + //extern int strcasecmp (const char *__s1, const char *__s2); 133 + 109 134 /*========== Portable file I/O */ 110 135 111 - extern MREADER* _mm_new_mem_reader(const void *buffer, int len); 136 + extern MREADER* _mm_new_mem_reader(const void *buffer, long len); 112 137 extern void _mm_delete_mem_reader(MREADER *reader); 113 138 114 139 extern MREADER* _mm_new_file_reader(int fp); ··· 117 142 extern MWRITER* _mm_new_file_writer(int fp); 118 143 extern void _mm_delete_file_writer(MWRITER*); 119 144 120 - extern int _mm_FileExists(CHAR *fname); 145 + extern int _mm_FileExists(const CHAR *fname); 121 146 122 - #define _mm_write_SBYTE(x,y) y->Put(y,(int)x) 123 - #define _mm_write_UBYTE(x,y) y->Put(y,(int)x) 147 + #define _mm_write_SBYTE(x,y) y->Put(y,(int)x) 148 + #define _mm_write_UBYTE(x,y) y->Put(y,(int)x) 124 149 125 - #define _mm_read_SBYTE(x) (SBYTE)x->Get(x) 126 - #define _mm_read_UBYTE(x) (UBYTE)x->Get(x) 150 + #define _mm_read_SBYTE(x) (SBYTE)x->Get(x) 151 + #define _mm_read_UBYTE(x) (UBYTE)x->Get(x) 152 + #define _mm_skip_BYTE(x) (void)x->Get(x) 127 153 128 - #define _mm_write_SBYTES(x,y,z) z->Write(z,(void *)x,y) 129 - #define _mm_write_UBYTES(x,y,z) z->Write(z,(void *)x,y) 154 + #define _mm_write_SBYTES(x,y,z) z->Write(z,(const void *)x,y) 155 + #define _mm_write_UBYTES(x,y,z) z->Write(z,(const void *)x,y) 130 156 #define _mm_read_SBYTES(x,y,z) z->Read(z,(void *)x,y) 131 157 #define _mm_read_UBYTES(x,y,z) z->Read(z,(void *)x,y) 132 158 133 - #define _mm_fseek(x,y,z) x->Seek(x,y,z) 134 - #define _mm_ftell(x) x->Tell(x) 135 - #define _mm_rewind(x) _mm_fseek(x,0,SEEK_SET) 159 + #define _mm_fseek(x,y,z) x->Seek(x,y,z) 160 + #define _mm_ftell(x) x->Tell(x) 161 + #define _mm_rewind(x) _mm_fseek(x,0,SEEK_SET) 136 162 137 - #define _mm_eof(x) x->Eof(x) 163 + #define _mm_eof(x) x->Eof(x) 138 164 139 165 extern void _mm_iobase_setcur(MREADER*); 140 166 extern void _mm_iobase_revert(MREADER*); 141 - extern int _mm_fopen(CHAR*,CHAR*); 142 - extern int _mm_fclose(int); 143 - #if !defined(ROCKBOX) 144 - extern void _mm_write_string(CHAR*,MWRITER*); 145 - #endif 146 - extern int _mm_read_string (CHAR*,int,MREADER*); 167 + extern int _mm_fopen(const CHAR *, const CHAR *); 168 + extern int _mm_fclose(int); 169 + extern void _mm_write_string(const CHAR*,MWRITER*); 170 + extern int _mm_read_string (CHAR*,int,MREADER*); 147 171 148 172 extern SWORD _mm_read_M_SWORD(MREADER*); 149 173 extern SWORD _mm_read_I_SWORD(MREADER*); ··· 186 210 extern void _mm_write_I_ULONGS(ULONG*,int,MWRITER*); 187 211 188 212 /*========== Samples */ 213 + 214 + #define MAX_SAMPLE_SIZE 0x10000000 /* a sane value guaranteed to not overflow an SLONG */ 189 215 190 216 /* This is a handle of sorts attached to any sample registered with 191 217 SL_RegisterSample. Generally, this only need be used or changed by the 192 218 loaders and drivers of mikmod. */ 193 219 typedef struct SAMPLOAD { 194 - struct SAMPLOAD *next; 220 + struct SAMPLOAD *next; 195 221 196 - ULONG length; /* length of sample (in samples!) */ 197 - ULONG loopstart; /* repeat position (relative to start, in samples) */ 198 - ULONG loopend; /* repeat end */ 199 - UWORD infmt,outfmt; 200 - int scalefactor; 201 - SAMPLE* sample; 202 - MREADER* reader; 222 + ULONG length; /* length of sample (in samples!) */ 223 + ULONG loopstart; /* repeat position (relative to start, in samples) */ 224 + ULONG loopend; /* repeat end */ 225 + UWORD infmt,outfmt; 226 + int scalefactor; 227 + SAMPLE* sample; 228 + MREADER* reader; 203 229 } SAMPLOAD; 204 230 205 231 /*========== Sample and waves loading interface */ ··· 209 235 extern void SL_Sample16to8(SAMPLOAD*); 210 236 extern void SL_SampleSigned(SAMPLOAD*); 211 237 extern void SL_SampleUnsigned(SAMPLOAD*); 212 - extern int SL_LoadSamples(void); 238 + extern int SL_LoadSamples(void); 213 239 extern SAMPLOAD* SL_RegisterSample(SAMPLE*,int,MREADER*); 214 - extern int SL_Load(void*,SAMPLOAD*,ULONG); 240 + extern int SL_Load(void*,SAMPLOAD*,ULONG); 215 241 extern int SL_Init(SAMPLOAD*); 216 242 extern void SL_Exit(SAMPLOAD*); 217 243 ··· 233 259 extern int UniInit(void); 234 260 extern void UniCleanup(void); 235 261 extern void UniEffect(UWORD,UWORD); 236 - #define UniInstrument(x) UniEffect(UNI_INSTRUMENT,x) 237 - #define UniNote(x) UniEffect(UNI_NOTE,x) 262 + #define UniInstrument(x) UniEffect(UNI_INSTRUMENT,x) 263 + #define UniNote(x) UniEffect(UNI_NOTE,x) 238 264 extern void UniPTEffect(UBYTE,UBYTE); 239 265 extern void UniVolEffect(UWORD,UBYTE); 240 266 241 267 /*========== Module Commands */ 242 268 243 269 enum { 244 - /* Simple note */ 245 - UNI_NOTE = 1, 246 - /* Instrument change */ 247 - UNI_INSTRUMENT, 248 - /* Protracker effects */ 249 - UNI_PTEFFECT0, /* arpeggio */ 250 - UNI_PTEFFECT1, /* porta up */ 251 - UNI_PTEFFECT2, /* porta down */ 252 - UNI_PTEFFECT3, /* porta to note */ 253 - UNI_PTEFFECT4, /* vibrato */ 254 - UNI_PTEFFECT5, /* dual effect 3+A */ 255 - UNI_PTEFFECT6, /* dual effect 4+A */ 256 - UNI_PTEFFECT7, /* tremolo */ 257 - UNI_PTEFFECT8, /* pan */ 258 - UNI_PTEFFECT9, /* sample offset */ 259 - UNI_PTEFFECTA, /* volume slide */ 260 - UNI_PTEFFECTB, /* pattern jump */ 261 - UNI_PTEFFECTC, /* set volume */ 262 - UNI_PTEFFECTD, /* pattern break */ 263 - UNI_PTEFFECTE, /* extended effects */ 264 - UNI_PTEFFECTF, /* set speed */ 265 - /* Scream Tracker effects */ 266 - UNI_S3MEFFECTA, /* set speed */ 267 - UNI_S3MEFFECTD, /* volume slide */ 268 - UNI_S3MEFFECTE, /* porta down */ 269 - UNI_S3MEFFECTF, /* porta up */ 270 - UNI_S3MEFFECTI, /* tremor */ 271 - UNI_S3MEFFECTQ, /* retrig */ 272 - UNI_S3MEFFECTR, /* tremolo */ 273 - UNI_S3MEFFECTT, /* set tempo */ 274 - UNI_S3MEFFECTU, /* fine vibrato */ 275 - UNI_KEYOFF, /* note off */ 276 - /* Fast Tracker effects */ 277 - UNI_KEYFADE, /* note fade */ 278 - UNI_VOLEFFECTS, /* volume column effects */ 279 - UNI_XMEFFECT4, /* vibrato */ 280 - UNI_XMEFFECT6, /* dual effect 4+A */ 281 - UNI_XMEFFECTA, /* volume slide */ 282 - UNI_XMEFFECTE1, /* fine porta up */ 283 - UNI_XMEFFECTE2, /* fine porta down */ 284 - UNI_XMEFFECTEA, /* fine volume slide up */ 285 - UNI_XMEFFECTEB, /* fine volume slide down */ 286 - UNI_XMEFFECTG, /* set global volume */ 287 - UNI_XMEFFECTH, /* global volume slide */ 288 - UNI_XMEFFECTL, /* set envelope position */ 289 - UNI_XMEFFECTP, /* pan slide */ 290 - UNI_XMEFFECTX1, /* extra fine porta up */ 291 - UNI_XMEFFECTX2, /* extra fine porta down */ 292 - /* Impulse Tracker effects */ 293 - UNI_ITEFFECTG, /* porta to note */ 294 - UNI_ITEFFECTH, /* vibrato */ 295 - UNI_ITEFFECTI, /* tremor (xy not incremented) */ 296 - UNI_ITEFFECTM, /* set channel volume */ 297 - UNI_ITEFFECTN, /* slide / fineslide channel volume */ 298 - UNI_ITEFFECTP, /* slide / fineslide channel panning */ 299 - UNI_ITEFFECTT, /* slide tempo */ 300 - UNI_ITEFFECTU, /* fine vibrato */ 301 - UNI_ITEFFECTW, /* slide / fineslide global volume */ 302 - UNI_ITEFFECTY, /* panbrello */ 303 - UNI_ITEFFECTZ, /* resonant filters */ 304 - UNI_ITEFFECTS0, 305 - /* UltraTracker effects */ 306 - UNI_ULTEFFECT9, /* Sample fine offset */ 307 - /* OctaMED effects */ 308 - UNI_MEDSPEED, 309 - UNI_MEDEFFECTF1, /* play note twice */ 310 - UNI_MEDEFFECTF2, /* delay note */ 311 - UNI_MEDEFFECTF3, /* play note three times */ 312 - /* Oktalyzer effects */ 313 - UNI_OKTARP, /* arpeggio */ 270 + /* Simple note */ 271 + UNI_NOTE = 1, 272 + /* Instrument change */ 273 + UNI_INSTRUMENT, 274 + /* Protracker effects */ 275 + UNI_PTEFFECT0, /* arpeggio */ 276 + UNI_PTEFFECT1, /* porta up */ 277 + UNI_PTEFFECT2, /* porta down */ 278 + UNI_PTEFFECT3, /* porta to note */ 279 + UNI_PTEFFECT4, /* vibrato */ 280 + UNI_PTEFFECT5, /* dual effect 3+A */ 281 + UNI_PTEFFECT6, /* dual effect 4+A */ 282 + UNI_PTEFFECT7, /* tremolo */ 283 + UNI_PTEFFECT8, /* pan */ 284 + UNI_PTEFFECT9, /* sample offset */ 285 + UNI_PTEFFECTA, /* volume slide */ 286 + UNI_PTEFFECTB, /* pattern jump */ 287 + UNI_PTEFFECTC, /* set volume */ 288 + UNI_PTEFFECTD, /* pattern break */ 289 + UNI_PTEFFECTE, /* extended effects */ 290 + UNI_PTEFFECTF, /* set speed */ 291 + /* Scream Tracker effects */ 292 + UNI_S3MEFFECTA, /* set speed */ 293 + UNI_S3MEFFECTD, /* volume slide */ 294 + UNI_S3MEFFECTE, /* porta down */ 295 + UNI_S3MEFFECTF, /* porta up */ 296 + UNI_S3MEFFECTI, /* tremor */ 297 + UNI_S3MEFFECTQ, /* retrig */ 298 + UNI_S3MEFFECTR, /* tremolo */ 299 + UNI_S3MEFFECTT, /* set tempo */ 300 + UNI_S3MEFFECTU, /* fine vibrato */ 301 + UNI_KEYOFF, /* note off */ 302 + /* Fast Tracker effects */ 303 + UNI_KEYFADE, /* note fade */ 304 + UNI_VOLEFFECTS, /* volume column effects */ 305 + UNI_XMEFFECT4, /* vibrato */ 306 + UNI_XMEFFECT6, /* dual effect 4+A */ 307 + UNI_XMEFFECTA, /* volume slide */ 308 + UNI_XMEFFECTE1, /* fine porta up */ 309 + UNI_XMEFFECTE2, /* fine porta down */ 310 + UNI_XMEFFECTEA, /* fine volume slide up */ 311 + UNI_XMEFFECTEB, /* fine volume slide down */ 312 + UNI_XMEFFECTG, /* set global volume */ 313 + UNI_XMEFFECTH, /* global volume slide */ 314 + UNI_XMEFFECTL, /* set envelope position */ 315 + UNI_XMEFFECTP, /* pan slide */ 316 + UNI_XMEFFECTX1, /* extra fine porta up */ 317 + UNI_XMEFFECTX2, /* extra fine porta down */ 318 + /* Impulse Tracker effects */ 319 + UNI_ITEFFECTG, /* porta to note */ 320 + UNI_ITEFFECTH, /* vibrato */ 321 + UNI_ITEFFECTI, /* tremor (xy not incremented) */ 322 + UNI_ITEFFECTM, /* set channel volume */ 323 + UNI_ITEFFECTN, /* slide / fineslide channel volume */ 324 + UNI_ITEFFECTP, /* slide / fineslide channel panning */ 325 + UNI_ITEFFECTT, /* slide tempo */ 326 + UNI_ITEFFECTU, /* fine vibrato */ 327 + UNI_ITEFFECTW, /* slide / fineslide global volume */ 328 + UNI_ITEFFECTY, /* panbrello */ 329 + UNI_ITEFFECTZ, /* resonant filters */ 330 + UNI_ITEFFECTS0, 331 + /* UltraTracker effects */ 332 + UNI_ULTEFFECT9, /* Sample fine offset */ 333 + /* OctaMED effects */ 334 + UNI_MEDSPEED, 335 + UNI_MEDEFFECTF1,/* play note twice */ 336 + UNI_MEDEFFECTF2,/* delay note */ 337 + UNI_MEDEFFECTF3,/* play note three times */ 338 + /* Oktalyzer effects */ 339 + UNI_OKTARP, /* arpeggio */ 314 340 315 - UNI_LAST 341 + UNI_LAST 316 342 }; 317 343 318 - extern UWORD unioperands[UNI_LAST]; 344 + extern const UWORD unioperands[UNI_LAST]; 319 345 320 346 /* IT / S3M Extended SS effects: */ 321 347 enum { 322 - SS_GLISSANDO = 1, 323 - SS_FINETUNE, 324 - SS_VIBWAVE, 325 - SS_TREMWAVE, 326 - SS_PANWAVE, 327 - SS_FRAMEDELAY, 328 - SS_S7EFFECTS, 329 - SS_PANNING, 330 - SS_SURROUND, 331 - SS_HIOFFSET, 332 - SS_PATLOOP, 333 - SS_NOTECUT, 334 - SS_NOTEDELAY, 335 - SS_PATDELAY 348 + SS_GLISSANDO = 1, 349 + SS_FINETUNE, 350 + SS_VIBWAVE, 351 + SS_TREMWAVE, 352 + SS_PANWAVE, 353 + SS_FRAMEDELAY, 354 + SS_S7EFFECTS, 355 + SS_PANNING, 356 + SS_SURROUND, 357 + SS_HIOFFSET, 358 + SS_PATLOOP, 359 + SS_NOTECUT, 360 + SS_NOTEDELAY, 361 + SS_PATDELAY 336 362 }; 337 363 338 364 /* IT Volume column effects */ 339 365 enum { 340 - VOL_VOLUME = 1, 341 - VOL_PANNING, 342 - VOL_VOLSLIDE, 343 - VOL_PITCHSLIDEDN, 344 - VOL_PITCHSLIDEUP, 345 - VOL_PORTAMENTO, 346 - VOL_VIBRATO 366 + VOL_VOLUME = 1, 367 + VOL_PANNING, 368 + VOL_VOLSLIDE, 369 + VOL_PITCHSLIDEDN, 370 + VOL_PITCHSLIDEUP, 371 + VOL_PORTAMENTO, 372 + VOL_VIBRATO 347 373 }; 348 374 349 375 /* IT resonant filter information */ 350 376 351 - #define UF_MAXMACRO 0x10 352 - #define UF_MAXFILTER 0x100 377 + #define UF_MAXMACRO 0x10 378 + #define UF_MAXFILTER 0x100 353 379 354 - #define FILT_CUT 0x80 355 - #define FILT_RESONANT 0x81 380 + #define FILT_CUT 0x80 381 + #define FILT_RESONANT 0x81 356 382 357 383 typedef struct FILTER { 358 384 UBYTE filter,inf; ··· 401 427 402 428 /*========== Playing */ 403 429 404 - #define POS_NONE (-2) /* no loop position defined */ 430 + #define POS_NONE (-2) /* no loop position defined */ 405 431 406 - #define LAST_PATTERN (UWORD)(-1) /* special ``end of song'' pattern */ 432 + #define LAST_PATTERN (UWORD)(-1) /* special ``end of song'' pattern */ 407 433 408 434 typedef struct ENVPR { 409 - UBYTE flg; /* envelope flag */ 410 - UBYTE pts; /* number of envelope points */ 411 - UBYTE susbeg; /* envelope sustain index begin */ 412 - UBYTE susend; /* envelope sustain index end */ 413 - UBYTE beg; /* envelope loop begin */ 414 - UBYTE end; /* envelope loop end */ 415 - SWORD p; /* current envelope counter */ 416 - UWORD a; /* envelope index a */ 417 - UWORD b; /* envelope index b */ 418 - ENVPT* env; /* envelope points */ 435 + UBYTE flg; /* envelope flag */ 436 + UBYTE pts; /* number of envelope points */ 437 + UBYTE susbeg; /* envelope sustain index begin */ 438 + UBYTE susend; /* envelope sustain index end */ 439 + UBYTE beg; /* envelope loop begin */ 440 + UBYTE end; /* envelope loop end */ 441 + SWORD p; /* current envelope counter */ 442 + UWORD a; /* envelope index a */ 443 + UWORD b; /* envelope index b */ 444 + ENVPT* env; /* envelope points */ 419 445 } ENVPR; 420 446 421 447 typedef struct MP_CHANNEL { 422 - INSTRUMENT* i; 423 - SAMPLE* s; 424 - UBYTE sample; /* which sample number */ 425 - UBYTE note; /* the audible note as heard, direct rep of period */ 426 - SWORD outvolume; /* output volume (vol + sampcol + instvol) */ 427 - SBYTE chanvol; /* channel's "global" volume */ 428 - UWORD fadevol; /* fading volume rate */ 429 - SWORD panning; /* panning position */ 430 - UBYTE kick; /* if true = sample has to be restarted */ 431 - UBYTE kick_flag; /* kick has been true */ 432 - UWORD period; /* period to play the sample at */ 433 - UBYTE nna; /* New note action type + master/slave flags */ 448 + INSTRUMENT* i; 449 + SAMPLE *s; 450 + UBYTE sample; /* which sample number */ 451 + UBYTE note; /* the audible note as heard, direct rep of period */ 452 + SWORD outvolume; /* output volume (vol + sampcol + instvol) */ 453 + SBYTE chanvol; /* channel's "global" volume */ 454 + UWORD fadevol; /* fading volume rate */ 455 + SWORD panning; /* panning position */ 456 + UBYTE kick; /* if true = sample has to be restarted */ 457 + UBYTE kick_flag; /* kick has been true */ 458 + UWORD period; /* period to play the sample at */ 459 + UBYTE nna; /* New note action type + master/slave flags */ 434 460 435 - UBYTE volflg; /* volume envelope settings */ 436 - UBYTE panflg; /* panning envelope settings */ 437 - UBYTE pitflg; /* pitch envelope settings */ 461 + UBYTE volflg; /* volume envelope settings */ 462 + UBYTE panflg; /* panning envelope settings */ 463 + UBYTE pitflg; /* pitch envelope settings */ 438 464 439 - UBYTE keyoff; /* if true = fade out and stuff */ 440 - SWORD handle; /* which sample-handle */ 441 - UBYTE notedelay; /* (used for note delay) */ 442 - SLONG start; /* The starting byte index in the sample */ 465 + UBYTE keyoff; /* if true = fade out and stuff */ 466 + SWORD handle; /* which sample-handle */ 467 + UBYTE notedelay; /* (used for note delay) */ 468 + SLONG start; /* The starting byte index in the sample */ 443 469 } MP_CHANNEL; 444 470 445 471 typedef struct MP_CONTROL { 446 - struct MP_CHANNEL main; 472 + struct MP_CHANNEL main; 447 473 448 - struct MP_VOICE *slave; /* Audio Slave of current effects control channel */ 474 + struct MP_VOICE* slave; /* Audio Slave of current effects control channel */ 449 475 450 - UBYTE slavechn; /* Audio Slave of current effects control channel */ 451 - UBYTE muted; /* if set, channel not played */ 452 - UWORD ultoffset; /* fine sample offset memory */ 453 - UBYTE anote; /* the note that indexes the audible */ 454 - UBYTE oldnote; 455 - SWORD ownper; 456 - SWORD ownvol; 457 - UBYTE dca; /* duplicate check action */ 458 - UBYTE dct; /* duplicate check type */ 459 - UBYTE* row; /* row currently playing on this channel */ 460 - SBYTE retrig; /* retrig value (0 means don't retrig) */ 461 - ULONG speed; /* what finetune to use */ 462 - SWORD volume; /* amiga volume (0 t/m 64) to play the sample at */ 476 + UBYTE slavechn; /* Audio Slave of current effects control channel */ 477 + UBYTE muted; /* if set, channel not played */ 478 + UWORD ultoffset; /* fine sample offset memory */ 479 + UBYTE anote; /* the note that indexes the audible */ 480 + UBYTE oldnote; 481 + SWORD ownper; 482 + SWORD ownvol; 483 + UBYTE dca; /* duplicate check action */ 484 + UBYTE dct; /* duplicate check type */ 485 + UBYTE* row; /* row currently playing on this channel */ 486 + SBYTE retrig; /* retrig value (0 means don't retrig) */ 487 + ULONG speed; /* what finetune to use */ 488 + SWORD volume; /* amiga volume (0 t/m 64) to play the sample at */ 463 489 464 - SWORD tmpvolume; /* tmp volume */ 465 - UWORD tmpperiod; /* tmp period */ 466 - UWORD wantedperiod; /* period to slide to (with effect 3 or 5) */ 490 + SWORD tmpvolume; /* tmp volume */ 491 + UWORD tmpperiod; /* tmp period */ 492 + UWORD wantedperiod;/* period to slide to (with effect 3 or 5) */ 467 493 468 - UBYTE arpmem; /* arpeggio command memory */ 469 - UBYTE pansspd; /* panslide speed */ 470 - UWORD slidespeed; 471 - UWORD portspeed; /* noteslide speed (toneportamento) */ 494 + UBYTE arpmem; /* arpeggio command memory */ 495 + UBYTE pansspd; /* panslide speed */ 496 + UWORD slidespeed; 497 + UWORD portspeed; /* noteslide speed (toneportamento) */ 472 498 473 - UBYTE s3mtremor; /* s3m tremor (effect I) counter */ 474 - UBYTE s3mtronof; /* s3m tremor ontime/offtime */ 475 - UBYTE s3mvolslide; /* last used volslide */ 476 - SBYTE sliding; 477 - UBYTE s3mrtgspeed; /* last used retrig speed */ 478 - UBYTE s3mrtgslide; /* last used retrig slide */ 499 + UBYTE s3mtremor; /* s3m tremor (effect I) counter */ 500 + UBYTE s3mtronof; /* s3m tremor ontime/offtime */ 501 + UBYTE s3mvolslide;/* last used volslide */ 502 + SBYTE sliding; 503 + UBYTE s3mrtgspeed;/* last used retrig speed */ 504 + UBYTE s3mrtgslide;/* last used retrig slide */ 479 505 480 - UBYTE glissando; /* glissando (0 means off) */ 481 - UBYTE wavecontrol; 506 + UBYTE glissando; /* glissando (0 means off) */ 507 + UBYTE wavecontrol; 482 508 483 - SBYTE vibpos; /* current vibrato position */ 484 - UBYTE vibspd; /* "" speed */ 485 - UBYTE vibdepth; /* "" depth */ 509 + SBYTE vibpos; /* current vibrato position */ 510 + UBYTE vibspd; /* "" speed */ 511 + UBYTE vibdepth; /* "" depth */ 486 512 487 - SBYTE trmpos; /* current tremolo position */ 488 - UBYTE trmspd; /* "" speed */ 489 - UBYTE trmdepth; /* "" depth */ 513 + SBYTE trmpos; /* current tremolo position */ 514 + UBYTE trmspd; /* "" speed */ 515 + UBYTE trmdepth; /* "" depth */ 490 516 491 - UBYTE fslideupspd; 492 - UBYTE fslidednspd; 493 - UBYTE fportupspd; /* fx E1 (extra fine portamento up) data */ 494 - UBYTE fportdnspd; /* fx E2 (extra fine portamento dn) data */ 495 - UBYTE ffportupspd; /* fx X1 (extra fine portamento up) data */ 496 - UBYTE ffportdnspd; /* fx X2 (extra fine portamento dn) data */ 517 + UBYTE fslideupspd; 518 + UBYTE fslidednspd; 519 + UBYTE fportupspd; /* fx E1 (extra fine portamento up) data */ 520 + UBYTE fportdnspd; /* fx E2 (extra fine portamento dn) data */ 521 + UBYTE ffportupspd;/* fx X1 (extra fine portamento up) data */ 522 + UBYTE ffportdnspd;/* fx X2 (extra fine portamento dn) data */ 497 523 498 - ULONG hioffset; /* last used high order of sample offset */ 499 - UWORD soffset; /* last used low order of sample-offset (effect 9) */ 524 + ULONG hioffset; /* last used high order of sample offset */ 525 + UWORD soffset; /* last used low order of sample-offset (effect 9) */ 500 526 501 - UBYTE sseffect; /* last used Sxx effect */ 502 - UBYTE ssdata; /* last used Sxx data info */ 503 - UBYTE chanvolslide; /* last used channel volume slide */ 527 + UBYTE sseffect; /* last used Sxx effect */ 528 + UBYTE ssdata; /* last used Sxx data info */ 529 + UBYTE chanvolslide;/* last used channel volume slide */ 504 530 505 - UBYTE panbwave; /* current panbrello waveform */ 506 - UBYTE panbpos; /* current panbrello position */ 507 - SBYTE panbspd; /* "" speed */ 508 - UBYTE panbdepth; /* "" depth */ 531 + UBYTE panbwave; /* current panbrello waveform */ 532 + UBYTE panbpos; /* current panbrello position */ 533 + SBYTE panbspd; /* "" speed */ 534 + UBYTE panbdepth; /* "" depth */ 509 535 510 - UWORD newsamp; /* set to 1 upon a sample / inst change */ 511 - UBYTE voleffect; /* Volume Column Effect Memory as used by IT */ 512 - UBYTE voldata; /* Volume Column Data Memory */ 536 + UWORD newsamp; /* set to 1 upon a sample / inst change */ 537 + UBYTE voleffect; /* Volume Column Effect Memory as used by IT */ 538 + UBYTE voldata; /* Volume Column Data Memory */ 513 539 514 - SWORD pat_reppos; /* patternloop position */ 515 - UWORD pat_repcnt; /* times to loop */ 540 + SWORD pat_reppos; /* patternloop position */ 541 + UWORD pat_repcnt; /* times to loop */ 516 542 } MP_CONTROL; 517 543 518 544 /* Used by NNA only player (audio control. AUDTMP is used for full effects 519 545 control). */ 520 546 typedef struct MP_VOICE { 521 - struct MP_CHANNEL main; 547 + struct MP_CHANNEL main; 522 548 523 - ENVPR venv; 524 - ENVPR penv; 525 - ENVPR cenv; 549 + ENVPR venv; 550 + ENVPR penv; 551 + ENVPR cenv; 526 552 527 - UWORD avibpos; /* autovibrato pos */ 528 - UWORD aswppos; /* autovibrato sweep pos */ 553 + UWORD avibpos; /* autovibrato pos */ 554 + UWORD aswppos; /* autovibrato sweep pos */ 529 555 530 - ULONG totalvol; /* total volume of channel (before global mixings) */ 556 + ULONG totalvol; /* total volume of channel (before global mixings) */ 531 557 532 - int mflag; 533 - SWORD masterchn; 534 - UWORD masterperiod; 558 + int mflag; 559 + SWORD masterchn; 560 + UWORD masterperiod; 535 561 536 - MP_CONTROL* master; /* index of "master" effects channel */ 562 + MP_CONTROL* master; /* index of "master" effects channel */ 537 563 } MP_VOICE; 538 564 539 565 /*========== Loaders */ 540 566 541 567 typedef struct MLOADER { 542 - struct MLOADER* next; 543 - CHAR* type; 544 - CHAR* version; 545 - int (*Init)(void); 546 - int (*Test)(void); 547 - int (*Load)(int); 548 - void (*Cleanup)(void); 549 - CHAR* (*LoadTitle)(void); 568 + struct MLOADER* next; 569 + const CHAR* type; 570 + const CHAR* version; 571 + int (*Init)(void); 572 + int (*Test)(void); 573 + int (*Load)(int); 574 + void (*Cleanup)(void); 575 + CHAR* (*LoadTitle)(void); 550 576 } MLOADER; 551 577 552 578 /* internal loader variables */ 553 579 extern MREADER* modreader; 554 - extern UWORD finetune[16]; 555 580 extern MODULE of; /* static unimod loading space */ 556 - extern UWORD npertab[7*OCTAVE]; /* used by the original MOD loaders */ 581 + extern const UWORD finetune[16]; 582 + extern const UWORD npertab[7*OCTAVE];/* used by the original MOD loaders */ 557 583 558 584 extern SBYTE remap[UF_MAXCHAN]; /* for removing empty channels */ 559 585 extern UBYTE* poslookup; /* lookup table for pattern jumps after 560 - blank pattern removal */ 586 + blank pattern removal */ 561 587 extern UWORD poslookupcnt; 562 588 extern UWORD* origpositions; 563 589 ··· 577 603 extern int AllocTracks(void); 578 604 extern int AllocInstruments(void); 579 605 extern int AllocSamples(void); 580 - extern CHAR* DupStr(CHAR*,UWORD,int); 581 - extern CHAR* StrDup(CHAR *s); 606 + extern CHAR* DupStr(const CHAR*, UWORD, int); 582 607 583 608 /* loader utility functions */ 584 609 extern int* AllocLinear(void); ··· 588 613 extern void S3MIT_CreateOrders(int); 589 614 590 615 /* flags for S3MIT_ProcessCmd */ 591 - #define S3MIT_OLDSTYLE 1 /* behave as old scream tracker */ 592 - #define S3MIT_IT 2 /* behave as impulse tracker */ 593 - #define S3MIT_SCREAM 4 /* enforce scream tracker specific limits */ 616 + #define S3MIT_OLDSTYLE 1 /* behave as old scream tracker */ 617 + #define S3MIT_IT 2 /* behave as impulse tracker */ 618 + #define S3MIT_SCREAM 4 /* enforce scream tracker specific limits */ 594 619 595 620 /* used to convert c4spd to linear XM periods (IT and IMF loaders). */ 596 621 extern UWORD getlinearperiod(UWORD,ULONG); 597 622 extern ULONG getfrequency(UWORD,ULONG); 598 623 599 624 /* loader shared data */ 600 - #define STM_NTRACKERS 3 601 - extern CHAR *STM_Signatures[STM_NTRACKERS]; 625 + #define STM_NTRACKERS 3 626 + extern const CHAR *STM_Signatures[STM_NTRACKERS]; 602 627 603 628 /*========== Player interface */ 604 629 605 - extern int Player_Init(MODULE*); 630 + extern int Player_Init(MODULE*); 606 631 extern void Player_Exit(MODULE*); 607 632 extern void Player_HandleTick(void); 608 633 634 + /*========== UnPackers */ 635 + 636 + typedef int (*MUNPACKER) (struct MREADER*, 637 + void** /* unpacked data out */ , 638 + long* /* unpacked data size */ ); 639 + extern int PP20_Unpack(MREADER*, void**, long*); 640 + extern int MMCMP_Unpack(MREADER*, void**, long*); 641 + extern int XPK_Unpack(MREADER*, void**, long*); 642 + extern int S404_Unpack(MREADER*, void**, long*); 643 + 609 644 /*========== Drivers */ 610 645 611 646 /* max. number of handles a driver has to provide. (not strict) */ 612 - #define MAXSAMPLEHANDLES 384 647 + #define MAXSAMPLEHANDLES 384 613 648 614 649 /* These variables can be changed at ANY time and results will be immediate */ 615 650 extern UWORD md_bpm; /* current song / hardware BPM rate */ ··· 625 660 626 661 /* This is for use by the hardware drivers only. It points to the registered 627 662 tickhandler function. */ 628 - extern void (*md_player)(void); 663 + extern MikMod_player_t md_player; 629 664 630 665 extern SWORD MD_SampleLoad(SAMPLOAD*,int); 631 666 extern void MD_SampleUnload(SWORD); ··· 636 671 extern void unsignedtoulaw(char *,int); 637 672 638 673 /* Parameter extraction helper */ 639 - extern CHAR *MD_GetAtom(CHAR*,CHAR*,int); 674 + extern CHAR *MD_GetAtom(const CHAR*, const CHAR*, int); 640 675 641 676 /* Internal software mixer stuff */ 642 677 extern void VC_SetupPointers(void); 643 - extern int VC1_Init(void); 644 - extern int VC2_Init(void); 678 + extern int VC1_Init(void); 679 + extern int VC2_Init(void); 645 680 646 - #if defined(unix) || defined(__APPLE__) && defined(__MACH__) 681 + #if (MIKMOD_UNIX) 647 682 /* POSIX helper functions */ 648 - extern int MD_Access(CHAR *); 649 - extern int MD_DropPrivileges(void); 683 + extern int MD_Access(const CHAR *); 684 + extern int MD_DropPrivileges(void); 650 685 #endif 651 686 652 687 /* Macro to define a missing driver, yet allowing binaries to dynamically link ··· 659 694 extern void _mm_registerloader(struct MLOADER*); 660 695 extern int MikMod_Active_internal(void); 661 696 extern void MikMod_DisableOutput_internal(void); 662 - extern int MikMod_EnableOutput_internal(void); 697 + extern int MikMod_EnableOutput_internal(void); 663 698 extern void MikMod_Exit_internal(void); 664 - extern int MikMod_SetNumVoices_internal(int,int); 699 + extern int MikMod_SetNumVoices_internal(int,int); 665 700 extern void Player_Exit_internal(MODULE*); 666 701 extern void Player_Stop_internal(void); 667 702 extern int Player_Paused_internal(void); ··· 673 708 extern void Voice_Stop_internal(SBYTE); 674 709 extern int Voice_Stopped_internal(SBYTE); 675 710 711 + extern int VC1_PlayStart(void); 712 + extern int VC2_PlayStart(void); 713 + extern void VC1_PlayStop(void); 714 + extern void VC2_PlayStop(void); 715 + extern int VC1_SetNumVoices(void); 716 + extern int VC2_SetNumVoices(void); 717 + 718 + extern MikMod_callback_t vc_callback; 719 + 676 720 #ifdef __cplusplus 677 721 } 678 722 #endif ··· 680 724 /*========== SIMD mixing routines */ 681 725 #undef HAVE_ALTIVEC 682 726 #undef HAVE_SSE2 683 - 684 - #if defined(__APPLE__) && !defined (__i386__) 727 + #if defined(MIKMOD_SIMD) 685 728 686 - #if defined __VEC__ && !(defined(__GNUC__) && (__GNUC__ < 3)) 729 + #if (defined(__ppc__) || defined(__ppc64__)) && defined(__VEC__) && !(defined(__GNUC__) && (__GNUC__ < 3)) 687 730 #define HAVE_ALTIVEC 688 - #endif // __VEC__ 689 731 690 - #elif defined WIN32 || defined __WIN64 || (defined __APPLE__ && defined (__i386__) && defined __VEC__) 691 - 692 - // FIXME: emmintrin.h requires VC6 processor pack or VC2003+ 732 + #elif defined(__GNUC__) && defined(__SSE2__) /* x86 / x86_64 */ 693 733 #define HAVE_SSE2 694 734 695 - /* Fixes couples warnings */ 696 - #ifdef _MSC_VER 735 + #elif defined(_MSC_VER) && (_MSC_VER >= 1300) && (defined(_M_IX86) || defined(_M_AMD64)) 736 + /* FIXME: emmintrin.h requires VC6 processor pack or VC2003+ */ 737 + #define HAVE_SSE2 738 + /* avoid some warnings */ 697 739 #pragma warning(disable:4761) 698 740 #pragma warning(disable:4391) 699 741 #pragma warning(disable:4244) 700 - #endif 701 - #endif 702 - // TODO: Test for GCC Linux 742 + 743 + #endif /* AltiVec/SSE2 */ 744 + #endif /* MIKMOD_SIMD */ 703 745 704 746 /*========== SIMD mixing helper functions =============*/ 705 747 706 - #define IS_ALIGNED_16(ptr) (!(((intptr_t)(ptr)) & 15)) 748 + #if defined(_WIN64) 749 + # if defined(_MSC_VER) 750 + # define IS_ALIGNED_16(ptr) (!((__int64)(ptr) & 15i64)) 751 + # else /* GCC, LCC, .. */ 752 + # define IS_ALIGNED_16(ptr) (!((long long)(ptr) & 15LL)) 753 + # endif 754 + #else /* long cast should be OK for all else */ 755 + #define IS_ALIGNED_16(ptr) (!((long)(ptr) & 15L)) 756 + #endif 707 757 708 758 /* Altivec helper function */ 709 759 #if defined HAVE_ALTIVEC ··· 715 765 #include <ppc_intrinsics.h> 716 766 #endif 717 767 718 - // Helper functions 768 + /* Helper functions */ 719 769 720 - // Set single float across the four values 721 - static inline vector float vec_mul( const vector float a, const vector float b) 722 - { 770 + /* Set single float across the four values */ 771 + static inline vector float vec_mul(const vector float a, const vector float b) { 723 772 return vec_madd(a, b, (const vector float)(0.f)); 724 773 } 725 774 726 - // Set single float across the four values 727 - static inline vector float vec_load_ps1(const float *pF ) 728 - { 775 + /* Set single float across the four values */ 776 + static inline vector float vec_load_ps1(const float *pF) { 729 777 vector float data = vec_lde(0, pF); 730 778 return vec_splat(vec_perm(data, data, vec_lvsl(0, pF)), 0); 731 779 } 732 780 733 - // Set vector to 0 734 - static inline const vector float vec_setzero() 735 - { 736 - return (const vector float) (0.); 781 + /* Set vector to 0 */ 782 + static inline vector float vec_setzero() { 783 + return (vector float) (0.); 737 784 } 738 785 739 - static inline vector signed char vec_set1_8(unsigned char splatchar) 740 - { 741 - vector unsigned char splatmap = vec_lvsl(0, &splatchar); 742 - vector unsigned char result = vec_lde(0, &splatchar); 743 - splatmap = vec_splat(splatmap, 0); 744 - return (vector signed char)vec_perm(result, result, splatmap); 786 + static inline vector signed char vec_set1_8(unsigned char splatchar) { 787 + vector unsigned char splatmap = vec_lvsl(0, &splatchar); 788 + vector unsigned char result = vec_lde(0, &splatchar); 789 + splatmap = vec_splat(splatmap, 0); 790 + return (vector signed char)vec_perm(result, result, splatmap); 745 791 } 746 792 747 793 #define PERM_A0 0x00,0x01,0x02,0x03 ··· 753 799 #define PERM_B2 0x18,0x19,0x1A,0x1B 754 800 #define PERM_B3 0x1C,0x1D,0x1E,0x1F 755 801 756 - // Equivalent to _mm_unpacklo_epi32 757 - static inline vector signed int vec_unpacklo(vector signed int a, vector signed int b) 758 - { 802 + /* Equivalent to _mm_unpacklo_epi32 */ 803 + static inline vector signed int vec_unpacklo(vector signed int a, vector signed int b) { 759 804 return vec_perm(a, b, (vector unsigned char)(PERM_A0,PERM_A1,PERM_B0,PERM_B1)); 760 805 } 761 806 762 - // Equivalent to _mm_srli_si128(a, 8) (without the zeroing in high part). 763 - static inline vector signed int vec_hiqq(vector signed int a) 764 - { 807 + /* Equivalent to _mm_srli_si128(a, 8) (without the zeroing in high part). */ 808 + static inline vector signed int vec_hiqq(vector signed int a) { 765 809 vector signed int b = vec_splat_s32(0); 766 810 return vec_perm(a, b, (vector unsigned char)(PERM_A2,PERM_A3,PERM_B2,PERM_B3)); 767 811 } 768 812 769 - // vec_sra is max +15. We have to do in two times ... 770 - #define EXTRACT_SAMPLE_SIMD_F(srce, var, size, mul) var = vec_mul(vec_ctf(vec_sra(vec_ld(0, (vector signed int*)(srce)), vec_splat_u32(BITSHIFT-size)),0), mul); 771 - #define EXTRACT_SAMPLE_SIMD_0(srce, var) var = vec_sra(vec_sra(vec_ld(0, (vector signed int*)(srce)), vec_splat_u32(15)), vec_splat_u32(BITSHIFT+16-15-0)); 772 - #define EXTRACT_SAMPLE_SIMD_8(srce, var) var = vec_sra(vec_sra(vec_ld(0, (vector signed int*)(srce)), vec_splat_u32(15)), vec_splat_u32(BITSHIFT+16-15-8)); 773 - #define EXTRACT_SAMPLE_SIMD_16(srce, var) var = vec_sra(vec_ld(0, (vector signed int*)(srce)), vec_splat_u32(BITSHIFT+16-16)); 774 - #define PUT_SAMPLE_SIMD_W(dste, v1, v2) vec_st(vec_packs(v1, v2), 0, dste); 775 - #define PUT_SAMPLE_SIMD_B(dste, v1, v2, v3, v4) vec_st(vec_add(vec_packs((vector signed short)vec_packs(v1, v2), (vector signed short)vec_packs(v3, v4)), vec_set1_8(128)), 0, dste); 813 + /* vec_sra is max +15. We have to do in two times ... */ 814 + #define EXTRACT_SAMPLE_SIMD_F(srce, var, size, mul) var = vec_mul(vec_ctf(vec_sra(vec_ld(0, (vector signed int const *)(srce)), vec_splat_u32(BITSHIFT-size)),0), mul); 815 + #define EXTRACT_SAMPLE_SIMD_0(srce, var) var = vec_sra(vec_sra(vec_ld(0, (vector signed int const *)(srce)), vec_splat_u32(15)), vec_splat_u32(BITSHIFT+16-15-0)); 816 + #define EXTRACT_SAMPLE_SIMD_8(srce, var) var = vec_sra(vec_sra(vec_ld(0, (vector signed int const *)(srce)), vec_splat_u32(15)), vec_splat_u32(BITSHIFT+16-15-8)); 817 + #define EXTRACT_SAMPLE_SIMD_16(srce, var) var = vec_sra(vec_ld(0, (vector signed int const *)(srce)), vec_splat_u32(BITSHIFT+16-16)); 818 + #define PUT_SAMPLE_SIMD_W(dste, v1, v2) vec_st(vec_packs(v1, v2), 0, dste); 819 + #define PUT_SAMPLE_SIMD_B(dste, v1, v2, v3, v4) vec_st(vec_add(vec_packs((vector signed short)vec_packs(v1, v2), (vector signed short)vec_packs(v3, v4)), vec_set1_8(128)), 0, dste); 776 820 #define PUT_SAMPLE_SIMD_F(dste, v1) vec_st(v1, 0, dste); 777 821 #define LOAD_PS1_SIMD(ptr) vec_load_ps1(ptr) 778 822 779 823 #elif defined HAVE_SSE2 780 824 781 - /* SSE2 helper function */ 782 - 783 825 #include <emmintrin.h> 784 826 785 - static __inline __m128i mm_hiqq(const __m128i a) 786 - { 787 - return _mm_srli_si128(a, 8); // get the 64bit upper part. new 64bit upper is undefined (zeroed is fine). 827 + /* SSE2 helper function */ 828 + 829 + static __inline __m128i mm_hiqq(const __m128i a) { 830 + return _mm_srli_si128(a, 8); /* get the 64bit upper part. new 64bit upper is undefined (zeroed is fine). */ 788 831 } 789 832 790 833 /* 128-bit mixing macros */ 791 - #define EXTRACT_SAMPLE_SIMD(srce, var, size) var = _mm_srai_epi32(_mm_load_si128((__m128i*)(srce)), BITSHIFT+16-size); 792 - #define EXTRACT_SAMPLE_SIMD_F(srce, var, size, mul) var = _mm_mul_ps(_mm_cvtepi32_ps(_mm_srai_epi32(_mm_load_si128((__m128i*)(srce)), BITSHIFT-size)), mul); 834 + #define EXTRACT_SAMPLE_SIMD(srce, var, size) var = _mm_srai_epi32(_mm_load_si128((__m128i const *)(srce)), BITSHIFT+16-size); 835 + #define EXTRACT_SAMPLE_SIMD_F(srce, var, size, mul) var = _mm_mul_ps(_mm_cvtepi32_ps(_mm_srai_epi32(_mm_load_si128((__m128i const *)(srce)), BITSHIFT-size)), mul); 793 836 #define EXTRACT_SAMPLE_SIMD_0(srce, var) EXTRACT_SAMPLE_SIMD(srce, var, 0) 794 837 #define EXTRACT_SAMPLE_SIMD_8(srce, var) EXTRACT_SAMPLE_SIMD(srce, var, 8) 795 838 #define EXTRACT_SAMPLE_SIMD_16(srce, var) EXTRACT_SAMPLE_SIMD(srce, var, 16) 796 - #define PUT_SAMPLE_SIMD_W(dste, v1, v2) _mm_store_si128((__m128i*)(dste), _mm_packs_epi32(v1, v2)); 797 - #define PUT_SAMPLE_SIMD_B(dste, v1, v2, v3, v4) _mm_store_si128((__m128i*)(dste), _mm_add_epi8(_mm_packs_epi16(_mm_packs_epi32(v1, v2), _mm_packs_epi32(v3, v4)), _mm_set1_epi8(128))); 839 + #define PUT_SAMPLE_SIMD_W(dste, v1, v2) _mm_store_si128((__m128i*)(dste), _mm_packs_epi32(v1, v2)); 840 + #define PUT_SAMPLE_SIMD_B(dste, v1, v2, v3, v4) _mm_store_si128((__m128i*)(dste), _mm_add_epi8(_mm_packs_epi16(_mm_packs_epi32(v1, v2), _mm_packs_epi32(v3, v4)), _mm_set1_epi8(128))); 798 841 #define PUT_SAMPLE_SIMD_F(dste, v1) _mm_store_ps((float*)(dste), v1); 799 842 #define LOAD_PS1_SIMD(ptr) _mm_load_ps1(ptr) 800 843 #define simd_m128i __m128i ··· 802 845 803 846 #endif 804 847 848 + #if defined(HAVE_SSE2) || defined(HAVE_ALTIVEC) 849 + /* MikMod_amalloc() returns a 16 byte aligned zero-filled 850 + memory in SIMD-enabled builds. 851 + - the returned memory can be freed with MikMod_afree() 852 + - the returned memory CAN NOT be realloc()'ed safely. */ 853 + #ifdef __cplusplus 854 + extern "C" { 855 + #endif 856 + void* MikMod_amalloc(size_t); 857 + void MikMod_afree(void *); /* frees if ptr != NULL */ 858 + #ifdef __cplusplus 859 + } 860 + #endif 805 861 862 + #else /* NO SIMD */ 863 + #define MikMod_amalloc MikMod_malloc 864 + #define MikMod_afree MikMod_free 806 865 #endif 866 + 867 + #endif /* _MIKMOD_INTERNALS_H */ 807 868 808 869 /* ex:set ts=4: */
+3
apps/plugins/mikmod/mikmod_supp.h
··· 8 8 9 9 #undef WIN32 10 10 11 + #define NO_DEPACKERS // We don't support these 12 + //#define NO_HQMIXER // We don't have the oomph 13 + 11 14 #ifndef NO_MMSUPP_DEFINES 12 15 #define snprintf(...) rb->snprintf(__VA_ARGS__) 13 16 #define fdprintf(...) rb->fdprintf(__VA_ARGS__)
+196 -119
apps/plugins/mikmod/mloader.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: mloader.c,v 1.3 2005/04/07 19:57:39 realtech Exp $ 23 + $Id$ 24 24 25 25 These routines are used to access the available module loaders 26 26 ··· 50 50 51 51 static MLOADER *firstloader=NULL; 52 52 53 - UWORD finetune[16]={ 53 + #ifndef NO_DEPACKERS 54 + static MUNPACKER unpackers[] = { 55 + PP20_Unpack, 56 + MMCMP_Unpack, 57 + XPK_Unpack, 58 + S404_Unpack, 59 + NULL 60 + }; 61 + #endif 62 + 63 + const UWORD finetune[16] = { 54 64 8363,8413,8463,8529,8581,8651,8723,8757, 55 65 7895,7941,7985,8046,8107,8169,8232,8280 56 66 }; ··· 63 73 64 74 MUTEX_LOCK(lists); 65 75 /* compute size of buffer */ 66 - for(l=firstloader;l;l=l->next) len+=1+(l->next?1:0)+strlen(l->version); 76 + for(l = firstloader; l; l = l->next) 77 + len += 1 + (l->next ? 1 : 0) + strlen(l->version); 67 78 68 79 if(len) 69 - if((list=MikMod_malloc(len*sizeof(CHAR)))) { 70 - list[0]=0; 71 - /* list all registered module loders */ 72 - for(l=firstloader;l;l=l->next) 73 - sprintf(list,(l->next)?"%s%s\n":"%s%s",list,l->version); 80 + if((list=(CHAR*)MikMod_malloc(len*sizeof(CHAR))) != NULL) { 81 + CHAR *list_end = list; 82 + list[0] = 0; 83 + /* list all registered module loders */ 84 + for(l = firstloader; l; l = l->next) { 85 + list_end += sprintf(list_end, "%s%s", l->version, (l->next) ? "\n" : ""); 74 86 } 87 + } 75 88 MUTEX_UNLOCK(lists); 76 89 return list; 77 90 } ··· 84 97 while(cruise->next) cruise = cruise->next; 85 98 cruise->next=ldr; 86 99 } else 87 - firstloader=ldr; 100 + firstloader=ldr; 88 101 } 89 102 90 103 MIKMODAPI void MikMod_RegisterLoader(struct MLOADER* ldr) ··· 106 119 107 120 if(!(of.comment=(CHAR*)MikMod_malloc(len+1))) return 0; 108 121 _mm_read_UBYTES(of.comment,len,modreader); 109 - 122 + 110 123 /* translate IT linefeeds */ 111 124 for(i=0;i<len;i++) 112 125 if(of.comment[i]=='\r') of.comment[i]='\n'; ··· 122 135 123 136 int ReadLinedComment(UWORD len,UWORD linelen) 124 137 { 125 - CHAR *tempcomment,*line,*storage; 126 - UWORD total=0,t,lines; 127 - int i; 138 + /* Adapted from the OpenMPT project, C'ified. */ 139 + CHAR *buf, *storage, *p; 140 + size_t numlines, line, fpos, cpos, lpos, cnt; 128 141 129 - lines = (len + linelen - 1) / linelen; 130 - if (len) { 131 - if(!(tempcomment=(CHAR*)MikMod_malloc(len+1))) return 0; 132 - if(!(storage=(CHAR*)MikMod_malloc(linelen+1))) { 133 - MikMod_free(tempcomment); 134 - return 0; 135 - } 136 - memset(tempcomment, ' ', len); 137 - _mm_read_UBYTES(tempcomment,len,modreader); 142 + if (!linelen) return 0; 143 + if (!len) return 1; 138 144 139 - /* compute message length */ 140 - for(line=tempcomment,total=t=0;t<lines;t++,line+=linelen) { 141 - for(i=linelen;(i>=0)&&(line[i]==' ');i--) line[i]=0; 142 - for(i=0;i<linelen;i++) if (!line[i]) break; 143 - total+=1+i; 144 - } 145 + if (!(buf = (CHAR *) MikMod_malloc(len))) return 0; 146 + numlines = (len + linelen - 1) / linelen; 147 + cnt = (linelen + 1) * numlines; 148 + if (!(storage = (CHAR *) MikMod_malloc(cnt + 1))) { 149 + MikMod_free(buf); 150 + return 0; 151 + } 145 152 146 - if(total>lines) { 147 - if(!(of.comment=(CHAR*)MikMod_malloc(total+1))) { 148 - MikMod_free(storage); 149 - MikMod_free(tempcomment); 150 - return 0; 151 - } 152 - 153 - /* convert message */ 154 - for(line=tempcomment,t=0;t<lines;t++,line+=linelen) { 155 - for(i=0;i<linelen;i++) if(!(storage[i]=line[i])) break; 156 - storage[i]=0; /* if (i==linelen) */ 157 - strcat(of.comment,storage);strcat(of.comment,"\r"); 153 + _mm_read_UBYTES(buf,len,modreader); 154 + storage[cnt] = 0; 155 + for (line = 0, fpos = 0, cpos = 0; line < numlines; line++, fpos += linelen, cpos += (linelen + 1)) 156 + { 157 + cnt = len - fpos; 158 + if (cnt > linelen) cnt = linelen; 159 + p = storage + cpos; 160 + memcpy(p, buf + fpos, cnt); 161 + p[cnt] = '\r'; 162 + /* fix weird chars */ 163 + for (lpos = 0; lpos < linelen; lpos++, p++) { 164 + switch (*p) { 165 + case '\0': 166 + case '\n': 167 + case '\r': 168 + *p = ' '; 169 + break; 158 170 } 159 - MikMod_free(storage); 160 - MikMod_free(tempcomment); 161 171 } 162 172 } 173 + 174 + of.comment = storage; 175 + MikMod_free(buf); 163 176 return 1; 164 177 } 165 178 ··· 169 182 _mm_errno=MMERR_NOT_A_MODULE; 170 183 return 0; 171 184 } 172 - if(!(of.positions=MikMod_calloc(total,sizeof(UWORD)))) return 0; 185 + if(!(of.positions=(UWORD*)MikMod_calloc(total,sizeof(UWORD)))) return 0; 173 186 return 1; 174 187 } 175 188 ··· 207 220 int AllocInstruments(void) 208 221 { 209 222 int t,n; 210 - 223 + 211 224 if(!of.numins) { 212 225 _mm_errno=MMERR_NOT_A_MODULE; 213 226 return 0; ··· 216 229 return 0; 217 230 218 231 for(t=0;t<of.numins;t++) { 219 - for(n=0;n<INSTNOTES;n++) { 232 + for(n=0;n<INSTNOTES;n++) { 220 233 /* Init note / sample lookup table */ 221 234 of.instruments[t].samplenote[n] = n; 222 235 of.instruments[t].samplenumber[n] = t; 223 - } 236 + } 224 237 of.instruments[t].globvol = 64; 225 238 } 226 239 return 1; ··· 257 270 } 258 271 259 272 /* Creates a CSTR out of a character buffer of 'len' bytes, but strips any 260 - terminating non-printing characters like 0, spaces etc. */ 261 - CHAR *DupStr(CHAR* s,UWORD len,int strict) 273 + terminating non-printing characters like 0, spaces etc. */ 274 + CHAR *DupStr(const CHAR* s, UWORD len, int strict) 262 275 { 263 276 UWORD t; 264 277 CHAR *d=NULL; ··· 277 290 278 291 /* When the buffer wasn't completely empty, allocate a cstring and copy the 279 292 buffer into that string, except for any control-chars */ 280 - if((d=(CHAR*)MikMod_malloc(sizeof(CHAR)*(len+1)))) { 293 + if((d=(CHAR*)MikMod_malloc(sizeof(CHAR)*(len+1))) != NULL) { 281 294 for(t=0;t<len;t++) d[t]=(s[t]<32)?'.':s[t]; 282 295 d[len]=0; 283 296 } 284 297 return d; 285 298 } 286 299 287 - CHAR *StrDup(CHAR *s) 288 - { 289 - size_t l = strlen(s) + 1; 290 - CHAR *d = MikMod_malloc(l); 291 - strcpy(d, s); 292 - return d; 293 - } 294 - 295 300 static void ML_XFreeSample(SAMPLE *s) 296 301 { 297 302 if(s->handle>=0) 298 303 MD_SampleUnload(s->handle); 299 - if(s->samplename) MikMod_free(s->samplename); 304 + 305 + /* moved samplename freeing to our caller ML_FreeEx(), 306 + * because we are called conditionally. */ 300 307 } 301 308 302 309 static void ML_XFreeInstrument(INSTRUMENT *i) 303 310 { 304 - if(i->insname) MikMod_free(i->insname); 311 + MikMod_free(i->insname); 305 312 } 306 313 307 314 static void ML_FreeEx(MODULE *mf) 308 315 { 309 316 UWORD t; 310 317 311 - if(mf->songname) MikMod_free(mf->songname); 312 - if(mf->comment) MikMod_free(mf->comment); 318 + MikMod_free(mf->songname); 319 + MikMod_free(mf->comment); 313 320 314 - if(mf->modtype) MikMod_free(mf->modtype); 315 - if(mf->positions) MikMod_free(mf->positions); 316 - if(mf->patterns) MikMod_free(mf->patterns); 317 - if(mf->pattrows) MikMod_free(mf->pattrows); 321 + MikMod_free(mf->modtype); 322 + MikMod_free(mf->positions); 323 + MikMod_free(mf->patterns); 324 + MikMod_free(mf->pattrows); 318 325 319 326 if(mf->tracks) { 320 327 for(t=0;t<mf->numtrk;t++) 321 - if(mf->tracks[t]) MikMod_free(mf->tracks[t]); 328 + MikMod_free(mf->tracks[t]); 322 329 MikMod_free(mf->tracks); 323 330 } 324 331 if(mf->instruments) { ··· 327 334 MikMod_free(mf->instruments); 328 335 } 329 336 if(mf->samples) { 330 - for(t=0;t<mf->numsmp;t++) 337 + for(t=0;t<mf->numsmp;t++) { 338 + MikMod_free(mf->samples[t].samplename); 331 339 if(mf->samples[t].length) ML_XFreeSample(&mf->samples[t]); 340 + } 332 341 MikMod_free(mf->samples); 333 342 } 334 343 memset(mf,0,sizeof(MODULE)); ··· 337 346 338 347 static MODULE *ML_AllocUniMod(void) 339 348 { 340 - MODULE *mf; 349 + return (MODULE *) MikMod_malloc(sizeof(MODULE)); 350 + } 351 + 352 + #ifndef NO_DEPACKERS 353 + static int ML_TryUnpack(MREADER *reader,void **out,long *outlen) 354 + { 355 + int i; 356 + 357 + *out = NULL; 358 + *outlen = 0; 341 359 342 - return (mf=MikMod_malloc(sizeof(MODULE))); 360 + for(i=0;unpackers[i]!=NULL;++i) { 361 + _mm_rewind(reader); 362 + if(unpackers[i](reader,out,outlen)) return 1; 363 + } 364 + return 0; 343 365 } 366 + #endif 344 367 345 368 static void Player_Free_internal(MODULE *mf) 346 369 { ··· 360 383 static CHAR* Player_LoadTitle_internal(MREADER *reader) 361 384 { 362 385 MLOADER *l; 386 + CHAR *title; 387 + #ifndef NO_DEPACKERS 388 + void *unpk; 389 + long newlen; 390 + #endif 363 391 364 392 modreader=reader; 365 393 _mm_errno = 0; 366 394 _mm_critical = 0; 367 395 _mm_iobase_setcur(modreader); 368 396 397 + #ifndef NO_DEPACKERS 398 + if(ML_TryUnpack(modreader,&unpk,&newlen)) { 399 + if(!(modreader=_mm_new_mem_reader(unpk,newlen))) { 400 + modreader=reader; 401 + MikMod_free(unpk); 402 + return NULL; 403 + } 404 + } 405 + #endif 406 + 369 407 /* Try to find a loader that recognizes the module */ 370 408 for(l=firstloader;l;l=l->next) { 371 409 _mm_rewind(modreader); 372 410 if(l->Test()) break; 373 411 } 374 412 375 - if(!l) { 413 + if(l) { 414 + title = l->LoadTitle(); 415 + } 416 + else { 376 417 _mm_errno = MMERR_NOT_A_MODULE; 377 418 if(_mm_errorhandler) _mm_errorhandler(); 378 - return NULL; 419 + title = NULL; 379 420 } 380 421 381 - return l->LoadTitle(); 422 + #ifndef NO_DEPACKERS 423 + if (modreader!=reader) { 424 + _mm_delete_mem_reader(modreader); 425 + modreader=reader; 426 + MikMod_free(unpk); 427 + } 428 + #endif 429 + return title; 382 430 } 383 431 384 432 MIKMODAPI CHAR* Player_LoadTitleFP(int fp) ··· 386 434 CHAR* result=NULL; 387 435 MREADER* reader; 388 436 389 - if(fp && (reader=_mm_new_file_reader(fp))) { 437 + if(fp && (reader=_mm_new_file_reader(fp)) != NULL) { 390 438 MUTEX_LOCK(lists); 391 439 result=Player_LoadTitle_internal(reader); 392 440 MUTEX_UNLOCK(lists); ··· 400 448 CHAR *result=NULL; 401 449 MREADER* reader; 402 450 403 - if ((reader=_mm_new_mem_reader(buffer,len))) 451 + if (!buffer || len <= 0) return NULL; 452 + if ((reader=_mm_new_mem_reader(buffer,len)) != NULL) 404 453 { 405 454 MUTEX_LOCK(lists); 406 455 result=Player_LoadTitle_internal(reader); 407 456 MUTEX_UNLOCK(lists); 408 457 _mm_delete_mem_reader(reader); 409 458 } 410 - 411 - 459 + 412 460 return result; 413 461 } 414 462 415 463 MIKMODAPI CHAR* Player_LoadTitleGeneric(MREADER *reader) 416 - { 464 + { 417 465 CHAR *result=NULL; 418 - 466 + 419 467 if (reader) { 420 468 MUTEX_LOCK(lists); 421 469 result=Player_LoadTitle_internal(reader); ··· 424 472 return result; 425 473 } 426 474 427 - MIKMODAPI CHAR* Player_LoadTitle(CHAR* filename) 475 + MIKMODAPI CHAR* Player_LoadTitle(const CHAR* filename) 428 476 { 429 477 CHAR* result=NULL; 430 478 int fp; 431 479 MREADER* reader; 432 480 433 - if((fp=_mm_fopen(filename,"rb"))) { 434 - if((reader=_mm_new_file_reader(fp))) { 481 + if((fp=_mm_fopen(filename,"rb")) >= 0) { 482 + if((reader=_mm_new_file_reader(fp)) != NULL) { 435 483 MUTEX_LOCK(lists); 436 484 result=Player_LoadTitle_internal(reader); 437 485 MUTEX_UNLOCK(lists); ··· 449 497 MLOADER *l; 450 498 int ok; 451 499 MODULE *mf; 500 + #ifndef NO_DEPACKERS 501 + void *unpk; 502 + long newlen; 503 + #endif 452 504 453 505 modreader = reader; 454 506 _mm_errno = 0; 455 507 _mm_critical = 0; 456 508 _mm_iobase_setcur(modreader); 457 509 510 + #ifndef NO_DEPACKERS 511 + if(ML_TryUnpack(modreader,&unpk,&newlen)) { 512 + if(!(modreader=_mm_new_mem_reader(unpk,newlen))) { 513 + modreader=reader; 514 + MikMod_free(unpk); 515 + return NULL; 516 + } 517 + } 518 + #endif 519 + 458 520 /* Try to find a loader that recognizes the module */ 459 521 for(l=firstloader;l;l=l->next) { 460 522 _mm_rewind(modreader); ··· 463 525 464 526 if(!l) { 465 527 _mm_errno = MMERR_NOT_A_MODULE; 528 + #ifndef NO_DEPACKERS 529 + if(modreader!=reader) { 530 + _mm_delete_mem_reader(modreader); 531 + modreader=reader; 532 + MikMod_free(unpk); 533 + } 534 + #endif 466 535 if(_mm_errorhandler) _mm_errorhandler(); 467 - _mm_rewind(modreader);_mm_iobase_revert(modreader); 536 + _mm_rewind(modreader); 537 + _mm_iobase_revert(modreader); 468 538 return NULL; 469 539 } 470 540 471 541 /* init unitrk routines */ 472 542 if(!UniInit()) { 543 + #ifndef NO_DEPACKERS 544 + if(modreader!=reader) { 545 + _mm_delete_mem_reader(modreader); 546 + modreader=reader; 547 + MikMod_free(unpk); 548 + } 549 + #endif 473 550 if(_mm_errorhandler) _mm_errorhandler(); 474 - _mm_rewind(modreader);_mm_iobase_revert(modreader); 551 + _mm_rewind(modreader); 552 + _mm_iobase_revert(modreader); 475 553 return NULL; 476 554 } 477 555 ··· 487 565 if (!l->Init || l->Init()) { 488 566 _mm_rewind(modreader); 489 567 ok = l->Load(curious); 490 - if (ok) { 568 + if (ok) { 491 569 /* propagate inflags=flags for in-module samples */ 492 570 for (t = 0; t < of.numsmp; t++) 493 571 if (of.samples[t].inflags == 0) ··· 500 578 if (l->Cleanup) l->Cleanup(); 501 579 UniCleanup(); 502 580 581 + if(ok) ok = ML_LoadSamples(); 582 + if(ok) ok = ((mf=ML_AllocUniMod()) != NULL); 503 583 if(!ok) { 504 584 ML_FreeEx(&of); 585 + #ifndef NO_DEPACKERS 586 + if(modreader!=reader) { 587 + _mm_delete_mem_reader(modreader); 588 + modreader=reader; 589 + MikMod_free(unpk); 590 + } 591 + #endif 505 592 if(_mm_errorhandler) _mm_errorhandler(); 506 - _mm_rewind(modreader);_mm_iobase_revert(modreader); 593 + _mm_rewind(modreader); 594 + _mm_iobase_revert(modreader); 507 595 return NULL; 508 596 } 509 597 510 - if(!ML_LoadSamples()) { 511 - ML_FreeEx(&of); 512 - if(_mm_errorhandler) _mm_errorhandler(); 513 - _mm_rewind(modreader);_mm_iobase_revert(modreader); 514 - return NULL; 515 - } 516 - 517 - if(!(mf=ML_AllocUniMod())) { 518 - ML_FreeEx(&of); 519 - _mm_rewind(modreader);_mm_iobase_revert(modreader); 520 - if(_mm_errorhandler) _mm_errorhandler(); 521 - return NULL; 522 - } 523 - 524 598 /* If the module doesn't have any specific panning, create a 525 599 MOD-like panning, with the channels half-separated. */ 526 600 if (!(of.flags & UF_PANNING)) ··· 539 613 540 614 if(maxchan<mf->numchn) mf->flags |= UF_NNA; 541 615 542 - if(MikMod_SetNumVoices_internal(maxchan,-1)) { 543 - _mm_iobase_revert(modreader); 544 - Player_Free(mf); 545 - return NULL; 546 - } 616 + ok = !MikMod_SetNumVoices_internal(maxchan,-1); 547 617 } 548 - if(SL_LoadSamples()) { 549 - _mm_iobase_revert(modreader); 618 + 619 + if(ok) ok = !SL_LoadSamples(); 620 + if(ok) ok = !Player_Init(mf); 621 + 622 + #ifndef NO_DEPACKERS 623 + if(modreader!=reader) { 624 + _mm_delete_mem_reader(modreader); 625 + modreader=reader; 626 + MikMod_free(unpk); 627 + } 628 + #endif 629 + _mm_iobase_revert(modreader); 630 + 631 + if(!ok) { 550 632 Player_Free_internal(mf); 551 633 return NULL; 552 634 } 553 - if(Player_Init(mf)) { 554 - _mm_iobase_revert(modreader); 555 - Player_Free_internal(mf); 556 - mf=NULL; 557 - } 558 - _mm_iobase_revert(modreader); 559 635 return mf; 560 636 } 561 637 ··· 577 653 MODULE* result=NULL; 578 654 MREADER* reader; 579 655 580 - if ((reader=_mm_new_mem_reader(buffer, len))) { 656 + if (!buffer || len <= 0) return NULL; 657 + if ((reader=_mm_new_mem_reader(buffer, len)) != NULL) { 581 658 result=Player_LoadGeneric(reader,maxchan,curious); 582 659 _mm_delete_mem_reader(reader); 583 660 } ··· 589 666 MIKMODAPI MODULE* Player_LoadFP(int fp,int maxchan,int curious) 590 667 { 591 668 MODULE* result=NULL; 592 - struct MREADER* reader=_mm_new_file_reader (fp); 669 + struct MREADER* reader; 593 670 594 - if (reader) { 671 + if (fp && (reader=_mm_new_file_reader(fp)) != NULL) { 595 672 result=Player_LoadGeneric(reader,maxchan,curious); 596 673 _mm_delete_file_reader(reader); 597 674 } ··· 600 677 601 678 /* Open a module via its filename. The loader will initialize the specified 602 679 song-player 'player'. */ 603 - MIKMODAPI MODULE* Player_Load(CHAR* filename,int maxchan,int curious) 680 + MIKMODAPI MODULE* Player_Load(const CHAR* filename,int maxchan,int curious) 604 681 { 605 682 int fp; 606 683 MODULE *mf=NULL; 607 684 608 - if((fp=_mm_fopen(filename,"rb"))) { 685 + if((fp=_mm_fopen(filename,"rb")) >= 0) { 609 686 mf=Player_LoadFP(fp,maxchan,curious); 610 687 _mm_fclose(fp); 611 688 }
+3 -2
apps/plugins/mikmod/mlreg.c
··· 40 40 _mm_registerloader(&load_dsm); 41 41 _mm_registerloader(&load_far); 42 42 _mm_registerloader(&load_gdm); 43 - _mm_registerloader(&load_gt2); 43 + /* _mm_registerloader(&load_gt2);*/ /* load_gt2 isn't complete */ 44 44 _mm_registerloader(&load_it); 45 45 _mm_registerloader(&load_imf); 46 46 _mm_registerloader(&load_mod); ··· 51 51 _mm_registerloader(&load_stm); 52 52 _mm_registerloader(&load_stx); 53 53 _mm_registerloader(&load_ult); 54 + _mm_registerloader(&load_umx); 54 55 _mm_registerloader(&load_uni); 55 56 _mm_registerloader(&load_xm); 56 57 57 58 _mm_registerloader(&load_m15); 58 59 } 59 60 60 - void MikMod_RegisterAllLoaders(void) 61 + MIKMODAPI void MikMod_RegisterAllLoaders(void) 61 62 { 62 63 MUTEX_LOCK(lists); 63 64 MikMod_RegisterAllLoaders_internal();
+19 -25
apps/plugins/mikmod/mlutil.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: mlutil.c,v 1.3 2007/12/06 17:43:10 denis111 Exp $ 23 + $Id$ 24 24 25 25 Utility functions for the module loader 26 26 ··· 43 43 44 44 /*========== Shared tracker identifiers */ 45 45 46 - CHAR *STM_Signatures[STM_NTRACKERS] = { 46 + const CHAR *STM_Signatures[STM_NTRACKERS] = { 47 47 "!Scream!", 48 48 "BMOD2STM", 49 49 "WUZAMOD!" 50 50 }; 51 51 52 - CHAR *STM_Version[STM_NTRACKERS] = { 52 + const CHAR *STM_Version[STM_NTRACKERS] = { 53 53 "Screamtracker 2", 54 54 "Converted by MOD2STM (STM format)", 55 55 "Wuzamod (STM format)" ··· 71 71 /*========== Linear periods stuff */ 72 72 73 73 int* noteindex=NULL; /* remap value for linear period modules */ 74 - static int noteindexcount=0; 74 + static unsigned noteindexcount=0; 75 75 76 76 int *AllocLinear(void) 77 77 { 78 78 if(of.numsmp>noteindexcount) { 79 79 noteindexcount=of.numsmp; 80 - noteindex=MikMod_realloc(noteindex,noteindexcount*sizeof(int)); 80 + noteindex=(int*)MikMod_realloc(noteindex,noteindexcount*sizeof(int)); 81 81 } 82 82 return noteindex; 83 83 } 84 84 85 85 void FreeLinear(void) 86 86 { 87 - if(noteindex) { 88 - MikMod_free(noteindex); 89 - noteindex=NULL; 90 - } 87 + MikMod_free(noteindex); 88 + noteindex=NULL; 91 89 noteindexcount=0; 92 90 } 93 91 94 92 int speed_to_finetune(ULONG speed,int sample) 95 93 { 96 - ULONG ctmp=0,tmp,note=1,finetune=0; 94 + ULONG ctmp=0,tmp,note=1,ft=0; 97 95 98 96 speed>>=1; 99 97 while((tmp=getfrequency(of.flags,getlinearperiod(note<<1,0)))<speed) { ··· 104 102 if(tmp!=speed) { 105 103 if((tmp-speed)<(speed-ctmp)) 106 104 while(tmp>speed) 107 - tmp=getfrequency(of.flags,getlinearperiod(note<<1,--finetune)); 105 + tmp=getfrequency(of.flags,getlinearperiod(note<<1,--ft)); 108 106 else { 109 107 note--; 110 108 while(ctmp<speed) 111 - ctmp=getfrequency(of.flags,getlinearperiod(note<<1,++finetune)); 109 + ctmp=getfrequency(of.flags,getlinearperiod(note<<1,++ft)); 112 110 } 113 111 } 114 112 115 113 noteindex[sample]=note-4*OCTAVE; 116 - return finetune; 114 + return ft; 117 115 } 118 116 119 117 /*========== Order stuff */ ··· 141 139 /*========== Effect stuff */ 142 140 143 141 /* handles S3M and IT effects */ 144 - void S3MIT_ProcessCmd(UBYTE cmd,UBYTE inf,unsigned int flags) 142 + void S3MIT_ProcessCmd(UBYTE cmd, UBYTE inf, unsigned int flags) 145 143 { 146 - UBYTE /* hi,*/ lo; 147 - 148 - lo=inf&0xf; 149 - /* hi=inf>>4; */ 150 - 144 + UBYTE lo = inf&0xF; 151 145 /* process S3M / IT specific command structure */ 152 146 153 147 if(cmd!=255) { ··· 196 190 case 9: /* Ixy tremor, ontime x, offtime y */ 197 191 if (flags & S3MIT_OLDSTYLE) 198 192 UniEffect(UNI_S3MEFFECTI,inf); 199 - else 193 + else 200 194 UniEffect(UNI_ITEFFECTI,inf); 201 195 break; 202 196 case 0xa: /* Jxy arpeggio */ ··· 204 198 break; 205 199 case 0xb: /* Kxy Dual command H00 & Dxy */ 206 200 if (flags & S3MIT_OLDSTYLE) 207 - UniPTEffect(0x4,0); 201 + UniPTEffect(0x4,0); 208 202 else 209 203 UniEffect(UNI_ITEFFECTH,0); 210 204 UniEffect(UNI_S3MEFFECTD,inf); ··· 218 212 break; 219 213 case 0xd: /* Mxx Set Channel Volume */ 220 214 UniEffect(UNI_ITEFFECTM,inf); 221 - break; 215 + break; 222 216 case 0xe: /* Nxy Slide Channel Volume */ 223 217 UniEffect(UNI_ITEFFECTN,inf); 224 218 break; ··· 233 227 if(inf && !lo && !(flags & S3MIT_OLDSTYLE)) 234 228 UniWriteByte(1); 235 229 else 236 - UniWriteByte(inf); 230 + UniWriteByte(inf); 237 231 break; 238 232 case 0x12: /* Rxy tremolo speed x, depth y */ 239 233 UniEffect(UNI_S3MEFFECTR,inf);
+85 -122
apps/plugins/mikmod/mmalloc.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: mmalloc.c,v 1.3 2007/12/03 20:42:58 denis111 Exp $ 23 + $Id$ 24 24 25 25 Dynamic memory routines 26 26 ··· 30 30 #include "config.h" 31 31 #endif 32 32 33 - #include "mikmod_internals.h" 34 - 35 - #define ALIGN_STRIDE 16 36 - /* not used 37 - static void * align_pointer(char *ptr, size_t stride) 38 - { 39 - char *pptr = ptr + sizeof(void*); 40 - char *fptr; 41 - size_t err = ((size_t)pptr)&(stride-1); 42 - if (err) 43 - fptr = pptr + (stride - err); 44 - else 45 - fptr = pptr; 46 - *(size_t*)(fptr - sizeof(void*)) = (size_t)ptr; 47 - return fptr; 48 - } 33 + #ifdef HAVE_POSIX_MEMALIGN 34 + #define _XOPEN_SOURCE 600 /* for posix_memalign */ 35 + #endif 49 36 50 - static void *get_pointer(void *data) 51 - { 52 - unsigned char *_pptr = (unsigned char*)data - sizeof(void*); 53 - size_t _ptr = *(size_t*)_pptr; 54 - return (void*)_ptr; 55 - } 56 - */ 37 + #include "string.h" 38 + #include "mikmod_internals.h" 57 39 58 - void* MikMod_realloc(void *data, size_t size) 59 - { 60 - return realloc(data, size); 61 - 62 - #if 0 63 - if (data) 64 - { 65 - #if defined __MACH__ 66 - void *d = realloc(data, size); 67 - if (d) 68 - { 69 - return d; 70 - } 71 - return 0; 72 - #elif (defined _WIN32 || defined _WIN64) && !defined(_WIN32_WCE) 73 - return _aligned_realloc(data, size, ALIGN_STRIDE); 74 - #else 75 - unsigned char *newPtr = (unsigned char *)realloc(get_pointer(data), size + ALIGN_STRIDE + sizeof(void*)); 76 - return align_pointer(newPtr, ALIGN_STRIDE); 77 - #endif 78 - } 79 - return MikMod_malloc(size); 40 + #if defined(HAVE_SSE2) || defined(HAVE_ALTIVEC) 41 + #undef WIN32_ALIGNED_MALLOC 42 + #if defined(_WIN32) && !defined(_WIN32_WCE) 43 + # if defined(_WIN64) /* OK with MSVC and MinGW */ 44 + # define WIN32_ALIGNED_MALLOC 45 + # elif defined(_MSC_VER) && (_MSC_VER >= 1300) 46 + # define WIN32_ALIGNED_MALLOC 47 + # elif defined(__MINGW32__) 48 + /* no guarantees that msvcrt.dll will have it */ 49 + # endif 80 50 #endif 81 - } 82 51 52 + #define PTRSIZE (sizeof(void*)) 83 53 84 - /* Same as malloc, but sets error variable _mm_error when fails. Returns a 16-byte aligned pointer */ 85 - void* MikMod_malloc(size_t size) 54 + /* return a 16 byte aligned address */ 55 + void* MikMod_amalloc(size_t size) 86 56 { 87 57 void *d; 88 - if(!(d=calloc(1,size))) { 89 - _mm_errno = MMERR_OUT_OF_MEMORY; 90 - if(_mm_errorhandler) _mm_errorhandler(); 91 - } 92 - return d; 93 - 94 - #if 0 95 - #if defined __MACH__ 96 - void *d = calloc(1, size); 97 - if (d) 98 - { 58 + #if defined(HAVE_POSIX_MEMALIGN) 59 + if (!posix_memalign(&d, 16, size)) { 60 + memset(d, 0, size); 99 61 return d; 100 62 } 101 - return 0; 102 - #elif (defined _WIN32 || defined _WIN64) && !defined(_WIN32_WCE) 103 - void * d = _aligned_malloc(size, ALIGN_STRIDE); 104 - if (d) 105 - { 63 + #elif defined(WIN32_ALIGNED_MALLOC) 64 + d = _aligned_malloc(size, 16); 65 + if (d) { 106 66 ZeroMemory(d, size); 107 67 return d; 108 68 } 109 - return 0; 110 69 #else 111 - void *d = calloc(1, size + ALIGN_STRIDE + sizeof(void*)); 112 - 113 - if(!d) { 114 - _mm_errno = MMERR_OUT_OF_MEMORY; 115 - if(_mm_errorhandler) _mm_errorhandler(); 70 + size_t s = (size)? ((size + (PTRSIZE-1)) & ~(PTRSIZE-1)) : PTRSIZE; 71 + s += PTRSIZE + 16; 72 + d = calloc(1, s); 73 + if (d) { 74 + char *pptr = (char *)d + PTRSIZE; 75 + size_t err = ((size_t)pptr) & 15; 76 + char *fptr = pptr + (16 - err); 77 + *(size_t*)(fptr - PTRSIZE) = (size_t)d; 78 + return fptr; 116 79 } 117 - return align_pointer(d, ALIGN_STRIDE); 118 80 #endif 81 + 82 + _mm_errno = MMERR_OUT_OF_MEMORY; 83 + if(_mm_errorhandler) _mm_errorhandler(); 84 + return NULL; 85 + } 86 + 87 + void MikMod_afree(void *data) 88 + { 89 + if (!data) return; 90 + #if defined(HAVE_POSIX_MEMALIGN) 91 + free(data); 92 + #elif defined(WIN32_ALIGNED_MALLOC) 93 + _aligned_free(data); 94 + #else 95 + free((void *) *(size_t*)((unsigned char *)data - PTRSIZE)); 119 96 #endif 120 97 } 98 + #endif /* (HAVE_SSE2) || (HAVE_ALTIVEC) */ 99 + 100 + void* MikMod_realloc(void *data, size_t size) 101 + { 102 + if (data) return realloc(data, size); 103 + return calloc(1, size); 104 + } 105 + 106 + /* Same as malloc, but sets error variable _mm_error when fails */ 107 + void* MikMod_malloc(size_t size) 108 + { 109 + return MikMod_calloc(1, size); 110 + } 121 111 122 112 /* Same as calloc, but sets error variable _mm_error when fails */ 123 - void* MikMod_calloc(size_t nitems,size_t size) 113 + void* MikMod_calloc(size_t nitems, size_t size) 124 114 { 125 - void *d; 126 - 127 - if(!(d=calloc(nitems,size))) { 128 - _mm_errno = MMERR_OUT_OF_MEMORY; 129 - if(_mm_errorhandler) _mm_errorhandler(); 130 - } 131 - return d; 132 - 133 - #if 0 134 - #if defined __MACH__ 135 115 void *d = calloc(nitems, size); 136 - if (d) 137 - { 138 - return d; 139 - } 140 - return 0; 141 - #elif (defined _WIN32 || defined _WIN64) && !defined(_WIN32_WCE) 142 - void * d = _aligned_malloc(size * nitems, ALIGN_STRIDE); 143 - if (d) 144 - { 145 - ZeroMemory(d, size * nitems); 146 - return d; 147 - } 148 - return 0; 149 - #else 150 - void *d = calloc(nitems, size + ALIGN_STRIDE + sizeof(void*)); 151 - 152 - if(!d) { 153 - _mm_errno = MMERR_OUT_OF_MEMORY; 154 - if(_mm_errorhandler) _mm_errorhandler(); 155 - } 156 - return align_pointer(d, ALIGN_STRIDE); 157 - #endif 158 - #endif 116 + if (d) return d; 117 + 118 + _mm_errno = MMERR_OUT_OF_MEMORY; 119 + if(_mm_errorhandler) _mm_errorhandler(); 120 + return NULL; 159 121 } 160 122 161 123 void MikMod_free(void *data) 162 124 { 163 - free(data); 164 - 165 - #if 0 166 - if (data) 167 - { 168 - #if defined __MACH__ 169 - free(data); 170 - #elif (defined _WIN32 || defined _WIN64) && !defined(_WIN32_WCE) 171 - _aligned_free(data); 172 - #else 173 - free(get_pointer(data)); 174 - #endif 175 - } 176 - #endif 125 + if (data) free(data); 126 + } 127 + 128 + /* like strdup(), but the result must be freed using MikMod_free() */ 129 + CHAR *MikMod_strdup(const CHAR *s) 130 + { 131 + size_t l; 132 + CHAR *d; 133 + 134 + if (!s) return NULL; 135 + 136 + l = strlen(s) + 1; 137 + d = (CHAR *) MikMod_calloc(1, l * sizeof(CHAR)); 138 + if (d) strcpy(d, s); 139 + return d; 177 140 } 178 141 179 142 /* ex:set ts=4: */
+126 -24
apps/plugins/mikmod/mmerror.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: mmerror.c,v 1.2 2005/03/30 19:10:41 realtech Exp $ 23 + $Id$ 24 24 25 25 Error handling functions. 26 26 Register an error handler with _mm_RegisterErrorHandler() and you're all set. ··· 40 40 41 41 #include "mikmod_internals.h" 42 42 43 - CHAR *_mm_errmsg[MMERR_MAX+1] = 43 + #define _mmerr_invalid "Invalid error code" 44 + 45 + static const char *_mm_errmsg[MMERR_MAX+1] = 44 46 { 45 47 /* No error */ 46 48 ··· 82 84 "Unable to set non-blocking mode for audio device", 83 85 84 86 /* AudioFile driver errors */ 85 - 87 + #ifdef DRV_AF 86 88 "Cannot find suitable AudioFile audio port", 89 + #else 90 + _mmerr_invalid, 91 + #endif 87 92 88 93 /* AIX driver errors */ 89 - 94 + #ifdef DRV_AIX 90 95 "Configuration (init step) of audio device failed", 91 96 "Configuration (control step) of audio device failed", 92 97 "Configuration (start step) of audio device failed", 93 - 94 - /* ALSA driver errors */ 95 - 96 - /* EsounD driver errors */ 98 + #else 99 + _mmerr_invalid, _mmerr_invalid, _mmerr_invalid, 100 + #endif 97 101 98 102 /* Ultrasound driver errors */ 99 - 103 + #ifdef DRV_ULTRA 100 104 "Ultrasound driver only works in 16 bit stereo 44 KHz", 101 105 "Ultrasound card could not be reset", 102 106 "Could not start Ultrasound timer", 107 + #else 108 + _mmerr_invalid, _mmerr_invalid, _mmerr_invalid, 109 + #endif 103 110 104 111 /* HP driver errors */ 105 - 112 + #ifdef DRV_HP 106 113 "Unable to select 16bit-linear sample format", 107 114 "Could not select requested sample-rate", 108 115 "Could not select requested number of channels", 109 116 "Unable to select audio output", 110 117 "Unable to get audio description", 111 118 "Could not set transmission buffer size", 119 + #else 120 + _mmerr_invalid, _mmerr_invalid, _mmerr_invalid, 121 + _mmerr_invalid, _mmerr_invalid, _mmerr_invalid, 122 + #endif 112 123 113 124 /* Open Sound System driver errors */ 114 - 125 + #ifdef DRV_OSS 115 126 "Could not set fragment size", 116 127 "Could not set sample size", 117 128 "Could not set mono/stereo setting", 118 129 "Could not set sample rate", 130 + #else 131 + _mmerr_invalid, _mmerr_invalid, _mmerr_invalid, 132 + _mmerr_invalid, 133 + #endif 119 134 120 135 /* SGI driver errors */ 121 - 136 + #ifdef DRV_SGI 122 137 "Unsupported sample rate", 123 138 "Hardware does not support 16 bit sound", 124 139 "Hardware does not support 8 bit sound", 125 140 "Hardware does not support stereo sound", 126 141 "Hardware does not support mono sound", 142 + #else 143 + _mmerr_invalid, _mmerr_invalid, _mmerr_invalid, 144 + _mmerr_invalid, _mmerr_invalid, 145 + #endif 127 146 128 147 /* Sun driver errors */ 129 - 148 + #ifdef DRV_SUN 130 149 "Sound device initialization failed", 150 + #else 151 + _mmerr_invalid, 152 + #endif 131 153 132 154 /* OS/2 drivers errors */ 133 - 155 + #if defined(DRV_OS2) || defined(DRV_DART) 134 156 "Could not set mixing parameters", 157 + #else 158 + _mmerr_invalid, 159 + #endif 160 + #ifdef DRV_OS2 135 161 "Could not create playback semaphores", 136 162 "Could not create playback timer", 137 163 "Could not create playback thread", 164 + #else 165 + _mmerr_invalid, _mmerr_invalid, _mmerr_invalid, 166 + #endif 138 167 139 168 /* DirectSound driver errors */ 140 - 169 + #ifdef DRV_DS 141 170 "Could not set playback priority", 142 171 "Could not create playback buffers", 143 172 "Could not set playback format", ··· 145 174 "Could not register event", 146 175 "Could not create playback thread", 147 176 "Could not initialize playback thread", 177 + #else 178 + _mmerr_invalid, _mmerr_invalid, _mmerr_invalid, 179 + _mmerr_invalid, _mmerr_invalid, _mmerr_invalid, 180 + _mmerr_invalid, 181 + #endif 148 182 149 183 /* Windows Multimedia API driver errors */ 150 - 184 + #ifdef DRV_WIN 151 185 "Invalid device handle", 152 186 "The resource is already allocated", 153 187 "Invalid device identifier", 154 188 "Unsupported output format", 155 189 "Unknown error", 190 + #else 191 + _mmerr_invalid, _mmerr_invalid, _mmerr_invalid, 192 + _mmerr_invalid, _mmerr_invalid, 193 + #endif 156 194 157 195 /* Macintosh driver errors */ 158 - 196 + #ifdef DRV_MAC 159 197 "Unsupported sample rate", 160 198 "Could not start playback", 199 + #else 200 + _mmerr_invalid, _mmerr_invalid, 201 + #endif 161 202 162 203 /* MacOS X/Darwin driver errors */ 163 - 204 + #ifdef DRV_OSX 164 205 "Unknown device", 165 206 "Bad property", 166 207 "Could not set playback format", ··· 169 210 "Could not create playback thread", 170 211 "Could not start audio device", 171 212 "Could not create buffer thread", 213 + #else 214 + _mmerr_invalid, _mmerr_invalid, _mmerr_invalid, 215 + _mmerr_invalid, _mmerr_invalid, _mmerr_invalid, 216 + _mmerr_invalid, _mmerr_invalid, 217 + #endif 172 218 173 219 /* DOS driver errors */ 174 - 220 + #ifdef DRV_WSS 175 221 "WSS_STARTDMA", 222 + #else 223 + _mmerr_invalid, 224 + #endif 225 + #ifdef DRV_SB 176 226 "SB_STARTDMA", 227 + #else 228 + _mmerr_invalid, 229 + #endif 230 + 231 + /* float32 output */ 232 + 233 + "This driver doesn't support 32 bit float output", 234 + 235 + /* OpenAL driver errors */ 236 + #ifdef DRV_OPENAL 237 + "Could not create context", 238 + "Could not make context current", 239 + "Could not create buffers", 240 + "Could not create sources", 241 + "Could not change source parameters", 242 + "Could not queue buffers", 243 + "Could not unqueue buffers", 244 + "Could not copy buffer data", 245 + "Could not get source parameters", 246 + "Could not play source", 247 + "Could not stop source", 248 + #else 249 + _mmerr_invalid, _mmerr_invalid, _mmerr_invalid, 250 + _mmerr_invalid, _mmerr_invalid, _mmerr_invalid, 251 + _mmerr_invalid, _mmerr_invalid, _mmerr_invalid, 252 + _mmerr_invalid, _mmerr_invalid, 253 + #endif 254 + 255 + /* ALSA driver errors */ 256 + #ifdef DRV_ALSA 257 + "No ALSA configurations available", 258 + "Could not set ALSA output params", 259 + "Could not set playback format", 260 + "Could not set sample rate", 261 + "Could not set mono/stereo setting", 262 + "Could not get buffer size from ALSA", 263 + "ALSA PCM start error", 264 + "ALSA PCM write error", 265 + "ALSA PCM recovery failure", 266 + #else 267 + _mmerr_invalid, _mmerr_invalid, _mmerr_invalid, 268 + _mmerr_invalid, _mmerr_invalid, _mmerr_invalid, 269 + _mmerr_invalid, _mmerr_invalid, _mmerr_invalid, 270 + #endif 271 + 272 + /* Sndio errors */ 273 + #ifdef DRV_SNDIO 274 + "Could not set SNDIO output params", 275 + "Unsupported SNDIO output params", 276 + #else 277 + _mmerr_invalid, _mmerr_invalid, 278 + #endif 177 279 178 280 /* Invalid error */ 179 281 180 - "Invalid error code" 282 + _mmerr_invalid 181 283 }; 182 284 183 - MIKMODAPI char *MikMod_strerror(int code) 285 + MIKMODAPI const char *MikMod_strerror(int code) 184 286 { 185 - if ((code<0)||(code>MMERR_MAX)) code=MMERR_MAX+1; 287 + if ((code<0)||(code>MMERR_MAX)) code=MMERR_MAX; 186 288 return _mm_errmsg[code]; 187 289 } 188 290
+171 -129
apps/plugins/mikmod/mmio.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 19 19 */ 20 20 21 21 /*============================================================================== 22 - 23 - $Id: mmio.c,v 1.3 2005/03/30 19:10:58 realtech Exp $ 24 22 25 23 Portable file I/O routines 26 24 ··· 49 47 50 48 #ifdef HAVE_UNISTD_H 51 49 #include <unistd.h> 50 + #endif 51 + 52 + #ifdef HAVE_LIMITS_H 53 + #include <limits.h> 52 54 #endif 53 55 54 56 #include <stdio.h> 55 57 #include <string.h> 58 + #include <limits.h> 56 59 57 - #include "mikmod.h" 58 60 #include "mikmod_internals.h" 59 61 60 62 #ifdef SUNOS ··· 66 68 extern size_t fwrite(const void *, size_t, size_t, FILE *); 67 69 #endif 68 70 69 - #define COPY_BUFSIZE 1024 70 - 71 71 /* some prototypes */ 72 72 static int _mm_MemReader_Eof(MREADER* reader); 73 73 static int _mm_MemReader_Read(MREADER* reader,void* ptr,size_t size); ··· 75 75 static int _mm_MemReader_Seek(MREADER* reader,long offset,int whence); 76 76 static long _mm_MemReader_Tell(MREADER* reader); 77 77 78 - //static long _mm_iobase=0,temp_iobase=0; 79 - 80 - int _mm_fopen(CHAR* fname,CHAR* attrib) 78 + int _mm_fopen(const CHAR* fname, const CHAR* attrib) 81 79 { 82 80 int fp; 83 - (void)attrib; 84 - 81 + (void)attrib; 85 82 //if(!(fp=fopen(fname,attrib))) { 86 - // _mm_errno = MMERR_OPENING_FILE; 87 - // if(_mm_errorhandler) _mm_errorhandler(); 83 + // _mm_errno = MMERR_OPENING_FILE; 84 + // if(_mm_errorhandler) _mm_errorhandler(); 88 85 //} 89 86 fp = open(fname, O_RDONLY); 90 87 if( fp < 0 ) { ··· 94 91 return fp; 95 92 } 96 93 97 - int _mm_FileExists(CHAR* fname) 94 + int _mm_FileExists(const CHAR* fname) 98 95 { 99 96 int fp; 100 97 ··· 103 100 fp = open(fname, O_RDONLY); 104 101 if ( fp < 0 ) return 0; 105 102 close(fp); 106 - 103 + 107 104 return 1; 108 105 } 109 106 ··· 130 127 131 128 typedef struct MFILEREADER { 132 129 MREADER core; 133 - int file; 130 + int file; 134 131 } MFILEREADER; 135 132 136 133 static int _mm_FileReader_Eof(MREADER* reader) 137 134 { 138 - //return feof(((MFILEREADER*)reader)->file); 135 + //return feof(((MFILEREADER*)reader)->file); 139 136 int size = filesize(((MFILEREADER*)reader)->file); 140 137 int offset = lseek(((MFILEREADER*)reader)->file, 0, SEEK_CUR); 141 138 return (size <= 0 || offset < 0 || offset >= size) ? 1 : 0; ··· 143 140 144 141 static int _mm_FileReader_Read(MREADER* reader,void* ptr,size_t size) 145 142 { 143 + return read(((MFILEREADER*)reader)->file, ptr, size); 146 144 //return !!fread(ptr,size,1,((MFILEREADER*)reader)->file); 147 - return read(((MFILEREADER*)reader)->file, ptr, size); 148 145 } 149 146 150 147 static int _mm_FileReader_Get(MREADER* reader) ··· 160 157 static int _mm_FileReader_Seek(MREADER* reader,long offset,int whence) 161 158 { 162 159 //return fseek(((MFILEREADER*)reader)->file, 163 - // (whence==SEEK_SET)?offset+reader->iobase:offset,whence); 160 + // (whence==SEEK_SET)?offset+reader->iobase:offset,whence); 164 161 return lseek(((MFILEREADER*)reader)->file, 165 162 (whence==SEEK_SET)?offset+reader->iobase:offset,whence); 166 163 } ··· 173 170 174 171 MREADER *_mm_new_file_reader(int fp) 175 172 { 176 - MFILEREADER* reader=(MFILEREADER*)MikMod_malloc(sizeof(MFILEREADER)); 173 + MFILEREADER* reader=(MFILEREADER*)MikMod_calloc(1,sizeof(MFILEREADER)); 177 174 if (reader) { 178 175 reader->core.Eof =&_mm_FileReader_Eof; 179 176 reader->core.Read=&_mm_FileReader_Read; ··· 187 184 188 185 void _mm_delete_file_reader (MREADER* reader) 189 186 { 190 - if(reader) MikMod_free(reader); 187 + MikMod_free(reader); 191 188 } 192 189 193 190 /*========== File Writer */ 194 191 195 192 typedef struct MFILEWRITER { 196 193 MWRITER core; 197 - int file; 194 + int file; 198 195 } MFILEWRITER; 199 196 200 197 static int _mm_FileWriter_Seek(MWRITER* writer,long offset,int whence) ··· 209 206 return lseek(((MFILEWRITER*)writer)->file, 0, SEEK_CUR); 210 207 } 211 208 212 - static int _mm_FileWriter_Write(MWRITER* writer,void* ptr,size_t size) 209 + static int _mm_FileWriter_Write(MWRITER* writer, const void* ptr, size_t size) 213 210 { 214 211 //return (fwrite(ptr,size,1,((MFILEWRITER*)writer)->file)==size); 215 - //return (write(ptr,size,((MFILEWRITER*)writer)->file)==(int)size); 216 - (void)writer; 217 - (void)ptr; 218 - (void)size; 219 - return 0; 212 + (void)writer; 213 + (void)ptr; 214 + (void)size; 215 + return 0; 220 216 } 221 217 222 218 static int _mm_FileWriter_Put(MWRITER* writer,int value) 223 219 { 224 - (void)writer; 225 - (void)value; 220 + (void)writer; 221 + (void)value; 226 222 //return fputc(value,((MFILEWRITER*)writer)->file); 227 - return 1; // TODO 223 + return 1; // TODO 228 224 } 229 225 230 226 MWRITER *_mm_new_file_writer(int fp) 231 227 { 232 - MFILEWRITER* writer=(MFILEWRITER*)MikMod_malloc(sizeof(MFILEWRITER)); 228 + MFILEWRITER* writer=(MFILEWRITER*)MikMod_calloc(1,sizeof(MFILEWRITER)); 233 229 if (writer) { 234 230 writer->core.Seek =&_mm_FileWriter_Seek; 235 231 writer->core.Tell =&_mm_FileWriter_Tell; ··· 242 238 243 239 void _mm_delete_file_writer (MWRITER* writer) 244 240 { 245 - if(writer) MikMod_free (writer); 241 + MikMod_free (writer); 246 242 } 247 243 248 244 /*========== Memory Reader */ 249 - 250 245 251 246 typedef struct MMEMREADER { 252 247 MREADER core; ··· 257 252 258 253 void _mm_delete_mem_reader(MREADER* reader) 259 254 { 260 - if (reader) { MikMod_free(reader); } 255 + MikMod_free(reader); 261 256 } 262 257 263 - MREADER *_mm_new_mem_reader(const void *buffer, int len) 258 + MREADER *_mm_new_mem_reader(const void *buffer, long len) 264 259 { 265 - MMEMREADER* reader=(MMEMREADER*)MikMod_malloc(sizeof(MMEMREADER)); 260 + MMEMREADER* reader=(MMEMREADER*)MikMod_calloc(1,sizeof(MMEMREADER)); 266 261 if (reader) 267 262 { 268 263 reader->core.Eof =&_mm_MemReader_Eof; ··· 279 274 280 275 static int _mm_MemReader_Eof(MREADER* reader) 281 276 { 282 - if (!reader) { return 1; } 283 - if ( ((MMEMREADER*)reader)->pos > ((MMEMREADER*)reader)->len ) { 284 - return 1; 285 - } 277 + MMEMREADER* mr = (MMEMREADER*) reader; 278 + if (!mr) return 1; 279 + if (mr->pos >= mr->len) return 1; 286 280 return 0; 287 281 } 288 282 289 283 static int _mm_MemReader_Read(MREADER* reader,void* ptr,size_t size) 290 284 { 291 - unsigned char *d=ptr; 285 + unsigned char *d; 292 286 const unsigned char *s; 293 - 294 - if (!reader) { return 0; } 287 + MMEMREADER* mr; 288 + long siz; 289 + int ret; 295 290 296 - if (reader->Eof(reader)) { return 0; } 291 + if (!reader || !size || (size > (size_t) LONG_MAX)) 292 + return 0; 297 293 298 - s = ((MMEMREADER*)reader)->buffer; 299 - s += ((MMEMREADER*)reader)->pos; 300 - 301 - if ( ((MMEMREADER*)reader)->pos + (long)size > ((MMEMREADER*)reader)->len) 302 - { 303 - ((MMEMREADER*)reader)->pos = ((MMEMREADER*)reader)->len; 304 - return 0; /* not enough remaining bytes */ 294 + mr = (MMEMREADER*) reader; 295 + siz = (long) size; 296 + if (mr->pos >= mr->len) return 0; /* @ eof */ 297 + if (mr->pos + siz > mr->len) { 298 + siz = mr->len - mr->pos; 299 + ret = 0; /* not enough remaining bytes */ 300 + } 301 + else { 302 + ret = 1; 305 303 } 306 304 307 - ((MMEMREADER*)reader)->pos += (long)size; 305 + s = (const unsigned char *) mr->buffer; 306 + s += mr->pos; 307 + mr->pos += siz; 308 + d = (unsigned char *) ptr; 308 309 309 - while (size--) 310 - { 311 - *d = *s; 312 - s++; 313 - d++; 310 + while (siz) { 311 + *d++ = *s++; 312 + siz--; 314 313 } 315 - 316 - return 1; 314 + 315 + return ret; 317 316 } 318 317 319 318 static int _mm_MemReader_Get(MREADER* reader) 320 319 { 321 - int pos; 320 + MMEMREADER* mr; 321 + int c; 322 322 323 - if (reader->Eof(reader)) { return 0; } 324 - 325 - pos = ((MMEMREADER*)reader)->pos; 326 - ((MMEMREADER*)reader)->pos++; 323 + mr = (MMEMREADER*) reader; 324 + if (mr->pos >= mr->len) return EOF; 325 + c = ((const unsigned char*) mr->buffer)[mr->pos]; 326 + mr->pos++; 327 327 328 - return ((unsigned char*)(((MMEMREADER*)reader)->buffer))[pos]; 328 + return c; 329 329 } 330 330 331 331 static int _mm_MemReader_Seek(MREADER* reader,long offset,int whence) 332 332 { 333 - if (!reader) { return -1; } 334 - 333 + MMEMREADER* mr; 334 + 335 + if (!reader) return -1; 336 + mr = (MMEMREADER*) reader; 335 337 switch(whence) 336 338 { 337 - case SEEK_CUR: 338 - ((MMEMREADER*)reader)->pos += offset; 339 - break; 340 - case SEEK_SET: 341 - ((MMEMREADER*)reader)->pos = offset; 342 - break; 343 - case SEEK_END: 344 - ((MMEMREADER*)reader)->pos = ((MMEMREADER*)reader)->len - offset - 1; 345 - break; 339 + case SEEK_CUR: 340 + mr->pos += offset; 341 + break; 342 + case SEEK_SET: 343 + mr->pos = reader->iobase + offset; 344 + break; 345 + case SEEK_END: 346 + mr->pos = mr->len + offset; 347 + break; 348 + default: /* invalid */ 349 + return -1; 346 350 } 347 - if ( ((MMEMREADER*)reader)->pos < 0) { ((MMEMREADER*)reader)->pos = 0; } 348 - if ( ((MMEMREADER*)reader)->pos > ((MMEMREADER*)reader)->len ) { 349 - ((MMEMREADER*)reader)->pos = ((MMEMREADER*)reader)->len; 351 + if (mr->pos < reader->iobase) { 352 + mr->pos = mr->core.iobase; 353 + return -1; 354 + } 355 + if (mr->pos > mr->len) { 356 + mr->pos = mr->len; 350 357 } 351 358 return 0; 352 359 } ··· 354 361 static long _mm_MemReader_Tell(MREADER* reader) 355 362 { 356 363 if (reader) { 357 - return ((MMEMREADER*)reader)->pos; 364 + return ((MMEMREADER*)reader)->pos - reader->iobase; 358 365 } 359 366 return 0; 360 367 } 361 368 362 369 /*========== Write functions */ 363 - void _mm_write_string(CHAR* data,MWRITER* writer) 370 + 371 + void _mm_write_string(const CHAR* data,MWRITER* writer) 364 372 { 365 373 if(data) 366 374 _mm_write_UBYTES(data,strlen(data),writer); ··· 410 418 _mm_write_I_ULONG((ULONG)data,writer); 411 419 } 412 420 413 - #if defined __STDC__ || defined _MSC_VER || defined MPW_C 414 - #define DEFINE_MULTIPLE_WRITE_FUNCTION(type_name,type) \ 415 - void _mm_write_##type_name##S (type *buffer,int number,MWRITER* writer) \ 416 - { \ 417 - while(number-->0) \ 418 - _mm_write_##type_name(*(buffer++),writer); \ 421 + void _mm_write_M_SWORDS(SWORD *buffer,int cnt,MWRITER* writer) 422 + { 423 + while(cnt-- > 0) _mm_write_M_SWORD(*(buffer++),writer); 424 + } 425 + 426 + void _mm_write_M_UWORDS(UWORD *buffer,int cnt,MWRITER* writer) 427 + { 428 + while(cnt-- > 0) _mm_write_M_UWORD(*(buffer++),writer); 429 + } 430 + 431 + void _mm_write_I_SWORDS(SWORD *buffer,int cnt,MWRITER* writer) 432 + { 433 + while(cnt-- > 0) _mm_write_I_SWORD(*(buffer++),writer); 434 + } 435 + 436 + void _mm_write_I_UWORDS(UWORD *buffer,int cnt,MWRITER* writer) 437 + { 438 + while(cnt-- > 0) _mm_write_I_UWORD(*(buffer++),writer); 419 439 } 420 - #else 421 - #define DEFINE_MULTIPLE_WRITE_FUNCTION(type_name,type) \ 422 - void _mm_write_/**/type_name/**/S (type *buffer,int number,MWRITER* writer) \ 423 - { \ 424 - while(number-->0) \ 425 - _mm_write_/**/type_name(*(buffer++),writer); \ 440 + 441 + void _mm_write_M_SLONGS(SLONG *buffer,int cnt,MWRITER* writer) 442 + { 443 + while(cnt-- > 0) _mm_write_M_SLONG(*(buffer++),writer); 426 444 } 427 - #endif 428 445 429 - DEFINE_MULTIPLE_WRITE_FUNCTION(M_SWORD,SWORD) 430 - DEFINE_MULTIPLE_WRITE_FUNCTION(M_UWORD,UWORD) 431 - DEFINE_MULTIPLE_WRITE_FUNCTION(I_SWORD,SWORD) 432 - DEFINE_MULTIPLE_WRITE_FUNCTION(I_UWORD,UWORD) 446 + void _mm_write_M_ULONGS(ULONG *buffer,int cnt,MWRITER* writer) 447 + { 448 + while(cnt-- > 0) _mm_write_M_ULONG(*(buffer++),writer); 449 + } 433 450 434 - DEFINE_MULTIPLE_WRITE_FUNCTION(M_SLONG,SLONG) 435 - DEFINE_MULTIPLE_WRITE_FUNCTION(M_ULONG,ULONG) 436 - DEFINE_MULTIPLE_WRITE_FUNCTION(I_SLONG,SLONG) 437 - DEFINE_MULTIPLE_WRITE_FUNCTION(I_ULONG,ULONG) 451 + void _mm_write_I_SLONGS(SLONG *buffer,int cnt,MWRITER* writer) 452 + { 453 + while(cnt-- > 0) _mm_write_I_SLONG(*(buffer++),writer); 454 + } 455 + 456 + void _mm_write_I_ULONGS(ULONG *buffer,int cnt,MWRITER* writer) 457 + { 458 + while(cnt-- > 0) _mm_write_I_ULONG(*(buffer++),writer); 459 + } 438 460 439 461 /*========== Read functions */ 440 462 441 - int _mm_read_string(CHAR* buffer,int number,MREADER* reader) 463 + int _mm_read_string(CHAR* buffer,int cnt,MREADER* reader) 442 464 { 443 - return reader->Read(reader,buffer,number); 465 + return reader->Read(reader,buffer,cnt); 444 466 } 445 467 446 468 UWORD _mm_read_M_UWORD(MREADER* reader) ··· 491 513 return((SLONG)_mm_read_I_ULONG(reader)); 492 514 } 493 515 494 - #if defined __STDC__ || defined _MSC_VER || defined MPW_C 495 - #define DEFINE_MULTIPLE_READ_FUNCTION(type_name,type) \ 496 - int _mm_read_##type_name##S (type *buffer,int number,MREADER* reader) \ 497 - { \ 498 - while(number-->0) \ 499 - *(buffer++)=_mm_read_##type_name(reader); \ 500 - return !reader->Eof(reader); \ 516 + int _mm_read_M_SWORDS(SWORD *buffer,int cnt,MREADER* reader) 517 + { 518 + while(cnt-- > 0) *(buffer++)=_mm_read_M_SWORD(reader); 519 + return !reader->Eof(reader); 520 + } 521 + 522 + int _mm_read_M_UWORDS(UWORD *buffer,int cnt,MREADER* reader) 523 + { 524 + while(cnt-- > 0) *(buffer++)=_mm_read_M_UWORD(reader); 525 + return !reader->Eof(reader); 526 + } 527 + 528 + int _mm_read_I_SWORDS(SWORD *buffer,int cnt,MREADER* reader) 529 + { 530 + while(cnt-- > 0) *(buffer++)=_mm_read_I_SWORD(reader); 531 + return !reader->Eof(reader); 532 + } 533 + 534 + int _mm_read_I_UWORDS(UWORD *buffer,int cnt,MREADER* reader) 535 + { 536 + while(cnt-- > 0) *(buffer++)=_mm_read_I_UWORD(reader); 537 + return !reader->Eof(reader); 538 + } 539 + 540 + int _mm_read_M_SLONGS(SLONG *buffer,int cnt,MREADER* reader) 541 + { 542 + while(cnt-- > 0) *(buffer++)=_mm_read_M_SLONG(reader); 543 + return !reader->Eof(reader); 501 544 } 502 - #else 503 - #define DEFINE_MULTIPLE_READ_FUNCTION(type_name,type) \ 504 - int _mm_read_/**/type_name/**/S (type *buffer,int number,MREADER* reader) \ 505 - { \ 506 - while(number-->0) \ 507 - *(buffer++)=_mm_read_/**/type_name(reader); \ 508 - return !reader->Eof(reader); \ 545 + 546 + int _mm_read_M_ULONGS(ULONG *buffer,int cnt,MREADER* reader) 547 + { 548 + while(cnt-- > 0) *(buffer++)=_mm_read_M_ULONG(reader); 549 + return !reader->Eof(reader); 509 550 } 510 - #endif 511 551 512 - DEFINE_MULTIPLE_READ_FUNCTION(M_SWORD,SWORD) 513 - DEFINE_MULTIPLE_READ_FUNCTION(M_UWORD,UWORD) 514 - DEFINE_MULTIPLE_READ_FUNCTION(I_SWORD,SWORD) 515 - DEFINE_MULTIPLE_READ_FUNCTION(I_UWORD,UWORD) 552 + int _mm_read_I_SLONGS(SLONG *buffer,int cnt,MREADER* reader) 553 + { 554 + while(cnt-- > 0) *(buffer++)=_mm_read_I_SLONG(reader); 555 + return !reader->Eof(reader); 556 + } 516 557 517 - DEFINE_MULTIPLE_READ_FUNCTION(M_SLONG,SLONG) 518 - DEFINE_MULTIPLE_READ_FUNCTION(M_ULONG,ULONG) 519 - DEFINE_MULTIPLE_READ_FUNCTION(I_SLONG,SLONG) 520 - DEFINE_MULTIPLE_READ_FUNCTION(I_ULONG,ULONG) 558 + int _mm_read_I_ULONGS(ULONG *buffer,int cnt,MREADER* reader) 559 + { 560 + while(cnt-- > 0) *(buffer++)=_mm_read_I_ULONG(reader); 561 + return !reader->Eof(reader); 562 + } 521 563 522 564 /* ex:set ts=4: */
+223 -187
apps/plugins/mikmod/mplayer.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: mplayer.c,v 1.4 2006/08/08 00:06:31 realtech Exp $ 23 + $Id$ 24 24 25 25 The Protracker Player Driver 26 26 ··· 40 40 #include <stdlib.h> 41 41 #endif 42 42 43 + #include <limits.h> 44 + 43 45 #include "mikmod_internals.h" 44 46 45 47 #ifdef SUNOS 46 - extern int fprintf(FILE *, const char *, ...); 48 + extern int fprintf(int, const char *, ...); 47 49 extern long int random(void); 48 50 #endif 49 51 50 52 /* The currently playing module */ 51 53 MODULE *pf = NULL; 52 54 55 + #define NUMVOICES(mod) (md_sngchn < (mod)->numvoices ? md_sngchn : (mod)->numvoices) 56 + 53 57 #define HIGH_OCTAVE 2 /* number of above-range octaves */ 54 58 55 - static UWORD oldperiods[OCTAVE*2]={ 59 + static const UWORD oldperiods[OCTAVE*2]={ 56 60 0x6b00, 0x6800, 0x6500, 0x6220, 0x5f50, 0x5c80, 57 61 0x5a00, 0x5740, 0x54d0, 0x5260, 0x5010, 0x4dc0, 58 62 0x4b90, 0x4960, 0x4750, 0x4540, 0x4350, 0x4160, 59 63 0x3f90, 0x3dc0, 0x3c10, 0x3a40, 0x38b0, 0x3700 60 64 }; 61 65 62 - static UBYTE VibratoTable[32]={ 66 + static const UBYTE VibratoTable[32]={ 63 67 0, 24, 49, 74, 97,120,141,161,180,197,212,224,235,244,250,253, 64 68 255,253,250,244,235,224,212,197,180,161,141,120, 97, 74, 49, 24 65 69 }; 66 70 67 - static UBYTE avibtab[128]={ 71 + static const UBYTE avibtab[128]={ 68 72 0, 1, 3, 4, 6, 7, 9,10,12,14,15,17,18,20,21,23, 69 73 24,25,27,28,30,31,32,34,35,36,38,39,40,41,42,44, 70 74 45,46,47,48,49,50,51,52,53,54,54,55,56,57,57,58, ··· 76 80 }; 77 81 78 82 /* Triton's linear periods to frequency translation table (for XM modules) */ 79 - static ULONG lintab[768]={ 83 + static const ULONG lintab[768]={ 80 84 535232,534749,534266,533784,533303,532822,532341,531861, 81 85 531381,530902,530423,529944,529466,528988,528511,528034, 82 86 527558,527082,526607,526131,525657,525183,524709,524236, ··· 176 180 }; 177 181 178 182 #define LOGFAC 2*16 179 - static UWORD logtab[104]={ 183 + static const UWORD logtab[104]={ 180 184 LOGFAC*907,LOGFAC*900,LOGFAC*894,LOGFAC*887, 181 185 LOGFAC*881,LOGFAC*875,LOGFAC*868,LOGFAC*862, 182 186 LOGFAC*856,LOGFAC*850,LOGFAC*844,LOGFAC*838, ··· 205 209 LOGFAC*440,LOGFAC*437,LOGFAC*434,LOGFAC*431 206 210 }; 207 211 208 - static SBYTE PanbrelloTable[256]={ 212 + static const SBYTE PanbrelloTable[256]={ 209 213 0, 2, 3, 5, 6, 8, 9, 11, 12, 14, 16, 17, 19, 20, 22, 23, 210 214 24, 26, 27, 29, 30, 32, 33, 34, 36, 37, 38, 39, 41, 42, 43, 44, 211 215 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, ··· 225 229 }; 226 230 227 231 /* returns a random value between 0 and ceil-1, ceil must be a power of two */ 228 - static int getrandom(int ceil) 232 + static int getrandom(int ceilval) 229 233 { 230 - #ifdef HAVE_SRANDOM 231 - return random()&(ceil-1); 234 + #if defined(HAVE_SRANDOM) && !defined(_MIKMOD_AMIGA) 235 + return random()&(ceilval-1); 232 236 #else 233 - return (rand()*ceil)/(RAND_MAX+1.0); 237 + return (rand()*ceilval)/(RAND_MAX+1.0); 234 238 #endif 235 239 } 236 240 ··· 246 250 MP_VOICE *a; 247 251 ULONG t,k,tvol,pp; 248 252 249 - for (t=0;t<md_sngchn;t++) 253 + for (t=0;t<NUMVOICES(mod);t++) 250 254 if (((mod->voice[t].main.kick==KICK_ABSENT)|| 251 255 (mod->voice[t].main.kick==KICK_ENV))&& 252 256 Voice_Stopped_internal(t)) 253 257 return t; 254 258 255 259 tvol=0xffffffUL;t=-1;a=mod->voice; 256 - for (k=0;k<md_sngchn;k++,a++) { 260 + for (k=0;k<NUMVOICES(mod);k++,a++) { 257 261 /* allow us to take over a nonexisting sample */ 258 262 if (!a->main.s) 259 263 return k; ··· 325 329 { 326 330 if (flags & UF_XMPERIODS) { 327 331 if (flags & UF_LINEAR) 328 - return getlinearperiod(note, speed); 332 + return getlinearperiod(note, speed); 329 333 else 330 - return getlogperiod(note, speed); 334 + return getlogperiod(note, speed); 331 335 } else 332 336 return getoldperiod(note, speed); 333 337 } ··· 359 363 t->a=0; 360 364 t->b=((t->flg&EF_SUSTAIN)&&(!(keyoff&KEY_OFF)))?0:1; 361 365 366 + if (!t->pts) { /* FIXME: bad/crafted file. better/more general solution? */ 367 + t->b=0; 368 + return t->env[0].val; 369 + } 370 + 362 371 /* Imago Orpheus sometimes stores an extra initial point in the envelope */ 363 372 if ((t->pts>=2)&&(t->env[0].pos==t->env[1].pos)) { 364 - t->a++;t->b++; 373 + t->a++; 374 + t->b++; 365 375 } 366 376 367 377 /* Fit in the envelope, still */ ··· 615 625 /* ...make tmpperiod equal tperiod */ 616 626 a->tmpperiod=a->main.period=a->wantedperiod; 617 627 else if (dist>0) { 618 - a->tmpperiod-=a->portspeed; 628 + a->tmpperiod-=a->portspeed; 619 629 a->main.period-=a->portspeed; /* dist>0, slide up */ 620 630 } else { 621 - a->tmpperiod+=a->portspeed; 631 + a->tmpperiod+=a->portspeed; 622 632 a->main.period+=a->portspeed; /* dist<0, slide down */ 623 633 } 624 634 } else ··· 786 796 static int DoPTEffect8(UWORD tick, UWORD flags, MP_CONTROL *a, MODULE *mod, SWORD channel) 787 797 { 788 798 UBYTE dat; 789 - (void)tick; 790 - (void)flags; 799 + (void)tick; 800 + (void)flags; 791 801 792 802 dat = UniGetByte(); 793 803 if (mod->panflag) ··· 799 809 static int DoPTEffect9(UWORD tick, UWORD flags, MP_CONTROL *a, MODULE *mod, SWORD channel) 800 810 { 801 811 UBYTE dat; 802 - (void)flags; 803 - (void)mod; 804 - (void)channel; 812 + (void)flags; 813 + (void)mod; 814 + (void)channel; 805 815 806 816 dat=UniGetByte(); 807 817 if (!tick) { 808 818 if (dat) a->soffset=(UWORD)dat<<8; 809 819 a->main.start=a->hioffset|a->soffset; 810 820 811 - if ((a->main.s)&&(a->main.start > (SLONG)a->main.s->length)) 821 + if ((a->main.s)&&(a->main.start>(SLONG)a->main.s->length)) 812 822 a->main.start=a->main.s->flags&(SF_LOOP|SF_BIDI)? 813 823 a->main.s->loopstart:a->main.s->length; 814 824 } ··· 819 829 static int DoPTEffectA(UWORD tick, UWORD flags, MP_CONTROL *a, MODULE *mod, SWORD channel) 820 830 { 821 831 UBYTE dat; 822 - (void)flags; 823 - (void)mod; 824 - (void)channel; 832 + (void)flags; 833 + (void)mod; 834 + (void)channel; 825 835 826 836 dat=UniGetByte(); 827 837 if (tick) ··· 842 852 static int DoPTEffectB(UWORD tick, UWORD flags, MP_CONTROL *a, MODULE *mod, SWORD channel) 843 853 { 844 854 UBYTE dat; 845 - (void)a; 846 - (void)channel; 855 + (void)a; 856 + (void)channel; 847 857 848 858 dat=UniGetByte(); 849 859 850 860 if (tick || mod->patdly2) 851 861 return 0; 852 862 863 + if (dat >= mod->numpos) { /* crafted file? */ 864 + /* fprintf(stderr,"DoPTEffectB: numpos=%d, dat=%d -> %d\n",mod->numpos,dat,mod->numpos-1);*/ 865 + dat=mod->numpos-1; 866 + } 867 + 853 868 /* Vincent Voois uses a nasty trick in "Universal Bolero" */ 854 869 if (dat == mod->sngpos && mod->patbrk == mod->patpos) 855 870 return 0; ··· 857 872 if (!mod->loop && !mod->patbrk && 858 873 (dat < mod->sngpos || 859 874 (mod->sngpos == (mod->numpos - 1) && !mod->patbrk) || 860 - (dat == mod->sngpos && (flags & UF_NOWRAP)) 861 - )) { 875 + (dat == mod->sngpos && (flags & UF_NOWRAP)) ) ) 876 + { 862 877 /* if we don't loop, better not to skip the end of the 863 878 pattern, after all... so: 864 879 mod->patbrk=0; */ ··· 870 885 mod->sngpos=dat; 871 886 mod->posjmp=2; 872 887 mod->patpos=0; 888 + /* cancel the FT2 pattern loop (E60) bug. 889 + * also see DoEEffects() below for it. */ 890 + if (flags & UF_FT2QUIRKS) mod->patbrk=0; 873 891 } 874 892 875 893 return 0; ··· 878 896 static int DoPTEffectC(UWORD tick, UWORD flags, MP_CONTROL *a, MODULE *mod, SWORD channel) 879 897 { 880 898 UBYTE dat; 881 - (void)flags; 882 - (void)mod; 883 - (void)channel; 899 + (void)flags; 900 + (void)mod; 901 + (void)channel; 884 902 885 - dat=UniGetByte(); 886 - if (tick) return 0; 887 - if (dat==(UBYTE)-1) a->anote=dat=0; /* note cut */ 888 - else if (dat>64) dat=64; 889 - a->tmpvolume=dat; 903 + dat=UniGetByte(); 904 + if (tick) return 0; 905 + if (dat==(UBYTE)-1) a->anote=dat=0; /* note cut */ 906 + else if (dat>64) dat=64; 907 + a->tmpvolume=dat; 890 908 891 909 return 0; 892 910 } ··· 894 912 static int DoPTEffectD(UWORD tick, UWORD flags, MP_CONTROL *a, MODULE *mod, SWORD channel) 895 913 { 896 914 UBYTE dat; 897 - (void)a; 898 - (void)channel; 915 + (void)a; 916 + (void)channel; 899 917 900 - dat=UniGetByte(); 901 - if ((tick)||(mod->patdly2)) return 0; 902 - if ((mod->positions[mod->sngpos]!=LAST_PATTERN)&& 903 - (dat>mod->pattrows[mod->positions[mod->sngpos]])) 904 - dat=mod->pattrows[mod->positions[mod->sngpos]]; 905 - mod->patbrk=dat; 906 - if (!mod->posjmp) { 907 - /* don't ask me to explain this code - it makes 908 - backwards.s3m and children.xm (heretic's version) play 909 - correctly, among others. Take that for granted, or write 910 - the page of comments yourself... you might need some 911 - aspirin - Miod */ 912 - if ((mod->sngpos==mod->numpos-1)&&(dat)&&((mod->loop)|| 913 - (mod->positions[mod->sngpos]==(mod->numpat-1) 914 - && !(flags&UF_NOWRAP)))) { 915 - mod->sngpos=0; 916 - mod->posjmp=2; 917 - } else 918 - mod->posjmp=3; 919 - } 918 + dat=UniGetByte(); 919 + if ((tick)||(mod->patdly2)) return 0; 920 + if (dat && dat >= mod->numrow) { /* crafted file? */ 921 + /* fprintf(stderr,"DoPTEffectD: numrow=%d, dat=%d -> 0\n",mod->numrow,dat);*/ 922 + dat=0; 923 + } 924 + if ((mod->positions[mod->sngpos]!=LAST_PATTERN)&& 925 + (dat>mod->pattrows[mod->positions[mod->sngpos]])) { 926 + dat=mod->pattrows[mod->positions[mod->sngpos]]; 927 + } 928 + mod->patbrk=dat; 929 + if (!mod->posjmp) { 930 + /* don't ask me to explain this code - it makes 931 + backwards.s3m and children.xm (heretic's version) play 932 + correctly, among others. Take that for granted, or write 933 + the page of comments yourself... you might need some 934 + aspirin - Miod */ 935 + if ((mod->sngpos==mod->numpos-1)&&(dat)&& 936 + ((mod->loop) || (mod->positions[mod->sngpos]==(mod->numpat-1) && !(flags&UF_NOWRAP)))) { 937 + mod->sngpos=0; 938 + mod->posjmp=2; 939 + } else 940 + mod->posjmp=3; 941 + } 920 942 921 943 return 0; 922 944 } ··· 982 1004 } else 983 1005 mod->patpos=a->pat_reppos; 984 1006 } else a->pat_reppos=POS_NONE; 985 - } else 1007 + } else { 986 1008 a->pat_reppos=mod->patpos-1; /* set reppos - can be (-1) */ 1009 + /* emulate the FT2 pattern loop (E60) bug: 1010 + * http://milkytracker.org/docs/MilkyTracker.html#fxE6x 1011 + * roadblas.xm plays correctly with this. */ 1012 + if (flags & UF_FT2QUIRKS) mod->patbrk=mod->patpos; 1013 + } 987 1014 break; 988 1015 case 0x7: /* set tremolo waveform */ 989 1016 a->wavecontrol&=0x0f; ··· 1065 1092 if (tick||mod->patdly2) return 0; 1066 1093 if (mod->extspd&&(dat>=mod->bpmlimit)) 1067 1094 mod->bpm=dat; 1068 - else 1095 + else 1069 1096 if (dat) { 1070 1097 mod->sngspd=(dat>=mod->bpmlimit)?mod->bpmlimit-1:dat; 1071 1098 mod->vbtick=0; ··· 1465 1492 a->s3mvolslide = inf; 1466 1493 else 1467 1494 inf = a->s3mvolslide; 1468 - 1495 + 1469 1496 if (tick) { 1470 1497 lo=inf&0xf; 1471 1498 hi=inf>>4; ··· 1608 1635 INSTRUMENT *i=a->main.i; 1609 1636 MP_VOICE *aout; 1610 1637 1611 - if ((aout=a->slave)) { 1638 + if ((aout=a->slave) != NULL) { 1612 1639 if (aout->venv.env) { 1613 1640 points=i->volenv[i->volpts-1].pos; 1614 1641 aout->venv.p=aout->venv.env[(dat>points)?points:dat].pos; ··· 1710 1737 /* if we don't come from another note, ignore the slide and play the note 1711 1738 as is */ 1712 1739 if (!a->oldnote || !a->main.period) 1713 - return; 1740 + return; 1714 1741 1715 1742 if ((!tick)&&(a->newsamp)){ 1716 1743 a->main.kick=KICK_NOTE; ··· 1725 1752 difference between those two values */ 1726 1753 dist=a->main.period-a->wantedperiod; 1727 1754 1728 - /* if they are equal or if portamentospeed is too big... */ 1755 + /* if they are equal or if portamentospeed is too big... */ 1729 1756 if ((!dist)||((a->portspeed<<2)>abs(dist))) 1730 1757 /* ... make tmpperiod equal tperiod */ 1731 1758 a->tmpperiod=a->main.period=a->wantedperiod; 1732 1759 else 1733 - if (dist>0) { 1760 + if (dist>0) { 1734 1761 a->tmpperiod-=a->portspeed<<2; 1735 1762 a->main.period-=a->portspeed<<2; /* dist>0 slide up */ 1736 - } else { 1763 + } else { 1737 1764 a->tmpperiod+=a->portspeed<<2; 1738 1765 a->main.period+=a->portspeed<<2; /* dist<0 slide down */ 1739 1766 } ··· 1762 1789 if (dat&0xf0) a->vibspd=(dat&0xf0)>>2; 1763 1790 } 1764 1791 if (!a->main.period) 1765 - return; 1792 + return; 1766 1793 1767 1794 q=(a->vibpos>>2)&0x1f; 1768 1795 ··· 1867 1894 lo=inf&0xf; 1868 1895 hi=inf>>4; 1869 1896 1870 - if (!hi) 1897 + if (!hi) 1871 1898 a->main.chanvol-=lo; 1872 1899 else 1873 1900 if (!lo) { ··· 2105 2132 switch (c) { 2106 2133 case SS_GLISSANDO: /* S1x set glissando voice */ 2107 2134 DoEEffects(tick, flags, a, mod, channel, 0x30|inf); 2108 - break; 2135 + break; 2109 2136 case SS_FINETUNE: /* S2x set finetune */ 2110 2137 DoEEffects(tick, flags, a, mod, channel, 0x50|inf); 2111 2138 break; 2112 2139 case SS_VIBWAVE: /* S3x set vibrato waveform */ 2113 2140 DoEEffects(tick, flags, a, mod, channel, 0x40|inf); 2114 - break; 2141 + break; 2115 2142 case SS_TREMWAVE: /* S4x set tremolo waveform */ 2116 2143 DoEEffects(tick, flags, a, mod, channel, 0x70|inf); 2117 2144 break; ··· 2130 2157 case SS_SURROUND: /* S9x set surround sound */ 2131 2158 if (mod->panflag) 2132 2159 a->main.panning = mod->panning[channel] = PAN_SURROUND; 2133 - break; 2160 + break; 2134 2161 case SS_HIOFFSET: /* SAy set high order sample offset yxx00h */ 2135 2162 if (!tick) { 2136 2163 a->hioffset=inf<<16; 2137 2164 a->main.start=a->hioffset|a->soffset; 2138 2165 2139 - if ((a->main.s)&&(a->main.start > (SLONG)a->main.s->length)) 2166 + if ((a->main.s)&&(a->main.start>(SLONG)a->main.s->length)) 2140 2167 a->main.start=a->main.s->flags&(SF_LOOP|SF_BIDI)? 2141 2168 a->main.s->loopstart:a->main.s->length; 2142 2169 } ··· 2168 2195 static int DoVolEffects(UWORD tick, UWORD flags, MP_CONTROL *a, MODULE *mod, SWORD channel) 2169 2196 { 2170 2197 UBYTE c, inf; 2171 - (void)channel; 2172 - 2173 - c = UniGetByte(); 2174 - inf = UniGetByte(); 2198 + (void)channel; 2199 + 2200 + c = UniGetByte(); 2201 + inf = UniGetByte(); 2175 2202 2176 2203 if ((!c)&&(!inf)) { 2177 2204 c=a->voleffect; ··· 2219 2246 static int DoULTEffect9(UWORD tick, UWORD flags, MP_CONTROL *a, MODULE *mod, SWORD channel) 2220 2247 { 2221 2248 UWORD offset=UniGetWord(); 2222 - (void)tick; 2223 - (void)flags; 2224 - (void)mod; 2225 - (void)channel; 2249 + (void)tick; 2250 + (void)flags; 2251 + (void)mod; 2252 + (void)channel; 2226 2253 2227 2254 if (offset) 2228 2255 a->ultoffset=offset; 2229 2256 2230 2257 a->main.start=a->ultoffset<<2; 2231 - if ((a->main.s)&&(a->main.start > (SLONG)a->main.s->length)) 2258 + if ((a->main.s)&&(a->main.start>(SLONG)a->main.s->length)) 2232 2259 a->main.start=a->main.s->flags&(SF_LOOP|SF_BIDI)? 2233 2260 a->main.s->loopstart:a->main.s->length; 2234 2261 ··· 2310 2337 typedef int (*effect_func) (UWORD, UWORD, MP_CONTROL *, MODULE *, SWORD); 2311 2338 2312 2339 static effect_func effects[UNI_LAST] = { 2313 - DoNothing, /* 0 */ 2314 - DoNothing, /* UNI_NOTE */ 2315 - DoNothing, /* UNI_INSTRUMENT */ 2316 - DoPTEffect0, /* UNI_PTEFFECT0 */ 2317 - DoPTEffect1, /* UNI_PTEFFECT1 */ 2318 - DoPTEffect2, /* UNI_PTEFFECT2 */ 2319 - DoPTEffect3, /* UNI_PTEFFECT3 */ 2320 - DoPTEffect4, /* UNI_PTEFFECT4 */ 2321 - DoPTEffect5, /* UNI_PTEFFECT5 */ 2322 - DoPTEffect6, /* UNI_PTEFFECT6 */ 2323 - DoPTEffect7, /* UNI_PTEFFECT7 */ 2324 - DoPTEffect8, /* UNI_PTEFFECT8 */ 2325 - DoPTEffect9, /* UNI_PTEFFECT9 */ 2326 - DoPTEffectA, /* UNI_PTEFFECTA */ 2327 - DoPTEffectB, /* UNI_PTEFFECTB */ 2328 - DoPTEffectC, /* UNI_PTEFFECTC */ 2329 - DoPTEffectD, /* UNI_PTEFFECTD */ 2330 - DoPTEffectE, /* UNI_PTEFFECTE */ 2331 - DoPTEffectF, /* UNI_PTEFFECTF */ 2332 - DoS3MEffectA, /* UNI_S3MEFFECTA */ 2333 - DoS3MEffectD, /* UNI_S3MEFFECTD */ 2334 - DoS3MEffectE, /* UNI_S3MEFFECTE */ 2335 - DoS3MEffectF, /* UNI_S3MEFFECTF */ 2336 - DoS3MEffectI, /* UNI_S3MEFFECTI */ 2337 - DoS3MEffectQ, /* UNI_S3MEFFECTQ */ 2338 - DoS3MEffectR, /* UNI_S3MEFFECTR */ 2339 - DoS3MEffectT, /* UNI_S3MEFFECTT */ 2340 - DoS3MEffectU, /* UNI_S3MEFFECTU */ 2341 - DoKeyOff, /* UNI_KEYOFF */ 2342 - DoKeyFade, /* UNI_KEYFADE */ 2343 - DoVolEffects, /* UNI_VOLEFFECTS */ 2344 - DoPTEffect4, /* UNI_XMEFFECT4 */ 2345 - DoXMEffect6, /* UNI_XMEFFECT6 */ 2346 - DoXMEffectA, /* UNI_XMEFFECTA */ 2347 - DoXMEffectE1, /* UNI_XMEFFECTE1 */ 2348 - DoXMEffectE2, /* UNI_XMEFFECTE2 */ 2349 - DoXMEffectEA, /* UNI_XMEFFECTEA */ 2350 - DoXMEffectEB, /* UNI_XMEFFECTEB */ 2351 - DoXMEffectG, /* UNI_XMEFFECTG */ 2352 - DoXMEffectH, /* UNI_XMEFFECTH */ 2353 - DoXMEffectL, /* UNI_XMEFFECTL */ 2354 - DoXMEffectP, /* UNI_XMEFFECTP */ 2355 - DoXMEffectX1, /* UNI_XMEFFECTX1 */ 2356 - DoXMEffectX2, /* UNI_XMEFFECTX2 */ 2357 - DoITEffectG, /* UNI_ITEFFECTG */ 2358 - DoITEffectH, /* UNI_ITEFFECTH */ 2359 - DoITEffectI, /* UNI_ITEFFECTI */ 2360 - DoITEffectM, /* UNI_ITEFFECTM */ 2361 - DoITEffectN, /* UNI_ITEFFECTN */ 2362 - DoITEffectP, /* UNI_ITEFFECTP */ 2363 - DoITEffectT, /* UNI_ITEFFECTT */ 2364 - DoITEffectU, /* UNI_ITEFFECTU */ 2365 - DoITEffectW, /* UNI_ITEFFECTW */ 2366 - DoITEffectY, /* UNI_ITEFFECTY */ 2367 - DoNothing, /* UNI_ITEFFECTZ */ 2368 - DoITEffectS0, /* UNI_ITEFFECTS0 */ 2369 - DoULTEffect9, /* UNI_ULTEFFECT9 */ 2370 - DoMEDSpeed, /* UNI_MEDSPEED */ 2371 - DoMEDEffectF1, /* UNI_MEDEFFECTF1 */ 2372 - DoMEDEffectF2, /* UNI_MEDEFFECTF2 */ 2373 - DoMEDEffectF3, /* UNI_MEDEFFECTF3 */ 2374 - DoOktArp, /* UNI_OKTARP */ 2340 + DoNothing, /* 0 */ 2341 + DoNothing, /* UNI_NOTE */ 2342 + DoNothing, /* UNI_INSTRUMENT */ 2343 + DoPTEffect0, /* UNI_PTEFFECT0 */ 2344 + DoPTEffect1, /* UNI_PTEFFECT1 */ 2345 + DoPTEffect2, /* UNI_PTEFFECT2 */ 2346 + DoPTEffect3, /* UNI_PTEFFECT3 */ 2347 + DoPTEffect4, /* UNI_PTEFFECT4 */ 2348 + DoPTEffect5, /* UNI_PTEFFECT5 */ 2349 + DoPTEffect6, /* UNI_PTEFFECT6 */ 2350 + DoPTEffect7, /* UNI_PTEFFECT7 */ 2351 + DoPTEffect8, /* UNI_PTEFFECT8 */ 2352 + DoPTEffect9, /* UNI_PTEFFECT9 */ 2353 + DoPTEffectA, /* UNI_PTEFFECTA */ 2354 + DoPTEffectB, /* UNI_PTEFFECTB */ 2355 + DoPTEffectC, /* UNI_PTEFFECTC */ 2356 + DoPTEffectD, /* UNI_PTEFFECTD */ 2357 + DoPTEffectE, /* UNI_PTEFFECTE */ 2358 + DoPTEffectF, /* UNI_PTEFFECTF */ 2359 + DoS3MEffectA, /* UNI_S3MEFFECTA */ 2360 + DoS3MEffectD, /* UNI_S3MEFFECTD */ 2361 + DoS3MEffectE, /* UNI_S3MEFFECTE */ 2362 + DoS3MEffectF, /* UNI_S3MEFFECTF */ 2363 + DoS3MEffectI, /* UNI_S3MEFFECTI */ 2364 + DoS3MEffectQ, /* UNI_S3MEFFECTQ */ 2365 + DoS3MEffectR, /* UNI_S3MEFFECTR */ 2366 + DoS3MEffectT, /* UNI_S3MEFFECTT */ 2367 + DoS3MEffectU, /* UNI_S3MEFFECTU */ 2368 + DoKeyOff, /* UNI_KEYOFF */ 2369 + DoKeyFade, /* UNI_KEYFADE */ 2370 + DoVolEffects, /* UNI_VOLEFFECTS */ 2371 + DoPTEffect4, /* UNI_XMEFFECT4 */ 2372 + DoXMEffect6, /* UNI_XMEFFECT6 */ 2373 + DoXMEffectA, /* UNI_XMEFFECTA */ 2374 + DoXMEffectE1, /* UNI_XMEFFECTE1 */ 2375 + DoXMEffectE2, /* UNI_XMEFFECTE2 */ 2376 + DoXMEffectEA, /* UNI_XMEFFECTEA */ 2377 + DoXMEffectEB, /* UNI_XMEFFECTEB */ 2378 + DoXMEffectG, /* UNI_XMEFFECTG */ 2379 + DoXMEffectH, /* UNI_XMEFFECTH */ 2380 + DoXMEffectL, /* UNI_XMEFFECTL */ 2381 + DoXMEffectP, /* UNI_XMEFFECTP */ 2382 + DoXMEffectX1, /* UNI_XMEFFECTX1 */ 2383 + DoXMEffectX2, /* UNI_XMEFFECTX2 */ 2384 + DoITEffectG, /* UNI_ITEFFECTG */ 2385 + DoITEffectH, /* UNI_ITEFFECTH */ 2386 + DoITEffectI, /* UNI_ITEFFECTI */ 2387 + DoITEffectM, /* UNI_ITEFFECTM */ 2388 + DoITEffectN, /* UNI_ITEFFECTN */ 2389 + DoITEffectP, /* UNI_ITEFFECTP */ 2390 + DoITEffectT, /* UNI_ITEFFECTT */ 2391 + DoITEffectU, /* UNI_ITEFFECTU */ 2392 + DoITEffectW, /* UNI_ITEFFECTW */ 2393 + DoITEffectY, /* UNI_ITEFFECTY */ 2394 + DoNothing, /* UNI_ITEFFECTZ */ 2395 + DoITEffectS0, /* UNI_ITEFFECTS0 */ 2396 + DoULTEffect9, /* UNI_ULTEFFECT9 */ 2397 + DoMEDSpeed, /* UNI_MEDSPEED */ 2398 + DoMEDEffectF1, /* UNI_MEDEFFECTF1 */ 2399 + DoMEDEffectF2, /* UNI_MEDEFFECTF2 */ 2400 + DoMEDEffectF3, /* UNI_MEDEFFECTF3 */ 2401 + DoOktArp, /* UNI_OKTARP */ 2375 2402 }; 2376 2403 2377 2404 static int pt_playeffects(MODULE *mod, SWORD channel, MP_CONTROL *a) ··· 2382 2409 int explicitslides = 0; 2383 2410 effect_func f; 2384 2411 2385 - while((c=UniGetByte())) { 2412 + while((c=UniGetByte()) != 0) { 2413 + #if 0 /* this doesn't normally happen unless things go fubar elsewhere */ 2414 + if (c >= UNI_LAST) 2415 + fprintf(stderr,"fubar'ed opcode %u\n",c); 2416 + #endif 2386 2417 f = effects[c]; 2387 2418 if (f != DoNothing) 2388 - a->sliding = 0; 2419 + a->sliding = 0; 2389 2420 explicitslides |= f(tick, flags, a, mod, channel); 2390 2421 } 2391 2422 return explicitslides; ··· 2396 2427 int t; 2397 2428 MP_VOICE *aout; 2398 2429 2399 - dat&=0xf; 2430 + dat&=0xf; 2400 2431 aout=(a->slave)?a->slave:NULL; 2401 2432 2402 2433 switch (dat) { 2403 2434 case 0x0: /* past note cut */ 2404 - for (t=0;t<md_sngchn;t++) 2435 + for (t=0;t<NUMVOICES(mod);t++) 2405 2436 if (mod->voice[t].master==a) 2406 2437 mod->voice[t].main.fadevol=0; 2407 2438 break; 2408 2439 case 0x1: /* past note off */ 2409 - for (t=0;t<md_sngchn;t++) 2440 + for (t=0;t<NUMVOICES(mod);t++) 2410 2441 if (mod->voice[t].master==a) { 2411 2442 mod->voice[t].main.keyoff|=KEY_OFF; 2412 2443 if ((!(mod->voice[t].venv.flg & EF_ON))|| ··· 2415 2446 } 2416 2447 break; 2417 2448 case 0x2: /* past note fade */ 2418 - for (t=0;t<md_sngchn;t++) 2449 + for (t=0;t<NUMVOICES(mod);t++) 2419 2450 if (mod->voice[t].master==a) 2420 2451 mod->voice[t].main.keyoff|=KEY_FADE; 2421 2452 break; ··· 2427 2458 break; 2428 2459 case 0x5: /* set NNA note off */ 2429 2460 a->main.nna=(a->main.nna&~NNA_MASK)|NNA_OFF; 2430 - break; 2461 + break; 2431 2462 case 0x6: /* set NNA note fade */ 2432 2463 a->main.nna=(a->main.nna&~NNA_MASK)|NNA_FADE; 2433 2464 break; ··· 2442 2473 case 0x9: /* disable panning envelope */ 2443 2474 if (aout) 2444 2475 aout->main.panflg&=~EF_ON; 2445 - break; 2476 + break; 2446 2477 case 0xa: /* enable panning envelope */ 2447 2478 if (aout) 2448 2479 aout->main.panflg|=EF_ON; ··· 2470 2501 SAMPLE *s; 2471 2502 2472 2503 mod->totalchn=mod->realchn=0; 2473 - for (channel=0;channel<md_sngchn;channel++) { 2504 + for (channel=0;channel<NUMVOICES(mod);channel++) { 2474 2505 aout=&mod->voice[channel]; 2475 2506 i=aout->main.i; 2476 2507 s=aout->main.s; ··· 2484 2515 2485 2516 if ((aout->main.kick==KICK_NOTE)||(aout->main.kick==KICK_KEYOFF)) { 2486 2517 Voice_Play_internal(channel,s,(aout->main.start==-1)? 2487 - ((s->flags&SF_UST_LOOP) ? (SLONG)s->loopstart : 0) : aout->main.start); 2518 + ((s->flags&SF_UST_LOOP)?(SLONG)s->loopstart:0):aout->main.start); 2488 2519 aout->main.fadevol=32768; 2489 2520 aout->aswppos=0; 2490 2521 } ··· 2687 2718 UniSetRow(a->row); 2688 2719 funky=0; 2689 2720 2690 - while((c=UniGetByte())) 2721 + while((c=UniGetByte()) != 0) 2691 2722 switch (c) { 2692 2723 case UNI_NOTE: 2693 2724 funky|=1; ··· 2720 2751 INSTRUMENT *i; 2721 2752 SAMPLE *s; 2722 2753 2723 - if ((i=a->main.i)) { 2754 + if ((i=a->main.i) != NULL) { 2724 2755 if (i->samplenumber[a->anote] >= mod->numsmp) continue; 2725 2756 s=&mod->samples[i->samplenumber[a->anote]]; 2726 2757 a->main.note=i->samplenote[a->anote]; ··· 2809 2840 for (channel=0;channel<mod->numchn;channel++) { 2810 2841 a=&mod->control[channel]; 2811 2842 2812 - if ((aout=a->slave)) { 2843 + if ((aout=a->slave) != NULL) { 2813 2844 a->main.fadevol=aout->main.fadevol; 2814 2845 a->main.period=aout->main.period; 2815 2846 if (a->main.kick==KICK_KEYOFF) ··· 2891 2922 if (a->dct!=DCT_OFF) { 2892 2923 int t; 2893 2924 2894 - for (t=0;t<md_sngchn;t++) 2925 + for (t=0;t<NUMVOICES(mod);t++) 2895 2926 if ((!Voice_Stopped_internal(t))&& 2896 2927 (mod->voice[t].masterchn==channel)&& 2897 2928 (a->main.sample==mod->voice[t].main.sample)) { ··· 2951 2982 if ((newchn=MP_FindEmptyChannel(mod))!=-1) 2952 2983 a->slave=&mod->voice[a->slavechn=newchn]; 2953 2984 } 2954 - } else 2985 + } else 2955 2986 a->slave=&mod->voice[a->slavechn=channel]; 2956 2987 2957 2988 /* assign parts of MP_VOICE only done for a KICK_NOTE */ 2958 - if ((aout=a->slave)) { 2989 + if ((aout=a->slave) != NULL) { 2959 2990 if (aout->mflag && aout->master) aout->master->slave=NULL; 2960 2991 aout->master=a; 2961 2992 a->slave=aout; ··· 2984 3015 if (!a->row) continue; 2985 3016 UniSetRow(a->row); 2986 3017 2987 - while((c=UniGetByte())) 3018 + while((c=UniGetByte()) != 0) 2988 3019 if (c==UNI_ITEFFECTS0) { 2989 3020 c=UniGetByte(); 2990 3021 if ((c>>4)==SS_S7EFFECTS) ··· 3016 3047 pf->sngremainder%=pf->bpm; 3017 3048 3018 3049 if (++pf->vbtick>=pf->sngspd) { 3019 - if (pf->pat_repcrazy) 3050 + if (pf->pat_repcrazy) 3020 3051 pf->pat_repcrazy=0; /* play 2 times row 0 */ 3021 3052 else 3022 3053 pf->patpos++; ··· 3046 3077 pf->control[channel].pat_reppos=-1; 3047 3078 3048 3079 pf->patbrk=pf->posjmp=0; 3080 + 3081 + if (pf->sngpos<0) pf->sngpos=(SWORD)(pf->numpos-1); 3082 + 3049 3083 /* handle the "---" (end of song) pattern since it can occur 3050 3084 *inside* the module in some formats */ 3051 3085 if ((pf->sngpos>=pf->numpos)|| ··· 3060 3094 pf->bpm=pf->inittempo<32?32:pf->inittempo; 3061 3095 } 3062 3096 } 3063 - if (pf->sngpos<0) pf->sngpos=pf->numpos-1; 3064 3097 } 3065 3098 3066 3099 if (!pf->patdly2) ··· 3093 3126 mod->control[t].main.chanvol=mod->chanvol[t]; 3094 3127 mod->control[t].main.panning=mod->panning[t]; 3095 3128 } 3096 - 3129 + 3097 3130 mod->sngtime=0; 3098 3131 mod->sngremainder=0; 3099 3132 ··· 3133 3166 if (!(mod->voice=(MP_VOICE*)MikMod_calloc(md_sngchn,sizeof(MP_VOICE)))) 3134 3167 return 1; 3135 3168 3169 + /* mod->numvoices was used during loading to clamp md_sngchn. 3170 + After loading it's used to remember how big mod->voice is. 3171 + */ 3172 + mod->numvoices = md_sngchn; 3173 + 3136 3174 Player_Init_internal(mod); 3137 3175 return 0; 3138 3176 } ··· 3148 3186 pf=NULL; 3149 3187 } 3150 3188 3151 - if (mod->control) 3152 - MikMod_free(mod->control); 3153 - if (mod->voice) 3154 - MikMod_free(mod->voice); 3189 + MikMod_free(mod->control); 3190 + MikMod_free(mod->voice); 3155 3191 mod->control=NULL; 3156 3192 mod->voice=NULL; 3157 3193 } ··· 3166 3202 MIKMODAPI void Player_SetVolume(SWORD volume) 3167 3203 { 3168 3204 MUTEX_LOCK(vars); 3169 - if (pf) 3205 + if (pf) { 3170 3206 pf->volume=(volume<0)?0:(volume>128)?128:volume; 3207 + pf->initvolume=pf->volume; 3208 + } 3171 3209 MUTEX_UNLOCK(vars); 3172 3210 } 3173 3211 ··· 3241 3279 pf->patbrk=0; 3242 3280 pf->vbtick=pf->sngspd; 3243 3281 3244 - for (t=0;t<md_sngchn;t++) { 3282 + for (t=0;t<NUMVOICES(pf);t++) { 3245 3283 Voice_Stop_internal(t); 3246 3284 pf->voice[t].main.i=NULL; 3247 3285 pf->voice[t].main.s=NULL; ··· 3266 3304 pf->patbrk=0; 3267 3305 pf->vbtick=pf->sngspd; 3268 3306 3269 - for (t=0;t<md_sngchn;t++) { 3307 + for (t=0;t<NUMVOICES(pf);t++) { 3270 3308 Voice_Stop_internal(t); 3271 3309 pf->voice[t].main.i=NULL; 3272 3310 pf->voice[t].main.s=NULL; ··· 3293 3331 pf->sngpos=pos; 3294 3332 pf->vbtick=pf->sngspd; 3295 3333 3296 - for (t=0;t<md_sngchn;t++) { 3334 + for (t=0;t<NUMVOICES(pf);t++) { 3297 3335 Voice_Stop_internal(t); 3298 3336 pf->voice[t].main.i=NULL; 3299 3337 pf->voice[t].main.s=NULL; ··· 3303 3341 pf->control[t].main.s=NULL; 3304 3342 } 3305 3343 pf->forbid=0; 3306 - 3344 + 3307 3345 if (!pos) 3308 3346 Player_Init_internal(pf); 3309 3347 } 3310 3348 MUTEX_UNLOCK(vars); 3311 - } 3349 + } 3312 3350 3313 3351 static void Player_Unmute_internal(SLONG arg1,va_list ap) 3314 3352 { ··· 3418 3456 } 3419 3457 break; 3420 3458 default: 3421 - if (arg1<pf->numchn) 3459 + if (arg1<pf->numchn) 3422 3460 pf->control[arg1].muted=1-pf->control[arg1].muted; 3423 3461 break; 3424 3462 } ··· 3465 3503 UWORD result=0; 3466 3504 3467 3505 MUTEX_LOCK(vars); 3468 - if (pf) 3506 + if (pf) 3469 3507 result=(chan<pf->numchn)?pf->control[chan].main.period:0; 3470 3508 MUTEX_UNLOCK(vars); 3471 3509 ··· 3499 3537 MIKMODAPI void Player_SetSpeed(UWORD speed) 3500 3538 { 3501 3539 MUTEX_LOCK(vars); 3502 - if (pf) 3540 + if (pf) 3503 3541 pf->sngspd=speed?(speed<32?speed:32):1; 3504 3542 MUTEX_UNLOCK(vars); 3505 3543 } ··· 3538 3576 return numvoices; 3539 3577 } 3540 3578 3541 - 3542 - // Get current module order 3579 + /* Get current module order */ 3543 3580 MIKMODAPI int Player_GetOrder(void) 3544 3581 { 3545 3582 int ret; 3546 3583 MUTEX_LOCK(vars); 3547 - ret = pf ? pf->sngpos :0; // pf->positions[pf->sngpos ? pf->sngpos-1 : 0]: 0; 3584 + ret = pf ? pf->sngpos :0; /* pf->positions[pf->sngpos ? pf->sngpos-1 : 0]: 0; */ 3548 3585 MUTEX_UNLOCK(vars); 3549 3586 return ret; 3550 3587 } 3551 3588 3552 - // Get current module row 3589 + /* Get current module row */ 3553 3590 MIKMODAPI int Player_GetRow(void) 3554 3591 { 3555 3592 int ret; ··· 3558 3595 MUTEX_UNLOCK(vars); 3559 3596 return ret; 3560 3597 } 3561 - 3562 3598 3563 3599 /* ex:set ts=4: */
+11 -11
apps/plugins/mikmod/munitrk.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: munitrk.c,v 1.2 2005/03/30 19:11:46 realtech Exp $ 23 + $Id$ 24 24 25 25 All routines dealing with the manipulation of UNITRK streams 26 26 ··· 37 37 /* Unibuffer chunk size */ 38 38 #define BUFPAGE 128 39 39 40 - UWORD unioperands[UNI_LAST]={ 40 + const UWORD unioperands[UNI_LAST] = { 41 41 0, /* not used */ 42 42 1, /* UNI_NOTE */ 43 43 1, /* UNI_INSTRUMENT */ ··· 214 214 unibuf = newbuf; 215 215 unimax+=BUFPAGE; 216 216 return 1; 217 - } else 217 + } else 218 218 return 0; 219 219 } 220 220 return 1; ··· 236 236 } 237 237 } 238 238 239 - static int MyCmp(UBYTE* a,UBYTE* b,UWORD l) 239 + static int MyCmp(const UBYTE* a,const UBYTE* b,UWORD l) 240 240 { 241 241 UWORD t; 242 242 ··· 275 275 stream. */ 276 276 UBYTE* UniDup(void) 277 277 { 278 - UBYTE *d; 278 + void *d; 279 279 280 - if (!UniExpand(unitt-unipc)) return NULL; 280 + if (!UniExpand(unipc-unitt)) return NULL; 281 281 unibuf[unitt] = 0; 282 282 283 - if(!(d=(UBYTE *)MikMod_malloc(unipc))) return NULL; 283 + if(!(d=MikMod_malloc(unipc))) return NULL; 284 284 memcpy(d,unibuf,unipc); 285 285 286 - return d; 286 + return (UBYTE *)d; 287 287 } 288 288 289 289 int UniInit(void) ··· 296 296 297 297 void UniCleanup(void) 298 298 { 299 - if(unibuf) MikMod_free(unibuf); 299 + MikMod_free(unibuf); 300 300 unibuf = NULL; 301 301 } 302 302
+4 -4
apps/plugins/mikmod/npertab.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: npertab.c,v 1.2 2005/03/30 19:11:47 realtech Exp $ 23 + $Id$ 24 24 25 25 MOD format period table. Used by both the MOD and M15 (15-inst mod) Loaders. 26 26 ··· 32 32 33 33 #include "mikmod_internals.h" 34 34 35 - UWORD npertab[7 * OCTAVE] = { 35 + const UWORD npertab[7 * OCTAVE] = { 36 36 /* Octaves 6 -> 0 */ 37 37 /* C C# D D# E F F# G G# A A# B */ 38 38 0x6b0,0x650,0x5f4,0x5a0,0x54c,0x500,0x4b8,0x474,0x434,0x3f8,0x3c0,0x38a,
+34 -26
apps/plugins/mikmod/sloader.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: sloader.c,v 1.3 2007/12/06 17:46:08 denis111 Exp $ 23 + $Id$ 24 24 25 25 Routines for loading samples. The sample loader utilizes the routines 26 26 provided by the "registered" sample loader. ··· 56 56 int SL_Init(SAMPLOAD* s) 57 57 { 58 58 if(!sl_buffer) 59 - if(!(sl_buffer=MikMod_malloc(SLBUFSIZE*sizeof(SWORD)))) return 0; 59 + if(!(sl_buffer=(SWORD*)MikMod_malloc(SLBUFSIZE*sizeof(SWORD)))) return 0; 60 60 61 61 sl_rlength = s->length; 62 62 if(s->infmt & SF_16BITS) sl_rlength>>=1; ··· 68 68 void SL_Exit(SAMPLOAD *s) 69 69 { 70 70 if(sl_rlength>0) _mm_fseek(s->reader,sl_rlength,SEEK_CUR); 71 - if(sl_buffer) { 72 - MikMod_free(sl_buffer); 73 - sl_buffer=NULL; 74 - } 71 + 72 + MikMod_free(sl_buffer); 73 + sl_buffer=NULL; 75 74 } 76 75 77 76 /* unpack a 8bit IT packed sample */ 78 - static int read_itcompr8(ITPACK* status,MREADER *reader,SWORD *sl_buffer,UWORD count,UWORD* incnt) 77 + static int read_itcompr8(ITPACK* status,MREADER *reader,SWORD *out,UWORD count,UWORD* incnt) 79 78 { 80 - SWORD *dest=sl_buffer,*end=sl_buffer+count; 79 + SWORD *dest=out,*end=out+count; 81 80 UWORD x,y,needbits,havebits,new_count=0; 82 81 UWORD bits = status->bits; 83 82 UWORD bufbits = status->bufbits; ··· 145 144 status->bufbits = bufbits; 146 145 status->last = last; 147 146 status->buf = buf; 148 - return (dest-sl_buffer); 147 + return (dest-out); 149 148 } 150 149 151 150 /* unpack a 16bit IT packed sample */ 152 - static int read_itcompr16(ITPACK *status,MREADER *reader,SWORD *sl_buffer,UWORD count,UWORD* incnt) 151 + static int read_itcompr16(ITPACK *status,MREADER *reader,SWORD *out,UWORD count,UWORD* incnt) 153 152 { 154 - SWORD *dest=sl_buffer,*end=sl_buffer+count; 153 + SWORD *dest=out,*end=out+count; 155 154 SLONG x,y,needbits,havebits,new_count=0; 156 155 UWORD bits = status->bits; 157 156 UWORD bufbits = status->bufbits; ··· 219 218 status->bufbits = bufbits; 220 219 status->last = last; 221 220 status->buf = buf; 222 - return (dest-sl_buffer); 221 + return (dest-out); 223 222 } 224 223 225 224 static int SL_LoadInternal(void* buffer,UWORD infmt,UWORD outfmt,int scalefactor,ULONG length,MREADER* reader,int dither) ··· 231 230 int result,c_block=0; /* compression bytes until next block */ 232 231 ITPACK status; 233 232 UWORD incnt = 0; 234 - 235 - memset(&status, 0, sizeof(status)); /* initialize status */ 236 - 233 + 234 + status.buf = 0; 235 + status.last = 0; 236 + status.bufbits = 0; 237 + status.bits = 0; 237 238 238 239 while(length) { 239 240 stodo=(length<SLBUFSIZE)?length:SLBUFSIZE; ··· 261 262 c_block -= stodo; 262 263 } else { 263 264 if(infmt&SF_16BITS) { 265 + if(_mm_eof(reader)) { 266 + _mm_errno=MMERR_NOT_A_STREAM;/* better error? */ 267 + return 1; 268 + } 264 269 if(infmt&SF_BIG_ENDIAN) 265 270 _mm_read_M_SWORDS(sl_buffer,stodo,reader); 266 271 else ··· 269 274 SBYTE *src; 270 275 SWORD *dest; 271 276 277 + if(_mm_eof(reader)) { 278 + _mm_errno=MMERR_NOT_A_STREAM;/* better error? */ 279 + return 1; 280 + } 272 281 reader->Read(reader,sl_buffer,sizeof(SBYTE)*stodo); 273 282 src = (SBYTE*)sl_buffer; 274 283 dest = sl_buffer; ··· 288 297 sl_old = sl_buffer[t]; 289 298 } 290 299 291 - if((infmt^outfmt) & SF_SIGNED) 300 + if((infmt^outfmt) & SF_SIGNED) 292 301 for(t=0;t<stodo;t++) 293 302 sl_buffer[t]^= 0x8000; 294 303 ··· 340 349 int SL_Load(void* buffer,SAMPLOAD *smp,ULONG length) 341 350 { 342 351 return SL_LoadInternal(buffer,smp->infmt,smp->outfmt,smp->scalefactor, 343 - length,smp->reader,0); 352 + length,smp->reader,0); 344 353 } 345 354 346 355 /* Registers a sample for loading when SL_LoadSamples() is called. */ ··· 357 366 cruise = sndfxlist; 358 367 } else 359 368 return NULL; 360 - 369 + 361 370 /* Allocate and add structure to the END of the list */ 362 371 if(!(news=(SAMPLOAD*)MikMod_malloc(sizeof(SAMPLOAD)))) return NULL; 363 372 ··· 407 416 static ULONG RealSpeed(SAMPLOAD *s) 408 417 { 409 418 return(s->sample->speed/(s->scalefactor?s->scalefactor:1)); 410 - } 419 + } 411 420 412 421 static int DitherSamples(SAMPLOAD* samplist,int type) 413 422 { ··· 417 426 418 427 if(!samplist) return 0; 419 428 420 - if((maxsize=MD_SampleSpace(type)*1024)) 429 + if((maxsize=MD_SampleSpace(type)*1024) != 0) 421 430 while(SampleTotal(samplist,type)>maxsize) { 422 431 /* First Pass - check for any 16 bit samples */ 423 432 s = samplist; ··· 473 482 474 483 int SL_LoadSamples(void) 475 484 { 476 - int ok; 485 + int rc; 477 486 478 487 _mm_critical = 0; 479 488 480 489 if((!musiclist)&&(!sndfxlist)) return 0; 481 - ok=DitherSamples(musiclist,MD_MUSIC)||DitherSamples(sndfxlist,MD_SNDFX); 490 + rc=DitherSamples(musiclist,MD_MUSIC)||DitherSamples(sndfxlist,MD_SNDFX); 482 491 musiclist=sndfxlist=NULL; 483 492 484 - return ok; 493 + return rc; 485 494 } 486 495 487 496 void SL_Sample16to8(SAMPLOAD* s) ··· 517 526 s->sample->loopstart = s->loopstart / s->scalefactor; 518 527 s->sample->loopend = s->loopend / s->scalefactor; 519 528 } 520 - 521 529 522 530 /* ex:set ts=4: */
+341 -309
apps/plugins/mikmod/virtch.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: virtch.c,v 1.4 2005/05/18 13:42:23 raphassenat Exp $ 23 + $Id$ 24 24 25 25 Sample mixing routines, using a 32 bits mixing buffer. 26 26 ··· 33 33 (b) Interpolation of sample data during mixing 34 34 (c) Dolby Surround Sound 35 35 */ 36 - #if 0 37 - #include <assert.h> 38 - #endif 39 36 40 37 #ifdef HAVE_CONFIG_H 41 38 #include "config.h" 42 39 #endif 43 40 44 - #include <stddef.h> 45 41 #ifdef HAVE_MEMORY_H 46 42 #include <memory.h> 47 43 #endif 48 44 #include <string.h> 49 45 50 46 #include "mikmod_internals.h" 51 - #include "mikmod.h" 52 47 53 48 /* 54 49 Constant definitions 55 50 ==================== 56 51 57 - BITSHIFT 52 + BITSHIFT 58 53 Controls the maximum volume of the sound output. All data is shifted 59 54 right by BITSHIFT after being mixed. Higher values result in quieter 60 55 sound and less chance of distortion. ··· 130 125 #else 131 126 #define NATIVE SLONG 132 127 #endif 128 + 133 129 #if defined HAVE_SSE2 || defined HAVE_ALTIVEC 134 130 135 - static size_t MixSIMDMonoNormal(const SWORD* srce,SLONG* dest,size_t index, size_t increment,size_t todo) 131 + # if !defined(NATIVE_64BIT_INT) 132 + static SINTPTR_T MixSIMDMonoNormal(const SWORD* srce,SLONG* dest,SINTPTR_T idx,SINTPTR_T increment,SINTPTR_T todo) 136 133 { 137 - // TODO: 134 + /* TODO: */ 138 135 SWORD sample; 139 136 SLONG lvolsel = vnf->lvolsel; 140 137 141 138 while(todo--) { 142 - sample = srce[index >> FRACBITS]; 143 - index += increment; 139 + sample = srce[idx >> FRACBITS]; 140 + idx += increment; 144 141 145 142 *dest++ += lvolsel * sample; 146 143 } 147 - return index; 144 + return idx; 148 145 } 146 + # endif /* !NATIVE_64BIT_INT */ 149 147 150 - static size_t MixSIMDStereoNormal(const SWORD* srce, SLONG* dest, size_t index, size_t increment,size_t todo) 151 - { 148 + static SINTPTR_T MixSIMDStereoNormal(const SWORD* srce,SLONG* dest,SINTPTR_T idx,SINTPTR_T increment,SINTPTR_T todo) 149 + { 152 150 SWORD vol[8] = {vnf->lvolsel, vnf->rvolsel}; 153 151 SWORD sample; 154 152 SLONG remain = todo; 155 153 156 - // Dest can be misaligned ... 154 + /* Dest can be misaligned */ 157 155 while(!IS_ALIGNED_16(dest)) { 158 - sample=srce[(index += increment) >> FRACBITS]; 156 + sample=srce[idx >> FRACBITS]; 157 + idx += increment; 159 158 *dest++ += vol[0] * sample; 160 159 *dest++ += vol[1] * sample; 161 160 todo--; 161 + if(!todo) return idx; 162 162 } 163 163 164 - // Srce is always aligned ... 164 + /* Srce is always aligned */ 165 165 166 166 #if defined HAVE_SSE2 167 - remain = todo&3; 167 + remain = todo&3; 168 168 { 169 - __m128i v0 = _mm_set_epi16(0, vol[1], 170 - 0, vol[0], 171 - 0, vol[1], 172 - 0, vol[0]); 169 + __m128i v0 = _mm_set_epi16(0, vol[1], 170 + 0, vol[0], 171 + 0, vol[1], 172 + 0, vol[0]); 173 173 for(todo>>=2;todo; todo--) 174 174 { 175 - SWORD s0 = srce[(index += increment) >> FRACBITS]; 176 - SWORD s1 = srce[(index += increment) >> FRACBITS]; 177 - SWORD s2 = srce[(index += increment) >> FRACBITS]; 178 - SWORD s3 = srce[(index += increment) >> FRACBITS]; 175 + SWORD s0 = srce[idx >> FRACBITS]; 176 + SWORD s1 = srce[(idx += increment) >> FRACBITS]; 177 + SWORD s2 = srce[(idx += increment) >> FRACBITS]; 178 + SWORD s3 = srce[(idx += increment) >> FRACBITS]; 179 179 __m128i v1 = _mm_set_epi16(0, s1, 0, s1, 0, s0, 0, s0); 180 180 __m128i v2 = _mm_set_epi16(0, s3, 0, s3, 0, s2, 0, s2); 181 181 __m128i v3 = _mm_load_si128((__m128i*)(dest+0)); 182 182 __m128i v4 = _mm_load_si128((__m128i*)(dest+4)); 183 183 _mm_store_si128((__m128i*)(dest+0), _mm_add_epi32(v3, _mm_madd_epi16(v0, v1))); 184 184 _mm_store_si128((__m128i*)(dest+4), _mm_add_epi32(v4, _mm_madd_epi16(v0, v2))); 185 - dest+=8; 185 + dest+=8; 186 + idx += increment; 186 187 } 187 188 } 188 189 189 190 #elif defined HAVE_ALTIVEC 190 191 remain = todo&3; 191 192 { 193 + SWORD s[8]; 192 194 vector signed short r0 = vec_ld(0, vol); 193 - vector signed short v0 = vec_perm(r0, r0, (vector unsigned char)(0, 1, // l 194 - 0, 1, // l 195 - 2, 3, // r 196 - 2, 1, // r 197 - 0, 1, // l 198 - 0, 1, // l 199 - 2, 3, // r 200 - 2, 3 // r 201 - )); 202 - SWORD s[8]; 203 - 195 + vector signed short v0 = vec_perm(r0, r0, (vector unsigned char)(0, 1, /* l */ 196 + 0, 1, /* l */ 197 + 2, 3, /* r */ 198 + 2, 1, /* r */ 199 + 0, 1, /* l */ 200 + 0, 1, /* l */ 201 + 2, 3, /* r */ 202 + 2, 3 /* r */ 203 + )); 204 + 204 205 for(todo>>=2;todo; todo--) 205 206 { 206 - // Load constants 207 - s[0] = srce[(index += increment) >> FRACBITS]; 208 - s[1] = srce[(index += increment) >> FRACBITS]; 209 - s[2] = srce[(index += increment) >> FRACBITS]; 210 - s[3] = srce[(index += increment) >> FRACBITS]; 207 + vector short int r1; 208 + vector signed short v1, v2; 209 + vector signed int v3, v4, v5, v6; 210 + 211 + /* Load constants */ 212 + s[0] = srce[idx >> FRACBITS]; 213 + s[1] = srce[(idx += increment) >> FRACBITS]; 214 + s[2] = srce[(idx += increment) >> FRACBITS]; 215 + s[3] = srce[(idx += increment) >> FRACBITS]; 211 216 s[4] = 0; 212 - 213 - vector short int r1 = vec_ld(0, s); 214 - vector signed short v1 = vec_perm(r1, r1, (vector unsigned char)(0*2, 0*2+1, // s0 215 - 4*2, 4*2+1, // 0 216 - 0*2, 0*2+1, // s0 217 - 4*2, 4*2+1, // 0 218 - 1*2, 1*2+1, // s1 219 - 4*2, 4*2+1, // 0 220 - 1*2, 1*2+1, // s1 221 - 4*2, 4*2+1 // 0 222 - )); 223 - 224 - vector signed short v2 = vec_perm(r1, r1, (vector unsigned char)(2*2, 2*2+1, // s2 225 - 4*2, 4*2+1, // 0 226 - 2*2, 2*2+1, // s2 227 - 4*2, 4*2+1, // 0 228 - 3*2, 3*2+1, // s3 229 - 4*2, 4*2+1, // 0 230 - 3*2, 3*2+1, // s3 231 - 4*2, 4*2+1 // 0 232 - )); 233 - vector signed int v3 = vec_ld(0, dest); 234 - vector signed int v4 = vec_ld(0, dest + 4); 235 - vector signed int v5 = vec_mule(v0, v1); 236 - vector signed int v6 = vec_mule(v0, v2); 217 + 218 + r1 = vec_ld(0, s); 219 + v1 = vec_perm(r1, r1, (vector unsigned char) 220 + (0*2, 0*2+1, /* s0 */ 221 + 4*2, 4*2+1, /* 0 */ 222 + 0*2, 0*2+1, /* s0 */ 223 + 4*2, 4*2+1, /* 0 */ 224 + 1*2, 1*2+1, /* s1 */ 225 + 4*2, 4*2+1, /* 0 */ 226 + 1*2, 1*2+1, /* s1 */ 227 + 4*2, 4*2+1 /* 0 */ 228 + ) ); 229 + v2 = vec_perm(r1, r1, (vector unsigned char) 230 + (2*2, 2*2+1, /* s2 */ 231 + 4*2, 4*2+1, /* 0 */ 232 + 2*2, 2*2+1, /* s2 */ 233 + 4*2, 4*2+1, /* 0 */ 234 + 3*2, 3*2+1, /* s3 */ 235 + 4*2, 4*2+1, /* 0 */ 236 + 3*2, 3*2+1, /* s3 */ 237 + 4*2, 4*2+1 /* 0 */ 238 + ) ); 239 + 240 + v3 = vec_ld(0, dest); 241 + v4 = vec_ld(0, dest + 4); 242 + v5 = vec_mule(v0, v1); 243 + v6 = vec_mule(v0, v2); 237 244 238 - vec_st(vec_add(v3, v5), 0, dest); 245 + vec_st(vec_add(v3, v5), 0, dest); 239 246 vec_st(vec_add(v4, v6), 0x10, dest); 240 247 241 248 dest+=8; 249 + idx += increment; 242 250 } 243 251 } 244 - #endif // HAVE_ALTIVEC 252 + #endif /* HAVE_ALTIVEC */ 245 253 246 - // Remaining bits ... 254 + /* Remaining bits */ 247 255 while(remain--) { 248 - sample=srce[(index += increment) >> FRACBITS]; 256 + sample=srce[idx >> FRACBITS]; 257 + idx += increment; 249 258 250 259 *dest++ += vol[0] * sample; 251 260 *dest++ += vol[1] * sample; 252 261 } 253 - return index; 262 + return idx; 254 263 } 255 264 #endif 256 265 257 266 /*========== 32 bit sample mixers - only for 32 bit platforms */ 258 267 #ifndef NATIVE_64BIT_INT 259 268 260 - static SLONG Mix32MonoNormal(const SWORD* srce,SLONG* dest,SLONG index,SLONG increment,SLONG todo) 269 + static SLONG Mix32MonoNormal(const SWORD* srce,SLONG* dest,SLONG idx,SLONG increment,SLONG todo) 261 270 { 262 271 #if defined HAVE_ALTIVEC || defined HAVE_SSE2 263 - if (md_mode & DMODE_SIMDMIXER) 264 - { 265 - return MixSIMDMonoNormal(srce, dest, index, increment, todo); 272 + if (md_mode & DMODE_SIMDMIXER) { 273 + return MixSIMDMonoNormal(srce, dest, idx, increment, todo); 266 274 } 267 275 else 268 276 #endif 269 277 { 270 278 SWORD sample; 271 279 SLONG lvolsel = vnf->lvolsel; 272 - 280 + 273 281 while(todo--) { 274 - sample = srce[index >> FRACBITS]; 275 - index += increment; 276 - 282 + sample = srce[idx >> FRACBITS]; 283 + idx += increment; 284 + 277 285 *dest++ += lvolsel * sample; 278 286 } 279 287 } 280 - return index; 288 + return idx; 281 289 } 282 290 283 - // FIXME: This mixer should works also on 64-bit platform 284 - // Hint : changes SLONG / SLONGLONG mess with size_t 285 - static SLONG Mix32StereoNormal(const SWORD* srce,SLONG* dest,SLONG index,SLONG increment,SLONG todo) 291 + /* FIXME: This mixer should works also on 64-bit platform */ 292 + /* Hint : changes SLONG / SLONGLONG mess with intptr */ 293 + static SLONG Mix32StereoNormal(const SWORD* srce,SLONG* dest,SLONG idx,SLONG increment,SLONG todo) 286 294 { 287 295 #if defined HAVE_ALTIVEC || defined HAVE_SSE2 288 - if (md_mode & DMODE_SIMDMIXER) 289 - { 290 - return MixSIMDStereoNormal(srce, dest, index, increment, todo); 296 + if (md_mode & DMODE_SIMDMIXER) { 297 + return MixSIMDStereoNormal(srce, dest, idx, increment, todo); 291 298 } 292 299 else 293 300 #endif ··· 297 304 SLONG rvolsel = vnf->rvolsel; 298 305 299 306 while(todo--) { 300 - sample=srce[(index += increment) >> FRACBITS]; 307 + sample=srce[idx >> FRACBITS]; 308 + idx += increment; 301 309 302 310 *dest++ += lvolsel * sample; 303 311 *dest++ += rvolsel * sample; 304 312 } 305 313 } 306 - return index; 314 + return idx; 307 315 } 308 316 309 - 310 - static SLONG Mix32SurroundNormal(const SWORD* srce,SLONG* dest,SLONG index,SLONG increment,SLONG todo) 317 + static SLONG Mix32SurroundNormal(const SWORD* srce,SLONG* dest,SLONG idx,SLONG increment,SLONG todo) 311 318 { 312 319 SWORD sample; 313 320 SLONG lvolsel = vnf->lvolsel; ··· 315 322 316 323 if (lvolsel>=rvolsel) { 317 324 while(todo--) { 318 - sample = srce[index >> FRACBITS]; 319 - index += increment; 325 + sample = srce[idx >> FRACBITS]; 326 + idx += increment; 320 327 321 328 *dest++ += lvolsel*sample; 322 329 *dest++ -= lvolsel*sample; 323 330 } 324 - } else { 331 + } 332 + else { 325 333 while(todo--) { 326 - sample = srce[index >> FRACBITS]; 327 - index += increment; 334 + sample = srce[idx >> FRACBITS]; 335 + idx += increment; 328 336 329 337 *dest++ -= rvolsel*sample; 330 338 *dest++ += rvolsel*sample; 331 339 } 332 340 } 333 - return index; 341 + return idx; 334 342 } 335 343 336 - static SLONG Mix32MonoInterp(const SWORD* srce,SLONG* dest,SLONG index,SLONG increment,SLONG todo) 344 + static SLONG Mix32MonoInterp(const SWORD* srce,SLONG* dest,SLONG idx,SLONG increment,SLONG todo) 337 345 { 338 346 SLONG sample; 339 347 SLONG lvolsel = vnf->lvolsel; ··· 342 350 if (rampvol) { 343 351 SLONG oldlvol = vnf->oldlvol - lvolsel; 344 352 while(todo--) { 345 - sample=(SLONG)srce[index>>FRACBITS]+ 346 - ((SLONG)(srce[(index>>FRACBITS)+1]-srce[index>>FRACBITS]) 347 - *(index&FRACMASK)>>FRACBITS); 348 - index += increment; 353 + sample=(SLONG)srce[idx>>FRACBITS]+ 354 + ((SLONG)(srce[(idx>>FRACBITS)+1]-srce[idx>>FRACBITS]) 355 + *(idx&FRACMASK)>>FRACBITS); 356 + idx += increment; 349 357 350 358 *dest++ += ((lvolsel << CLICK_SHIFT) + oldlvol * rampvol) 351 - * sample >> CLICK_SHIFT; 359 + * sample >> CLICK_SHIFT; 352 360 if (!--rampvol) 353 361 break; 354 362 } 355 363 vnf->rampvol = rampvol; 356 364 if (todo < 0) 357 - return index; 365 + return idx; 358 366 } 359 367 360 368 while(todo--) { 361 - sample=(SLONG)srce[index>>FRACBITS]+ 362 - ((SLONG)(srce[(index>>FRACBITS)+1]-srce[index>>FRACBITS]) 363 - *(index&FRACMASK)>>FRACBITS); 364 - index += increment; 369 + sample=(SLONG)srce[idx>>FRACBITS]+ 370 + ((SLONG)(srce[(idx>>FRACBITS)+1]-srce[idx>>FRACBITS]) 371 + *(idx&FRACMASK)>>FRACBITS); 372 + idx += increment; 365 373 366 374 *dest++ += lvolsel * sample; 367 375 } 368 - return index; 376 + return idx; 369 377 } 370 378 371 - static SLONG Mix32StereoInterp(const SWORD* srce,SLONG* dest,SLONG index,SLONG increment,SLONG todo) 379 + static SLONG Mix32StereoInterp(const SWORD* srce,SLONG* dest,SLONG idx,SLONG increment,SLONG todo) 372 380 { 373 381 SLONG sample; 374 382 SLONG lvolsel = vnf->lvolsel; ··· 379 387 SLONG oldlvol = vnf->oldlvol - lvolsel; 380 388 SLONG oldrvol = vnf->oldrvol - rvolsel; 381 389 while(todo--) { 382 - sample=(SLONG)srce[index>>FRACBITS]+ 383 - ((SLONG)(srce[(index>>FRACBITS)+1]-srce[index>>FRACBITS]) 384 - *(index&FRACMASK)>>FRACBITS); 385 - index += increment; 390 + sample=(SLONG)srce[idx>>FRACBITS]+ 391 + ((SLONG)(srce[(idx>>FRACBITS)+1]-srce[idx>>FRACBITS]) 392 + *(idx&FRACMASK)>>FRACBITS); 393 + idx += increment; 386 394 387 395 *dest++ += ((lvolsel << CLICK_SHIFT) + oldlvol * rampvol) 388 - * sample >> CLICK_SHIFT; 396 + * sample >> CLICK_SHIFT; 389 397 *dest++ += ((rvolsel << CLICK_SHIFT) + oldrvol * rampvol) 390 398 * sample >> CLICK_SHIFT; 391 399 if (!--rampvol) ··· 393 401 } 394 402 vnf->rampvol = rampvol; 395 403 if (todo < 0) 396 - return index; 404 + return idx; 397 405 } 398 406 399 407 while(todo--) { 400 - sample=(SLONG)srce[index>>FRACBITS]+ 401 - ((SLONG)(srce[(index>>FRACBITS)+1]-srce[index>>FRACBITS]) 402 - *(index&FRACMASK)>>FRACBITS); 403 - index += increment; 408 + sample=(SLONG)srce[idx>>FRACBITS]+ 409 + ((SLONG)(srce[(idx>>FRACBITS)+1]-srce[idx>>FRACBITS]) 410 + *(idx&FRACMASK)>>FRACBITS); 411 + idx += increment; 404 412 405 413 *dest++ += lvolsel * sample; 406 414 *dest++ += rvolsel * sample; 407 415 } 408 - return index; 416 + return idx; 409 417 } 410 418 411 - static SLONG Mix32SurroundInterp(const SWORD* srce,SLONG* dest,SLONG index,SLONG increment,SLONG todo) 419 + static SLONG Mix32SurroundInterp(const SWORD* srce,SLONG* dest,SLONG idx,SLONG increment,SLONG todo) 412 420 { 413 421 SLONG sample; 414 422 SLONG lvolsel = vnf->lvolsel; ··· 427 435 if (rampvol) { 428 436 oldvol -= vol; 429 437 while(todo--) { 430 - sample=(SLONG)srce[index>>FRACBITS]+ 431 - ((SLONG)(srce[(index>>FRACBITS)+1]-srce[index>>FRACBITS]) 432 - *(index&FRACMASK)>>FRACBITS); 433 - index += increment; 438 + sample=(SLONG)srce[idx>>FRACBITS]+ 439 + ((SLONG)(srce[(idx>>FRACBITS)+1]-srce[idx>>FRACBITS]) 440 + *(idx&FRACMASK)>>FRACBITS); 441 + idx += increment; 434 442 435 443 sample=((vol << CLICK_SHIFT) + oldvol * rampvol) 436 - * sample >> CLICK_SHIFT; 444 + * sample >> CLICK_SHIFT; 437 445 *dest++ += sample; 438 446 *dest++ -= sample; 439 447 ··· 442 450 } 443 451 vnf->rampvol = rampvol; 444 452 if (todo < 0) 445 - return index; 453 + return idx; 446 454 } 447 455 448 456 while(todo--) { 449 - sample=(SLONG)srce[index>>FRACBITS]+ 450 - ((SLONG)(srce[(index>>FRACBITS)+1]-srce[index>>FRACBITS]) 451 - *(index&FRACMASK)>>FRACBITS); 452 - index += increment; 457 + sample=(SLONG)srce[idx>>FRACBITS]+ 458 + ((SLONG)(srce[(idx>>FRACBITS)+1]-srce[idx>>FRACBITS]) 459 + *(idx&FRACMASK)>>FRACBITS); 460 + idx += increment; 453 461 454 462 *dest++ += vol*sample; 455 463 *dest++ -= vol*sample; 456 464 } 457 - return index; 465 + return idx; 458 466 } 459 467 #endif 460 468 461 469 /*========== 64 bit sample mixers - all platforms */ 462 470 463 - static SLONGLONG MixMonoNormal(const SWORD* srce,SLONG* dest,SLONGLONG index,SLONGLONG increment,SLONG todo) 471 + static SLONGLONG MixMonoNormal(const SWORD* srce,SLONG* dest,SLONGLONG idx,SLONGLONG increment,SLONG todo) 464 472 { 465 473 SWORD sample; 466 474 SLONG lvolsel = vnf->lvolsel; 467 475 468 476 while(todo--) { 469 - sample = srce[index >> FRACBITS]; 470 - index += increment; 477 + sample = srce[idx >> FRACBITS]; 478 + idx += increment; 471 479 472 480 *dest++ += lvolsel * sample; 473 481 } 474 - return index; 482 + return idx; 475 483 } 476 484 477 - static SLONGLONG MixStereoNormal(const SWORD* srce,SLONG* dest,SLONGLONG index,SLONGLONG increment,SLONG todo) 485 + static SLONGLONG MixStereoNormal(const SWORD* srce,SLONG* dest,SLONGLONG idx,SLONGLONG increment,SLONG todo) 478 486 { 479 487 SWORD sample; 480 488 SLONG lvolsel = vnf->lvolsel; 481 489 SLONG rvolsel = vnf->rvolsel; 482 490 483 491 while(todo--) { 484 - sample=srce[index >> FRACBITS]; 485 - index += increment; 492 + sample=srce[idx >> FRACBITS]; 493 + idx += increment; 486 494 487 495 *dest++ += lvolsel * sample; 488 496 *dest++ += rvolsel * sample; 489 497 } 490 - return index; 498 + return idx; 491 499 } 492 500 493 - static SLONGLONG MixSurroundNormal(const SWORD* srce,SLONG* dest,SLONGLONG index,SLONGLONG increment,SLONG todo) 501 + static SLONGLONG MixSurroundNormal(const SWORD* srce,SLONG* dest,SLONGLONG idx,SLONGLONG increment,SLONG todo) 494 502 { 495 503 SWORD sample; 496 504 SLONG lvolsel = vnf->lvolsel; ··· 498 506 499 507 if(vnf->lvolsel>=vnf->rvolsel) { 500 508 while(todo--) { 501 - sample = srce[index >> FRACBITS]; 502 - index += increment; 509 + sample = srce[idx >> FRACBITS]; 510 + idx += increment; 503 511 504 512 *dest++ += lvolsel*sample; 505 513 *dest++ -= lvolsel*sample; 506 514 } 507 - } else { 515 + } 516 + else { 508 517 while(todo--) { 509 - sample = srce[index >> FRACBITS]; 510 - index += increment; 518 + sample = srce[idx >> FRACBITS]; 519 + idx += increment; 511 520 512 521 *dest++ -= rvolsel*sample; 513 522 *dest++ += rvolsel*sample; 514 523 } 515 524 } 516 - return index; 525 + return idx; 517 526 } 518 527 519 - static SLONGLONG MixMonoInterp(const SWORD* srce,SLONG* dest,SLONGLONG index,SLONGLONG increment,SLONG todo) 528 + static SLONGLONG MixMonoInterp(const SWORD* srce,SLONG* dest,SLONGLONG idx,SLONGLONG increment,SLONG todo) 520 529 { 521 530 SLONG sample; 522 531 SLONG lvolsel = vnf->lvolsel; ··· 525 534 if (rampvol) { 526 535 SLONG oldlvol = vnf->oldlvol - lvolsel; 527 536 while(todo--) { 528 - sample=(SLONG)srce[index>>FRACBITS]+ 529 - ((SLONG)(srce[(index>>FRACBITS)+1]-srce[index>>FRACBITS]) 530 - *(index&FRACMASK)>>FRACBITS); 531 - index += increment; 537 + sample=(SLONG)srce[idx>>FRACBITS]+ 538 + ((SLONG)(srce[(idx>>FRACBITS)+1]-srce[idx>>FRACBITS]) 539 + *(idx&FRACMASK)>>FRACBITS); 540 + idx += increment; 532 541 533 542 *dest++ += ((lvolsel << CLICK_SHIFT) + oldlvol * rampvol) 534 543 * sample >> CLICK_SHIFT; ··· 537 546 } 538 547 vnf->rampvol = rampvol; 539 548 if (todo < 0) 540 - return index; 549 + return idx; 541 550 } 542 551 543 552 while(todo--) { 544 - sample=(SLONG)srce[index>>FRACBITS]+ 545 - ((SLONG)(srce[(index>>FRACBITS)+1]-srce[index>>FRACBITS]) 546 - *(index&FRACMASK)>>FRACBITS); 547 - index += increment; 553 + sample=(SLONG)srce[idx>>FRACBITS]+ 554 + ((SLONG)(srce[(idx>>FRACBITS)+1]-srce[idx>>FRACBITS]) 555 + *(idx&FRACMASK)>>FRACBITS); 556 + idx += increment; 548 557 549 558 *dest++ += lvolsel * sample; 550 559 } 551 - return index; 560 + return idx; 552 561 } 553 562 554 - static SLONGLONG MixStereoInterp(const SWORD* srce,SLONG* dest,SLONGLONG index,SLONGLONG increment,SLONG todo) 563 + static SLONGLONG MixStereoInterp(const SWORD* srce,SLONG* dest,SLONGLONG idx,SLONGLONG increment,SLONG todo) 555 564 { 556 565 SLONG sample; 557 566 SLONG lvolsel = vnf->lvolsel; ··· 562 571 SLONG oldlvol = vnf->oldlvol - lvolsel; 563 572 SLONG oldrvol = vnf->oldrvol - rvolsel; 564 573 while(todo--) { 565 - sample=(SLONG)srce[index>>FRACBITS]+ 566 - ((SLONG)(srce[(index>>FRACBITS)+1]-srce[index>>FRACBITS]) 567 - *(index&FRACMASK)>>FRACBITS); 568 - index += increment; 574 + sample=(SLONG)srce[idx>>FRACBITS]+ 575 + ((SLONG)(srce[(idx>>FRACBITS)+1]-srce[idx>>FRACBITS]) 576 + *(idx&FRACMASK)>>FRACBITS); 577 + idx += increment; 569 578 570 579 *dest++ +=((lvolsel << CLICK_SHIFT) + oldlvol * rampvol) 571 580 * sample >> CLICK_SHIFT; ··· 576 585 } 577 586 vnf->rampvol = rampvol; 578 587 if (todo < 0) 579 - return index; 588 + return idx; 580 589 } 581 590 582 591 while(todo--) { 583 - sample=(SLONG)srce[index>>FRACBITS]+ 584 - ((SLONG)(srce[(index>>FRACBITS)+1]-srce[index>>FRACBITS]) 585 - *(index&FRACMASK)>>FRACBITS); 586 - index += increment; 592 + sample=(SLONG)srce[idx>>FRACBITS]+ 593 + ((SLONG)(srce[(idx>>FRACBITS)+1]-srce[idx>>FRACBITS]) 594 + *(idx&FRACMASK)>>FRACBITS); 595 + idx += increment; 587 596 588 597 *dest++ += lvolsel * sample; 589 598 *dest++ += rvolsel * sample; 590 599 } 591 - return index; 600 + return idx; 592 601 } 593 602 594 - static SLONGLONG MixSurroundInterp(const SWORD* srce,SLONG* dest,SLONGLONG index,SLONGLONG increment,SLONG todo) 603 + static SLONGLONG MixSurroundInterp(const SWORD* srce,SLONG* dest,SLONGLONG idx,SLONGLONG increment,SLONG todo) 595 604 { 596 605 SLONG sample; 597 606 SLONG lvolsel = vnf->lvolsel; ··· 610 619 if (rampvol) { 611 620 oldvol -= vol; 612 621 while(todo--) { 613 - sample=(SLONG)srce[index>>FRACBITS]+ 614 - ((SLONG)(srce[(index>>FRACBITS)+1]-srce[index>>FRACBITS]) 615 - *(index&FRACMASK)>>FRACBITS); 616 - index += increment; 622 + sample=(SLONG)srce[idx>>FRACBITS]+ 623 + ((SLONG)(srce[(idx>>FRACBITS)+1]-srce[idx>>FRACBITS]) 624 + *(idx&FRACMASK)>>FRACBITS); 625 + idx += increment; 617 626 618 627 sample=((vol << CLICK_SHIFT) + oldvol * rampvol) 619 - * sample >> CLICK_SHIFT; 628 + * sample >> CLICK_SHIFT; 620 629 *dest++ += sample; 621 630 *dest++ -= sample; 622 631 if (!--rampvol) ··· 624 633 } 625 634 vnf->rampvol = rampvol; 626 635 if (todo < 0) 627 - return index; 636 + return idx; 628 637 } 629 638 630 639 while(todo--) { 631 - sample=(SLONG)srce[index>>FRACBITS]+ 632 - ((SLONG)(srce[(index>>FRACBITS)+1]-srce[index>>FRACBITS]) 633 - *(index&FRACMASK)>>FRACBITS); 634 - index += increment; 640 + sample=(SLONG)srce[idx>>FRACBITS]+ 641 + ((SLONG)(srce[(idx>>FRACBITS)+1]-srce[idx>>FRACBITS]) 642 + *(idx&FRACMASK)>>FRACBITS); 643 + idx += increment; 635 644 636 645 *dest++ += vol*sample; 637 646 *dest++ -= vol*sample; 638 647 } 639 - return index; 648 + return idx; 640 649 } 641 650 642 651 static void (*MixReverb)(SLONG* srce,NATIVE count); ··· 673 682 674 683 /* left channel */ 675 684 *srce++ +=RVbufL1[loc1]-RVbufL2[loc2]+RVbufL3[loc3]-RVbufL4[loc4]+ 676 - RVbufL5[loc5]-RVbufL6[loc6]+RVbufL7[loc7]-RVbufL8[loc8]; 685 + RVbufL5[loc5]-RVbufL6[loc6]+RVbufL7[loc7]-RVbufL8[loc8]; 677 686 } 678 687 } 679 688 ··· 710 719 711 720 /* left channel then right channel */ 712 721 *srce++ +=RVbufL1[loc1]-RVbufL2[loc2]+RVbufL3[loc3]-RVbufL4[loc4]+ 713 - RVbufL5[loc5]-RVbufL6[loc6]+RVbufL7[loc7]-RVbufL8[loc8]; 722 + RVbufL5[loc5]-RVbufL6[loc6]+RVbufL7[loc7]-RVbufL8[loc8]; 714 723 715 724 *srce++ +=RVbufR1[loc1]-RVbufR2[loc2]+RVbufR3[loc3]-RVbufR4[loc4]+ 716 - RVbufR5[loc5]-RVbufR6[loc6]+RVbufR7[loc7]-RVbufR8[loc8]; 725 + RVbufR5[loc5]-RVbufR6[loc6]+RVbufR7[loc7]-RVbufR8[loc8]; 717 726 } 718 727 } 719 728 ··· 839 848 840 849 #if defined HAVE_ALTIVEC || defined HAVE_SSE2 841 850 842 - // Mix 32bit input to floating point. 32 samples per iteration 843 - // PC: ?, Mac OK 844 - static void Mix32ToFP_SIMD(float* dste,SLONG* srce,NATIVE count) 851 + /* Mix 32bit input to floating point. 32 samples per iteration */ 852 + /* PC: ?, Mac OK */ 853 + static void Mix32ToFP_SIMD(float* dste,const SLONG* srce,NATIVE count) 845 854 { 846 - int remain=count; 855 + const float k = ((1.0f / 32768.0f) / (1 << FP_SHIFT)); 856 + int remain=count; 857 + simd_m128 x1, x2, xk; 847 858 848 859 while(!IS_ALIGNED_16(dste) || !IS_ALIGNED_16(srce)) 849 860 { 850 - float x1; 851 - EXTRACT_SAMPLE_FP(x1,FP_SHIFT); 852 - CHECK_SAMPLE_FP(x1,1.0f); 853 - PUT_SAMPLE_FP(x1); 861 + float xf; 862 + EXTRACT_SAMPLE_FP(xf,FP_SHIFT); 863 + CHECK_SAMPLE_FP(xf,1.0f); 864 + PUT_SAMPLE_FP(xf); 854 865 count--; 855 - if (!count) 856 - { 857 - return; 858 - } 866 + if (!count) return; 859 867 } 860 868 861 - remain = count&7; 862 - 863 - const float k = ((1.0f / 32768.0f) / (1 << FP_SHIFT)); 864 - simd_m128 x1, x2; 865 - simd_m128 xk = LOAD_PS1_SIMD(&k); // Scale factor 869 + remain = count&7; 870 + 871 + xk = LOAD_PS1_SIMD(&k); /* Scale factor */ 866 872 867 873 for(count>>=3;count;count--) { 868 - EXTRACT_SAMPLE_SIMD_F(srce, x1, FP_SHIFT, xk); // Load 4 samples 869 - EXTRACT_SAMPLE_SIMD_F(srce+4, x2, FP_SHIFT, xk); // Load 4 samples 870 - PUT_SAMPLE_SIMD_F(dste, x1); // Store 4 samples 871 - PUT_SAMPLE_SIMD_F(dste+4, x2); // Store 4 samples 872 - srce+=8; 873 - dste+=8; 874 - } 874 + EXTRACT_SAMPLE_SIMD_F(srce, x1, FP_SHIFT, xk); /* Load 4 samples */ 875 + EXTRACT_SAMPLE_SIMD_F(srce+4, x2, FP_SHIFT, xk); /* Load 4 samples */ 876 + PUT_SAMPLE_SIMD_F(dste, x1); /* Store 4 samples */ 877 + PUT_SAMPLE_SIMD_F(dste+4, x2); /* Store 4 samples */ 878 + srce+=8; 879 + dste+=8; 880 + } 875 881 876 882 if (remain&4) { 877 - EXTRACT_SAMPLE_SIMD_F(srce, x1, FP_SHIFT, xk); // Load 4 samples 878 - PUT_SAMPLE_SIMD_F(dste, x1); // Store 4 samples 879 - srce+=4; 880 - dste+=4; 881 - remain &= 3; 882 - } 883 + EXTRACT_SAMPLE_SIMD_F(srce, x1, FP_SHIFT, xk); /* Load 4 samples */ 884 + PUT_SAMPLE_SIMD_F(dste, x1); /* Store 4 samples */ 885 + srce+=4; 886 + dste+=4; 887 + remain &= 3; 888 + } 883 889 884 890 while(remain--) { 885 - float x1; 886 - EXTRACT_SAMPLE_FP(x1,FP_SHIFT); 887 - CHECK_SAMPLE_FP(x1,1.0f); 888 - PUT_SAMPLE_FP(x1); 891 + float xf; 892 + EXTRACT_SAMPLE_FP(xf,FP_SHIFT); 893 + CHECK_SAMPLE_FP(xf,1.0f); 894 + PUT_SAMPLE_FP(xf); 889 895 } 890 896 } 891 - // PC: Ok, Mac Ok 892 - static void Mix32To16_SIMD(SWORD* dste,SLONG* srce,NATIVE count) 893 - { 897 + 898 + /* PC: Ok, Mac Ok */ 899 + static void Mix32To16_SIMD(SWORD* dste,const SLONG* srce,NATIVE count) 900 + { 894 901 int remain = count; 895 902 896 903 while(!IS_ALIGNED_16(dste) || !IS_ALIGNED_16(srce)) ··· 900 907 CHECK_SAMPLE(x1,32768); 901 908 PUT_SAMPLE(x1); 902 909 count--; 903 - if (!count) 904 - { 905 - return; 906 - } 910 + if (!count) return; 907 911 } 908 912 909 913 remain = count&7; 910 914 911 - for(count>>=3;count;count--) 915 + for(count>>=3;count;count--) 912 916 { 913 917 simd_m128i x1,x2; 914 - EXTRACT_SAMPLE_SIMD_16(srce, x1); // Load 4 samples 915 - EXTRACT_SAMPLE_SIMD_16(srce+4, x2); // Load 4 samples 916 - PUT_SAMPLE_SIMD_W(dste, x1, x2); // Store 8 samples 918 + EXTRACT_SAMPLE_SIMD_16(srce, x1); /* Load 4 samples */ 919 + EXTRACT_SAMPLE_SIMD_16(srce+4, x2); /* Load 4 samples */ 920 + PUT_SAMPLE_SIMD_W(dste, x1, x2); /* Store 8 samples */ 917 921 srce+=8; 918 922 dste+=8; 919 923 } 920 924 921 925 if (remain) 922 - Mix32To16(dste, srce, remain); 926 + Mix32To16(dste, srce, remain); 923 927 } 924 928 925 - // Mix 32bit input to 8bit. 128 samples per iteration 926 - // PC:OK, Mac: Ok 927 - static void Mix32To8_SIMD(SBYTE* dste,SLONG* srce,NATIVE count) 928 - { 929 + /* Mix 32bit input to 8bit. 128 samples per iteration */ 930 + /* PC:OK, Mac: Ok */ 931 + static void Mix32To8_SIMD(SBYTE* dste,const SLONG* srce,NATIVE count) 932 + { 929 933 int remain=count; 930 - 934 + 931 935 while(!IS_ALIGNED_16(dste) || !IS_ALIGNED_16(srce)) 932 936 { 933 937 SWORD x1; ··· 935 939 CHECK_SAMPLE(x1,128); 936 940 PUT_SAMPLE(x1+128); 937 941 count--; 938 - if (!count) 939 - { 940 - return; 941 - } 942 + if (!count) return; 942 943 } 943 - 944 + 944 945 remain = count&15; 945 946 946 947 for(count>>=4;count;count--) { 947 - simd_m128i x1,x2,x3,x4; 948 - EXTRACT_SAMPLE_SIMD_8(srce, x1); // Load 4 samples 949 - EXTRACT_SAMPLE_SIMD_8(srce+4, x2); // Load 4 samples 950 - EXTRACT_SAMPLE_SIMD_8(srce+8, x3); // Load 4 samples 951 - EXTRACT_SAMPLE_SIMD_8(srce+12, x4); // Load 4 samples 952 - PUT_SAMPLE_SIMD_B(dste, x1, x2, x3, x4); // Store 16 samples 953 - srce+=16; 954 - dste+=16; 948 + simd_m128i x1,x2,x3,x4; 949 + EXTRACT_SAMPLE_SIMD_8(srce, x1); /* Load 4 samples */ 950 + EXTRACT_SAMPLE_SIMD_8(srce+4, x2); /* Load 4 samples */ 951 + EXTRACT_SAMPLE_SIMD_8(srce+8, x3); /* Load 4 samples */ 952 + EXTRACT_SAMPLE_SIMD_8(srce+12, x4); /* Load 4 samples */ 953 + PUT_SAMPLE_SIMD_B(dste, x1, x2, x3, x4); /* Store 16 samples */ 954 + srce+=16; 955 + dste+=16; 955 956 } 957 + 956 958 if (remain) 957 - Mix32To8(dste, srce, remain); 959 + Mix32To8(dste, srce, remain); 958 960 } 959 961 960 962 #endif 961 - 962 963 963 964 964 965 static void AddChannel(SLONG* ptr,NATIVE todo) ··· 1050 1051 if(vc_mode & DMODE_STEREO) { 1051 1052 if((vnf->pan==PAN_SURROUND)&&(md_mode&DMODE_SURROUND)) 1052 1053 vnf->current=Mix32SurroundInterp 1053 - (s,ptr,vnf->current,vnf->increment,done); 1054 + (s,ptr,vnf->current,vnf->increment,done); 1054 1055 else 1055 1056 vnf->current=Mix32StereoInterp 1056 - (s,ptr,vnf->current,vnf->increment,done); 1057 + (s,ptr,vnf->current,vnf->increment,done); 1057 1058 } else 1058 1059 vnf->current=Mix32MonoInterp 1059 - (s,ptr,vnf->current,vnf->increment,done); 1060 + (s,ptr,vnf->current,vnf->increment,done); 1060 1061 } else if(vc_mode & DMODE_STEREO) { 1061 1062 if((vnf->pan==PAN_SURROUND)&&(md_mode&DMODE_SURROUND)) 1062 1063 vnf->current=Mix32SurroundNormal 1063 - (s,ptr,vnf->current,vnf->increment,done); 1064 + (s,ptr,vnf->current,vnf->increment,done); 1064 1065 else 1065 1066 { 1066 1067 #if defined HAVE_ALTIVEC || defined HAVE_SSE2 1067 - if (md_mode & DMODE_SIMDMIXER) 1068 + if (md_mode & DMODE_SIMDMIXER) 1068 1069 vnf->current=MixSIMDStereoNormal 1069 - (s,ptr,vnf->current,vnf->increment,done); 1070 - 1071 - else 1070 + (s,ptr,vnf->current,vnf->increment,done); 1071 + else 1072 1072 #endif 1073 1073 vnf->current=Mix32StereoNormal 1074 - (s,ptr,vnf->current,vnf->increment,done); 1074 + (s,ptr,vnf->current,vnf->increment,done); 1075 1075 } 1076 1076 } else 1077 1077 vnf->current=Mix32MonoNormal 1078 - (s,ptr,vnf->current,vnf->increment,done); 1079 - } else 1078 + (s,ptr,vnf->current,vnf->increment,done); 1079 + } 1080 + else 1080 1081 #endif 1081 - { 1082 + { 1082 1083 if((md_mode & DMODE_INTERP)) { 1083 1084 if(vc_mode & DMODE_STEREO) { 1084 1085 if((vnf->pan==PAN_SURROUND)&&(md_mode&DMODE_SURROUND)) 1085 1086 vnf->current=MixSurroundInterp 1086 - (s,ptr,vnf->current,vnf->increment,done); 1087 + (s,ptr,vnf->current,vnf->increment,done); 1087 1088 else 1088 1089 vnf->current=MixStereoInterp 1089 - (s,ptr,vnf->current,vnf->increment,done); 1090 + (s,ptr,vnf->current,vnf->increment,done); 1090 1091 } else 1091 1092 vnf->current=MixMonoInterp 1092 - (s,ptr,vnf->current,vnf->increment,done); 1093 + (s,ptr,vnf->current,vnf->increment,done); 1093 1094 } else if(vc_mode & DMODE_STEREO) { 1094 1095 if((vnf->pan==PAN_SURROUND)&&(md_mode&DMODE_SURROUND)) 1095 1096 vnf->current=MixSurroundNormal 1096 - (s,ptr,vnf->current,vnf->increment,done); 1097 + (s,ptr,vnf->current,vnf->increment,done); 1097 1098 else 1098 1099 { 1099 1100 #if defined HAVE_ALTIVEC || defined HAVE_SSE2 1100 - if (md_mode & DMODE_SIMDMIXER) 1101 + if (md_mode & DMODE_SIMDMIXER) 1101 1102 vnf->current=MixSIMDStereoNormal 1102 - (s,ptr,vnf->current,vnf->increment,done); 1103 - 1104 - else 1103 + (s,ptr,vnf->current,vnf->increment,done); 1104 + else 1105 1105 #endif 1106 1106 vnf->current=MixStereoNormal 1107 - (s,ptr,vnf->current,vnf->increment,done); 1107 + (s,ptr,vnf->current,vnf->increment,done); 1108 1108 } 1109 1109 } else 1110 1110 vnf->current=MixMonoNormal 1111 - (s,ptr,vnf->current,vnf->increment,done); 1111 + (s,ptr,vnf->current,vnf->increment,done); 1112 1112 } 1113 1113 } else 1114 1114 /* update sample position */ ··· 1119 1119 } 1120 1120 } 1121 1121 1122 + #ifdef NO_HQMIXER 1123 + #define VC_SetupPointers() do{}while(0) 1124 + #define VC1_Init VC_Init 1125 + #define VC1_Exit VC_Exit 1126 + #define VC1_PlayStart VC_PlayStart 1127 + #define VC1_PlayStop VC_PlayStop 1128 + #define VC1_SampleLength VC_SampleLength 1129 + #define VC1_SampleSpace VC_SampleSpace 1130 + #define VC1_SampleLoad VC_SampleLoad 1131 + #define VC1_SampleUnload VC_SampleUnload 1132 + #define VC1_SetNumVoices VC_SetNumVoices 1133 + #define VC1_SilenceBytes VC_SilenceBytes 1134 + #define VC1_VoicePlay VC_VoicePlay 1135 + #define VC1_VoiceStop VC_VoiceStop 1136 + #define VC1_VoiceGetFrequency VC_VoiceGetFrequency 1137 + #define VC1_VoiceGetPanning VC_VoiceGetPanning 1138 + #define VC1_VoiceGetPosition VC_VoiceGetPosition 1139 + #define VC1_VoiceGetVolume VC_VoiceGetVolume 1140 + #define VC1_VoiceRealVolume VC_VoiceRealVolume 1141 + #define VC1_VoiceSetFrequency VC_VoiceSetFrequency 1142 + #define VC1_VoiceSetPanning VC_VoiceSetPanning 1143 + #define VC1_VoiceSetVolume VC_VoiceSetVolume 1144 + #define VC1_VoiceStopped VC_VoiceStopped 1145 + #define VC1_WriteBytes VC_WriteBytes 1146 + #define VC1_WriteSamples VC_WriteSamples 1147 + #endif 1148 + 1122 1149 #define _IN_VIRTCH_ 1123 1150 #include "virtch_common.c" 1124 1151 #undef _IN_VIRTCH_ ··· 1190 1217 vc_callback((unsigned char*)vc_tickbuf, portion); 1191 1218 } 1192 1219 1193 - 1194 1220 #if defined HAVE_ALTIVEC || defined HAVE_SSE2 1195 1221 if (md_mode & DMODE_SIMDMIXER) 1196 1222 { ··· 1219 1245 1220 1246 int VC1_Init(void) 1221 1247 { 1248 + #ifndef NO_HQMIXER 1222 1249 VC_SetupPointers(); 1223 - 1224 - //if (md_mode&DMODE_HQMIXER) 1225 - // return VC2_Init(); 1226 1250 1227 - if(!(Samples=(SWORD**)MikMod_calloc(MAXSAMPLEHANDLES,sizeof(SWORD*)))) { 1251 + if (md_mode&DMODE_HQMIXER) 1252 + return VC2_Init(); 1253 + #endif 1254 + 1255 + if(!(Samples=(SWORD**)MikMod_amalloc(MAXSAMPLEHANDLES*sizeof(SWORD*)))) { 1228 1256 _mm_errno = MMERR_INITIALIZING_MIXER; 1229 1257 return 1; 1230 1258 } 1231 - if(!vc_tickbuf) 1232 - if(!(vc_tickbuf=(SLONG*)MikMod_malloc((TICKLSIZE+32)*sizeof(SLONG)))) { 1259 + if(!vc_tickbuf) { 1260 + if(!(vc_tickbuf=(SLONG*)MikMod_amalloc((TICKLSIZE+32)*sizeof(SLONG)))) { 1233 1261 _mm_errno = MMERR_INITIALIZING_MIXER; 1234 1262 return 1; 1235 1263 } 1264 + } 1236 1265 1237 1266 MixReverb=(md_mode&DMODE_STEREO)?MixReverb_Stereo:MixReverb_Normal; 1238 1267 MixLowPass=(md_mode&DMODE_STEREO)?MixLowPass_Stereo:MixLowPass_Normal; ··· 1264 1293 if(!(RVbufL7=(SLONG*)MikMod_calloc((RVc7+1),sizeof(SLONG)))) return 1; 1265 1294 if(!(RVbufL8=(SLONG*)MikMod_calloc((RVc8+1),sizeof(SLONG)))) return 1; 1266 1295 1267 - if(!(RVbufR1=(SLONG*)MikMod_calloc((RVc1+1),sizeof(SLONG)))) return 1; 1268 - if(!(RVbufR2=(SLONG*)MikMod_calloc((RVc2+1),sizeof(SLONG)))) return 1; 1269 - if(!(RVbufR3=(SLONG*)MikMod_calloc((RVc3+1),sizeof(SLONG)))) return 1; 1270 - if(!(RVbufR4=(SLONG*)MikMod_calloc((RVc4+1),sizeof(SLONG)))) return 1; 1271 - if(!(RVbufR5=(SLONG*)MikMod_calloc((RVc5+1),sizeof(SLONG)))) return 1; 1272 - if(!(RVbufR6=(SLONG*)MikMod_calloc((RVc6+1),sizeof(SLONG)))) return 1; 1273 - if(!(RVbufR7=(SLONG*)MikMod_calloc((RVc7+1),sizeof(SLONG)))) return 1; 1274 - if(!(RVbufR8=(SLONG*)MikMod_calloc((RVc8+1),sizeof(SLONG)))) return 1; 1296 + /* allocate reverb buffers for the right channel if in stereo mode only. */ 1297 + if (vc_mode & DMODE_STEREO) { 1298 + if(!(RVbufR1=(SLONG*)MikMod_calloc((RVc1+1),sizeof(SLONG)))) return 1; 1299 + if(!(RVbufR2=(SLONG*)MikMod_calloc((RVc2+1),sizeof(SLONG)))) return 1; 1300 + if(!(RVbufR3=(SLONG*)MikMod_calloc((RVc3+1),sizeof(SLONG)))) return 1; 1301 + if(!(RVbufR4=(SLONG*)MikMod_calloc((RVc4+1),sizeof(SLONG)))) return 1; 1302 + if(!(RVbufR5=(SLONG*)MikMod_calloc((RVc5+1),sizeof(SLONG)))) return 1; 1303 + if(!(RVbufR6=(SLONG*)MikMod_calloc((RVc6+1),sizeof(SLONG)))) return 1; 1304 + if(!(RVbufR7=(SLONG*)MikMod_calloc((RVc7+1),sizeof(SLONG)))) return 1; 1305 + if(!(RVbufR8=(SLONG*)MikMod_calloc((RVc8+1),sizeof(SLONG)))) return 1; 1306 + } 1275 1307 1276 1308 RVRindex = 0; 1277 1309 return 0; ··· 1279 1311 1280 1312 void VC1_PlayStop(void) 1281 1313 { 1282 - if(RVbufL1) MikMod_free(RVbufL1); 1283 - if(RVbufL2) MikMod_free(RVbufL2); 1284 - if(RVbufL3) MikMod_free(RVbufL3); 1285 - if(RVbufL4) MikMod_free(RVbufL4); 1286 - if(RVbufL5) MikMod_free(RVbufL5); 1287 - if(RVbufL6) MikMod_free(RVbufL6); 1288 - if(RVbufL7) MikMod_free(RVbufL7); 1289 - if(RVbufL8) MikMod_free(RVbufL8); 1314 + MikMod_free(RVbufL1); 1315 + MikMod_free(RVbufL2); 1316 + MikMod_free(RVbufL3); 1317 + MikMod_free(RVbufL4); 1318 + MikMod_free(RVbufL5); 1319 + MikMod_free(RVbufL6); 1320 + MikMod_free(RVbufL7); 1321 + MikMod_free(RVbufL8); 1290 1322 RVbufL1=RVbufL2=RVbufL3=RVbufL4=RVbufL5=RVbufL6=RVbufL7=RVbufL8=NULL; 1291 - if(RVbufR1) MikMod_free(RVbufR1); 1292 - if(RVbufR2) MikMod_free(RVbufR2); 1293 - if(RVbufR3) MikMod_free(RVbufR3); 1294 - if(RVbufR4) MikMod_free(RVbufR4); 1295 - if(RVbufR5) MikMod_free(RVbufR5); 1296 - if(RVbufR6) MikMod_free(RVbufR6); 1297 - if(RVbufR7) MikMod_free(RVbufR7); 1298 - if(RVbufR8) MikMod_free(RVbufR8); 1323 + MikMod_free(RVbufR1); 1324 + MikMod_free(RVbufR2); 1325 + MikMod_free(RVbufR3); 1326 + MikMod_free(RVbufR4); 1327 + MikMod_free(RVbufR5); 1328 + MikMod_free(RVbufR6); 1329 + MikMod_free(RVbufR7); 1330 + MikMod_free(RVbufR8); 1299 1331 RVbufR1=RVbufR2=RVbufR3=RVbufR4=RVbufR5=RVbufR6=RVbufR7=RVbufR8=NULL; 1300 1332 } 1301 1333 ··· 1305 1337 1306 1338 if(!(vc_softchn=md_softchn)) return 0; 1307 1339 1308 - if(vinf) MikMod_free(vinf); 1309 - if(!(vinf= MikMod_calloc(sizeof(VINFO),vc_softchn))) return 1; 1340 + MikMod_free(vinf); 1341 + if(!(vinf=(VINFO*)MikMod_calloc(vc_softchn,sizeof(VINFO)))) return 1; 1310 1342 1311 1343 for(t=0;t<vc_softchn;t++) { 1312 1344 vinf[t].frq=10000;
+1370
apps/plugins/mikmod/virtch2.c
··· 1 + /* MikMod sound library 2 + (c) 1998, 1999, 2000 Miodrag Vallat and others - see file AUTHORS for 3 + complete list. 4 + 5 + This library is free software; you can redistribute it and/or modify 6 + it under the terms of the GNU Library General Public License as 7 + published by the Free Software Foundation; either version 2 of 8 + the License, or (at your option) any later version. 9 + 10 + This program is distributed in the hope that it will be useful, 11 + but WITHOUT ANY WARRANTY; without even the implied warranty of 12 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 + GNU Library General Public License for more details. 14 + 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 17 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 18 + 02111-1307, USA. 19 + */ 20 + 21 + /*============================================================================== 22 + 23 + $Id$ 24 + 25 + High-quality sample mixing routines, using a 32 bits mixing buffer, 26 + interpolation, and sample smoothing to improve sound quality and remove 27 + clicks. 28 + 29 + ==============================================================================*/ 30 + 31 + /* 32 + 33 + Future Additions: 34 + Low-Pass filter to remove annoying staticy buzz. 35 + 36 + */ 37 + 38 + #ifdef HAVE_CONFIG_H 39 + #include "config.h" 40 + #endif 41 + 42 + #include "mikmod.h" 43 + 44 + #ifndef NO_HQMIXER 45 + 46 + #ifdef HAVE_MEMORY_H 47 + #include <memory.h> 48 + #endif 49 + #include <string.h> 50 + 51 + #include "mikmod_internals.h" 52 + 53 + /* 54 + Constant Definitions 55 + ==================== 56 + 57 + MAXVOL_FACTOR (was BITSHIFT in virtch.c) 58 + Controls the maximum volume of the output data. All mixed data is 59 + divided by this number after mixing, so larger numbers result in 60 + quieter mixing. Smaller numbers will increase the likeliness of 61 + distortion on loud modules. 62 + 63 + REVERBERATION 64 + Larger numbers result in shorter reverb duration. Longer reverb 65 + durations can cause unwanted static and make the reverb sound more 66 + like a crappy echo. 67 + 68 + SAMPLING_SHIFT 69 + Specified the shift multiplier which controls by how much the mixing 70 + rate is multiplied while mixing. Higher values can improve quality by 71 + smoothing the sound and reducing pops and clicks. Note, this is a shift 72 + value, so a value of 2 becomes a mixing-rate multiplier of 4, and a 73 + value of 3 = 8, etc. 74 + 75 + FRACBITS 76 + The number of bits per integer devoted to the fractional part of the 77 + number. Generally, this number should not be changed for any reason. 78 + 79 + !!! IMPORTANT !!! All values below MUST ALWAYS be greater than 0 80 + 81 + */ 82 + 83 + #define BITSHIFT 9 84 + #define MAXVOL_FACTOR (1<<BITSHIFT) 85 + #define REVERBERATION 11000L 86 + 87 + #define SAMPLING_SHIFT 2 88 + #define SAMPLING_FACTOR (1UL<<SAMPLING_SHIFT) 89 + 90 + #define FRACBITS 28 91 + #define FRACMASK ((1UL<<FRACBITS)-1UL) 92 + 93 + #define TICKLSIZE 8192 94 + #define TICKWSIZE (TICKLSIZE * 2) 95 + #define TICKBSIZE (TICKWSIZE * 2) 96 + 97 + #define CLICK_SHIFT_BASE 6 98 + #define CLICK_SHIFT (CLICK_SHIFT_BASE + SAMPLING_SHIFT) 99 + #define CLICK_BUFFER (1L << CLICK_SHIFT) 100 + 101 + #ifndef MIN 102 + #define MIN(a,b) (((a)<(b)) ? (a) : (b)) 103 + #endif 104 + 105 + typedef struct VINFO { 106 + UBYTE kick; /* =1 -> sample has to be restarted */ 107 + UBYTE active; /* =1 -> sample is playing */ 108 + UWORD flags; /* 16/8 bits looping/one-shot */ 109 + SWORD handle; /* identifies the sample */ 110 + ULONG start; /* start index */ 111 + ULONG size; /* samplesize */ 112 + ULONG reppos; /* loop start */ 113 + ULONG repend; /* loop end */ 114 + ULONG frq; /* current frequency */ 115 + int vol; /* current volume */ 116 + int pan; /* current panning position */ 117 + 118 + int click; 119 + int rampvol; 120 + SLONG lastvalL,lastvalR; 121 + int lvolsel,rvolsel; /* Volume factor in range 0-255 */ 122 + int oldlvol,oldrvol; 123 + 124 + SLONGLONG current; /* current index in the sample */ 125 + SLONGLONG increment; /* increment value */ 126 + } VINFO; 127 + 128 + static SWORD **Samples; 129 + static VINFO *vinf=NULL,*vnf; 130 + static long tickleft,samplesthatfit,vc_memory=0; 131 + static int vc_softchn; 132 + static SLONGLONG idxsize,idxlpos,idxlend; 133 + static SLONG *vc_tickbuf=NULL; 134 + static UWORD vc_mode; 135 + 136 + #ifdef _MSC_VER 137 + /* Weird bug in compiler */ /* FIXME is this still needed? */ 138 + typedef void (*MikMod_callback_t)(unsigned char *data, size_t len); 139 + #endif 140 + 141 + /* Reverb control variables */ 142 + 143 + static int RVc1, RVc2, RVc3, RVc4, RVc5, RVc6, RVc7, RVc8; 144 + static ULONG RVRindex; 145 + 146 + /* For Mono or Left Channel */ 147 + static SLONG *RVbufL1=NULL,*RVbufL2=NULL,*RVbufL3=NULL,*RVbufL4=NULL, 148 + *RVbufL5=NULL,*RVbufL6=NULL,*RVbufL7=NULL,*RVbufL8=NULL; 149 + 150 + /* For Stereo only (Right Channel) */ 151 + static SLONG *RVbufR1=NULL,*RVbufR2=NULL,*RVbufR3=NULL,*RVbufR4=NULL, 152 + *RVbufR5=NULL,*RVbufR6=NULL,*RVbufR7=NULL,*RVbufR8=NULL; 153 + 154 + #ifdef NATIVE_64BIT_INT 155 + #define NATIVE SLONGLONG 156 + #else 157 + #define NATIVE SLONG 158 + #endif 159 + 160 + /*========== 32 bit sample mixers - only for 32 bit platforms */ 161 + #ifndef NATIVE_64BIT_INT 162 + 163 + static SLONG Mix32MonoNormal(const SWORD* const srce,SLONG* dest,SLONG idx,SLONG increment,SLONG todo) 164 + { 165 + SWORD sample=0; 166 + SLONG i,f; 167 + 168 + while(todo--) { 169 + i=idx>>FRACBITS,f=idx&FRACMASK; 170 + sample=(SWORD)( (((SLONG)(srce[i]*(FRACMASK+1L-f)) + 171 + ((SLONG)srce[i+1]*f)) >> FRACBITS)); 172 + idx+=increment; 173 + 174 + if(vnf->rampvol) { 175 + *dest++ += (long)( 176 + ( ( (SLONG)(vnf->oldlvol*vnf->rampvol) + 177 + (vnf->lvolsel*(CLICK_BUFFER-vnf->rampvol)) ) * 178 + (SLONG)sample ) >> CLICK_SHIFT ); 179 + vnf->rampvol--; 180 + } else 181 + if(vnf->click) { 182 + *dest++ += (long)( 183 + ( ( ((SLONG)vnf->lvolsel*(CLICK_BUFFER-vnf->click)) * 184 + (SLONG)sample ) + 185 + (vnf->lastvalL*vnf->click) ) >> CLICK_SHIFT ); 186 + vnf->click--; 187 + } else 188 + *dest++ +=vnf->lvolsel*sample; 189 + } 190 + vnf->lastvalL=vnf->lvolsel * sample; 191 + 192 + return idx; 193 + } 194 + 195 + static SLONG Mix32StereoNormal(const SWORD* const srce,SLONG* dest,SLONG idx,SLONG increment,ULONG todo) 196 + { 197 + SWORD sample=0; 198 + SLONG i,f; 199 + 200 + while(todo--) { 201 + i=idx>>FRACBITS,f=idx&FRACMASK; 202 + sample=(SWORD)(((((SLONG)srce[i]*(FRACMASK+1L-f)) + 203 + ((SLONG)srce[i+1] * f)) >> FRACBITS)); 204 + idx += increment; 205 + 206 + if(vnf->rampvol) { 207 + *dest++ += (long)( 208 + ( ( ((SLONG)vnf->oldlvol*vnf->rampvol) + 209 + (vnf->lvolsel*(CLICK_BUFFER-vnf->rampvol)) 210 + ) * (SLONG)sample ) >> CLICK_SHIFT ); 211 + *dest++ += (long)( 212 + ( ( ((SLONG)vnf->oldrvol*vnf->rampvol) + 213 + (vnf->rvolsel*(CLICK_BUFFER-vnf->rampvol)) 214 + ) * (SLONG)sample ) >> CLICK_SHIFT ); 215 + vnf->rampvol--; 216 + } else 217 + if(vnf->click) { 218 + *dest++ += (long)( 219 + ( ( (SLONG)(vnf->lvolsel*(CLICK_BUFFER-vnf->click)) * 220 + (SLONG)sample ) + (vnf->lastvalL * vnf->click) ) 221 + >> CLICK_SHIFT ); 222 + *dest++ += (long)( 223 + ( ( ((SLONG)vnf->rvolsel*(CLICK_BUFFER-vnf->click)) * 224 + (SLONG)sample ) + (vnf->lastvalR * vnf->click) ) 225 + >> CLICK_SHIFT ); 226 + vnf->click--; 227 + } else { 228 + *dest++ +=vnf->lvolsel*sample; 229 + *dest++ +=vnf->rvolsel*sample; 230 + } 231 + } 232 + vnf->lastvalL=vnf->lvolsel*sample; 233 + vnf->lastvalR=vnf->rvolsel*sample; 234 + 235 + return idx; 236 + } 237 + 238 + static SLONG Mix32StereoSurround(const SWORD* const srce,SLONG* dest,SLONG idx,SLONG increment,ULONG todo) 239 + { 240 + SWORD sample=0; 241 + long whoop; 242 + SLONG i, f; 243 + 244 + while(todo--) { 245 + i=idx>>FRACBITS,f=idx&FRACMASK; 246 + sample=(SWORD)(((((SLONG)srce[i]*(FRACMASK+1L-f)) + 247 + ((SLONG)srce[i+1]*f)) >> FRACBITS)); 248 + idx+=increment; 249 + 250 + if(vnf->rampvol) { 251 + whoop=(long)( 252 + ( ( (SLONG)(vnf->oldlvol*vnf->rampvol) + 253 + (vnf->lvolsel*(CLICK_BUFFER-vnf->rampvol)) ) * 254 + (SLONG)sample) >> CLICK_SHIFT ); 255 + *dest++ +=whoop; 256 + *dest++ -=whoop; 257 + vnf->rampvol--; 258 + } else 259 + if(vnf->click) { 260 + whoop = (long)( 261 + ( ( ((SLONG)vnf->lvolsel*(CLICK_BUFFER-vnf->click)) * 262 + (SLONG)sample) + 263 + (vnf->lastvalL * vnf->click) ) >> CLICK_SHIFT ); 264 + *dest++ +=whoop; 265 + *dest++ -=whoop; 266 + vnf->click--; 267 + } else { 268 + *dest++ +=vnf->lvolsel*sample; 269 + *dest++ -=vnf->lvolsel*sample; 270 + } 271 + } 272 + vnf->lastvalL=vnf->lvolsel*sample; 273 + vnf->lastvalR=vnf->lvolsel*sample; 274 + 275 + return idx; 276 + } 277 + #endif 278 + 279 + /*========== 64 bit mixers */ 280 + 281 + static SLONGLONG MixMonoNormal(const SWORD* const srce,SLONG* dest,SLONGLONG idx,SLONGLONG increment,SLONG todo) 282 + { 283 + SWORD sample=0; 284 + SLONGLONG i,f; 285 + 286 + while(todo--) { 287 + i=idx>>FRACBITS,f=idx&FRACMASK; 288 + sample=(SWORD)((((SLONGLONG)(srce[i]*(FRACMASK+1L-f)) + 289 + ((SLONGLONG)srce[i+1]*f)) >> FRACBITS)); 290 + idx+=increment; 291 + 292 + if(vnf->rampvol) { 293 + *dest++ += (long)( 294 + ( ( (SLONGLONG)(vnf->oldlvol*vnf->rampvol) + 295 + (vnf->lvolsel*(CLICK_BUFFER-vnf->rampvol)) ) * 296 + (SLONGLONG)sample ) >> CLICK_SHIFT ); 297 + vnf->rampvol--; 298 + } else 299 + if(vnf->click) { 300 + *dest++ += (long)( 301 + ( ( ((SLONGLONG)vnf->lvolsel*(CLICK_BUFFER-vnf->click)) * 302 + (SLONGLONG)sample ) + 303 + (vnf->lastvalL*vnf->click) ) >> CLICK_SHIFT ); 304 + vnf->click--; 305 + } else 306 + *dest++ +=vnf->lvolsel*sample; 307 + } 308 + vnf->lastvalL=vnf->lvolsel * sample; 309 + 310 + return idx; 311 + } 312 + 313 + /* Slowest part... */ 314 + 315 + #if defined HAVE_SSE2 || defined HAVE_ALTIVEC 316 + 317 + static __inline SWORD GetSample(const SWORD* const srce, SLONGLONG idx) 318 + { 319 + SLONGLONG i=idx>>FRACBITS; 320 + SLONGLONG f=idx&FRACMASK; 321 + return (SWORD)(((((SLONGLONG)srce[i]*(FRACMASK+1L-f)) + 322 + ((SLONGLONG)srce[i+1] * f)) >> FRACBITS)); 323 + } 324 + 325 + static SLONGLONG MixSIMDStereoNormal(const SWORD* const srce,SLONG* dest,SLONGLONG idx,SLONGLONG increment,ULONG todo) 326 + { 327 + SWORD vol[8] = {vnf->lvolsel, vnf->rvolsel}; 328 + SWORD sample=0; 329 + SLONG remain = todo; 330 + 331 + /* Dest can be misaligned */ 332 + while(!IS_ALIGNED_16(dest)) { 333 + sample=srce[idx >> FRACBITS]; 334 + idx += increment; 335 + *dest++ += vol[0] * sample; 336 + *dest++ += vol[1] * sample; 337 + todo--; 338 + if(!todo) goto end; 339 + } 340 + 341 + /* Srce is always aligned */ 342 + 343 + #if defined HAVE_SSE2 344 + remain = todo&3; 345 + { 346 + __m128i v0 = _mm_set_epi16(0, vol[1], 347 + 0, vol[0], 348 + 0, vol[1], 349 + 0, vol[0]); 350 + for(todo>>=2;todo; todo--) 351 + { 352 + SWORD s0 = GetSample(srce, idx); 353 + SWORD s1 = GetSample(srce, idx += increment); 354 + SWORD s2 = GetSample(srce, idx += increment); 355 + SWORD s3 = GetSample(srce, idx += increment); 356 + __m128i v1 = _mm_set_epi16(0, s1, 0, s1, 0, s0, 0, s0); 357 + __m128i v2 = _mm_set_epi16(0, s3, 0, s3, 0, s2, 0, s2); 358 + __m128i v3 = _mm_load_si128((__m128i*)(dest+0)); 359 + __m128i v4 = _mm_load_si128((__m128i*)(dest+4)); 360 + _mm_store_si128((__m128i*)(dest+0), _mm_add_epi32(v3, _mm_madd_epi16(v0, v1))); 361 + _mm_store_si128((__m128i*)(dest+4), _mm_add_epi32(v4, _mm_madd_epi16(v0, v2))); 362 + dest+=8; 363 + idx += increment; 364 + } 365 + } 366 + 367 + #elif defined HAVE_ALTIVEC 368 + remain = todo&3; 369 + { 370 + SWORD s[8]; 371 + vector signed short r0 = vec_ld(0, vol); 372 + vector signed short v0 = vec_perm(r0, r0, (vector unsigned char)(0, 1, /* l */ 373 + 0, 1, /* l */ 374 + 2, 3, /* r */ 375 + 2, 1, /* r */ 376 + 0, 1, /* l */ 377 + 0, 1, /* l */ 378 + 2, 3, /* r */ 379 + 2, 3 /* r */ 380 + )); 381 + 382 + for(todo>>=2;todo; todo--) 383 + { 384 + vector short int r1; 385 + vector signed short v1, v2; 386 + vector signed int v3, v4, v5, v6; 387 + 388 + /* Load constants */ 389 + s[0] = GetSample(srce, idx); 390 + s[1] = GetSample(srce, idx += increment); 391 + s[2] = GetSample(srce, idx += increment); 392 + s[3] = GetSample(srce, idx += increment); 393 + s[4] = 0; 394 + 395 + r1 = vec_ld(0, s); 396 + v1 = vec_perm(r1, r1, (vector unsigned char) 397 + (0*2, 0*2+1, /* s0 */ 398 + 4*2, 4*2+1, /* 0 */ 399 + 0*2, 0*2+1, /* s0 */ 400 + 4*2, 4*2+1, /* 0 */ 401 + 1*2, 1*2+1, /* s1 */ 402 + 4*2, 4*2+1, /* 0 */ 403 + 1*2, 1*2+1, /* s1 */ 404 + 4*2, 4*2+1 /* 0 */ 405 + ) ); 406 + v2 = vec_perm(r1, r1, (vector unsigned char) 407 + (2*2, 2*2+1, /* s2 */ 408 + 4*2, 4*2+1, /* 0 */ 409 + 2*2, 2*2+1, /* s2 */ 410 + 4*2, 4*2+1, /* 0 */ 411 + 3*2, 3*2+1, /* s3 */ 412 + 4*2, 4*2+1, /* 0 */ 413 + 3*2, 3*2+1, /* s3 */ 414 + 4*2, 4*2+1 /* 0 */ 415 + ) ); 416 + 417 + v3 = vec_ld(0, dest); 418 + v4 = vec_ld(0x10, dest); 419 + v5 = vec_mule(v0, v1); 420 + v6 = vec_mule(v0, v2); 421 + 422 + vec_st(vec_add(v3, v5), 0, dest); 423 + vec_st(vec_add(v4, v6), 0x10, dest); 424 + 425 + dest+=8; 426 + idx += increment; 427 + } 428 + } 429 + #endif /* HAVE_ALTIVEC */ 430 + 431 + /* Remaining bits */ 432 + while(remain--) { 433 + sample=GetSample(srce, idx); 434 + idx+= increment; 435 + *dest++ += vol[0] * sample; 436 + *dest++ += vol[1] * sample; 437 + } 438 + end: 439 + vnf->lastvalL=vnf->lvolsel*sample; 440 + vnf->lastvalR=vnf->rvolsel*sample; 441 + return idx; 442 + } 443 + 444 + static SLONGLONG MixStereoNormal(const SWORD* const srce,SLONG* dest,SLONGLONG idx,SLONGLONG increment,ULONG todo) 445 + { 446 + SWORD sample=0; 447 + SLONGLONG i,f; 448 + 449 + if (vnf->rampvol) 450 + while(todo) { 451 + todo--; 452 + i=idx>>FRACBITS,f=idx&FRACMASK; 453 + sample=(SWORD)(((((SLONGLONG)srce[i]*(FRACMASK+1L-f)) + 454 + ((SLONGLONG)srce[i+1] * f)) >> FRACBITS)); 455 + idx += increment; 456 + 457 + *dest++ += (long)( 458 + ( ( ((SLONGLONG)vnf->oldlvol*vnf->rampvol) + 459 + (vnf->lvolsel*(CLICK_BUFFER-vnf->rampvol)) 460 + ) * (SLONGLONG)sample ) >> CLICK_SHIFT ); 461 + *dest++ += (long)( 462 + ( ( ((SLONGLONG)vnf->oldrvol*vnf->rampvol) + 463 + (vnf->rvolsel*(CLICK_BUFFER-vnf->rampvol)) 464 + ) * (SLONGLONG)sample ) >> CLICK_SHIFT ); 465 + vnf->rampvol--; 466 + 467 + if (!vnf->rampvol) 468 + break; 469 + } 470 + 471 + if (vnf->click) 472 + while(todo) { 473 + todo--; 474 + i=idx>>FRACBITS,f=idx&FRACMASK; 475 + sample=(SWORD)(((((SLONGLONG)srce[i]*(FRACMASK+1L-f)) + 476 + ((SLONGLONG)srce[i+1] * f)) >> FRACBITS)); 477 + idx += increment; 478 + 479 + *dest++ += (long)( 480 + ( ( (SLONGLONG)(vnf->lvolsel*(CLICK_BUFFER-vnf->click)) * 481 + (SLONGLONG)sample ) + (vnf->lastvalL * vnf->click) ) 482 + >> CLICK_SHIFT ); 483 + 484 + *dest++ += (long)( 485 + ( ( ((SLONGLONG)vnf->rvolsel*(CLICK_BUFFER-vnf->click)) * 486 + (SLONGLONG)sample ) + (vnf->lastvalR * vnf->click) ) 487 + >> CLICK_SHIFT ); 488 + vnf->click--; 489 + 490 + if (!vnf->click) 491 + break; 492 + } 493 + 494 + if (todo) 495 + { 496 + if (md_mode & DMODE_SIMDMIXER) { 497 + return MixSIMDStereoNormal(srce, dest, idx, increment, todo); 498 + } 499 + while(todo) 500 + { 501 + i=idx>>FRACBITS, 502 + f=idx&FRACMASK; 503 + sample=(SWORD)(((((SLONGLONG)srce[i]*(FRACMASK+1L-f)) + 504 + ((SLONGLONG)srce[i+1] * f)) >> FRACBITS)); 505 + idx += increment; 506 + 507 + *dest++ +=vnf->lvolsel*sample; 508 + *dest++ +=vnf->rvolsel*sample; 509 + todo--; 510 + } 511 + } 512 + vnf->lastvalL=vnf->lvolsel*sample; 513 + vnf->lastvalR=vnf->rvolsel*sample; 514 + 515 + return idx; 516 + } 517 + 518 + #else /* HAVE_SSE2 || HAVE_ALTIVEC */ 519 + static SLONGLONG MixStereoNormal(const SWORD* const srce,SLONG* dest,SLONGLONG idx,SLONGLONG increment,ULONG todo) 520 + { 521 + SWORD sample=0; 522 + SLONGLONG i,f; 523 + 524 + while(todo--) { 525 + i=idx>>FRACBITS,f=idx&FRACMASK; 526 + sample=(SWORD)(((((SLONGLONG)srce[i]*(FRACMASK+1L-f)) + 527 + ((SLONGLONG)srce[i+1] * f)) >> FRACBITS)); 528 + idx += increment; 529 + 530 + if(vnf->rampvol) { 531 + *dest++ += (long)( 532 + ( ( ((SLONGLONG)vnf->oldlvol*vnf->rampvol) + 533 + (vnf->lvolsel*(CLICK_BUFFER-vnf->rampvol)) 534 + ) * (SLONGLONG)sample ) >> CLICK_SHIFT ); 535 + *dest++ += (long)( 536 + ( ( ((SLONGLONG)vnf->oldrvol*vnf->rampvol) + 537 + (vnf->rvolsel*(CLICK_BUFFER-vnf->rampvol)) 538 + ) * (SLONGLONG)sample ) >> CLICK_SHIFT ); 539 + vnf->rampvol--; 540 + } else 541 + if(vnf->click) { 542 + *dest++ += (long)( 543 + ( ( (SLONGLONG)(vnf->lvolsel*(CLICK_BUFFER-vnf->click)) * 544 + (SLONGLONG)sample ) + (vnf->lastvalL * vnf->click) ) 545 + >> CLICK_SHIFT ); 546 + *dest++ += (long)( 547 + ( ( ((SLONGLONG)vnf->rvolsel*(CLICK_BUFFER-vnf->click)) * 548 + (SLONGLONG)sample ) + (vnf->lastvalR * vnf->click) ) 549 + >> CLICK_SHIFT ); 550 + vnf->click--; 551 + } else { 552 + *dest++ +=vnf->lvolsel*sample; 553 + *dest++ +=vnf->rvolsel*sample; 554 + } 555 + } 556 + vnf->lastvalL=vnf->lvolsel*sample; 557 + vnf->lastvalR=vnf->rvolsel*sample; 558 + 559 + return idx; 560 + } 561 + #endif /* HAVE_SSE2 || HAVE_ALTIVEC */ 562 + 563 + 564 + static SLONGLONG MixStereoSurround(const SWORD* srce,SLONG* dest,SLONGLONG idx,SLONGLONG increment,ULONG todo) 565 + { 566 + SWORD sample=0; 567 + long whoop; 568 + SLONGLONG i, f; 569 + 570 + while(todo--) { 571 + i=idx>>FRACBITS,f=idx&FRACMASK; 572 + sample=(SWORD)(((((SLONGLONG)srce[i]*(FRACMASK+1L-f)) + 573 + ((SLONGLONG)srce[i+1]*f)) >> FRACBITS)); 574 + idx+=increment; 575 + 576 + if(vnf->rampvol) { 577 + whoop=(long)( 578 + ( ( (SLONGLONG)(vnf->oldlvol*vnf->rampvol) + 579 + (vnf->lvolsel*(CLICK_BUFFER-vnf->rampvol)) ) * 580 + (SLONGLONG)sample) >> CLICK_SHIFT ); 581 + *dest++ +=whoop; 582 + *dest++ -=whoop; 583 + vnf->rampvol--; 584 + } else 585 + if(vnf->click) { 586 + whoop = (long)( 587 + ( ( ((SLONGLONG)vnf->lvolsel*(CLICK_BUFFER-vnf->click)) * 588 + (SLONGLONG)sample) + 589 + (vnf->lastvalL * vnf->click) ) >> CLICK_SHIFT ); 590 + *dest++ +=whoop; 591 + *dest++ -=whoop; 592 + vnf->click--; 593 + } else { 594 + *dest++ +=vnf->lvolsel*sample; 595 + *dest++ -=vnf->lvolsel*sample; 596 + } 597 + } 598 + vnf->lastvalL=vnf->lvolsel*sample; 599 + vnf->lastvalR=vnf->lvolsel*sample; 600 + 601 + return idx; 602 + } 603 + 604 + static void(*Mix32toFP)(float* dste,const SLONG *srce,NATIVE count); 605 + static void(*Mix32to16)(SWORD* dste,const SLONG *srce,NATIVE count); 606 + static void(*Mix32to8)(SBYTE* dste,const SLONG *srce,NATIVE count); 607 + static void(*MixReverb)(SLONG *srce,NATIVE count); 608 + 609 + /* Reverb macros */ 610 + #define COMPUTE_LOC(n) loc##n = RVRindex % RVc##n 611 + #define COMPUTE_LECHO(n) RVbufL##n [loc##n ]=speedup+((ReverbPct*RVbufL##n [loc##n ])>>7) 612 + #define COMPUTE_RECHO(n) RVbufR##n [loc##n ]=speedup+((ReverbPct*RVbufR##n [loc##n ])>>7) 613 + 614 + static void MixReverb_Normal(SLONG *srce,NATIVE count) 615 + { 616 + NATIVE speedup; 617 + int ReverbPct; 618 + unsigned int loc1,loc2,loc3,loc4,loc5,loc6,loc7,loc8; 619 + 620 + ReverbPct=58+(md_reverb*4); 621 + 622 + COMPUTE_LOC(1); COMPUTE_LOC(2); COMPUTE_LOC(3); COMPUTE_LOC(4); 623 + COMPUTE_LOC(5); COMPUTE_LOC(6); COMPUTE_LOC(7); COMPUTE_LOC(8); 624 + 625 + while(count--) { 626 + /* Compute the left channel echo buffers */ 627 + speedup = *srce >> 3; 628 + 629 + COMPUTE_LECHO(1); COMPUTE_LECHO(2); COMPUTE_LECHO(3); COMPUTE_LECHO(4); 630 + COMPUTE_LECHO(5); COMPUTE_LECHO(6); COMPUTE_LECHO(7); COMPUTE_LECHO(8); 631 + 632 + /* Prepare to compute actual finalized data */ 633 + RVRindex++; 634 + 635 + COMPUTE_LOC(1); COMPUTE_LOC(2); COMPUTE_LOC(3); COMPUTE_LOC(4); 636 + COMPUTE_LOC(5); COMPUTE_LOC(6); COMPUTE_LOC(7); COMPUTE_LOC(8); 637 + 638 + /* left channel */ 639 + *srce++ +=RVbufL1[loc1]-RVbufL2[loc2]+RVbufL3[loc3]-RVbufL4[loc4]+ 640 + RVbufL5[loc5]-RVbufL6[loc6]+RVbufL7[loc7]-RVbufL8[loc8]; 641 + } 642 + } 643 + 644 + static void MixReverb_Stereo(SLONG *srce,NATIVE count) 645 + { 646 + NATIVE speedup; 647 + int ReverbPct; 648 + unsigned int loc1,loc2,loc3,loc4,loc5,loc6,loc7,loc8; 649 + 650 + ReverbPct=58+(md_reverb*4); 651 + 652 + COMPUTE_LOC(1); COMPUTE_LOC(2); COMPUTE_LOC(3); COMPUTE_LOC(4); 653 + COMPUTE_LOC(5); COMPUTE_LOC(6); COMPUTE_LOC(7); COMPUTE_LOC(8); 654 + 655 + while(count--) { 656 + /* Compute the left channel echo buffers */ 657 + speedup = *srce >> 3; 658 + 659 + COMPUTE_LECHO(1); COMPUTE_LECHO(2); COMPUTE_LECHO(3); COMPUTE_LECHO(4); 660 + COMPUTE_LECHO(5); COMPUTE_LECHO(6); COMPUTE_LECHO(7); COMPUTE_LECHO(8); 661 + 662 + /* Compute the right channel echo buffers */ 663 + speedup = srce[1] >> 3; 664 + 665 + COMPUTE_RECHO(1); COMPUTE_RECHO(2); COMPUTE_RECHO(3); COMPUTE_RECHO(4); 666 + COMPUTE_RECHO(5); COMPUTE_RECHO(6); COMPUTE_RECHO(7); COMPUTE_RECHO(8); 667 + 668 + /* Prepare to compute actual finalized data */ 669 + RVRindex++; 670 + 671 + COMPUTE_LOC(1); COMPUTE_LOC(2); COMPUTE_LOC(3); COMPUTE_LOC(4); 672 + COMPUTE_LOC(5); COMPUTE_LOC(6); COMPUTE_LOC(7); COMPUTE_LOC(8); 673 + 674 + /* left channel */ 675 + *srce++ +=RVbufL1[loc1]-RVbufL2[loc2]+RVbufL3[loc3]-RVbufL4[loc4]+ 676 + RVbufL5[loc5]-RVbufL6[loc6]+RVbufL7[loc7]-RVbufL8[loc8]; 677 + 678 + /* right channel */ 679 + *srce++ +=RVbufR1[loc1]-RVbufR2[loc2]+RVbufR3[loc3]-RVbufR4[loc4]+ 680 + RVbufR5[loc5]-RVbufR6[loc6]+RVbufR7[loc7]-RVbufR8[loc8]; 681 + } 682 + } 683 + 684 + static void (*MixLowPass)(SLONG* srce,NATIVE count); 685 + 686 + static int nLeftNR, nRightNR; 687 + 688 + static void MixLowPass_Stereo(SLONG* srce,NATIVE count) 689 + { 690 + int n1 = nLeftNR, n2 = nRightNR; 691 + SLONG *pnr = srce; 692 + int nr=count; 693 + for (; nr; nr--) 694 + { 695 + int vnr = pnr[0] >> 1; 696 + pnr[0] = vnr + n1; 697 + n1 = vnr; 698 + vnr = pnr[1] >> 1; 699 + pnr[1] = vnr + n2; 700 + n2 = vnr; 701 + pnr += 2; 702 + } 703 + nLeftNR = n1; 704 + nRightNR = n2; 705 + } 706 + 707 + static void MixLowPass_Normal(SLONG* srce,NATIVE count) 708 + { 709 + int n1 = nLeftNR; 710 + SLONG *pnr = srce; 711 + int nr=count; 712 + for (; nr; nr--) 713 + { 714 + int vnr = pnr[0] >> 1; 715 + pnr[0] = vnr + n1; 716 + n1 = vnr; 717 + pnr ++; 718 + } 719 + nLeftNR = n1; 720 + } 721 + 722 + /* Mixing macros */ 723 + #define EXTRACT_SAMPLE_FP(var,attenuation) var=*srce++*((1.0f / 32768.0f) / (MAXVOL_FACTOR*attenuation)) 724 + #define CHECK_SAMPLE_FP(var,bound) var=(var>bound)?bound:(var<-bound)?-bound:var 725 + 726 + static void Mix32ToFP_Normal(float* dste,const SLONG *srce,NATIVE count) 727 + { 728 + float x1,x2,tmpx; 729 + int i; 730 + 731 + for(count/=SAMPLING_FACTOR;count;count--) { 732 + tmpx=0.0f; 733 + 734 + for(i=SAMPLING_FACTOR/2;i;i--) { 735 + EXTRACT_SAMPLE_FP(x1,1.0f); EXTRACT_SAMPLE_FP(x2,1.0f); 736 + 737 + CHECK_SAMPLE_FP(x1,1.0f); CHECK_SAMPLE_FP(x2,1.0f); 738 + 739 + tmpx+=x1+x2; 740 + } 741 + *dste++ =tmpx*(1.0f/SAMPLING_FACTOR); 742 + } 743 + } 744 + 745 + static void Mix32ToFP_Stereo(float* dste,const SLONG *srce,NATIVE count) 746 + { 747 + float x1,x2,x3,x4,tmpx,tmpy; 748 + int i; 749 + 750 + for(count/=SAMPLING_FACTOR;count;count--) { 751 + tmpx=tmpy=0.0f; 752 + 753 + for(i=SAMPLING_FACTOR/2;i;i--) { 754 + EXTRACT_SAMPLE_FP(x1,1.0f); EXTRACT_SAMPLE_FP(x2,1.0f); 755 + EXTRACT_SAMPLE_FP(x3,1.0f); EXTRACT_SAMPLE_FP(x4,1.0f); 756 + 757 + CHECK_SAMPLE_FP(x1,1.0f); CHECK_SAMPLE_FP(x2,1.0f); 758 + CHECK_SAMPLE_FP(x3,1.0f); CHECK_SAMPLE_FP(x4,1.0f); 759 + 760 + tmpx+=x1+x3; 761 + tmpy+=x2+x4; 762 + } 763 + *dste++ =tmpx*(1.0f/SAMPLING_FACTOR); 764 + *dste++ =tmpy*(1.0f/SAMPLING_FACTOR); 765 + } 766 + } 767 + 768 + /* Mixing macros */ 769 + #define EXTRACT_SAMPLE(var,attenuation) var=*srce++/(MAXVOL_FACTOR*attenuation) 770 + #define CHECK_SAMPLE(var,bound) var=(var>=bound)?bound-1:(var<-bound)?-bound:var 771 + 772 + static void Mix32To16_Normal(SWORD* dste,const SLONG *srce,NATIVE count) 773 + { 774 + NATIVE x1,x2,tmpx; 775 + int i; 776 + 777 + for(count/=SAMPLING_FACTOR;count;count--) { 778 + tmpx=0; 779 + 780 + for(i=SAMPLING_FACTOR/2;i;i--) { 781 + EXTRACT_SAMPLE(x1,1); EXTRACT_SAMPLE(x2,1); 782 + 783 + CHECK_SAMPLE(x1,32768); CHECK_SAMPLE(x2,32768); 784 + 785 + tmpx+=x1+x2; 786 + } 787 + *dste++ =(SWORD)(tmpx/SAMPLING_FACTOR); 788 + } 789 + } 790 + 791 + 792 + static void Mix32To16_Stereo(SWORD* dste,const SLONG *srce,NATIVE count) 793 + { 794 + NATIVE x1,x2,x3,x4,tmpx,tmpy; 795 + int i; 796 + 797 + for(count/=SAMPLING_FACTOR;count;count--) { 798 + tmpx=tmpy=0; 799 + 800 + for(i=SAMPLING_FACTOR/2;i;i--) { 801 + EXTRACT_SAMPLE(x1,1); EXTRACT_SAMPLE(x2,1); 802 + EXTRACT_SAMPLE(x3,1); EXTRACT_SAMPLE(x4,1); 803 + 804 + CHECK_SAMPLE(x1,32768); CHECK_SAMPLE(x2,32768); 805 + CHECK_SAMPLE(x3,32768); CHECK_SAMPLE(x4,32768); 806 + 807 + tmpx+=x1+x3; 808 + tmpy+=x2+x4; 809 + } 810 + *dste++ =(SWORD)(tmpx/SAMPLING_FACTOR); 811 + *dste++ =(SWORD)(tmpy/SAMPLING_FACTOR); 812 + } 813 + } 814 + 815 + static void Mix32To8_Normal(SBYTE* dste,const SLONG *srce,NATIVE count) 816 + { 817 + NATIVE x1,x2,tmpx; 818 + int i; 819 + 820 + for(count/=SAMPLING_FACTOR;count;count--) { 821 + tmpx = 0; 822 + 823 + for(i=SAMPLING_FACTOR/2;i;i--) { 824 + EXTRACT_SAMPLE(x1,256); EXTRACT_SAMPLE(x2,256); 825 + 826 + CHECK_SAMPLE(x1,128); CHECK_SAMPLE(x2,128); 827 + 828 + tmpx+=x1+x2; 829 + } 830 + *dste++ = (SBYTE)((tmpx/SAMPLING_FACTOR)+128); 831 + } 832 + } 833 + 834 + static void Mix32To8_Stereo(SBYTE* dste,const SLONG *srce,NATIVE count) 835 + { 836 + NATIVE x1,x2,x3,x4,tmpx,tmpy; 837 + int i; 838 + 839 + for(count/=SAMPLING_FACTOR;count;count--) { 840 + tmpx=tmpy=0; 841 + 842 + for(i=SAMPLING_FACTOR/2;i;i--) { 843 + EXTRACT_SAMPLE(x1,256); EXTRACT_SAMPLE(x2,256); 844 + EXTRACT_SAMPLE(x3,256); EXTRACT_SAMPLE(x4,256); 845 + 846 + CHECK_SAMPLE(x1,128); CHECK_SAMPLE(x2,128); 847 + CHECK_SAMPLE(x3,128); CHECK_SAMPLE(x4,128); 848 + 849 + tmpx+=x1+x3; 850 + tmpy+=x2+x4; 851 + } 852 + *dste++ =(SBYTE)((tmpx/SAMPLING_FACTOR)+128); 853 + *dste++ =(SBYTE)((tmpy/SAMPLING_FACTOR)+128); 854 + } 855 + } 856 + 857 + #if defined HAVE_SSE2 858 + #define SHIFT_MIX_TO_16 (BITSHIFT + 16 - 16) 859 + /* TEST: Ok */ 860 + static void Mix32To16_Stereo_SIMD_4Tap(SWORD* dste, const SLONG* srce, NATIVE count) 861 + { 862 + int remain = count; 863 + 864 + /* Check unaligned dste buffer. srce is always aligned. */ 865 + while(!IS_ALIGNED_16(dste)) 866 + { 867 + Mix32To16_Stereo(dste, srce, SAMPLING_FACTOR); 868 + dste+=2; 869 + srce+=8; 870 + count--; 871 + if(!count) return; 872 + } 873 + 874 + /* dste and srce aligned. srce is always aligned. */ 875 + remain = count & 15; 876 + /* count / 2 for 1 sample */ 877 + 878 + for(count>>=4;count;count--) 879 + { 880 + /* Load 32bit sample. 1st average */ 881 + __m128i v0 = _mm_add_epi32( 882 + _mm_srai_epi32(_mm_loadu_si128((__m128i const *)(srce+0)), SHIFT_MIX_TO_16), 883 + _mm_srai_epi32(_mm_loadu_si128((__m128i const *)(srce+4)), SHIFT_MIX_TO_16) 884 + ); /* v0: s0.l+s2.l | s0.r+s2.r | s1.l+s3.l | s1.r+s3.r */ 885 + 886 + /* 2nd average (s0.l+s2.l+s1.l+s3.l / 4, s0.r+s2.r+s1.r+s3.r / 4). Upper 64bit is unused (1 stereo sample) */ 887 + __m128i v1 = _mm_srai_epi32(_mm_add_epi32(v0, mm_hiqq(v0)), 2); 888 + /* v1: s0.l+s2.l / 4 | s0.r+s2.r / 4 | s1.l+s3.l+s0.l+s2.l / 4 | s1.r+s3.r+s0.r+s2.r / 4 */ 889 + 890 + __m128i v2 = _mm_add_epi32( 891 + _mm_srai_epi32(_mm_loadu_si128((__m128i const *)(srce+8)), SHIFT_MIX_TO_16), 892 + _mm_srai_epi32(_mm_loadu_si128((__m128i const *)(srce+12)), SHIFT_MIX_TO_16) 893 + ); /* v2: s4.l+s6.l | s4.r+s6.r | s5.l+s7.l | s5.r+s7.r */ 894 + 895 + __m128i v3 = _mm_srai_epi32(_mm_add_epi32(v2, mm_hiqq(v2)), 2); /* Upper 64bit is unused */ 896 + /* v3: s4.l+s6.l /4 | s4.r+s6.r / 4| s5.l+s7.l+s4.l+s6.l / 4 | s5.r+s7.r+s4.r+s6.l / 4 */ 897 + 898 + /* pack two stereo samples in one */ 899 + __m128i v4 = _mm_unpacklo_epi64(v1, v3); /* v4 = avg(s0,s1,s2,s3) | avg(s4,s5,s6,s7) */ 900 + 901 + __m128i v6; 902 + 903 + /* Load 32bit sample. 1st average (s0.l+s2.l, s0.r+s2.r, s1.l+s3.l, s1.r+s3.r) */ 904 + v0 = _mm_add_epi32( 905 + _mm_srai_epi32(_mm_loadu_si128((__m128i const *)(srce+16)), SHIFT_MIX_TO_16), 906 + _mm_srai_epi32(_mm_loadu_si128((__m128i const *)(srce+20)), SHIFT_MIX_TO_16) 907 + ); /* 128bit = 2 stereo samples */ 908 + 909 + /* 2nd average (s0.l+s2.l+s1.l+s3.l / 4, s0.r+s2.r+s1.r+s3.r / 4). Upper 64bit is unused (1 stereo sample) */ 910 + v1 = _mm_srai_epi32(_mm_add_epi32(v0, mm_hiqq(v0)), 2); 911 + 912 + v2 = _mm_add_epi32( 913 + _mm_srai_epi32(_mm_loadu_si128((__m128i const *)(srce+24)), SHIFT_MIX_TO_16), 914 + _mm_srai_epi32(_mm_loadu_si128((__m128i const *)(srce+28)), SHIFT_MIX_TO_16) 915 + ); 916 + 917 + v3 = _mm_srai_epi32(_mm_add_epi32(v2, mm_hiqq(v2)), 2); /* Upper 64bit is unused */ 918 + 919 + /* pack two stereo samples in one */ 920 + v6 = _mm_unpacklo_epi64(v1, v3); /* v6 = avg(s8,s9,s10,s11) | avg(s12,s13,s14,s15) */ 921 + 922 + _mm_store_si128((__m128i*)dste, _mm_packs_epi32(v4, v6)); /* 4 interpolated stereo sample 32bit to 4 */ 923 + 924 + dste+=8; 925 + srce+=32; /* 32 = 4 * 8 */ 926 + } 927 + 928 + /* FIXME: THIS PART WRITES PAST DST !! */ 929 + if (remain) 930 + { 931 + Mix32To16_Stereo(dste, srce, remain); 932 + } 933 + } 934 + 935 + #elif defined HAVE_ALTIVEC 936 + #define SHIFT_MIX_TO_16 vec_splat_u32(BITSHIFT + 16 - 16) 937 + /* TEST: Ok */ 938 + static void Mix32To16_Stereo_SIMD_4Tap(SWORD* dste, const SLONG* srce, NATIVE count) 939 + { 940 + int remain = count; 941 + 942 + /* Check unaligned dste buffer. srce is always aligned. */ 943 + while(!IS_ALIGNED_16(dste)) 944 + { 945 + Mix32To16_Stereo(dste, srce, SAMPLING_FACTOR); 946 + dste+=2; 947 + srce+=8; 948 + count--; 949 + if(!count) return; 950 + } 951 + 952 + /* dste and srce aligned. srce is always aligned. */ 953 + remain = count & 15; 954 + for(count>>=4;count;count--) 955 + { 956 + /* Load 32bit sample. 1st average (s0.l+s2.l, s0.r+s2.r, s1.l+s3.l, s1.r+s3.r) */ 957 + vector signed int v0 = vec_add( 958 + vec_sra(vec_ld(0, srce), SHIFT_MIX_TO_16), /* 128bit = 2 stereo samples */ 959 + vec_sra(vec_ld(0x10, srce), SHIFT_MIX_TO_16) 960 + ); /* 128bit = 2 stereo samples */ 961 + 962 + /* 2nd average (s0.l+s2.l+s1.l+s3.l / 4, s0.r+s2.r+s1.r+s3.r / 4). Upper 64bit is unused (1 stereo sample) */ 963 + vector signed int v1 = vec_sra(vec_add(v0, vec_hiqq(v0)), vec_splat_u32(2)); 964 + 965 + vector signed int v2 = vec_add( 966 + vec_sra(vec_ld(0x20, srce), SHIFT_MIX_TO_16), 967 + vec_sra(vec_ld(0x30, srce), SHIFT_MIX_TO_16) 968 + ); 969 + 970 + vector signed int v3 = vec_sra(vec_add(v2, vec_hiqq(v2)), vec_splat_u32(2)); /* Upper 64bit is unused */ 971 + 972 + /* pack two stereo samples in one */ 973 + vector signed int v6, v4 = vec_unpacklo(v1, v3); /* v4 = lo64(v1) | lo64(v3) */ 974 + 975 + /* Load 32bit sample. 1st average (s0.l+s2.l, s0.r+s2.r, s1.l+s3.l, s1.r+s3.r) */ 976 + v0 = vec_add( 977 + vec_sra(vec_ld(0x40, srce), SHIFT_MIX_TO_16), /* 128bit = 2 stereo samples */ 978 + vec_sra(vec_ld(0x50, srce), SHIFT_MIX_TO_16) 979 + ); /* 128bit = 2 stereo samples */ 980 + 981 + /* 2nd average (s0.l+s2.l+s1.l+s3.l / 4, s0.r+s2.r+s1.r+s3.r / 4). Upper 64bit is unused (1 stereo sample) */ 982 + v1 = vec_sra(vec_add(v0, vec_hiqq(v0)), vec_splat_u32(2)); 983 + 984 + v2 = vec_add( 985 + vec_sra(vec_ld(0x60, srce), SHIFT_MIX_TO_16), 986 + vec_sra(vec_ld(0x70, srce), SHIFT_MIX_TO_16) 987 + ); 988 + 989 + v3 = vec_sra(vec_add(v2, vec_hiqq(v2)), vec_splat_u32(2)); /* Upper 64bit is unused */ 990 + 991 + /* pack two stereo samples in one */ 992 + v6 = vec_unpacklo(v1, v3); 993 + 994 + vec_st(vec_packs(v4, v6), 0, dste); /* 4 interpolated stereo sample 32bit to 4 interpolated stereo sample 16bit + saturation */ 995 + 996 + dste+=8; 997 + srce+=32; /* 32 = 4 * 8 */ 998 + } 999 + 1000 + if (remain) 1001 + { 1002 + Mix32To16_Stereo(dste, srce, remain); 1003 + } 1004 + } 1005 + 1006 + #endif 1007 + 1008 + 1009 + static void AddChannel(SLONG* ptr,NATIVE todo) 1010 + { 1011 + SLONGLONG end,done; 1012 + SWORD *s; 1013 + 1014 + if(!(s=Samples[vnf->handle])) { 1015 + vnf->current = vnf->active = 0; 1016 + vnf->lastvalL = vnf->lastvalR = 0; 1017 + return; 1018 + } 1019 + 1020 + /* update the 'current' index so the sample loops, or stops playing if it 1021 + reached the end of the sample */ 1022 + while(todo>0) { 1023 + SLONGLONG endpos; 1024 + 1025 + if(vnf->flags & SF_REVERSE) { 1026 + /* The sample is playing in reverse */ 1027 + if((vnf->flags&SF_LOOP)&&(vnf->current<idxlpos)) { 1028 + /* the sample is looping and has reached the loopstart index */ 1029 + if(vnf->flags & SF_BIDI) { 1030 + /* sample is doing bidirectional loops, so 'bounce' the 1031 + current index against the idxlpos */ 1032 + vnf->current = idxlpos+(idxlpos-vnf->current); 1033 + vnf->flags &= ~SF_REVERSE; 1034 + vnf->increment = -vnf->increment; 1035 + } else 1036 + /* normal backwards looping, so set the current position to 1037 + loopend index */ 1038 + vnf->current=idxlend-(idxlpos-vnf->current); 1039 + } else { 1040 + /* the sample is not looping, so check if it reached index 0 */ 1041 + if(vnf->current < 0) { 1042 + /* playing index reached 0, so stop playing this sample */ 1043 + vnf->current = vnf->active = 0; 1044 + break; 1045 + } 1046 + } 1047 + } else { 1048 + /* The sample is playing forward */ 1049 + if((vnf->flags & SF_LOOP) && 1050 + (vnf->current >= idxlend)) { 1051 + /* the sample is looping, check the loopend index */ 1052 + if(vnf->flags & SF_BIDI) { 1053 + /* sample is doing bidirectional loops, so 'bounce' the 1054 + current index against the idxlend */ 1055 + vnf->flags |= SF_REVERSE; 1056 + vnf->increment = -vnf->increment; 1057 + vnf->current = idxlend-(vnf->current-idxlend); 1058 + } else 1059 + /* normal backwards looping, so set the current position 1060 + to loopend index */ 1061 + vnf->current=idxlpos+(vnf->current-idxlend); 1062 + } else { 1063 + /* sample is not looping, so check if it reached the last 1064 + position */ 1065 + if(vnf->current >= idxsize) { 1066 + /* yes, so stop playing this sample */ 1067 + vnf->current = vnf->active = 0; 1068 + break; 1069 + } 1070 + } 1071 + } 1072 + 1073 + end=(vnf->flags&SF_REVERSE)?(vnf->flags&SF_LOOP)?idxlpos:0: 1074 + (vnf->flags&SF_LOOP)?idxlend:idxsize; 1075 + 1076 + /* if the sample is not blocked... */ 1077 + if((end==vnf->current)||(!vnf->increment)) 1078 + done=0; 1079 + else { 1080 + done=MIN((end-vnf->current)/vnf->increment+1,todo); 1081 + if(done<0) done=0; 1082 + } 1083 + 1084 + if(!done) { 1085 + vnf->active = 0; 1086 + break; 1087 + } 1088 + 1089 + endpos=vnf->current+done*vnf->increment; 1090 + 1091 + if(vnf->vol || vnf->rampvol) { 1092 + #ifndef NATIVE_64BIT_INT 1093 + /* use the 32 bit mixers as often as we can (they're much faster) */ 1094 + if((vnf->current<0x7fffffff)&&(endpos<0x7fffffff)) { 1095 + if(vc_mode & DMODE_STEREO) { 1096 + if((vnf->pan==PAN_SURROUND)&&(vc_mode&DMODE_SURROUND)) 1097 + vnf->current=(SLONGLONG)Mix32StereoSurround 1098 + (s,ptr,vnf->current,vnf->increment,done); 1099 + else 1100 + vnf->current=Mix32StereoNormal 1101 + (s,ptr,vnf->current,vnf->increment,done); 1102 + } else 1103 + vnf->current=Mix32MonoNormal 1104 + (s,ptr,vnf->current,vnf->increment,done); 1105 + } 1106 + else 1107 + #endif 1108 + { 1109 + if(vc_mode & DMODE_STEREO) { 1110 + if((vnf->pan==PAN_SURROUND)&&(vc_mode&DMODE_SURROUND)) 1111 + vnf->current=MixStereoSurround 1112 + (s,ptr,vnf->current,vnf->increment,done); 1113 + else 1114 + vnf->current=MixStereoNormal 1115 + (s,ptr,vnf->current,vnf->increment,done); 1116 + } else 1117 + vnf->current=MixMonoNormal 1118 + (s,ptr,vnf->current,vnf->increment,done); 1119 + } 1120 + } else { 1121 + vnf->lastvalL = vnf->lastvalR = 0; 1122 + /* update sample position */ 1123 + vnf->current=endpos; 1124 + } 1125 + 1126 + todo -= done; 1127 + ptr += (vc_mode & DMODE_STEREO)?(done<<1):done; 1128 + } 1129 + } 1130 + 1131 + #define _IN_VIRTCH_ 1132 + 1133 + #define VC1_SilenceBytes VC2_SilenceBytes 1134 + #define VC1_WriteSamples VC2_WriteSamples 1135 + #define VC1_WriteBytes VC2_WriteBytes 1136 + #define VC1_Exit VC2_Exit 1137 + #define VC1_VoiceSetVolume VC2_VoiceSetVolume 1138 + #define VC1_VoiceGetVolume VC2_VoiceGetVolume 1139 + #define VC1_VoiceSetPanning VC2_VoiceSetPanning 1140 + #define VC1_VoiceGetPanning VC2_VoiceGetPanning 1141 + #define VC1_VoiceSetFrequency VC2_VoiceSetFrequency 1142 + #define VC1_VoiceGetFrequency VC2_VoiceGetFrequency 1143 + #define VC1_VoicePlay VC2_VoicePlay 1144 + #define VC1_VoiceStop VC2_VoiceStop 1145 + #define VC1_VoiceStopped VC2_VoiceStopped 1146 + #define VC1_VoiceGetPosition VC2_VoiceGetPosition 1147 + #define VC1_SampleUnload VC2_SampleUnload 1148 + #define VC1_SampleLoad VC2_SampleLoad 1149 + #define VC1_SampleSpace VC2_SampleSpace 1150 + #define VC1_SampleLength VC2_SampleLength 1151 + #define VC1_VoiceRealVolume VC2_VoiceRealVolume 1152 + 1153 + #include "virtch_common.c" 1154 + #undef _IN_VIRTCH_ 1155 + 1156 + void VC2_WriteSamples(SBYTE* buf,ULONG todo) 1157 + { 1158 + int left,portion=0; 1159 + SBYTE *buffer; 1160 + int t,pan,vol; 1161 + 1162 + todo*=SAMPLING_FACTOR; 1163 + 1164 + while(todo) { 1165 + if(!tickleft) { 1166 + if(vc_mode & DMODE_SOFT_MUSIC) md_player(); 1167 + tickleft=(md_mixfreq*125L*SAMPLING_FACTOR)/(md_bpm*50L); 1168 + tickleft&=~(SAMPLING_FACTOR-1); 1169 + } 1170 + left = MIN(tickleft, (int)todo); 1171 + buffer = buf; 1172 + tickleft -= left; 1173 + todo -= left; 1174 + buf += samples2bytes(left)/SAMPLING_FACTOR; 1175 + 1176 + while(left) { 1177 + portion = MIN(left, samplesthatfit); 1178 + memset(vc_tickbuf,0,portion<<((vc_mode&DMODE_STEREO)?3:2)); 1179 + for(t=0;t<vc_softchn;t++) { 1180 + vnf = &vinf[t]; 1181 + 1182 + if(vnf->kick) { 1183 + vnf->current=((SLONGLONG)(vnf->start))<<FRACBITS; 1184 + vnf->kick = 0; 1185 + vnf->active = 1; 1186 + vnf->click = CLICK_BUFFER; 1187 + vnf->rampvol = 0; 1188 + } 1189 + 1190 + if(!vnf->frq) vnf->active = 0; 1191 + 1192 + if(vnf->active) { 1193 + vnf->increment=((SLONGLONG)(vnf->frq)<<(FRACBITS-SAMPLING_SHIFT)) 1194 + /md_mixfreq; 1195 + if(vnf->flags&SF_REVERSE) vnf->increment=-vnf->increment; 1196 + vol = vnf->vol; pan = vnf->pan; 1197 + 1198 + vnf->oldlvol=vnf->lvolsel;vnf->oldrvol=vnf->rvolsel; 1199 + if(vc_mode & DMODE_STEREO) { 1200 + if(pan!=PAN_SURROUND) { 1201 + vnf->lvolsel=(vol*(PAN_RIGHT-pan))>>8; 1202 + vnf->rvolsel=(vol*pan)>>8; 1203 + } else { 1204 + vnf->lvolsel=vnf->rvolsel=(vol * 256L) / 480; 1205 + } 1206 + } else 1207 + vnf->lvolsel=vol; 1208 + 1209 + idxsize=(vnf->size)?((SLONGLONG)(vnf->size)<<FRACBITS)-1:0; 1210 + idxlend=(vnf->repend)?((SLONGLONG)(vnf->repend)<<FRACBITS)-1:0; 1211 + idxlpos=(SLONGLONG)(vnf->reppos)<<FRACBITS; 1212 + AddChannel(vc_tickbuf,portion); 1213 + } 1214 + } 1215 + 1216 + if(md_mode & DMODE_NOISEREDUCTION) { 1217 + MixLowPass(vc_tickbuf, portion); 1218 + } 1219 + 1220 + if(md_reverb) { 1221 + if(md_reverb>15) md_reverb=15; 1222 + MixReverb(vc_tickbuf,portion); 1223 + } 1224 + 1225 + if (vc_callback) { 1226 + vc_callback((unsigned char*)vc_tickbuf, portion); 1227 + } 1228 + 1229 + if(vc_mode & DMODE_FLOAT) 1230 + Mix32toFP((float*)buffer,vc_tickbuf,portion); 1231 + else if(vc_mode & DMODE_16BITS) 1232 + Mix32to16((SWORD*)buffer,vc_tickbuf,portion); 1233 + else 1234 + Mix32to8((SBYTE*)buffer,vc_tickbuf,portion); 1235 + 1236 + buffer += samples2bytes(portion) / SAMPLING_FACTOR; 1237 + left -= portion; 1238 + } 1239 + } 1240 + } 1241 + 1242 + int VC2_Init(void) 1243 + { 1244 + VC_SetupPointers(); 1245 + 1246 + if (!(md_mode&DMODE_HQMIXER)) 1247 + return VC1_Init(); 1248 + 1249 + if(!(Samples=(SWORD**)MikMod_amalloc(MAXSAMPLEHANDLES*sizeof(SWORD*)))) { 1250 + _mm_errno = MMERR_INITIALIZING_MIXER; 1251 + return 1; 1252 + } 1253 + if(!vc_tickbuf) { 1254 + if(!(vc_tickbuf=(SLONG*)MikMod_amalloc((TICKLSIZE+32)*sizeof(SLONG)))) { 1255 + _mm_errno = MMERR_INITIALIZING_MIXER; 1256 + return 1; 1257 + } 1258 + } 1259 + 1260 + if(md_mode & DMODE_STEREO) { 1261 + Mix32toFP = Mix32ToFP_Stereo; 1262 + #if ((defined HAVE_ALTIVEC || defined HAVE_SSE2) && (SAMPLING_FACTOR == 4)) 1263 + if (md_mode & DMODE_SIMDMIXER) 1264 + Mix32to16 = Mix32To16_Stereo_SIMD_4Tap; 1265 + else 1266 + #endif 1267 + Mix32to16 = Mix32To16_Stereo; 1268 + Mix32to8 = Mix32To8_Stereo; 1269 + MixReverb = MixReverb_Stereo; 1270 + MixLowPass = MixLowPass_Stereo; 1271 + } else { 1272 + Mix32toFP = Mix32ToFP_Normal; 1273 + Mix32to16 = Mix32To16_Normal; 1274 + Mix32to8 = Mix32To8_Normal; 1275 + MixReverb = MixReverb_Normal; 1276 + MixLowPass = MixLowPass_Normal; 1277 + } 1278 + 1279 + md_mode |= DMODE_INTERP; 1280 + vc_mode = md_mode; 1281 + return 0; 1282 + } 1283 + 1284 + int VC2_PlayStart(void) 1285 + { 1286 + md_mode|=DMODE_INTERP; 1287 + 1288 + samplesthatfit = TICKLSIZE; 1289 + if(vc_mode & DMODE_STEREO) samplesthatfit >>= 1; 1290 + tickleft = 0; 1291 + 1292 + RVc1 = (5000L * md_mixfreq) / (REVERBERATION * 10); 1293 + RVc2 = (5078L * md_mixfreq) / (REVERBERATION * 10); 1294 + RVc3 = (5313L * md_mixfreq) / (REVERBERATION * 10); 1295 + RVc4 = (5703L * md_mixfreq) / (REVERBERATION * 10); 1296 + RVc5 = (6250L * md_mixfreq) / (REVERBERATION * 10); 1297 + RVc6 = (6953L * md_mixfreq) / (REVERBERATION * 10); 1298 + RVc7 = (7813L * md_mixfreq) / (REVERBERATION * 10); 1299 + RVc8 = (8828L * md_mixfreq) / (REVERBERATION * 10); 1300 + 1301 + if(!(RVbufL1=(SLONG*)MikMod_calloc((RVc1+1),sizeof(SLONG)))) return 1; 1302 + if(!(RVbufL2=(SLONG*)MikMod_calloc((RVc2+1),sizeof(SLONG)))) return 1; 1303 + if(!(RVbufL3=(SLONG*)MikMod_calloc((RVc3+1),sizeof(SLONG)))) return 1; 1304 + if(!(RVbufL4=(SLONG*)MikMod_calloc((RVc4+1),sizeof(SLONG)))) return 1; 1305 + if(!(RVbufL5=(SLONG*)MikMod_calloc((RVc5+1),sizeof(SLONG)))) return 1; 1306 + if(!(RVbufL6=(SLONG*)MikMod_calloc((RVc6+1),sizeof(SLONG)))) return 1; 1307 + if(!(RVbufL7=(SLONG*)MikMod_calloc((RVc7+1),sizeof(SLONG)))) return 1; 1308 + if(!(RVbufL8=(SLONG*)MikMod_calloc((RVc8+1),sizeof(SLONG)))) return 1; 1309 + 1310 + /* allocate reverb buffers for the right channel if in stereo mode only. */ 1311 + if (vc_mode & DMODE_STEREO) { 1312 + if(!(RVbufR1=(SLONG*)MikMod_calloc((RVc1+1),sizeof(SLONG)))) return 1; 1313 + if(!(RVbufR2=(SLONG*)MikMod_calloc((RVc2+1),sizeof(SLONG)))) return 1; 1314 + if(!(RVbufR3=(SLONG*)MikMod_calloc((RVc3+1),sizeof(SLONG)))) return 1; 1315 + if(!(RVbufR4=(SLONG*)MikMod_calloc((RVc4+1),sizeof(SLONG)))) return 1; 1316 + if(!(RVbufR5=(SLONG*)MikMod_calloc((RVc5+1),sizeof(SLONG)))) return 1; 1317 + if(!(RVbufR6=(SLONG*)MikMod_calloc((RVc6+1),sizeof(SLONG)))) return 1; 1318 + if(!(RVbufR7=(SLONG*)MikMod_calloc((RVc7+1),sizeof(SLONG)))) return 1; 1319 + if(!(RVbufR8=(SLONG*)MikMod_calloc((RVc8+1),sizeof(SLONG)))) return 1; 1320 + } 1321 + 1322 + RVRindex = 0; 1323 + return 0; 1324 + } 1325 + 1326 + void VC2_PlayStop(void) 1327 + { 1328 + MikMod_free(RVbufL1); 1329 + MikMod_free(RVbufL2); 1330 + MikMod_free(RVbufL3); 1331 + MikMod_free(RVbufL4); 1332 + MikMod_free(RVbufL5); 1333 + MikMod_free(RVbufL6); 1334 + MikMod_free(RVbufL7); 1335 + MikMod_free(RVbufL8); 1336 + MikMod_free(RVbufR1); 1337 + MikMod_free(RVbufR2); 1338 + MikMod_free(RVbufR3); 1339 + MikMod_free(RVbufR4); 1340 + MikMod_free(RVbufR5); 1341 + MikMod_free(RVbufR6); 1342 + MikMod_free(RVbufR7); 1343 + MikMod_free(RVbufR8); 1344 + 1345 + RVbufL1=RVbufL2=RVbufL3=RVbufL4=RVbufL5=RVbufL6=RVbufL7=RVbufL8=NULL; 1346 + RVbufR1=RVbufR2=RVbufR3=RVbufR4=RVbufR5=RVbufR6=RVbufR7=RVbufR8=NULL; 1347 + } 1348 + 1349 + int VC2_SetNumVoices(void) 1350 + { 1351 + int t; 1352 + 1353 + md_mode|=DMODE_INTERP; 1354 + 1355 + if(!(vc_softchn=md_softchn)) return 0; 1356 + 1357 + MikMod_free(vinf); 1358 + if(!(vinf=(VINFO*)MikMod_calloc(vc_softchn,sizeof(VINFO)))) return 1; 1359 + 1360 + for(t=0;t<vc_softchn;t++) { 1361 + vinf[t].frq=10000; 1362 + vinf[t].pan=(t&1)?PAN_LEFT:PAN_RIGHT; 1363 + } 1364 + 1365 + return 0; 1366 + } 1367 + 1368 + #endif /* ! NO_HQMIXER */ 1369 + 1370 + /* ex:set ts=4: */
+102 -91
apps/plugins/mikmod/virtch_common.c
··· 6 6 it under the terms of the GNU Library General Public License as 7 7 published by the Free Software Foundation; either version 2 of 8 8 the License, or (at your option) any later version. 9 - 9 + 10 10 This program is distributed in the hope that it will be useful, 11 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 GNU Library General Public License for more details. 14 - 14 + 15 15 You should have received a copy of the GNU Library General Public 16 16 License along with this library; if not, write to the Free Software 17 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ··· 20 20 21 21 /*============================================================================== 22 22 23 - $Id: virtch_common.c,v 1.2 2005/03/30 19:11:50 realtech Exp $ 23 + $Id$ 24 24 25 25 Common source parts between the two software mixers. 26 26 This file is probably the ugliest part of libmikmod... 27 27 28 28 ==============================================================================*/ 29 29 30 - #ifndef _IN_VIRTCH_ 31 - 30 + #if defined(HAVE_CONFIG_H) && !defined(_IN_VIRTCH_) /* config.h isn't guarded */ 31 + #include "config.h" 32 + #endif 32 33 #include "mikmod_internals.h" 33 34 34 - extern int VC1_Init(void); 35 - //extern int VC2_Init(void); 36 - static int (*VC_Init_ptr)(void)=VC1_Init; 35 + #ifndef NO_HQMIXER 36 + extern ULONG VC1_SilenceBytes(SBYTE*,ULONG); 37 + extern ULONG VC2_SilenceBytes(SBYTE*,ULONG); 38 + extern ULONG VC1_WriteBytes(SBYTE*,ULONG); 39 + extern ULONG VC2_WriteBytes(SBYTE*,ULONG); 37 40 extern void VC1_Exit(void); 38 - //extern void VC2_Exit(void); 41 + extern void VC2_Exit(void); 42 + extern UWORD VC1_VoiceGetVolume(UBYTE); 43 + extern UWORD VC2_VoiceGetVolume(UBYTE); 44 + extern ULONG VC1_VoiceGetPanning(UBYTE); 45 + extern ULONG VC2_VoiceGetPanning(UBYTE); 46 + extern void VC1_VoiceSetFrequency(UBYTE,ULONG); 47 + extern void VC2_VoiceSetFrequency(UBYTE,ULONG); 48 + extern ULONG VC1_VoiceGetFrequency(UBYTE); 49 + extern ULONG VC2_VoiceGetFrequency(UBYTE); 50 + extern void VC1_VoicePlay(UBYTE,SWORD,ULONG,ULONG,ULONG,ULONG,UWORD); 51 + extern void VC2_VoicePlay(UBYTE,SWORD,ULONG,ULONG,ULONG,ULONG,UWORD); 52 + extern void VC1_VoiceStop(UBYTE); 53 + extern void VC2_VoiceStop(UBYTE); 54 + extern int VC1_VoiceStopped(UBYTE); 55 + extern int VC2_VoiceStopped(UBYTE); 56 + extern SLONG VC1_VoiceGetPosition(UBYTE); 57 + extern SLONG VC2_VoiceGetPosition(UBYTE); 58 + extern void VC1_VoiceSetVolume(UBYTE,UWORD); 59 + extern void VC2_VoiceSetVolume(UBYTE,UWORD); 60 + extern void VC1_VoiceSetPanning(UBYTE,ULONG); 61 + extern void VC2_VoiceSetPanning(UBYTE,ULONG); 62 + extern void VC1_SampleUnload(SWORD); 63 + extern void VC2_SampleUnload(SWORD); 64 + extern SWORD VC1_SampleLoad(struct SAMPLOAD*,int); 65 + extern SWORD VC2_SampleLoad(struct SAMPLOAD*,int); 66 + extern ULONG VC1_SampleSpace(int); 67 + extern ULONG VC2_SampleSpace(int); 68 + extern ULONG VC1_SampleLength(int,SAMPLE*); 69 + extern ULONG VC2_SampleLength(int,SAMPLE*); 70 + extern ULONG VC1_VoiceRealVolume(UBYTE); 71 + extern ULONG VC2_VoiceRealVolume(UBYTE); 72 + #endif 73 + 74 + 75 + #ifndef _IN_VIRTCH_ 76 + 77 + #ifndef NO_HQMIXER 78 + extern int VC1_Init(void); 79 + extern int VC2_Init(void); 80 + static int (*VC_Init_ptr)(void)=VC1_Init; 39 81 static void (*VC_Exit_ptr)(void)=VC1_Exit; 40 - extern int VC1_SetNumVoices(void); 41 - //extern int VC2_SetNumVoices(void); 42 - static int (*VC_SetNumVoices_ptr)(void); 43 - extern ULONG VC1_SampleSpace(int); 44 - //extern ULONG VC2_SampleSpace(int); 82 + extern int VC1_SetNumVoices(void); 83 + extern int VC2_SetNumVoices(void); 84 + static int (*VC_SetNumVoices_ptr)(void); 45 85 static ULONG (*VC_SampleSpace_ptr)(int); 46 - extern ULONG VC1_SampleLength(int,SAMPLE*); 47 - //extern ULONG VC2_SampleLength(int,SAMPLE*); 48 86 static ULONG (*VC_SampleLength_ptr)(int,SAMPLE*); 49 87 50 - extern int VC1_PlayStart(void); 51 - //extern int VC2_PlayStart(void); 52 - static int (*VC_PlayStart_ptr)(void); 53 - extern void VC1_PlayStop(void); 88 + extern int VC2_PlayStart(void); 89 + static int (*VC_PlayStart_ptr)(void); 54 90 extern void VC2_PlayStop(void); 55 91 static void (*VC_PlayStop_ptr)(void); 56 92 57 - extern SWORD VC1_SampleLoad(struct SAMPLOAD*,int); 58 - //extern SWORD VC2_SampleLoad(struct SAMPLOAD*,int); 59 93 static SWORD (*VC_SampleLoad_ptr)(struct SAMPLOAD*,int); 60 - extern void VC1_SampleUnload(SWORD); 61 - //extern void VC2_SampleUnload(SWORD); 62 94 static void (*VC_SampleUnload_ptr)(SWORD); 63 95 64 - extern ULONG VC1_WriteBytes(SBYTE*,ULONG); 65 - //extern ULONG VC2_WriteBytes(SBYTE*,ULONG); 66 96 static ULONG (*VC_WriteBytes_ptr)(SBYTE*,ULONG); 67 - extern ULONG VC1_SilenceBytes(SBYTE*,ULONG); 68 - //extern ULONG VC2_SilenceBytes(SBYTE*,ULONG); 69 97 static ULONG (*VC_SilenceBytes_ptr)(SBYTE*,ULONG); 70 98 71 - extern void VC1_VoiceSetVolume(UBYTE,UWORD); 72 - //extern void VC2_VoiceSetVolume(UBYTE,UWORD); 73 99 static void (*VC_VoiceSetVolume_ptr)(UBYTE,UWORD); 74 - extern UWORD VC1_VoiceGetVolume(UBYTE); 75 - //extern UWORD VC2_VoiceGetVolume(UBYTE); 76 100 static UWORD (*VC_VoiceGetVolume_ptr)(UBYTE); 77 - extern void VC1_VoiceSetFrequency(UBYTE,ULONG); 78 - //extern void VC2_VoiceSetFrequency(UBYTE,ULONG); 79 101 static void (*VC_VoiceSetFrequency_ptr)(UBYTE,ULONG); 80 - extern ULONG VC1_VoiceGetFrequency(UBYTE); 81 - //extern ULONG VC2_VoiceGetFrequency(UBYTE); 82 102 static ULONG (*VC_VoiceGetFrequency_ptr)(UBYTE); 83 - extern void VC1_VoiceSetPanning(UBYTE,ULONG); 84 - //extern void VC2_VoiceSetPanning(UBYTE,ULONG); 85 103 static void (*VC_VoiceSetPanning_ptr)(UBYTE,ULONG); 86 - extern ULONG VC1_VoiceGetPanning(UBYTE); 87 - //extern ULONG VC2_VoiceGetPanning(UBYTE); 88 104 static ULONG (*VC_VoiceGetPanning_ptr)(UBYTE); 89 - extern void VC1_VoicePlay(UBYTE,SWORD,ULONG,ULONG,ULONG,ULONG,UWORD); 90 - //extern void VC2_VoicePlay(UBYTE,SWORD,ULONG,ULONG,ULONG,ULONG,UWORD); 91 105 static void (*VC_VoicePlay_ptr)(UBYTE,SWORD,ULONG,ULONG,ULONG,ULONG,UWORD); 92 106 93 - extern void VC1_VoiceStop(UBYTE); 94 - //extern void VC2_VoiceStop(UBYTE); 95 107 static void (*VC_VoiceStop_ptr)(UBYTE); 96 - extern int VC1_VoiceStopped(UBYTE); 97 - //extern int VC2_VoiceStopped(UBYTE); 98 108 static int (*VC_VoiceStopped_ptr)(UBYTE); 99 - extern SLONG VC1_VoiceGetPosition(UBYTE); 100 - //extern SLONG VC2_VoiceGetPosition(UBYTE); 101 109 static SLONG (*VC_VoiceGetPosition_ptr)(UBYTE); 102 - extern ULONG VC1_VoiceRealVolume(UBYTE); 103 - //extern ULONG VC2_VoiceRealVolume(UBYTE); 104 110 static ULONG (*VC_VoiceRealVolume_ptr)(UBYTE); 105 111 106 - #if defined __STDC__ || defined _MSC_VER || defined MPW_C 112 + #if defined __STDC__ || defined _MSC_VER || defined __WATCOMC__ || defined MPW_C 107 113 #define VC_PROC0(suffix) \ 108 114 MIKMODAPI void VC_##suffix (void) { VC_##suffix##_ptr(); } 109 115 ··· 121 127 122 128 #define VC_FUNC2(suffix,ret,typ1,typ2) \ 123 129 MIKMODAPI ret VC_##suffix (typ1 a,typ2 b) { return VC_##suffix##_ptr(a,b); } 130 + 124 131 #else 132 + 125 133 #define VC_PROC0(suffix) \ 126 134 MIKMODAPI void VC_/**/suffix (void) { VC_/**/suffix/**/_ptr(); } 127 135 ··· 158 166 VC_FUNC1(VoiceGetFrequency,ULONG,UBYTE) 159 167 VC_PROC2(VoiceSetPanning,UBYTE,ULONG) 160 168 VC_FUNC1(VoiceGetPanning,ULONG,UBYTE) 161 - 162 - void VC_VoicePlay(UBYTE a,SWORD b,ULONG c,ULONG d,ULONG e,ULONG f,UWORD g) 163 - { VC_VoicePlay_ptr(a,b,c,d,e,f,g); } 169 + 170 + void VC_VoicePlay(UBYTE a,SWORD b,ULONG c,ULONG d,ULONG e,ULONG f,UWORD g) { 171 + VC_VoicePlay_ptr(a,b,c,d,e,f,g); 172 + } 164 173 165 174 VC_PROC1(VoiceStop,UBYTE) 166 175 VC_FUNC1(VoiceStopped,int,UBYTE) 167 176 VC_FUNC1(VoiceGetPosition,SLONG,UBYTE) 168 177 VC_FUNC1(VoiceRealVolume,ULONG,UBYTE) 169 - 178 + 170 179 void VC_SetupPointers(void) 171 180 { 172 - /* 173 181 if (md_mode&DMODE_HQMIXER) { 174 182 VC_Init_ptr=VC2_Init; 175 183 VC_Exit_ptr=VC2_Exit; ··· 194 202 VC_VoiceGetPosition_ptr=VC2_VoiceGetPosition; 195 203 VC_VoiceRealVolume_ptr=VC2_VoiceRealVolume; 196 204 } else { 197 - */ 198 205 VC_Init_ptr=VC1_Init; 199 206 VC_Exit_ptr=VC1_Exit; 200 207 VC_SetNumVoices_ptr=VC1_SetNumVoices; ··· 217 224 VC_VoiceStopped_ptr=VC1_VoiceStopped; 218 225 VC_VoiceGetPosition_ptr=VC1_VoiceGetPosition; 219 226 VC_VoiceRealVolume_ptr=VC1_VoiceRealVolume; 220 - //} 227 + } 221 228 } 229 + #endif/* !NO_HQMIXER */ 222 230 223 - #else 231 + #else /* _IN_VIRTCH_ */ 224 232 225 233 #ifndef _VIRTCH_COMMON_ 226 234 #define _VIRTCH_COMMON_ ··· 248 256 todo=samples2bytes(bytes2samples(todo)); 249 257 250 258 /* clear the buffer to zero (16 bits signed) or 0x80 (8 bits unsigned) */ 251 - if(vc_mode & DMODE_FLOAT) 252 - memset(buf,0,todo); 253 - else if(vc_mode & DMODE_16BITS) 259 + if(vc_mode &(DMODE_16BITS|DMODE_FLOAT)) 254 260 memset(buf,0,todo); 255 261 else 256 262 memset(buf,0x80,todo); ··· 276 282 277 283 void VC1_Exit(void) 278 284 { 279 - if(vc_tickbuf) MikMod_free(vc_tickbuf); 280 - if(vinf) MikMod_free(vinf); 281 - if(Samples) MikMod_free(Samples); 285 + MikMod_free(vinf); 286 + MikMod_afree(vc_tickbuf); 287 + MikMod_afree(Samples); 282 288 283 289 vc_tickbuf = NULL; 284 290 vinf = NULL; 285 291 Samples = NULL; 286 - 292 + 287 293 VC_SetupPointers(); 288 294 } 289 295 ··· 309 315 310 316 void VC1_VoicePlay(UBYTE voice,SWORD handle,ULONG start,ULONG size,ULONG reppos,ULONG repend,UWORD flags) 311 317 { 312 - vinf[voice].flags = flags; 313 - vinf[voice].handle = handle; 314 - vinf[voice].start = start; 315 - vinf[voice].size = size; 316 - vinf[voice].reppos = reppos; 317 - vinf[voice].repend = repend; 318 - vinf[voice].kick = 1; 318 + vinf[voice].flags = flags; 319 + vinf[voice].handle = handle; 320 + vinf[voice].start = start; 321 + vinf[voice].size = size; 322 + vinf[voice].reppos = reppos; 323 + vinf[voice].repend = repend; 324 + vinf[voice].kick = 1; 319 325 } 320 326 321 327 void VC1_VoiceStop(UBYTE voice) 322 328 { 323 329 vinf[voice].active = 0; 324 - } 330 + } 325 331 326 332 int VC1_VoiceStopped(UBYTE voice) 327 333 { ··· 334 340 } 335 341 336 342 void VC1_VoiceSetVolume(UBYTE voice,UWORD vol) 337 - { 343 + { 338 344 /* protect against clicks if volume variation is too high */ 339 345 if(abs((int)vinf[voice].vol-(int)vol)>32) 340 346 vinf[voice].rampvol=CLICK_BUFFER; ··· 353 359 354 360 void VC1_SampleUnload(SWORD handle) 355 361 { 356 - if (handle<MAXSAMPLEHANDLES) { 357 - if (Samples[handle]) 358 - MikMod_free(Samples[handle]); 362 + if (Samples && (handle < MAXSAMPLEHANDLES)) { 363 + MikMod_afree(Samples[handle]); 359 364 Samples[handle]=NULL; 360 365 } 361 366 } ··· 364 369 { 365 370 SAMPLE *s = sload->sample; 366 371 int handle; 367 - ULONG t, length,loopstart,loopend; 372 + ULONG t, length,loopstart,loopend,looplen; 368 373 369 374 if(type==MD_HARDWARE) return -1; 370 375 376 + if(s->length > MAX_SAMPLE_SIZE) { 377 + _mm_errno = MMERR_NOT_A_STREAM; /* better error? */ 378 + return -1; 379 + } 380 + 371 381 /* Find empty slot to put sample address in */ 372 382 for(handle=0;handle<MAXSAMPLEHANDLES;handle++) 373 383 if(!Samples[handle]) break; ··· 376 386 _mm_errno = MMERR_OUT_OF_HANDLES; 377 387 return -1; 378 388 } 379 - 389 + 380 390 /* Reality check for loop settings */ 381 391 if (s->loopend > s->length) 382 392 s->loopend = s->length; ··· 390 400 SL_SampleSigned(sload); 391 401 SL_Sample8to16(sload); 392 402 393 - if(!(Samples[handle]=(SWORD*)MikMod_malloc((length+20)<<1))) { 403 + if(!(Samples[handle]=(SWORD*)MikMod_amalloc((length+20)<<1))) { 394 404 _mm_errno = MMERR_SAMPLE_TOO_BIG; 395 405 return -1; 396 406 } 397 407 398 408 /* read sample into buffer */ 399 - if (SL_Load(Samples[handle],sload,length)) 409 + if (SL_Load(Samples[handle],sload,length)) { 410 + MikMod_afree(Samples[handle]); 411 + Samples[handle]=NULL; 400 412 return -1; 413 + } 401 414 402 415 /* Unclick sample */ 403 416 if(s->flags & SF_LOOP) { 417 + looplen = loopend - loopstart;/* handle short samples */ 404 418 if(s->flags & SF_BIDI) 405 - for(t=0;t<16;t++) 419 + for(t=0;t<16 && t<looplen;t++) 406 420 Samples[handle][loopend+t]=Samples[handle][(loopend-t)-1]; 407 421 else 408 - for(t=0;t<16;t++) 422 + for(t=0;t<16 && t<looplen;t++) 409 423 Samples[handle][loopend+t]=Samples[handle][t+loopstart]; 410 424 } else 411 425 for(t=0;t<16;t++) ··· 416 430 417 431 ULONG VC1_SampleSpace(int type) 418 432 { 419 - (void)type; 433 + (void)type; 420 434 return vc_memory; 421 435 } 422 436 423 437 ULONG VC1_SampleLength(int type,SAMPLE* s) 424 438 { 425 - (void)type; 439 + (void)type; 426 440 if (!s) return 0; 427 441 428 442 return (s->length*((s->flags&SF_16BITS)?2:1))+16; ··· 456 470 return abs(k-j); 457 471 } 458 472 459 - 460 - #endif 473 + #endif /* _VIRTCH_COMMON_ */ 461 474 462 - MikMod_callback_t vc_callback; 463 - 464 - #endif 475 + #endif /* _IN_VIRTCH_ */ 465 476 466 477 /* ex:set ts=4: */
+1 -1
apps/plugins/viewers.config
··· 44 44 dsm,viewers/mikmod,7 45 45 far,viewers/mikmod,7 46 46 gdm,viewers/mikmod,7 47 - gt2,viewers/mikmod,7 48 47 imf,viewers/mikmod,7 49 48 it,viewers/mikmod,7 50 49 m15,viewers/mikmod,7 ··· 57 56 stx,viewers/mikmod,7 58 57 ult,viewers/mikmod,7 59 58 uni,viewers/mikmod,7 59 + umx,viewers/mikmod,7 60 60 xm,viewers/mikmod,7 61 61 pd,viewers/pdbox,2 62 62 rsp,viewers/searchengine,8