2022-01-17 23:18:28 +00:00
|
|
|
#define _USE_MATH_DEFINES
|
2021-12-07 06:23:57 +00:00
|
|
|
#include "dispatch.h"
|
2021-05-12 08:58:55 +00:00
|
|
|
#include "engine.h"
|
2021-12-07 09:22:36 +00:00
|
|
|
#include "../ta-log.h"
|
2022-01-04 05:29:59 +00:00
|
|
|
#include <math.h>
|
2021-12-07 17:21:23 +00:00
|
|
|
#include <sndfile.h>
|
2021-05-12 08:58:55 +00:00
|
|
|
|
2022-01-18 02:08:14 +00:00
|
|
|
constexpr int MASTER_CLOCK_PREC=(sizeof(void*)==8)?8:0;
|
|
|
|
|
2021-05-12 08:58:55 +00:00
|
|
|
void DivEngine::nextOrder() {
|
|
|
|
curRow=0;
|
2021-12-21 22:42:27 +00:00
|
|
|
if (repeatPattern) return;
|
2021-05-12 08:58:55 +00:00
|
|
|
if (++curOrder>=song.ordersLen) {
|
2021-12-07 09:22:36 +00:00
|
|
|
endOfSong=true;
|
2021-05-12 08:58:55 +00:00
|
|
|
curOrder=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* notes[12]={
|
|
|
|
"C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#", "B-"
|
|
|
|
};
|
|
|
|
|
2021-05-19 07:05:24 +00:00
|
|
|
const char* cmdName[DIV_CMD_MAX]={
|
|
|
|
"NOTE_ON",
|
|
|
|
"NOTE_OFF",
|
|
|
|
"INSTRUMENT",
|
|
|
|
"VOLUME",
|
|
|
|
"GET_VOLUME",
|
|
|
|
"GET_VOLMAX",
|
|
|
|
"NOTE_PORTA",
|
|
|
|
"PITCH",
|
|
|
|
"PANNING",
|
|
|
|
"LEGATO",
|
|
|
|
"PRE_PORTA",
|
2021-12-05 21:11:12 +00:00
|
|
|
"PRE_NOTE",
|
2021-05-19 07:05:24 +00:00
|
|
|
|
|
|
|
"SAMPLE_MODE",
|
2021-12-08 23:29:50 +00:00
|
|
|
"SAMPLE_FREQ",
|
2021-12-09 08:13:37 +00:00
|
|
|
"SAMPLE_BANK",
|
2021-05-19 07:05:24 +00:00
|
|
|
|
2021-06-06 04:27:02 +00:00
|
|
|
"FM_LFO",
|
2021-12-09 05:46:48 +00:00
|
|
|
"FM_LFO_WAVE",
|
2021-05-19 07:05:24 +00:00
|
|
|
"FM_TL",
|
|
|
|
"FM_AR",
|
|
|
|
"FM_FB",
|
|
|
|
"FM_MULT",
|
|
|
|
"FM_EXTCH",
|
|
|
|
|
|
|
|
"GENESIS_LFO",
|
|
|
|
|
|
|
|
"ARCADE_LFO",
|
|
|
|
|
|
|
|
"STD_NOISE_FREQ",
|
2021-05-28 05:36:25 +00:00
|
|
|
"STD_NOISE_MODE",
|
|
|
|
|
|
|
|
"WAVE",
|
|
|
|
|
|
|
|
"GB_SWEEP_TIME",
|
|
|
|
"GB_SWEEP_DIR",
|
|
|
|
|
2021-06-09 06:08:42 +00:00
|
|
|
"PCE_LFO_MODE",
|
|
|
|
"PCE_LFO_SPEED",
|
|
|
|
|
2021-12-07 06:23:57 +00:00
|
|
|
"C64_CUTOFF",
|
|
|
|
"C64_RESONANCE",
|
|
|
|
"C64_FILTER_MODE",
|
|
|
|
"C64_RESET_TIME",
|
|
|
|
"C64_RESET_MASK",
|
|
|
|
"C64_FILTER_RESET",
|
|
|
|
"C64_DUTY_RESET",
|
|
|
|
"C64_EXTENDED",
|
2022-01-11 23:38:26 +00:00
|
|
|
"C64_FINE_DUTY",
|
|
|
|
"C64_FINE_CUTOFF",
|
2021-12-07 06:23:57 +00:00
|
|
|
|
2021-12-09 22:06:28 +00:00
|
|
|
"AY_ENVELOPE_SET",
|
|
|
|
"AY_ENVELOPE_LOW",
|
|
|
|
"AY_ENVELOPE_HIGH",
|
2022-01-11 23:38:26 +00:00
|
|
|
"AY_ENVELOPE_SLIDE",
|
2022-01-18 23:21:27 +00:00
|
|
|
"AY_NOISE_MASK_AND",
|
|
|
|
"AY_NOISE_MASK_OR",
|
2021-12-09 22:06:28 +00:00
|
|
|
|
2022-01-15 04:26:22 +00:00
|
|
|
"SAA_ENVELOPE",
|
|
|
|
|
2021-05-28 05:36:25 +00:00
|
|
|
"ALWAYS_SET_VOLUME"
|
2021-05-19 07:05:24 +00:00
|
|
|
};
|
|
|
|
|
2021-05-12 08:58:55 +00:00
|
|
|
const char* formatNote(unsigned char note, unsigned char octave) {
|
|
|
|
static char ret[4];
|
|
|
|
if (note==100) {
|
|
|
|
return "OFF";
|
2021-05-13 07:39:26 +00:00
|
|
|
} else if (octave==0 && note==0) {
|
2021-05-12 08:58:55 +00:00
|
|
|
return "---";
|
|
|
|
}
|
|
|
|
snprintf(ret,4,"%s%d",notes[note%12],octave+note/12);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-05-19 07:05:24 +00:00
|
|
|
int DivEngine::dispatchCmd(DivCommand c) {
|
|
|
|
if (view==DIV_STATUS_COMMANDS) {
|
2022-01-12 07:45:26 +00:00
|
|
|
printf("%8d | %d: %s(%d, %d)\n",totalTicksR,c.chan,cmdName[c.cmd],c.value,c.value2);
|
2021-05-19 07:05:24 +00:00
|
|
|
}
|
|
|
|
totalCmds++;
|
2022-01-08 21:03:32 +00:00
|
|
|
c.chan=dispatchChanOfChan[c.dis];
|
|
|
|
return disCont[dispatchOfChan[c.dis]].dispatch->dispatch(c);
|
2021-05-19 07:05:24 +00:00
|
|
|
}
|
|
|
|
|
2021-05-13 07:39:26 +00:00
|
|
|
bool DivEngine::perSystemEffect(int ch, unsigned char effect, unsigned char effectVal) {
|
2022-01-08 21:03:32 +00:00
|
|
|
switch (sysOfChan[ch]) {
|
2021-05-13 07:39:26 +00:00
|
|
|
case DIV_SYSTEM_GENESIS:
|
2021-05-16 22:43:10 +00:00
|
|
|
case DIV_SYSTEM_GENESIS_EXT:
|
2022-01-13 06:03:57 +00:00
|
|
|
case DIV_SYSTEM_YM2612:
|
2021-05-13 07:39:26 +00:00
|
|
|
switch (effect) {
|
|
|
|
case 0x17: // DAC enable
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_SAMPLE_MODE,ch,(effectVal>0)));
|
2021-05-13 07:39:26 +00:00
|
|
|
break;
|
2021-05-16 08:03:23 +00:00
|
|
|
case 0x20: // SN noise mode
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_MODE,ch,effectVal));
|
2021-05-16 08:03:23 +00:00
|
|
|
break;
|
2021-05-13 07:39:26 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2021-05-15 19:18:16 +00:00
|
|
|
case DIV_SYSTEM_SMS:
|
|
|
|
switch (effect) {
|
|
|
|
case 0x20: // SN noise mode
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_MODE,ch,effectVal));
|
2021-05-15 19:18:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2021-05-28 05:36:25 +00:00
|
|
|
case DIV_SYSTEM_GB:
|
|
|
|
switch (effect) {
|
|
|
|
case 0x10: // select waveform
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_WAVE,ch,effectVal));
|
|
|
|
break;
|
2021-05-28 06:26:57 +00:00
|
|
|
case 0x11: case 0x12: // duty or noise mode
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_MODE,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x13: // sweep params
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_GB_SWEEP_TIME,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x14: // sweep direction
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_GB_SWEEP_DIR,ch,effectVal));
|
|
|
|
break;
|
2021-05-28 05:36:25 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2021-06-09 01:45:38 +00:00
|
|
|
case DIV_SYSTEM_PCE:
|
|
|
|
switch (effect) {
|
|
|
|
case 0x10: // select waveform
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_WAVE,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x11: // noise mode
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_MODE,ch,effectVal));
|
|
|
|
break;
|
2021-06-09 06:08:42 +00:00
|
|
|
case 0x12: // LFO mode
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_PCE_LFO_MODE,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x13: // LFO speed
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_PCE_LFO_SPEED,ch,effectVal));
|
|
|
|
break;
|
2021-06-09 04:16:29 +00:00
|
|
|
case 0x17: // PCM enable
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_SAMPLE_MODE,ch,(effectVal>0)));
|
|
|
|
break;
|
2021-06-09 01:45:38 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2021-12-04 07:19:14 +00:00
|
|
|
case DIV_SYSTEM_NES:
|
|
|
|
switch (effect) {
|
|
|
|
case 0x12: // duty or noise mode
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_MODE,ch,effectVal));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2021-05-13 07:39:26 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-15 08:13:21 +00:00
|
|
|
bool DivEngine::perSystemPostEffect(int ch, unsigned char effect, unsigned char effectVal) {
|
2022-01-08 21:03:32 +00:00
|
|
|
switch (sysOfChan[ch]) {
|
2021-05-15 08:13:21 +00:00
|
|
|
case DIV_SYSTEM_GENESIS:
|
2021-05-16 22:43:10 +00:00
|
|
|
case DIV_SYSTEM_GENESIS_EXT:
|
2022-01-13 06:03:57 +00:00
|
|
|
case DIV_SYSTEM_YM2612:
|
2021-12-09 05:46:48 +00:00
|
|
|
case DIV_SYSTEM_ARCADE:
|
2022-01-13 06:03:57 +00:00
|
|
|
case DIV_SYSTEM_YM2151:
|
2021-12-09 22:06:28 +00:00
|
|
|
case DIV_SYSTEM_YM2610:
|
|
|
|
case DIV_SYSTEM_YM2610_EXT:
|
2021-05-15 08:13:21 +00:00
|
|
|
switch (effect) {
|
2021-12-09 05:46:48 +00:00
|
|
|
case 0x10: // LFO or noise mode
|
2022-01-13 06:03:57 +00:00
|
|
|
if (sysOfChan[ch]==DIV_SYSTEM_ARCADE || sysOfChan[ch]==DIV_SYSTEM_YM2151) {
|
2021-12-09 05:46:48 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_FREQ,ch,effectVal));
|
|
|
|
} else {
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_LFO,ch,effectVal));
|
|
|
|
}
|
2021-06-06 04:27:02 +00:00
|
|
|
break;
|
2021-05-15 08:13:21 +00:00
|
|
|
case 0x11: // FB
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_FB,ch,effectVal&7));
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
|
|
|
case 0x12: // TL op1
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_TL,ch,0,effectVal&0x7f));
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
|
|
|
case 0x13: // TL op2
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_TL,ch,1,effectVal&0x7f));
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
|
|
|
case 0x14: // TL op3
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_TL,ch,2,effectVal&0x7f));
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
|
|
|
case 0x15: // TL op4
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_TL,ch,3,effectVal&0x7f));
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
|
|
|
case 0x16: // MULT
|
|
|
|
if ((effectVal>>4)>0 && (effectVal>>4)<5) {
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_MULT,ch,(effectVal>>4)-1,effectVal&15));
|
2021-05-15 08:13:21 +00:00
|
|
|
}
|
|
|
|
break;
|
2021-12-09 05:46:48 +00:00
|
|
|
case 0x17: // arcade LFO
|
2022-01-13 06:03:57 +00:00
|
|
|
if (sysOfChan[ch]==DIV_SYSTEM_ARCADE || sysOfChan[ch]==DIV_SYSTEM_YM2151) {
|
2021-12-09 05:46:48 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_LFO,ch,effectVal));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x18: // EXT or LFO waveform
|
2022-01-13 06:03:57 +00:00
|
|
|
if (sysOfChan[ch]==DIV_SYSTEM_ARCADE || sysOfChan[ch]==DIV_SYSTEM_YM2151) {
|
2021-12-09 05:46:48 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_LFO_WAVE,ch,effectVal));
|
|
|
|
} else {
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_EXTCH,ch,effectVal));
|
|
|
|
}
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
|
|
|
case 0x19: // AR global
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_AR,ch,-1,effectVal&31));
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
|
|
|
case 0x1a: // AR op1
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_AR,ch,0,effectVal&31));
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
|
|
|
case 0x1b: // AR op2
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_AR,ch,1,effectVal&31));
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
|
|
|
case 0x1c: // AR op3
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_AR,ch,2,effectVal&31));
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
|
|
|
case 0x1d: // AR op4
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_FM_AR,ch,3,effectVal&31));
|
2021-05-15 08:13:21 +00:00
|
|
|
break;
|
2021-12-09 22:06:28 +00:00
|
|
|
case 0x20: // PCM frequency or Neo Geo PSG mode
|
2022-01-13 06:03:57 +00:00
|
|
|
if (sysOfChan[ch]==DIV_SYSTEM_ARCADE || sysOfChan[ch]==DIV_SYSTEM_YM2151) {
|
2021-12-09 05:46:48 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_SAMPLE_FREQ,ch,effectVal));
|
2022-01-08 21:03:32 +00:00
|
|
|
} else if (sysOfChan[ch]==DIV_SYSTEM_YM2610 || sysOfChan[ch]==DIV_SYSTEM_YM2610_EXT) {
|
2021-12-09 22:06:28 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_MODE,ch,effectVal));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x21: // Neo Geo PSG noise freq
|
2022-01-08 21:03:32 +00:00
|
|
|
if (sysOfChan[ch]==DIV_SYSTEM_YM2610 || sysOfChan[ch]==DIV_SYSTEM_YM2610_EXT) {
|
2021-12-09 22:06:28 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_FREQ,ch,effectVal));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x22: // UNOFFICIAL: Neo Geo PSG envelope enable
|
2022-01-08 21:03:32 +00:00
|
|
|
if (sysOfChan[ch]==DIV_SYSTEM_YM2610 || sysOfChan[ch]==DIV_SYSTEM_YM2610_EXT) {
|
2021-12-09 22:06:28 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_AY_ENVELOPE_SET,ch,effectVal));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x23: // UNOFFICIAL: Neo Geo PSG envelope period low
|
2022-01-08 21:03:32 +00:00
|
|
|
if (sysOfChan[ch]==DIV_SYSTEM_YM2610 || sysOfChan[ch]==DIV_SYSTEM_YM2610_EXT) {
|
2021-12-09 22:06:28 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_AY_ENVELOPE_LOW,ch,effectVal));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x24: // UNOFFICIAL: Neo Geo PSG envelope period high
|
2022-01-08 21:03:32 +00:00
|
|
|
if (sysOfChan[ch]==DIV_SYSTEM_YM2610 || sysOfChan[ch]==DIV_SYSTEM_YM2610_EXT) {
|
2021-12-09 22:06:28 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_AY_ENVELOPE_HIGH,ch,effectVal));
|
2021-12-09 05:46:48 +00:00
|
|
|
}
|
|
|
|
break;
|
2022-01-11 23:38:26 +00:00
|
|
|
case 0x25: // UNOFFICIAL: Neo Geo PSG envelope slide up
|
|
|
|
if (sysOfChan[ch]==DIV_SYSTEM_YM2610 || sysOfChan[ch]==DIV_SYSTEM_YM2610_EXT) {
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_AY_ENVELOPE_SLIDE,ch,-effectVal));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x26: // UNOFFICIAL: Neo Geo PSG envelope slide down
|
|
|
|
if (sysOfChan[ch]==DIV_SYSTEM_YM2610 || sysOfChan[ch]==DIV_SYSTEM_YM2610_EXT) {
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_AY_ENVELOPE_SLIDE,ch,effectVal));
|
|
|
|
}
|
|
|
|
break;
|
2021-05-15 08:13:21 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2021-12-14 17:40:26 +00:00
|
|
|
case DIV_SYSTEM_C64_6581: case DIV_SYSTEM_C64_8580:
|
2021-12-07 06:23:57 +00:00
|
|
|
switch (effect) {
|
|
|
|
case 0x10: // select waveform
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_WAVE,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x11: // cutoff
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_C64_CUTOFF,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x12: // duty
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_MODE,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x13: // resonance
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_C64_RESONANCE,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x14: // filter mode
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_C64_FILTER_MODE,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x15: // reset time
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_C64_RESET_TIME,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x1a: // reset mask
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_C64_RESET_MASK,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x1b: // cutoff reset
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_C64_FILTER_RESET,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x1c: // duty reset
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_C64_DUTY_RESET,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x1e: // extended
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_C64_EXTENDED,ch,effectVal));
|
|
|
|
break;
|
2022-01-11 23:38:26 +00:00
|
|
|
case 0x30: case 0x31: case 0x32: case 0x33:
|
|
|
|
case 0x34: case 0x35: case 0x36: case 0x37:
|
|
|
|
case 0x38: case 0x39: case 0x3a: case 0x3b:
|
|
|
|
case 0x3c: case 0x3d: case 0x3e: case 0x3f: // fine duty
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_C64_FINE_DUTY,ch,((effect&0x0f)<<8)|effectVal));
|
|
|
|
break;
|
|
|
|
case 0x40: case 0x41: case 0x42: case 0x43:
|
|
|
|
case 0x44: case 0x45: case 0x46: case 0x47: // fine cutoff
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_C64_FINE_CUTOFF,ch,((effect&0x07)<<8)|effectVal));
|
|
|
|
break;
|
2021-12-07 06:23:57 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2021-12-14 17:40:26 +00:00
|
|
|
break;
|
2022-01-13 07:52:19 +00:00
|
|
|
case DIV_SYSTEM_AY8910:
|
2022-01-14 05:02:10 +00:00
|
|
|
case DIV_SYSTEM_AY8930:
|
2022-01-13 07:52:19 +00:00
|
|
|
switch (effect) {
|
2022-01-14 05:02:10 +00:00
|
|
|
case 0x12: // duty on 8930
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_MODE,ch,0x10+effectVal));
|
|
|
|
break;
|
2022-01-13 07:52:19 +00:00
|
|
|
case 0x20: // mode
|
2022-01-14 05:02:10 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_MODE,ch,effectVal&15));
|
2022-01-13 07:52:19 +00:00
|
|
|
break;
|
|
|
|
case 0x21: // noise freq
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_FREQ,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x22: // envelope enable
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_AY_ENVELOPE_SET,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x23: // envelope period low
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_AY_ENVELOPE_LOW,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x24: // envelope period high
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_AY_ENVELOPE_HIGH,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x25: // envelope slide up
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_AY_ENVELOPE_SLIDE,ch,-effectVal));
|
|
|
|
break;
|
|
|
|
case 0x26: // envelope slide down
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_AY_ENVELOPE_SLIDE,ch,effectVal));
|
2022-01-18 23:21:27 +00:00
|
|
|
break;
|
|
|
|
case 0x27: // noise and mask
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_AY_NOISE_MASK_AND,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x28: // noise or mask
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_AY_NOISE_MASK_OR,ch,effectVal));
|
2022-01-13 07:52:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2022-01-15 04:26:22 +00:00
|
|
|
case DIV_SYSTEM_SAA1099:
|
|
|
|
switch (effect) {
|
|
|
|
case 0x10: // select channel mode
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_MODE,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x11: // set noise freq
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_STD_NOISE_FREQ,ch,effectVal));
|
|
|
|
break;
|
|
|
|
case 0x12: // setup envelope
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_SAA_ENVELOPE,ch,effectVal));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2022-01-18 20:12:36 +00:00
|
|
|
case DIV_SYSTEM_TIA:
|
|
|
|
switch (effect) {
|
|
|
|
case 0x10: // select waveform
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_WAVE,ch,effectVal));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2021-05-15 08:13:21 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-16 08:03:23 +00:00
|
|
|
void DivEngine::processRow(int i, bool afterDelay) {
|
2021-12-05 21:11:12 +00:00
|
|
|
int whatOrder=afterDelay?chan[i].delayOrder:curOrder;
|
|
|
|
int whatRow=afterDelay?chan[i].delayRow:curRow;
|
2021-12-13 19:40:03 +00:00
|
|
|
DivPattern* pat=song.pat[i].getPattern(song.orders.ord[i][whatOrder],false);
|
2021-05-16 08:03:23 +00:00
|
|
|
// pre effects
|
2021-12-13 19:40:03 +00:00
|
|
|
if (!afterDelay) for (int j=0; j<song.pat[i].effectRows; j++) {
|
2021-12-05 21:11:12 +00:00
|
|
|
short effect=pat->data[whatRow][4+(j<<1)];
|
|
|
|
short effectVal=pat->data[whatRow][5+(j<<1)];
|
2021-05-16 08:03:23 +00:00
|
|
|
|
|
|
|
if (effectVal==-1) effectVal=0;
|
2021-12-07 21:58:23 +00:00
|
|
|
if (effect==0xed && effectVal!=0) {
|
2021-12-08 05:27:20 +00:00
|
|
|
if (effectVal<=nextSpeed) {
|
|
|
|
chan[i].rowDelay=effectVal+1;
|
|
|
|
chan[i].delayOrder=whatOrder;
|
|
|
|
chan[i].delayRow=whatRow;
|
|
|
|
if (effectVal==nextSpeed) {
|
2022-01-18 20:24:42 +00:00
|
|
|
//if (sysOfChan[i]!=DIV_SYSTEM_YM2610 && sysOfChan[i]!=DIV_SYSTEM_YM2610_EXT) chan[i].delayLocked=true;
|
2021-12-08 05:27:20 +00:00
|
|
|
} else {
|
|
|
|
chan[i].delayLocked=false;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
chan[i].delayLocked=false;
|
|
|
|
}
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-08 05:27:20 +00:00
|
|
|
if (chan[i].delayLocked) return;
|
|
|
|
|
2021-05-16 08:03:23 +00:00
|
|
|
// instrument
|
2021-12-05 21:11:12 +00:00
|
|
|
if (pat->data[whatRow][2]!=-1) {
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_INSTRUMENT,i,pat->data[whatRow][2]));
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
|
|
|
// note
|
2021-12-05 21:11:12 +00:00
|
|
|
if (pat->data[whatRow][0]==100) {
|
2021-12-07 06:23:57 +00:00
|
|
|
//chan[i].note=-1;
|
2021-05-19 07:22:26 +00:00
|
|
|
chan[i].keyOn=false;
|
2022-01-19 06:36:20 +00:00
|
|
|
chan[i].keyOff=true;
|
2021-05-26 07:34:40 +00:00
|
|
|
if (chan[i].stopOnOff) {
|
|
|
|
chan[i].portaNote=-1;
|
|
|
|
chan[i].portaSpeed=-1;
|
|
|
|
chan[i].stopOnOff=false;
|
|
|
|
}
|
2022-01-08 21:03:32 +00:00
|
|
|
if (disCont[dispatchOfChan[i]].dispatch->keyOffAffectsPorta(dispatchChanOfChan[i])) {
|
2021-12-29 07:08:50 +00:00
|
|
|
chan[i].portaNote=-1;
|
|
|
|
chan[i].portaSpeed=-1;
|
2022-01-08 21:03:32 +00:00
|
|
|
if (i==2 && sysOfChan[i]==DIV_SYSTEM_SMS) {
|
2021-12-29 07:08:50 +00:00
|
|
|
chan[i+1].portaNote=-1;
|
|
|
|
chan[i+1].portaSpeed=-1;
|
|
|
|
}
|
|
|
|
}
|
2022-01-19 06:27:32 +00:00
|
|
|
chan[i].scheduledSlideReset=true;
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_NOTE_OFF,i));
|
2021-12-05 21:11:12 +00:00
|
|
|
} else if (!(pat->data[whatRow][0]==0 && pat->data[whatRow][1]==0)) {
|
2021-12-19 05:02:48 +00:00
|
|
|
chan[i].oldNote=chan[i].note;
|
2022-01-18 21:55:32 +00:00
|
|
|
chan[i].note=pat->data[whatRow][0]+((signed char)pat->data[whatRow][1])*12;
|
2021-05-26 07:06:40 +00:00
|
|
|
if (!chan[i].keyOn) {
|
2022-01-08 21:03:32 +00:00
|
|
|
if (disCont[dispatchOfChan[i]].dispatch->keyOffAffectsArp(dispatchChanOfChan[i])) {
|
2021-12-07 06:23:57 +00:00
|
|
|
chan[i].arp=0;
|
|
|
|
}
|
2021-05-26 07:06:40 +00:00
|
|
|
}
|
2021-05-16 08:03:23 +00:00
|
|
|
chan[i].doNote=true;
|
2021-05-28 05:36:25 +00:00
|
|
|
if (chan[i].arp!=0) {
|
|
|
|
chan[i].arpYield=true;
|
|
|
|
}
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// volume
|
2021-12-05 21:11:12 +00:00
|
|
|
if (pat->data[whatRow][3]!=-1) {
|
|
|
|
if (dispatchCmd(DivCommand(DIV_ALWAYS_SET_VOLUME,i)) || (MIN(chan[i].volMax,chan[i].volume)>>8)!=pat->data[whatRow][3]) {
|
|
|
|
chan[i].volume=pat->data[whatRow][3]<<8;
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_VOLUME,i,chan[i].volume>>8));
|
2021-05-17 20:06:11 +00:00
|
|
|
}
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
|
|
|
|
2022-01-19 05:01:34 +00:00
|
|
|
chan[i].retrigSpeed=0;
|
|
|
|
|
2021-05-16 08:03:23 +00:00
|
|
|
// effects
|
2021-12-13 19:40:03 +00:00
|
|
|
for (int j=0; j<song.pat[i].effectRows; j++) {
|
2021-12-05 21:11:12 +00:00
|
|
|
short effect=pat->data[whatRow][4+(j<<1)];
|
|
|
|
short effectVal=pat->data[whatRow][5+(j<<1)];
|
2021-05-16 08:03:23 +00:00
|
|
|
|
|
|
|
if (effectVal==-1) effectVal=0;
|
|
|
|
|
|
|
|
// per-system effect
|
|
|
|
if (!perSystemEffect(i,effect,effectVal)) switch (effect) {
|
|
|
|
case 0x09: // speed 1
|
2022-01-17 23:05:29 +00:00
|
|
|
if (effectVal>0) speed1=effectVal;
|
2021-05-16 08:03:23 +00:00
|
|
|
break;
|
|
|
|
case 0x0f: // speed 2
|
2022-01-17 23:05:29 +00:00
|
|
|
if (effectVal>0) speed2=effectVal;
|
2021-05-16 08:03:23 +00:00
|
|
|
break;
|
|
|
|
case 0x0b: // change order
|
2021-12-21 22:42:27 +00:00
|
|
|
if (changeOrd<0) {
|
2021-12-07 21:32:20 +00:00
|
|
|
changeOrd=effectVal;
|
|
|
|
changePos=0;
|
|
|
|
}
|
2021-05-16 08:03:23 +00:00
|
|
|
break;
|
|
|
|
case 0x0d: // next order
|
2021-12-21 22:42:27 +00:00
|
|
|
if (changeOrd<0) {
|
|
|
|
changeOrd=-2;
|
2021-12-07 21:32:20 +00:00
|
|
|
changePos=effectVal;
|
|
|
|
}
|
2021-05-16 08:03:23 +00:00
|
|
|
break;
|
|
|
|
case 0x08: // panning
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_PANNING,i,effectVal));
|
2021-05-16 08:03:23 +00:00
|
|
|
break;
|
|
|
|
case 0x01: // ramp up
|
|
|
|
if (effectVal==0) {
|
|
|
|
chan[i].portaNote=-1;
|
|
|
|
chan[i].portaSpeed=-1;
|
2021-12-19 05:27:04 +00:00
|
|
|
chan[i].inPorta=false;
|
2021-05-16 08:03:23 +00:00
|
|
|
} else {
|
|
|
|
chan[i].portaNote=0x60;
|
|
|
|
chan[i].portaSpeed=effectVal;
|
2021-05-26 07:34:40 +00:00
|
|
|
chan[i].portaStop=true;
|
|
|
|
chan[i].nowYouCanStop=false;
|
|
|
|
chan[i].stopOnOff=false;
|
2022-01-19 06:27:32 +00:00
|
|
|
chan[i].scheduledSlideReset=false;
|
|
|
|
chan[i].inPorta=false;
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x02: // ramp down
|
|
|
|
if (effectVal==0) {
|
|
|
|
chan[i].portaNote=-1;
|
|
|
|
chan[i].portaSpeed=-1;
|
2021-12-19 05:27:04 +00:00
|
|
|
chan[i].inPorta=false;
|
2021-05-16 08:03:23 +00:00
|
|
|
} else {
|
2022-01-08 21:03:32 +00:00
|
|
|
chan[i].portaNote=disCont[dispatchOfChan[i]].dispatch->getPortaFloor(dispatchChanOfChan[i]);
|
2021-05-16 08:03:23 +00:00
|
|
|
chan[i].portaSpeed=effectVal;
|
2021-05-19 08:09:51 +00:00
|
|
|
chan[i].portaStop=true;
|
|
|
|
chan[i].nowYouCanStop=false;
|
2021-05-26 07:34:40 +00:00
|
|
|
chan[i].stopOnOff=false;
|
2022-01-19 06:27:32 +00:00
|
|
|
chan[i].scheduledSlideReset=false;
|
|
|
|
chan[i].inPorta=false;
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x03: // portamento
|
|
|
|
if (effectVal==0) {
|
|
|
|
chan[i].portaNote=-1;
|
|
|
|
chan[i].portaSpeed=-1;
|
2021-12-19 05:27:04 +00:00
|
|
|
chan[i].inPorta=false;
|
2021-06-09 02:49:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_PRE_PORTA,i,false));
|
2021-05-16 08:03:23 +00:00
|
|
|
} else {
|
2021-12-19 05:27:04 +00:00
|
|
|
if (chan[i].note==chan[i].oldNote && !chan[i].inPorta) {
|
2021-12-19 05:02:48 +00:00
|
|
|
chan[i].portaNote=chan[i].note;
|
2021-12-19 05:27:04 +00:00
|
|
|
chan[i].portaSpeed=-1;
|
2021-12-19 05:02:48 +00:00
|
|
|
} else {
|
|
|
|
chan[i].portaNote=chan[i].note;
|
|
|
|
chan[i].portaSpeed=effectVal;
|
2021-12-19 05:27:04 +00:00
|
|
|
chan[i].inPorta=true;
|
2021-12-19 05:02:48 +00:00
|
|
|
}
|
2021-05-19 07:05:24 +00:00
|
|
|
chan[i].portaStop=true;
|
2021-12-19 05:27:04 +00:00
|
|
|
if (chan[i].keyOn) chan[i].doNote=false;
|
2021-05-26 07:34:40 +00:00
|
|
|
chan[i].stopOnOff=true;
|
2022-01-19 06:27:32 +00:00
|
|
|
chan[i].scheduledSlideReset=false;
|
2021-05-28 07:30:09 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_PRE_PORTA,i,true));
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x04: // vibrato
|
|
|
|
chan[i].vibratoDepth=effectVal&15;
|
|
|
|
chan[i].vibratoRate=effectVal>>4;
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_PITCH,i,chan[i].pitch+(((chan[i].vibratoDepth*vibTable[chan[i].vibratoPos]*chan[i].vibratoFine)>>4)/15)));
|
2021-05-16 08:03:23 +00:00
|
|
|
break;
|
|
|
|
case 0x0a: // volume ramp
|
|
|
|
if (effectVal!=0) {
|
|
|
|
if ((effectVal&15)!=0) {
|
|
|
|
chan[i].volSpeed=-(effectVal&15)*64;
|
|
|
|
} else {
|
|
|
|
chan[i].volSpeed=(effectVal>>4)*64;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
chan[i].volSpeed=0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x00: // arpeggio
|
|
|
|
chan[i].arp=effectVal;
|
|
|
|
break;
|
2021-05-18 07:29:17 +00:00
|
|
|
case 0x0c: // retrigger
|
2021-12-29 07:08:50 +00:00
|
|
|
if (effectVal!=0) {
|
2022-01-19 05:01:34 +00:00
|
|
|
chan[i].retrigSpeed=effectVal;
|
|
|
|
chan[i].retrigTick=0;
|
2021-12-29 07:08:50 +00:00
|
|
|
}
|
2021-05-18 07:29:17 +00:00
|
|
|
break;
|
2022-01-12 07:45:26 +00:00
|
|
|
case 0xc0: case 0xc1: case 0xc2: case 0xc3: // set Hz
|
|
|
|
divider=((effect&0x3)<<8)|effectVal;
|
|
|
|
if (divider<10) divider=10;
|
2022-01-18 02:08:14 +00:00
|
|
|
cycles=((int)(got.rate)<<MASTER_CLOCK_PREC)/divider;
|
2022-01-12 22:45:07 +00:00
|
|
|
clockDrift=0;
|
2022-01-12 07:45:26 +00:00
|
|
|
break;
|
|
|
|
case 0xc4: // set Hz by tempo
|
|
|
|
// TODO
|
|
|
|
break;
|
2021-05-18 07:53:59 +00:00
|
|
|
case 0xe0: // arp speed
|
|
|
|
song.arpLen=effectVal;
|
|
|
|
break;
|
2021-05-16 08:03:23 +00:00
|
|
|
case 0xe1: // portamento up
|
|
|
|
chan[i].portaNote=chan[i].note+(effectVal&15);
|
2021-05-18 06:37:14 +00:00
|
|
|
chan[i].portaSpeed=(effectVal>>4)*4;
|
2021-05-19 07:05:24 +00:00
|
|
|
chan[i].portaStop=true;
|
2021-05-19 08:09:51 +00:00
|
|
|
chan[i].nowYouCanStop=false;
|
2021-05-26 07:34:40 +00:00
|
|
|
chan[i].stopOnOff=true;
|
2022-01-19 06:27:32 +00:00
|
|
|
chan[i].scheduledSlideReset=false;
|
|
|
|
chan[i].inPorta=false;
|
2021-05-16 08:03:23 +00:00
|
|
|
break;
|
|
|
|
case 0xe2: // portamento down
|
|
|
|
chan[i].portaNote=chan[i].note-(effectVal&15);
|
2021-05-18 06:37:14 +00:00
|
|
|
chan[i].portaSpeed=(effectVal>>4)*4;
|
2021-05-19 07:05:24 +00:00
|
|
|
chan[i].portaStop=true;
|
2021-05-19 08:09:51 +00:00
|
|
|
chan[i].nowYouCanStop=false;
|
2021-05-26 07:34:40 +00:00
|
|
|
chan[i].stopOnOff=true;
|
2022-01-19 06:27:32 +00:00
|
|
|
chan[i].scheduledSlideReset=false;
|
|
|
|
chan[i].inPorta=false;
|
2021-05-16 08:03:23 +00:00
|
|
|
break;
|
2021-05-18 07:29:17 +00:00
|
|
|
case 0xe3: // vibrato direction
|
|
|
|
chan[i].vibratoDir=effectVal;
|
|
|
|
break;
|
2021-05-18 08:02:47 +00:00
|
|
|
case 0xe4: // vibrato fine
|
|
|
|
chan[i].vibratoFine=effectVal;
|
|
|
|
break;
|
2021-05-16 08:03:23 +00:00
|
|
|
case 0xe5: // pitch
|
|
|
|
chan[i].pitch=effectVal-0x80;
|
2022-01-13 06:03:57 +00:00
|
|
|
if (sysOfChan[i]==DIV_SYSTEM_ARCADE || sysOfChan[i]==DIV_SYSTEM_YM2151) { // YM2151 pitch oddity
|
2021-12-15 05:50:32 +00:00
|
|
|
chan[i].pitch*=2;
|
|
|
|
if (chan[i].pitch<-128) chan[i].pitch=-128;
|
|
|
|
if (chan[i].pitch>127) chan[i].pitch=127;
|
|
|
|
}
|
2021-12-27 20:22:01 +00:00
|
|
|
chan[i].pitch+=globalPitch;
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_PITCH,i,chan[i].pitch+(((chan[i].vibratoDepth*vibTable[chan[i].vibratoPos]*chan[i].vibratoFine)>>4)/15)));
|
2021-05-16 08:03:23 +00:00
|
|
|
break;
|
|
|
|
case 0xea: // legato mode
|
|
|
|
chan[i].legato=effectVal;
|
|
|
|
break;
|
2021-12-09 08:13:37 +00:00
|
|
|
case 0xeb: // sample bank
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_SAMPLE_BANK,i,effectVal));
|
|
|
|
break;
|
2021-05-16 08:03:23 +00:00
|
|
|
case 0xec: // delayed note cut
|
2021-12-08 05:37:23 +00:00
|
|
|
if (effectVal>0 && effectVal<nextSpeed) {
|
|
|
|
chan[i].cut=effectVal+1;
|
|
|
|
}
|
2021-05-16 08:03:23 +00:00
|
|
|
break;
|
2021-05-18 07:53:59 +00:00
|
|
|
case 0xee: // external command
|
2021-12-18 09:26:17 +00:00
|
|
|
//printf("\x1b[1;36m%d: extern command %d\x1b[m\n",i,effectVal);
|
2021-12-21 00:46:49 +00:00
|
|
|
extValue=effectVal;
|
|
|
|
extValuePresent=true;
|
2021-05-18 07:53:59 +00:00
|
|
|
break;
|
2021-12-27 20:22:01 +00:00
|
|
|
case 0xef: // global pitch
|
2021-12-28 05:51:38 +00:00
|
|
|
globalPitch+=(signed char)(effectVal-0x80);
|
2021-12-27 20:22:01 +00:00
|
|
|
break;
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chan[i].doNote) {
|
|
|
|
chan[i].vibratoPos=0;
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_PITCH,i,chan[i].pitch+(((chan[i].vibratoDepth*vibTable[chan[i].vibratoPos]*chan[i].vibratoFine)>>4)/15)));
|
2021-05-16 08:03:23 +00:00
|
|
|
if (chan[i].legato) {
|
2021-05-19 07:05:24 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_LEGATO,i,chan[i].note));
|
2021-05-16 08:03:23 +00:00
|
|
|
} else {
|
2022-01-19 06:27:32 +00:00
|
|
|
if (chan[i].inPorta && chan[i].keyOn) {
|
|
|
|
chan[i].portaNote=chan[i].note;
|
|
|
|
} else {
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_NOTE_ON,i,chan[i].note,chan[i].volume>>8));
|
|
|
|
}
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
|
|
|
chan[i].doNote=false;
|
2022-01-19 06:27:32 +00:00
|
|
|
if (!chan[i].keyOn && chan[i].scheduledSlideReset) {
|
|
|
|
chan[i].portaNote=-1;
|
|
|
|
chan[i].portaSpeed=-1;
|
|
|
|
chan[i].scheduledSlideReset=false;
|
|
|
|
}
|
2021-12-19 05:42:20 +00:00
|
|
|
if (!chan[i].keyOn && chan[i].volume>chan[i].volMax) {
|
|
|
|
chan[i].volume=chan[i].volMax;
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_VOLUME,i,chan[i].volume>>8));
|
|
|
|
}
|
2021-05-19 07:22:26 +00:00
|
|
|
chan[i].keyOn=true;
|
2022-01-19 06:36:20 +00:00
|
|
|
chan[i].keyOff=false;
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
2021-05-19 08:09:51 +00:00
|
|
|
chan[i].nowYouCanStop=true;
|
2021-05-16 08:03:23 +00:00
|
|
|
|
|
|
|
// post effects
|
2021-12-13 19:40:03 +00:00
|
|
|
for (int j=0; j<song.pat[i].effectRows; j++) {
|
2021-12-05 21:11:12 +00:00
|
|
|
short effect=pat->data[whatRow][4+(j<<1)];
|
|
|
|
short effectVal=pat->data[whatRow][5+(j<<1)];
|
2021-05-16 08:03:23 +00:00
|
|
|
|
|
|
|
if (effectVal==-1) effectVal=0;
|
|
|
|
perSystemPostEffect(i,effect,effectVal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-12 08:58:55 +00:00
|
|
|
void DivEngine::nextRow() {
|
|
|
|
static char pb[4096];
|
|
|
|
static char pb1[4096];
|
|
|
|
static char pb2[4096];
|
|
|
|
static char pb3[4096];
|
2021-05-19 07:05:24 +00:00
|
|
|
if (view==DIV_STATUS_PATTERN) {
|
|
|
|
strcpy(pb1,"");
|
|
|
|
strcpy(pb3,"");
|
|
|
|
for (int i=0; i<chans; i++) {
|
|
|
|
snprintf(pb,4095," %.2x",song.orders.ord[i][curOrder]);
|
|
|
|
strcat(pb1,pb);
|
|
|
|
|
2021-12-13 19:40:03 +00:00
|
|
|
DivPattern* pat=song.pat[i].getPattern(song.orders.ord[i][curOrder],false);
|
2021-05-19 07:05:24 +00:00
|
|
|
snprintf(pb2,4095,"\x1b[37m %s",
|
|
|
|
formatNote(pat->data[curRow][0],pat->data[curRow][1]));
|
2021-05-12 08:58:55 +00:00
|
|
|
strcat(pb3,pb2);
|
2021-05-19 07:05:24 +00:00
|
|
|
if (pat->data[curRow][3]==-1) {
|
2021-05-12 08:58:55 +00:00
|
|
|
strcat(pb3,"\x1b[m--");
|
|
|
|
} else {
|
2021-05-19 07:05:24 +00:00
|
|
|
snprintf(pb2,4095,"\x1b[1;32m%.2x",pat->data[curRow][3]);
|
2021-05-12 08:58:55 +00:00
|
|
|
strcat(pb3,pb2);
|
|
|
|
}
|
2021-05-19 07:05:24 +00:00
|
|
|
if (pat->data[curRow][2]==-1) {
|
2021-05-12 08:58:55 +00:00
|
|
|
strcat(pb3,"\x1b[m--");
|
|
|
|
} else {
|
2021-05-19 07:05:24 +00:00
|
|
|
snprintf(pb2,4095,"\x1b[0;36m%.2x",pat->data[curRow][2]);
|
2021-05-12 08:58:55 +00:00
|
|
|
strcat(pb3,pb2);
|
|
|
|
}
|
2021-12-13 19:40:03 +00:00
|
|
|
for (int j=0; j<song.pat[i].effectRows; j++) {
|
2021-05-19 07:05:24 +00:00
|
|
|
if (pat->data[curRow][4+(j<<1)]==-1) {
|
|
|
|
strcat(pb3,"\x1b[m--");
|
|
|
|
} else {
|
|
|
|
snprintf(pb2,4095,"\x1b[1;31m%.2x",pat->data[curRow][4+(j<<1)]);
|
|
|
|
strcat(pb3,pb2);
|
|
|
|
}
|
|
|
|
if (pat->data[curRow][5+(j<<1)]==-1) {
|
|
|
|
strcat(pb3,"\x1b[m--");
|
|
|
|
} else {
|
|
|
|
snprintf(pb2,4095,"\x1b[1;37m%.2x",pat->data[curRow][5+(j<<1)]);
|
|
|
|
strcat(pb3,pb2);
|
|
|
|
}
|
|
|
|
}
|
2021-05-12 08:58:55 +00:00
|
|
|
}
|
2021-05-19 07:05:24 +00:00
|
|
|
printf("| %.2x:%s | \x1b[1;33m%3d%s\x1b[m\n",curOrder,pb1,curRow,pb3);
|
2021-05-12 08:58:55 +00:00
|
|
|
}
|
2021-05-12 10:22:01 +00:00
|
|
|
|
|
|
|
for (int i=0; i<chans; i++) {
|
2021-05-18 07:29:17 +00:00
|
|
|
chan[i].rowDelay=0;
|
2021-05-16 08:03:23 +00:00
|
|
|
processRow(i,false);
|
2021-05-12 10:22:01 +00:00
|
|
|
}
|
2021-12-05 21:11:12 +00:00
|
|
|
|
2021-12-21 22:42:27 +00:00
|
|
|
if (changeOrd!=-1) {
|
|
|
|
if (repeatPattern) {
|
|
|
|
curRow=0;
|
|
|
|
changeOrd=-1;
|
|
|
|
} else {
|
|
|
|
curRow=changePos;
|
|
|
|
if (changeOrd==-2) changeOrd=curOrder+1;
|
|
|
|
if (changeOrd<=curOrder) endOfSong=true;
|
|
|
|
curOrder=changeOrd;
|
|
|
|
if (curOrder>=song.ordersLen) {
|
|
|
|
curOrder=0;
|
|
|
|
endOfSong=true;
|
|
|
|
}
|
|
|
|
changeOrd=-1;
|
2021-12-05 21:11:12 +00:00
|
|
|
}
|
2022-01-14 01:54:34 +00:00
|
|
|
} else if (++curRow>=song.patLen) {
|
|
|
|
nextOrder();
|
2021-12-05 21:11:12 +00:00
|
|
|
}
|
|
|
|
|
2022-01-09 22:08:14 +00:00
|
|
|
if (speedAB) {
|
|
|
|
ticks=speed2*(song.timeBase+1);
|
|
|
|
nextSpeed=speed1;
|
2021-12-05 21:11:12 +00:00
|
|
|
} else {
|
2022-01-09 22:08:14 +00:00
|
|
|
ticks=speed1*(song.timeBase+1);
|
|
|
|
nextSpeed=speed2;
|
2021-12-05 21:11:12 +00:00
|
|
|
}
|
|
|
|
speedAB=!speedAB;
|
|
|
|
|
|
|
|
// post row details
|
|
|
|
for (int i=0; i<chans; i++) {
|
2021-12-13 19:40:03 +00:00
|
|
|
DivPattern* pat=song.pat[i].getPattern(song.orders.ord[i][curOrder],false);
|
2021-12-05 21:11:12 +00:00
|
|
|
if (!(pat->data[curRow][0]==0 && pat->data[curRow][1]==0)) {
|
2021-12-05 21:45:29 +00:00
|
|
|
if (pat->data[curRow][0]!=100) {
|
2022-01-14 18:55:19 +00:00
|
|
|
if (!chan[i].legato) dispatchCmd(DivCommand(DIV_CMD_PRE_NOTE,i,ticks));
|
2021-12-05 21:45:29 +00:00
|
|
|
}
|
2021-12-05 21:11:12 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-12 08:58:55 +00:00
|
|
|
}
|
|
|
|
|
2021-12-21 07:30:09 +00:00
|
|
|
bool DivEngine::nextTick(bool noAccum) {
|
2021-12-07 09:22:36 +00:00
|
|
|
bool ret=false;
|
2022-01-12 07:45:26 +00:00
|
|
|
if (divider<10) divider=10;
|
2022-01-08 21:03:32 +00:00
|
|
|
|
2022-01-18 02:08:14 +00:00
|
|
|
cycles=((int)(got.rate)<<MASTER_CLOCK_PREC)/divider;
|
|
|
|
clockDrift+=((int)(got.rate)<<MASTER_CLOCK_PREC)%divider;
|
2022-01-12 22:45:07 +00:00
|
|
|
if (clockDrift>=divider) {
|
|
|
|
clockDrift-=divider;
|
|
|
|
cycles++;
|
2021-12-08 07:57:41 +00:00
|
|
|
}
|
|
|
|
|
2021-12-28 23:23:57 +00:00
|
|
|
while (!pendingNotes.empty()) {
|
|
|
|
DivNoteEvent& note=pendingNotes.front();
|
|
|
|
if (note.on) {
|
2022-01-17 23:01:40 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_INSTRUMENT,note.channel,note.ins,1));
|
2021-12-28 23:23:57 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_NOTE_ON,note.channel,note.note));
|
|
|
|
} else {
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_NOTE_OFF,note.channel));
|
2021-12-14 18:16:35 +00:00
|
|
|
}
|
2021-12-28 23:23:57 +00:00
|
|
|
pendingNotes.pop();
|
2021-05-12 08:58:55 +00:00
|
|
|
}
|
2021-12-28 23:23:57 +00:00
|
|
|
|
|
|
|
if (!freelance) {
|
|
|
|
if (--ticks<=0) {
|
|
|
|
ret=endOfSong;
|
|
|
|
if (endOfSong) {
|
|
|
|
playSub(true);
|
2021-05-18 07:29:17 +00:00
|
|
|
}
|
2021-12-28 23:23:57 +00:00
|
|
|
endOfSong=false;
|
|
|
|
nextRow();
|
2021-05-14 19:16:48 +00:00
|
|
|
}
|
2021-12-28 23:23:57 +00:00
|
|
|
// process stuff
|
|
|
|
for (int i=0; i<chans; i++) {
|
|
|
|
if (chan[i].rowDelay>0) {
|
|
|
|
if (--chan[i].rowDelay==0) {
|
|
|
|
processRow(i,true);
|
|
|
|
}
|
2021-05-14 19:16:48 +00:00
|
|
|
}
|
2022-01-19 05:01:34 +00:00
|
|
|
if (chan[i].retrigSpeed) {
|
|
|
|
if (--chan[i].retrigTick<0) {
|
|
|
|
chan[i].retrigTick=chan[i].retrigSpeed-1;
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_NOTE_ON,i,DIV_NOTE_NULL));
|
|
|
|
}
|
|
|
|
}
|
2021-12-28 23:23:57 +00:00
|
|
|
if (chan[i].volSpeed!=0) {
|
|
|
|
chan[i].volume=(chan[i].volume&0xff)|(dispatchCmd(DivCommand(DIV_CMD_GET_VOLUME,i))<<8);
|
|
|
|
chan[i].volume+=chan[i].volSpeed;
|
|
|
|
if (chan[i].volume>chan[i].volMax) {
|
|
|
|
chan[i].volume=chan[i].volMax;
|
|
|
|
chan[i].volSpeed=0;
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_VOLUME,i,chan[i].volume>>8));
|
|
|
|
} else if (chan[i].volume<0) {
|
|
|
|
chan[i].volSpeed=0;
|
|
|
|
chan[i].volume=chan[i].volMax+1;
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_VOLUME,i,chan[i].volume>>8));
|
|
|
|
} else {
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_VOLUME,i,chan[i].volume>>8));
|
|
|
|
}
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
2021-12-28 23:23:57 +00:00
|
|
|
if (chan[i].vibratoDepth>0) {
|
|
|
|
chan[i].vibratoPos+=chan[i].vibratoRate;
|
|
|
|
if (chan[i].vibratoPos>=64) chan[i].vibratoPos-=64;
|
|
|
|
switch (chan[i].vibratoDir) {
|
|
|
|
case 1: // up
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_PITCH,i,chan[i].pitch+(MAX(0,(chan[i].vibratoDepth*vibTable[chan[i].vibratoPos]*chan[i].vibratoFine)>>4)/15)));
|
2021-05-18 07:53:59 +00:00
|
|
|
break;
|
2021-12-28 23:23:57 +00:00
|
|
|
case 2: // down
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_PITCH,i,chan[i].pitch+(MIN(0,(chan[i].vibratoDepth*vibTable[chan[i].vibratoPos]*chan[i].vibratoFine)>>4)/15)));
|
2021-05-18 07:53:59 +00:00
|
|
|
break;
|
2021-12-28 23:23:57 +00:00
|
|
|
default: // both
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_PITCH,i,chan[i].pitch+(((chan[i].vibratoDepth*vibTable[chan[i].vibratoPos]*chan[i].vibratoFine)>>4)/15)));
|
2021-05-18 07:53:59 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-12-28 23:23:57 +00:00
|
|
|
|
|
|
|
}
|
2022-01-19 06:36:20 +00:00
|
|
|
if ((chan[i].keyOn || chan[i].keyOff) && chan[i].portaSpeed>0) {
|
2021-12-28 23:23:57 +00:00
|
|
|
if (dispatchCmd(DivCommand(DIV_CMD_NOTE_PORTA,i,chan[i].portaSpeed,chan[i].portaNote))==2 && chan[i].portaStop) {
|
|
|
|
chan[i].portaSpeed=0;
|
|
|
|
chan[i].oldNote=chan[i].note;
|
|
|
|
chan[i].note=chan[i].portaNote;
|
|
|
|
chan[i].inPorta=false;
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_LEGATO,i,chan[i].note));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (chan[i].cut>0) {
|
|
|
|
if (--chan[i].cut<1) {
|
|
|
|
chan[i].oldNote=chan[i].note;
|
|
|
|
chan[i].note=-1;
|
2022-01-20 02:53:09 +00:00
|
|
|
chan[i].keyOff=true;
|
|
|
|
chan[i].keyOn=false;
|
|
|
|
if (chan[i].stopOnOff) {
|
|
|
|
chan[i].portaNote=-1;
|
|
|
|
chan[i].portaSpeed=-1;
|
|
|
|
chan[i].stopOnOff=false;
|
|
|
|
}
|
|
|
|
if (disCont[dispatchOfChan[i]].dispatch->keyOffAffectsPorta(dispatchChanOfChan[i])) {
|
|
|
|
chan[i].portaNote=-1;
|
|
|
|
chan[i].portaSpeed=-1;
|
|
|
|
if (i==2 && sysOfChan[i]==DIV_SYSTEM_SMS) {
|
|
|
|
chan[i+1].portaNote=-1;
|
|
|
|
chan[i+1].portaSpeed=-1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_PRE_PORTA,i,false));
|
|
|
|
chan[i].scheduledSlideReset=true;
|
2021-12-28 23:23:57 +00:00
|
|
|
dispatchCmd(DivCommand(DIV_CMD_NOTE_OFF,i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (chan[i].arp!=0 && !chan[i].arpYield && chan[i].portaSpeed<1) {
|
|
|
|
if (--chan[i].arpTicks<1) {
|
|
|
|
chan[i].arpTicks=song.arpLen;
|
|
|
|
chan[i].arpStage++;
|
|
|
|
if (chan[i].arpStage>2) chan[i].arpStage=0;
|
|
|
|
switch (chan[i].arpStage) {
|
|
|
|
case 0:
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_LEGATO,i,chan[i].note));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_LEGATO,i,chan[i].note+(chan[i].arp>>4)));
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
dispatchCmd(DivCommand(DIV_CMD_LEGATO,i,chan[i].note+(chan[i].arp&15)));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
chan[i].arpYield=false;
|
2021-05-16 08:03:23 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-14 08:23:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// system tick
|
2022-01-08 21:03:32 +00:00
|
|
|
for (int i=0; i<song.systemLen; i++) disCont[i].dispatch->tick();
|
2021-05-19 07:05:24 +00:00
|
|
|
|
2021-12-28 23:23:57 +00:00
|
|
|
if (!freelance) {
|
2022-01-12 07:45:26 +00:00
|
|
|
if (!noAccum) {
|
|
|
|
totalTicksR++;
|
|
|
|
totalTicks+=1000000/divider;
|
2021-12-28 23:23:57 +00:00
|
|
|
}
|
2022-01-12 07:45:26 +00:00
|
|
|
if (totalTicks>=1000000) {
|
|
|
|
totalTicks-=1000000;
|
|
|
|
totalSeconds++;
|
2021-12-28 23:23:57 +00:00
|
|
|
cmdsPerSecond=totalCmds-lastCmds;
|
|
|
|
lastCmds=totalCmds;
|
|
|
|
}
|
2022-01-12 07:45:26 +00:00
|
|
|
|
|
|
|
if (consoleMode) fprintf(stderr,"\x1b[2K> %d:%.2d:%.2d.%.2d %.2x/%.2x:%.3d/%.3d %4dcmd/s\x1b[G",totalSeconds/3600,(totalSeconds/60)%60,totalSeconds%60,totalTicks/10000,curOrder,song.ordersLen,curRow,song.patLen,cmdsPerSecond);
|
2021-05-19 07:05:24 +00:00
|
|
|
}
|
2021-12-07 09:22:36 +00:00
|
|
|
|
|
|
|
return ret;
|
2021-05-12 08:58:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsigned int size) {
|
2021-12-21 21:05:21 +00:00
|
|
|
if (out!=NULL) {
|
|
|
|
memset(out[0],0,size*sizeof(float));
|
|
|
|
memset(out[1],0,size*sizeof(float));
|
|
|
|
}
|
2021-12-21 18:06:14 +00:00
|
|
|
|
|
|
|
isBusy.lock();
|
2021-12-21 21:05:21 +00:00
|
|
|
if (out!=NULL && sPreview.sample>=0 && sPreview.sample<(int)song.sample.size()) {
|
2021-12-21 18:06:14 +00:00
|
|
|
DivSample* s=song.sample[sPreview.sample];
|
2022-01-08 22:15:12 +00:00
|
|
|
size_t prevtotal=blip_clocks_needed(samp_bb,size);
|
2021-12-21 18:06:14 +00:00
|
|
|
|
|
|
|
for (size_t i=0; i<prevtotal; i++) {
|
|
|
|
if (sPreview.pos>=s->rendLength) {
|
2022-01-08 22:15:12 +00:00
|
|
|
samp_temp=0;
|
2021-12-21 18:06:14 +00:00
|
|
|
} else {
|
2022-01-08 22:15:12 +00:00
|
|
|
samp_temp=s->rendData[sPreview.pos++];
|
2021-12-21 18:06:14 +00:00
|
|
|
}
|
2022-01-08 22:15:12 +00:00
|
|
|
if (s->depth==8) samp_temp<<=8;
|
|
|
|
blip_add_delta(samp_bb,i,samp_temp-samp_prevSample);
|
|
|
|
samp_prevSample=samp_temp;
|
2021-12-21 18:06:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sPreview.pos>=s->rendLength) sPreview.sample=-1;
|
|
|
|
|
2022-01-08 22:15:12 +00:00
|
|
|
blip_end_frame(samp_bb,prevtotal);
|
|
|
|
blip_read_samples(samp_bb,samp_bbOut,size,0);
|
2021-12-21 18:06:14 +00:00
|
|
|
for (size_t i=0; i<size; i++) {
|
2022-01-08 22:15:12 +00:00
|
|
|
out[0][i]+=(float)samp_bbOut[i]/32768.0;
|
|
|
|
out[1][i]+=(float)samp_bbOut[i]/32768.0;
|
2021-12-21 18:06:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-08 21:03:32 +00:00
|
|
|
if (!playing) {
|
2021-12-21 18:06:14 +00:00
|
|
|
isBusy.unlock();
|
2021-12-11 08:34:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-01-08 21:03:32 +00:00
|
|
|
|
|
|
|
// logic starts here
|
2022-01-08 22:15:12 +00:00
|
|
|
size_t runtotal[32];
|
|
|
|
size_t runLeft[32];
|
|
|
|
size_t runPos[32];
|
|
|
|
for (int i=0; i<song.systemLen; i++) {
|
2022-01-14 09:41:32 +00:00
|
|
|
runtotal[i]=blip_clocks_needed(disCont[i].bb[0],size)-blip_samples_avail(disCont[i].bb[0]);
|
2022-01-08 22:15:12 +00:00
|
|
|
if (runtotal[i]>disCont[i].bbInLen) {
|
|
|
|
delete disCont[i].bbIn[0];
|
|
|
|
delete disCont[i].bbIn[1];
|
|
|
|
disCont[i].bbIn[0]=new short[runtotal[i]+256];
|
|
|
|
disCont[i].bbIn[1]=new short[runtotal[i]+256];
|
|
|
|
disCont[i].bbInLen=runtotal[i]+256;
|
|
|
|
}
|
|
|
|
runLeft[i]=runtotal[i];
|
|
|
|
runPos[i]=0;
|
2021-12-06 10:21:42 +00:00
|
|
|
}
|
|
|
|
|
2022-01-04 05:02:41 +00:00
|
|
|
if (metroTickLen<size) {
|
|
|
|
if (metroTick!=NULL) delete[] metroTick;
|
|
|
|
metroTick=new unsigned char[size];
|
|
|
|
metroTickLen=size;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(metroTick,0,size);
|
|
|
|
|
2022-01-12 07:45:26 +00:00
|
|
|
int attempts=0;
|
2022-01-18 02:08:14 +00:00
|
|
|
int runLeftG=size<<MASTER_CLOCK_PREC;
|
2022-01-12 22:02:48 +00:00
|
|
|
while (++attempts<100) {
|
2022-01-08 22:15:12 +00:00
|
|
|
// 1. check whether we are done with all buffers
|
2022-01-12 22:45:07 +00:00
|
|
|
if (runLeftG<=0) break;
|
2021-12-06 10:21:42 +00:00
|
|
|
|
2022-01-08 22:15:12 +00:00
|
|
|
// 2. check whether we gonna tick
|
2022-01-12 22:45:07 +00:00
|
|
|
if (cycles<=0) {
|
2022-01-08 22:15:12 +00:00
|
|
|
// we have to tick
|
2022-01-18 02:08:14 +00:00
|
|
|
unsigned int realPos=size-(runLeftG>>MASTER_CLOCK_PREC);
|
2022-01-08 22:15:12 +00:00
|
|
|
if (realPos>=size) realPos=size-1;
|
|
|
|
if (song.hilightA>0) {
|
|
|
|
if ((curRow%song.hilightA)==0 && ticks==1) metroTick[realPos]=1;
|
|
|
|
}
|
|
|
|
if (song.hilightB>0) {
|
|
|
|
if ((curRow%song.hilightB)==0 && ticks==1) metroTick[realPos]=2;
|
|
|
|
}
|
|
|
|
if (nextTick()) {
|
|
|
|
if (remainingLoops>0) {
|
|
|
|
remainingLoops--;
|
2022-01-18 04:34:29 +00:00
|
|
|
if (!remainingLoops) {
|
|
|
|
logI("end of song!\n");
|
|
|
|
remainingLoops=-1;
|
|
|
|
playing=false;
|
|
|
|
freelance=false;
|
|
|
|
extValuePresent=false;
|
|
|
|
break;
|
|
|
|
}
|
2022-01-08 22:15:12 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-12 22:45:07 +00:00
|
|
|
} else {
|
|
|
|
// 3. tick the clock and fill buffers as needed
|
|
|
|
if (cycles<runLeftG) {
|
|
|
|
for (int i=0; i<song.systemLen; i++) {
|
2022-01-18 02:08:14 +00:00
|
|
|
int total=(cycles*runtotal[i])/(size<<MASTER_CLOCK_PREC);
|
2022-01-12 22:45:07 +00:00
|
|
|
disCont[i].acquire(runPos[i],total);
|
|
|
|
runLeft[i]-=total;
|
|
|
|
runPos[i]+=total;
|
|
|
|
}
|
|
|
|
runLeftG-=cycles;
|
|
|
|
cycles=0;
|
2022-01-12 22:02:48 +00:00
|
|
|
} else {
|
2022-01-12 22:45:07 +00:00
|
|
|
cycles-=runLeftG;
|
|
|
|
runLeftG=0;
|
|
|
|
for (int i=0; i<song.systemLen; i++) {
|
|
|
|
disCont[i].acquire(runPos[i],runLeft[i]);
|
|
|
|
runLeft[i]=0;
|
|
|
|
}
|
2022-01-12 22:02:48 +00:00
|
|
|
}
|
2022-01-08 22:15:12 +00:00
|
|
|
}
|
2021-05-12 08:58:55 +00:00
|
|
|
}
|
2022-01-12 07:45:26 +00:00
|
|
|
logD("attempts: %d\n",attempts);
|
2022-01-12 22:02:48 +00:00
|
|
|
if (attempts>=100) {
|
|
|
|
logE("hang detected! stopping! at %d seconds %d micro\n",totalSeconds,totalTicks);
|
2022-01-12 07:45:26 +00:00
|
|
|
freelance=false;
|
|
|
|
playing=false;
|
|
|
|
extValuePresent=false;
|
|
|
|
}
|
2022-01-18 04:34:29 +00:00
|
|
|
totalProcessed=size-(runLeftG>>MASTER_CLOCK_PREC);
|
2021-05-12 08:58:55 +00:00
|
|
|
|
2022-01-08 22:15:12 +00:00
|
|
|
for (int i=0; i<song.systemLen; i++) {
|
|
|
|
disCont[i].fillBuf(runtotal[i],size);
|
2021-12-06 21:51:18 +00:00
|
|
|
}
|
|
|
|
|
2021-12-15 05:37:27 +00:00
|
|
|
if (out==NULL) {
|
|
|
|
isBusy.unlock();
|
|
|
|
return;
|
|
|
|
}
|
2021-12-07 17:21:23 +00:00
|
|
|
|
2022-01-08 22:15:12 +00:00
|
|
|
for (int i=0; i<song.systemLen; i++) {
|
2022-01-15 05:24:06 +00:00
|
|
|
float volL=((float)song.systemVol[i]/64.0f)*((float)MIN(127,127-(int)song.systemPan[i])/127.0f);
|
|
|
|
float volR=((float)song.systemVol[i]/64.0f)*((float)MIN(127,127+(int)song.systemPan[i])/127.0f);
|
2022-01-08 22:15:12 +00:00
|
|
|
if (disCont[i].dispatch->isStereo()) {
|
|
|
|
for (size_t j=0; j<size; j++) {
|
2022-01-15 05:24:06 +00:00
|
|
|
out[0][j]+=((float)disCont[i].bbOut[0][j]/16384.0)*volL;
|
|
|
|
out[1][j]+=((float)disCont[i].bbOut[1][j]/16384.0)*volR;
|
2022-01-08 22:15:12 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (size_t j=0; j<size; j++) {
|
2022-01-15 05:24:06 +00:00
|
|
|
out[0][j]+=((float)disCont[i].bbOut[0][j]/16384.0)*volL;
|
|
|
|
out[1][j]+=((float)disCont[i].bbOut[0][j]/16384.0)*volR;
|
2022-01-08 22:15:12 +00:00
|
|
|
}
|
2021-12-06 21:51:18 +00:00
|
|
|
}
|
2021-05-12 08:58:55 +00:00
|
|
|
}
|
2022-01-04 05:02:41 +00:00
|
|
|
|
|
|
|
if (metronome) for (size_t i=0; i<size; i++) {
|
|
|
|
if (metroTick[i]) {
|
|
|
|
if (metroTick[i]==2) {
|
2022-01-04 05:29:59 +00:00
|
|
|
metroFreq=1400/got.rate;
|
2022-01-04 05:02:41 +00:00
|
|
|
} else {
|
2022-01-04 05:29:59 +00:00
|
|
|
metroFreq=1050/got.rate;
|
2022-01-04 05:02:41 +00:00
|
|
|
}
|
2022-01-04 05:29:59 +00:00
|
|
|
metroPos=0;
|
|
|
|
metroAmp=0.7f;
|
2022-01-04 05:02:41 +00:00
|
|
|
}
|
2022-01-04 05:29:59 +00:00
|
|
|
if (metroAmp>0.0f) {
|
|
|
|
out[0][i]+=(sin(metroPos*2*M_PI))*metroAmp;
|
|
|
|
out[1][i]+=(sin(metroPos*2*M_PI))*metroAmp;
|
2022-01-04 05:02:41 +00:00
|
|
|
}
|
2022-01-04 05:29:59 +00:00
|
|
|
metroAmp-=0.0003f;
|
|
|
|
if (metroAmp<0.0f) metroAmp=0.0f;
|
|
|
|
metroPos+=metroFreq;
|
|
|
|
while (metroPos>=1) metroPos--;
|
2022-01-04 05:02:41 +00:00
|
|
|
}
|
2021-12-15 05:37:27 +00:00
|
|
|
isBusy.unlock();
|
2021-05-12 10:22:01 +00:00
|
|
|
}
|