81 #ifndef INCLUDE_JAR_MOD_H 82 #define INCLUDE_JAR_MOD_H 86 #define JARMOD_MALLOC(sz) malloc(sz) 89 #define JARMOD_FREE(p) free(p) 94 typedef unsigned char muchar;
95 typedef unsigned short muint;
97 typedef unsigned long mulong;
99 #define NUMMAXCHANNELS 32 100 #define MAXNOTES 12*12 101 #define DEFAULT_SAMPLE_RATE 48000 129 muchar patterntable[128];
161 muchar vibrapointeur;
164 muint patternloopcnt;
165 muint patternloopstartpoint;
170 char* sampledata[31];
171 note* patterndata[128];
177 muint jump_loop_effect;
180 mulong patterntickse;
181 mulong patternticksaim;
182 mulong sampleticksconst;
184 channel channels[NUMMAXCHANNELS];
185 muint number_of_channels;
186 muint fullperiod[MAXNOTES * 8];
191 mint stereo_separation;
205 unsigned char instrument_number;
206 unsigned short cur_period;
207 unsigned char cur_volume;
208 unsigned short cur_effect;
209 unsigned short cur_parameffect;
214 int number_of_tracks;
219 int cur_pattern_table_pos;
220 unsigned int buf_index;
246 bool jar_mod_setcfg(
jar_mod_context_t * modctx,
int samplerate,
int bits,
int stereo,
int stereo_separation,
int filter);
262 #ifdef JAR_MOD_IMPLEMENTATION 269 #define EFFECT_ARPEGGIO 0x0 // Supported 270 #define EFFECT_PORTAMENTO_UP 0x1 // Supported 271 #define EFFECT_PORTAMENTO_DOWN 0x2 // Supported 272 #define EFFECT_TONE_PORTAMENTO 0x3 // Supported 273 #define EFFECT_VIBRATO 0x4 // Supported 274 #define EFFECT_VOLSLIDE_TONEPORTA 0x5 // Supported 275 #define EFFECT_VOLSLIDE_VIBRATO 0x6 // Supported 276 #define EFFECT_VOLSLIDE_TREMOLO 0x7 // - TO BE DONE - 277 #define EFFECT_SET_PANNING 0x8 // - TO BE DONE - 278 #define EFFECT_SET_OFFSET 0x9 // Supported 279 #define EFFECT_VOLUME_SLIDE 0xA // Supported 280 #define EFFECT_JUMP_POSITION 0xB // Supported 281 #define EFFECT_SET_VOLUME 0xC // Supported 282 #define EFFECT_PATTERN_BREAK 0xD // Supported 284 #define EFFECT_EXTENDED 0xE 285 #define EFFECT_E_FINE_PORTA_UP 0x1 // Supported 286 #define EFFECT_E_FINE_PORTA_DOWN 0x2 // Supported 287 #define EFFECT_E_GLISSANDO_CTRL 0x3 // - TO BE DONE - 288 #define EFFECT_E_VIBRATO_WAVEFORM 0x4 // - TO BE DONE - 289 #define EFFECT_E_SET_FINETUNE 0x5 // - TO BE DONE - 290 #define EFFECT_E_PATTERN_LOOP 0x6 // Supported 291 #define EFFECT_E_TREMOLO_WAVEFORM 0x7 // - TO BE DONE - 292 #define EFFECT_E_SET_PANNING_2 0x8 // - TO BE DONE - 293 #define EFFECT_E_RETRIGGER_NOTE 0x9 // - TO BE DONE - 294 #define EFFECT_E_FINE_VOLSLIDE_UP 0xA // Supported 295 #define EFFECT_E_FINE_VOLSLIDE_DOWN 0xB // Supported 296 #define EFFECT_E_NOTE_CUT 0xC // Supported 297 #define EFFECT_E_NOTE_DELAY 0xD // - TO BE DONE - 298 #define EFFECT_E_PATTERN_DELAY 0xE // Supported 299 #define EFFECT_E_INVERT_LOOP 0xF // - TO BE DONE - 300 #define EFFECT_SET_SPEED 0xF0 // Supported 301 #define EFFECT_SET_TEMPO 0xF2 // Supported 303 #define PERIOD_TABLE_LENGTH MAXNOTES 304 #define FULL_PERIOD_TABLE_LENGTH ( PERIOD_TABLE_LENGTH * 8 ) 306 static const short periodtable[]=
308 27392, 25856, 24384, 23040, 21696, 20480, 19328, 18240, 17216, 16256, 15360, 14496,
309 13696, 12928, 12192, 11520, 10848, 10240, 9664, 9120, 8606, 8128, 7680, 7248,
310 6848, 6464, 6096, 5760, 5424, 5120, 4832, 4560, 4304, 4064, 3840, 3624,
311 3424, 3232, 3048, 2880, 2712, 2560, 2416, 2280, 2152, 2032, 1920, 1812,
312 1712, 1616, 1524, 1440, 1356, 1280, 1208, 1140, 1076, 1016, 960, 906,
313 856, 808, 762, 720, 678, 640, 604, 570, 538, 508, 480, 453,
314 428, 404, 381, 360, 339, 320, 302, 285, 269, 254, 240, 226,
315 214, 202, 190, 180, 170, 160, 151, 143, 135, 127, 120, 113,
316 107, 101, 95, 90, 85, 80, 75, 71, 67, 63, 60, 56,
317 53, 50, 47, 45, 42, 40, 37, 35, 33, 31, 30, 28,
318 27, 25, 24, 22, 21, 20, 19, 18, 17, 16, 15, 14,
319 13, 13, 12, 11, 11, 10, 9, 9, 8, 8, 7, 7
322 static const short sintable[]={
323 0, 24, 49, 74, 97, 120, 141,161,
324 180, 197, 212, 224, 235, 244, 250,253,
325 255, 253, 250, 244, 235, 224, 212,197,
326 180, 161, 141, 120, 97, 74, 49, 24
329 typedef struct modtype_
331 unsigned char signature[5];
332 int numberofchannels;
361 static void memcopy(
void * dest,
void *source,
unsigned long size )
364 unsigned char * d,*s;
366 d=(
unsigned char*)dest;
367 s=(
unsigned char*)source;
374 static void memclear(
void * dest,
unsigned char value,
unsigned long size )
379 d=(
unsigned char*)dest;
386 static int memcompare(
unsigned char * buf1,
unsigned char * buf2,
unsigned int size )
394 if(buf1[i] != buf2[i])
404 static int getnote(
jar_mod_context_t * mod,
unsigned short period,
int finetune )
408 for(i = 0; i < FULL_PERIOD_TABLE_LENGTH; i++)
410 if(period >= mod->fullperiod[i])
421 muint
sample, period, effect, operiod;
422 muint curnote, arpnote;
424 sample = (nptr->sampperiod & 0xF0) | (nptr->sampeffect >> 4);
425 period = ((nptr->sampperiod & 0xF) << 8) | nptr->period;
426 effect = ((nptr->sampeffect & 0xF) << 8) | nptr->effect;
428 operiod = cptr->period;
430 if ( period || sample )
432 if( sample && sample < 32 )
434 cptr->sampnum = sample - 1;
437 if( period || sample )
439 cptr->sampdata = (
char *) mod->sampledata[cptr->sampnum];
440 cptr->length = mod->song.samples[cptr->sampnum].length;
441 cptr->reppnt = mod->song.samples[cptr->sampnum].reppnt;
442 cptr->replen = mod->song.samples[cptr->sampnum].replen;
444 cptr->finetune = (mod->song.samples[cptr->sampnum].finetune)&0xF;
446 if(effect>>8!=4 && effect>>8!=6)
449 cptr->vibrapointeur=0;
453 if( (sample != 0) && ( (effect>>8) != EFFECT_VOLSLIDE_TONEPORTA ) )
455 cptr->volume = mod->song.samples[cptr->sampnum].volume;
456 cptr->volumeslide = 0;
459 if( ( (effect>>8) != EFFECT_TONE_PORTAMENTO && (effect>>8)!=EFFECT_VOLSLIDE_TONEPORTA) )
465 cptr->decalperiod = 0;
470 if( cptr->finetune <= 7 )
472 period = mod->fullperiod[getnote(mod,period,0) + cptr->finetune];
476 period = mod->fullperiod[getnote(mod,period,0) - (16 - (cptr->finetune)) ];
480 cptr->period = period;
486 cptr->parameffect = 0;
487 cptr->effect_code = effect;
491 case EFFECT_ARPEGGIO:
504 cptr->effect = EFFECT_ARPEGGIO;
505 cptr->parameffect = effect&0xff;
509 curnote = getnote(mod,cptr->period,cptr->finetune);
511 cptr->Arpperiods[0] = cptr->period;
513 arpnote = curnote + (((cptr->parameffect>>4)&0xF)*8);
514 if( arpnote >= FULL_PERIOD_TABLE_LENGTH )
515 arpnote = FULL_PERIOD_TABLE_LENGTH - 1;
517 cptr->Arpperiods[1] = mod->fullperiod[arpnote];
519 arpnote = curnote + (((cptr->parameffect)&0xF)*8);
520 if( arpnote >= FULL_PERIOD_TABLE_LENGTH )
521 arpnote = FULL_PERIOD_TABLE_LENGTH - 1;
523 cptr->Arpperiods[2] = mod->fullperiod[arpnote];
527 case EFFECT_PORTAMENTO_UP:
539 cptr->effect = EFFECT_PORTAMENTO_UP;
540 cptr->parameffect = effect&0xff;
543 case EFFECT_PORTAMENTO_DOWN:
552 cptr->effect = EFFECT_PORTAMENTO_DOWN;
553 cptr->parameffect = effect&0xff;
556 case EFFECT_TONE_PORTAMENTO:
568 cptr->effect = EFFECT_TONE_PORTAMENTO;
569 if( (effect&0xff) != 0 )
571 cptr->portaspeed = (short)(effect&0xff);
576 cptr->portaperiod = period;
577 cptr->period = operiod;
592 cptr->effect = EFFECT_VIBRATO;
593 if( ( effect & 0x0F ) != 0 )
594 cptr->vibraparam = (cptr->vibraparam & 0xF0) | ( effect & 0x0F );
595 if( ( effect & 0xF0 ) != 0 )
596 cptr->vibraparam = (cptr->vibraparam & 0x0F) | ( effect & 0xF0 );
600 case EFFECT_VOLSLIDE_TONEPORTA:
613 cptr->portaperiod = period;
614 cptr->period = operiod;
617 cptr->effect = EFFECT_VOLSLIDE_TONEPORTA;
618 if( ( effect & 0xFF ) != 0 )
619 cptr->volumeslide = ( effect & 0xFF );
623 case EFFECT_VOLSLIDE_VIBRATO:
632 cptr->effect = EFFECT_VOLSLIDE_VIBRATO;
633 if( (effect & 0xFF) != 0 )
634 cptr->volumeslide = (effect & 0xFF);
637 case EFFECT_SET_OFFSET:
646 cptr->samppos = ((effect>>4) * 4096) + ((effect&0xF)*256);
650 case EFFECT_VOLUME_SLIDE:
659 cptr->effect = EFFECT_VOLUME_SLIDE;
660 cptr->volumeslide = (effect & 0xFF);
663 case EFFECT_JUMP_POSITION:
672 mod->tablepos = (effect & 0xFF);
673 if(mod->tablepos >= mod->song.length)
678 mod->jump_loop_effect = 1;
682 case EFFECT_SET_VOLUME:
689 cptr->volume = (effect & 0xFF);
692 case EFFECT_PATTERN_BREAK:
701 mod->patternpos = ( ((effect>>4)&0xF)*10 + (effect&0xF) ) * mod->number_of_channels;
702 mod->jump_loop_effect = 1;
704 if(mod->tablepos >= mod->song.length)
711 case EFFECT_EXTENDED:
712 switch( (effect>>4) & 0xF )
714 case EFFECT_E_FINE_PORTA_UP:
723 cptr->period -= (effect & 0xF);
724 if( cptr->period < 113 )
728 case EFFECT_E_FINE_PORTA_DOWN:
736 cptr->period += (effect & 0xF);
737 if( cptr->period > 856 )
741 case EFFECT_E_FINE_VOLSLIDE_UP:
750 cptr->volume += (effect & 0xF);
751 if( cptr->volume>64 )
755 case EFFECT_E_FINE_VOLSLIDE_DOWN:
763 cptr->volume -= (effect & 0xF);
764 if( cptr->volume > 200 )
768 case EFFECT_E_PATTERN_LOOP:
782 if( cptr->patternloopcnt )
784 cptr->patternloopcnt--;
785 if( cptr->patternloopcnt )
787 mod->patternpos = cptr->patternloopstartpoint;
788 mod->jump_loop_effect = 1;
792 cptr->patternloopstartpoint = mod->patternpos ;
797 cptr->patternloopcnt = (effect & 0xF);
798 mod->patternpos = cptr->patternloopstartpoint;
799 mod->jump_loop_effect = 1;
804 cptr->patternloopstartpoint = mod->patternpos;
809 case EFFECT_E_PATTERN_DELAY:
819 mod->patterndelay = (effect & 0xF);
822 case EFFECT_E_NOTE_CUT:
832 cptr->effect = EFFECT_E_NOTE_CUT;
833 cptr->cut_param = (effect & 0xF);
873 if( (effect&0xFF) < 0x21 )
877 mod->song.speed = effect&0xFF;
878 mod->patternticksaim = (long)mod->song.speed * ((mod->playrate * 5 ) / (((long)2 * (
long)mod->bpm)));
882 if( (effect&0xFF) >= 0x21 )
885 mod->bpm = effect&0xFF;
886 mod->patternticksaim = (long)mod->song.speed * ((mod->playrate * 5 ) / (((long)2 * (
long)mod->bpm)));
899 static void workeffect(
note * nptr,
channel * cptr )
903 case EFFECT_ARPEGGIO:
905 if( cptr->parameffect )
907 cptr->decalperiod = cptr->period - cptr->Arpperiods[cptr->ArpIndex];
910 if( cptr->ArpIndex>2 )
915 case EFFECT_PORTAMENTO_UP:
919 cptr->period -= cptr->parameffect;
921 if( cptr->period < 113 || cptr->period > 20000 )
927 case EFFECT_PORTAMENTO_DOWN:
931 cptr->period += cptr->parameffect;
933 if( cptr->period > 20000 )
934 cptr->period = 20000;
939 case EFFECT_VOLSLIDE_TONEPORTA:
940 case EFFECT_TONE_PORTAMENTO:
942 if( cptr->period && ( cptr->period != cptr->portaperiod ) && cptr->portaperiod )
944 if( cptr->period > cptr->portaperiod )
946 if( cptr->period - cptr->portaperiod >= cptr->portaspeed )
948 cptr->period -= cptr->portaspeed;
952 cptr->period = cptr->portaperiod;
957 if( cptr->portaperiod - cptr->period >= cptr->portaspeed )
959 cptr->period += cptr->portaspeed;
963 cptr->period = cptr->portaperiod;
967 if( cptr->period == cptr->portaperiod )
970 cptr->portaperiod = 0;
974 if( cptr->effect == EFFECT_VOLSLIDE_TONEPORTA )
976 if( cptr->volumeslide > 0x0F )
978 cptr->volume = cptr->volume + (cptr->volumeslide>>4);
985 cptr->volume = cptr->volume - (cptr->volumeslide);
993 case EFFECT_VOLSLIDE_VIBRATO:
996 cptr->vibraperiod = ( (cptr->vibraparam&0xF) * sintable[cptr->vibrapointeur&0x1F] )>>7;
998 if( cptr->vibrapointeur > 31 )
999 cptr->vibraperiod = -cptr->vibraperiod;
1001 cptr->vibrapointeur = (cptr->vibrapointeur+(((cptr->vibraparam>>4))&0xf)) & 0x3F;
1003 if( cptr->effect == EFFECT_VOLSLIDE_VIBRATO )
1005 if( cptr->volumeslide > 0xF )
1007 cptr->volume = cptr->volume+(cptr->volumeslide>>4);
1009 if( cptr->volume > 64 )
1014 cptr->volume = cptr->volume - cptr->volumeslide;
1016 if( cptr->volume > 64 )
1023 case EFFECT_VOLUME_SLIDE:
1025 if( cptr->volumeslide > 0xF )
1027 cptr->volume += (cptr->volumeslide>>4);
1029 if( cptr->volume > 64 )
1034 cptr->volume -= (cptr->volumeslide&0xf);
1036 if( cptr->volume > 64 )
1041 case EFFECT_E_NOTE_CUT:
1045 if(!cptr->cut_param)
1064 modctx->playrate = DEFAULT_SAMPLE_RATE;
1066 modctx->stereo_separation = 1;
1070 for(i=0; i < PERIOD_TABLE_LENGTH - 1; i++)
1072 for(j=0; j < 8; j++)
1074 modctx->fullperiod[(i*8) + j] = periodtable[i] - ((( periodtable[i] - periodtable[i+1] ) / 8) * j);
1084 bool jar_mod_setcfg(
jar_mod_context_t * modctx,
int samplerate,
int bits,
int stereo,
int stereo_separation,
int filter)
1088 modctx->playrate = samplerate;
1095 if(stereo_separation < 4)
1097 modctx->stereo_separation = stereo_separation;
1100 if( bits == 8 || bits == 16 )
1101 modctx->bits = bits;
1117 static bool jar_mod_load(
jar_mod_context_t * modctx,
void * mod_data,
int mod_data_size )
1122 unsigned char * modmemory,* endmodmemory;
1124 modmemory = (
unsigned char *)mod_data;
1125 endmodmemory = modmemory + mod_data_size;
1133 memcopy(&(modctx->song.title),modmemory,1084);
1136 modctx->number_of_channels = 0;
1137 while(modlist[i].numberofchannels)
1139 if(memcompare(modctx->song.signature,modlist[i].signature,4))
1141 modctx->number_of_channels = modlist[i].numberofchannels;
1147 if( !modctx->number_of_channels )
1151 memcopy(&(modctx->song.signature),
"M.K.", 4);
1152 memcopy(&(modctx->song.length), &(modctx->song.samples[15]), 130);
1153 memclear(&(modctx->song.samples[15]), 0, 480);
1155 modctx->number_of_channels = 4;
1162 if( modmemory >= endmodmemory )
1166 for (i = max = 0; i < 128; i++)
1168 while (max <= modctx->song.patterntable[i])
1170 modctx->patterndata[max] = (
note*)modmemory;
1171 modmemory += (256*modctx->number_of_channels);
1174 if( modmemory >= endmodmemory )
1179 for (i = 0; i < 31; i++)
1180 modctx->sampledata[i]=0;
1183 for (i = 0, sptr = modctx->song.samples; i <31; i++, sptr++)
1185 t= (sptr->length &0xFF00)>>8 | (sptr->length &0xFF)<<8;
1188 t= (sptr->reppnt &0xFF00)>>8 | (sptr->reppnt &0xFF)<<8;
1191 t= (sptr->replen &0xFF00)>>8 | (sptr->replen &0xFF)<<8;
1195 if (sptr->length == 0)
continue;
1197 modctx->sampledata[i] = (
char*)modmemory;
1198 modmemory += sptr->length;
1200 if (sptr->replen + sptr->reppnt > sptr->length)
1201 sptr->replen = sptr->length - sptr->reppnt;
1203 if( modmemory > endmodmemory )
1209 modctx->tablepos = 0;
1210 modctx->patternpos = 0;
1211 modctx->song.speed = 6;
1213 modctx->samplenb = 0;
1215 modctx->patternticks = (((long)modctx->song.speed * modctx->playrate * 5)/ (2 * modctx->bpm)) + 1;
1216 modctx->patternticksaim = ((long)modctx->song.speed * modctx->playrate * 5) / (2 * modctx->bpm);
1218 modctx->sampleticksconst = 3546894UL / modctx->playrate;
1220 for(i=0; i < modctx->number_of_channels; i++)
1222 modctx->channels[i].volume = 0;
1223 modctx->channels[i].period = 0;
1226 modctx->mod_loaded = 1;
1240 unsigned int state_remaining_steps;
1248 if( modctx && outbuffer )
1250 if(modctx->mod_loaded)
1252 state_remaining_steps = 0;
1256 trkbuf->cur_rd_index = 0;
1258 memcopy(trkbuf->name,modctx->song.title,
sizeof(modctx->song.title));
1262 memcopy(trkbuf->instruments[i].name,modctx->song.samples[i].name,
sizeof(trkbuf->instruments[i].name));
1266 ll = modctx->last_l_sample;
1267 lr = modctx->last_r_sample;
1269 for (i = 0; i < nbsample; i++)
1272 if( modctx->patternticks++ > modctx->patternticksaim )
1274 if( !modctx->patterndelay )
1276 nptr = modctx->patterndata[modctx->song.patterntable[modctx->tablepos]];
1277 nptr = nptr + modctx->patternpos;
1278 cptr = modctx->channels;
1280 modctx->patternticks = 0;
1281 modctx->patterntickse = 0;
1283 for(c=0;c<modctx->number_of_channels;c++)
1285 worknote((
note*)(nptr+c), (
channel*)(cptr+c),(
char)(c+1),modctx);
1288 if( !modctx->jump_loop_effect )
1289 modctx->patternpos += modctx->number_of_channels;
1291 modctx->jump_loop_effect = 0;
1293 if( modctx->patternpos == 64*modctx->number_of_channels )
1296 modctx->patternpos = 0;
1297 if(modctx->tablepos >= modctx->song.length)
1299 modctx->tablepos = 0;
1300 modctx->loopcount++;
1306 modctx->patterndelay--;
1307 modctx->patternticks = 0;
1308 modctx->patterntickse = 0;
1313 if( modctx->patterntickse++ > (modctx->patternticksaim/modctx->song.speed) )
1315 nptr = modctx->patterndata[modctx->song.patterntable[modctx->tablepos]];
1316 nptr = nptr + modctx->patternpos;
1317 cptr = modctx->channels;
1319 for(c=0;c<modctx->number_of_channels;c++)
1321 workeffect(nptr+c, cptr+c);
1324 modctx->patterntickse = 0;
1329 if( trkbuf && !state_remaining_steps )
1331 if( trkbuf->nb_of_state < trkbuf->nb_max_of_state )
1333 memclear(&trkbuf->track_state_buf[trkbuf->nb_of_state], 0,
sizeof(
tracker_state));
1340 for(j =0, cptr = modctx->channels; j < modctx->number_of_channels ; j++, cptr++)
1342 if( cptr->period != 0 )
1344 finalperiod = cptr->period - cptr->decalperiod - cptr->vibraperiod;
1347 cptr->samppos += ( (modctx->sampleticksconst<<10) / finalperiod );
1352 if( cptr->replen<=2 )
1354 if( (cptr->samppos>>10) >= (cptr->length) )
1360 cptr->samppos = cptr->samppos % (((
unsigned long)cptr->length)<<10);
1367 if( (cptr->samppos>>10) >= (
unsigned long)(cptr->replen+cptr->reppnt) )
1369 cptr->samppos = ((
unsigned long)(cptr->reppnt)<<10) + (cptr->samppos % ((
unsigned long)(cptr->replen+cptr->reppnt)<<10));
1373 k = cptr->samppos >> 10;
1375 if( cptr->sampdata!=0 && ( ((j&3)==1) || ((j&3)==2) ) )
1377 r += ( cptr->sampdata[k] * cptr->volume );
1380 if( cptr->sampdata!=0 && ( ((j&3)==0) || ((j&3)==3) ) )
1382 l += ( cptr->sampdata[k] * cptr->volume );
1385 if( trkbuf && !state_remaining_steps )
1387 if( trkbuf->nb_of_state < trkbuf->nb_max_of_state )
1389 trkbuf->track_state_buf[trkbuf->nb_of_state].number_of_tracks = modctx->number_of_channels;
1390 trkbuf->track_state_buf[trkbuf->nb_of_state].buf_index = i;
1391 trkbuf->track_state_buf[trkbuf->nb_of_state].cur_pattern = modctx->song.patterntable[modctx->tablepos];
1392 trkbuf->track_state_buf[trkbuf->nb_of_state].cur_pattern_pos = modctx->patternpos / modctx->number_of_channels;
1393 trkbuf->track_state_buf[trkbuf->nb_of_state].cur_pattern_table_pos = modctx->tablepos;
1394 trkbuf->track_state_buf[trkbuf->nb_of_state].bpm = modctx->bpm;
1395 trkbuf->track_state_buf[trkbuf->nb_of_state].speed = modctx->song.speed;
1396 trkbuf->track_state_buf[trkbuf->nb_of_state].tracks[j].cur_effect = cptr->effect_code;
1397 trkbuf->track_state_buf[trkbuf->nb_of_state].tracks[j].cur_parameffect = cptr->parameffect;
1398 trkbuf->track_state_buf[trkbuf->nb_of_state].tracks[j].cur_period = finalperiod;
1399 trkbuf->track_state_buf[trkbuf->nb_of_state].tracks[j].cur_volume = cptr->volume;
1400 trkbuf->track_state_buf[trkbuf->nb_of_state].tracks[j].instrument_number = (
unsigned char)cptr->sampnum;
1406 if( trkbuf && !state_remaining_steps )
1408 state_remaining_steps = trkbuf->sample_step;
1410 if(trkbuf->nb_of_state < trkbuf->nb_max_of_state)
1411 trkbuf->nb_of_state++;
1415 state_remaining_steps--;
1421 if ( modctx->filter )
1428 if ( modctx->stereo_separation == 1 )
1436 if( l > 32767 ) l = 32767;
1437 if( l < -32768 ) l = -32768;
1438 if( r > 32767 ) r = 32767;
1439 if( r < -32768 ) r = -32768;
1442 outbuffer[(i*2)] = l;
1443 outbuffer[(i*2)+1] = r;
1450 modctx->last_l_sample = ll;
1451 modctx->last_r_sample = lr;
1453 modctx->samplenb = modctx->samplenb+nbsample;
1457 for (i = 0; i < nbsample; i++)
1460 outbuffer[(i*2)] = 0;
1461 outbuffer[(i*2)+1] = 0;
1466 trkbuf->nb_of_state = 0;
1467 trkbuf->cur_rd_index = 0;
1468 trkbuf->name[0] = 0;
1469 memclear(trkbuf->track_state_buf, 0,
sizeof(
tracker_state) * trkbuf->nb_max_of_state);
1470 memclear(trkbuf->instruments, 0,
sizeof(trkbuf->instruments));
1481 memclear(&modctx->song, 0,
sizeof(modctx->song));
1482 memclear(&modctx->sampledata, 0,
sizeof(modctx->sampledata));
1483 memclear(&modctx->patterndata, 0,
sizeof(modctx->patterndata));
1484 modctx->tablepos = 0;
1485 modctx->patternpos = 0;
1486 modctx->patterndelay = 0;
1487 modctx->jump_loop_effect = 0;
1489 modctx->patternticks = 0;
1490 modctx->patterntickse = 0;
1491 modctx->patternticksaim = 0;
1492 modctx->sampleticksconst = 0;
1493 modctx->samplenb = 0;
1494 memclear(modctx->channels, 0,
sizeof(modctx->channels));
1495 modctx->number_of_channels = 0;
1496 modctx->mod_loaded = 0;
1497 modctx->last_r_sample = 0;
1498 modctx->last_l_sample = 0;
1500 return jar_mod_init(modctx);
1511 JARMOD_FREE(modctx->modfile);
1512 modctx->modfile = 0;
1513 modctx->modfilesize = 0;
1514 modctx->loopcount = 0;
1516 jar_mod_reset(modctx);
1525 JARMOD_FREE(modctx->modfile);
1526 modctx->modfile = 0;
1529 FILE *f = fopen(filename,
"rb");
1532 fseek(f,0,SEEK_END);
1534 fseek(f,0,SEEK_SET);
1536 if(fsize && fsize < 32*1024*1024)
1538 modctx->modfile = JARMOD_MALLOC(fsize);
1539 modctx->modfilesize = fsize;
1540 memset(modctx->modfile, 0, fsize);
1541 fread(modctx->modfile, fsize, 1, f);
1544 if(!jar_mod_load(modctx, (
void*)modctx->modfile, fsize)) fsize = 0;
1553 return modctx->samplenb;
1563 mulong lastcount = ctx->loopcount;
1565 while(ctx->loopcount <= lastcount)
1566 jar_mod_fillbuffer(ctx, buff, 1, 0);
1568 len = ctx->samplenb;
1569 jar_mod_seek_start(ctx);
1577 if(ctx && ctx->modfile)
1579 muchar* ftmp = ctx->modfile;
1580 mulong stmp = ctx->modfilesize;
1581 muint lcnt = ctx->loopcount;
1583 if(jar_mod_reset(ctx)){
1584 jar_mod_load(ctx, ftmp, stmp);
1585 ctx->modfile = ftmp;
1586 ctx->modfilesize = stmp;
1587 ctx->loopcount = lcnt;
1592 #endif // end of JAR_MOD_IMPLEMENTATION 1596 #endif //end of header file Definition: jar_mod.h:117
Definition: jar_mod.h:168
Definition: jar_mod.h:124
Definition: jar_mod.h:224
Definition: jar_mod.h:108
Definition: jar_mod.h:139
Definition: jar_mod.h:212
Definition: jar_mod.h:203
Definition: jar_mod.h:230