better volume slide accuracy

volume slide seems to be kind of quirky:
- sliding all the way down and then up suddenly sets the vol to max
- apparently there is an overflow and the slide stops when it reaches
  its boundaries (instead of continuing)
This commit is contained in:
tildearrow 2021-05-17 15:06:11 -05:00
parent 67847d79cf
commit 9736b77401
8 changed files with 36 additions and 8 deletions

View file

@ -9,6 +9,7 @@ enum DivDispatchCmds {
DIV_CMD_INSTRUMENT,
DIV_CMD_VOLUME,
DIV_CMD_GET_VOLUME,
DIV_CMD_GET_VOLMAX,
DIV_CMD_NOTE_PORTA,
DIV_CMD_PITCH,
DIV_CMD_PANNING,

View file

@ -697,6 +697,11 @@ bool DivEngine::init() {
blip_set_rates(bb[0],dispatch->rate,got.rate);
blip_set_rates(bb[1],dispatch->rate,got.rate);
for (int i=0; i<chans; i++) {
chan[i].volMax=dispatch->dispatch(DivCommand(DIV_CMD_GET_VOLMAX,i))<<8;
chan[i].volume=chan[i].volMax;
}
if (!output->setRun(true)) {
logE("error while activating!\n");
return false;

View file

@ -8,7 +8,7 @@
struct DivChannelState {
std::vector<DivDelayedCommand> delayed;
int note, pitch, portaSpeed, portaNote;
int volume, volSpeed, cut, rowDelay;
int volume, volSpeed, cut, rowDelay, volMax;
int vibratoDepth, vibratoRate, vibratoPos;
int tremoloDepth, tremoloRate, tremoloPos;
unsigned char arp, arpStage;

View file

@ -32,6 +32,9 @@ int DivPlatformDummy::dispatch(DivCommand c) {
case DIV_CMD_GET_VOLUME:
return chan[c.chan].vol;
break;
case DIV_CMD_GET_VOLMAX:
return 15;
break;
default:
break;
}

View file

@ -301,6 +301,9 @@ int DivPlatformGenesis::dispatch(DivCommand c) {
break;
}
case DIV_CMD_GET_VOLMAX:
return 127;
break;
default:
printf("WARNING: unimplemented command %d\n",c.cmd);
break;

View file

@ -20,6 +20,9 @@ int DivPlatformGenesisExt::dispatch(DivCommand c) {
case DIV_CMD_VOLUME:
chan[c.chan].vol=c.value;
break;
case DIV_CMD_GET_VOLMAX:
return 127;
break;
default:
break;
}
@ -35,4 +38,4 @@ int DivPlatformGenesisExt::init(DivEngine* parent, int channels, int sugRate) {
extMode=true;
return 13;
}
}

View file

@ -144,6 +144,9 @@ int DivPlatformSMS::dispatch(DivCommand c) {
case DIV_CMD_PRE_PORTA:
chan[c.chan].std.init(parent->getIns(chan[c.chan].ins));
break;
case DIV_CMD_GET_VOLMAX:
return 15;
break;
default:
break;
}

View file

@ -134,8 +134,10 @@ void DivEngine::processRow(int i, bool afterDelay) {
// volume
if (pat->data[curRow][3]!=-1) {
chan[i].volume=pat->data[curRow][3]<<8;
dispatch->dispatch(DivCommand(DIV_CMD_VOLUME,i,chan[i].volume>>8));
if ((chan[i].volume>>8)!=pat->data[curRow][3]) {
chan[i].volume=pat->data[curRow][3]<<8;
dispatch->dispatch(DivCommand(DIV_CMD_VOLUME,i,chan[i].volume>>8));
}
}
// effects
@ -342,11 +344,19 @@ void DivEngine::nextTick() {
}
}
if (chan[i].volSpeed!=0) {
chan[i].volume=(chan[i].volume&0xff)|(dispatch->dispatch(DivCommand(DIV_CMD_GET_VOLUME,i))<<8);
//chan[i].volume=(chan[i].volume&0xff)|(dispatch->dispatch(DivCommand(DIV_CMD_GET_VOLUME,i))<<8);
chan[i].volume+=chan[i].volSpeed;
if (chan[i].volume>0x7f00) chan[i].volume=0x7f00;
if (chan[i].volume<0) chan[i].volume=0;
dispatch->dispatch(DivCommand(DIV_CMD_VOLUME,i,chan[i].volume>>8));
if (chan[i].volume>chan[i].volMax) {
chan[i].volume=chan[i].volMax;
chan[i].volSpeed=0;
dispatch->dispatch(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;
dispatch->dispatch(DivCommand(DIV_CMD_VOLUME,i,0));
} else {
dispatch->dispatch(DivCommand(DIV_CMD_VOLUME,i,chan[i].volume>>8));
}
}
if (chan[i].vibratoDepth>0) {
chan[i].vibratoPos+=chan[i].vibratoRate;