From c0f7f12c89884c5e68bb98d94cf646650f4069d5 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Tue, 18 May 2021 02:29:17 -0500 Subject: [PATCH] misc fixes and new effects - fix 8-bit samples - 0C effect - E3 effect --- src/engine/engine.cpp | 12 +++++++++--- src/engine/engine.h | 3 ++- src/engine/platform/genesis.cpp | 6 +++++- src/engine/playback.cpp | 20 +++++++++++++++++++- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 19202e2ed..a1e6a0b06 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -621,13 +621,19 @@ void DivEngine::renderSamples() { s->rendLength=(double)s->length/samplePitches[s->pitch]; s->rendData=new short[s->rendLength]; int k=0; - float mult=(float)(s->vol+100)/100.0f; + printf("Volume: %d\n",s->vol); + float mult=(float)(s->vol+100)/150.0f; for (double j=0; jlength; j+=samplePitches[s->pitch]) { if (k>=s->rendLength) { break; } - float next=(float)s->data[(unsigned int)j]*mult; - s->rendData[k++]=fmin(fmax(next,-32768),32767); + if (s->depth==8) { + float next=(float)(s->data[(unsigned int)j]-0x80)*mult; + s->rendData[k++]=fmin(fmax(next,-128),127); + } else { + float next=(float)s->data[(unsigned int)j]*mult; + s->rendData[k++]=fmin(fmax(next,-32768),32767); + } } } } diff --git a/src/engine/engine.h b/src/engine/engine.h index adbfcea13..29aea64b3 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -9,7 +9,7 @@ struct DivChannelState { std::vector delayed; int note, pitch, portaSpeed, portaNote; int volume, volSpeed, cut, rowDelay, volMax; - int vibratoDepth, vibratoRate, vibratoPos; + int vibratoDepth, vibratoRate, vibratoPos, vibratoDir; int tremoloDepth, tremoloRate, tremoloPos; unsigned char arp, arpStage; bool doNote, legato; @@ -26,6 +26,7 @@ struct DivChannelState { vibratoDepth(0), vibratoRate(0), vibratoPos(0), + vibratoDir(0), tremoloDepth(0), tremoloRate(0), tremoloPos(0), diff --git a/src/engine/platform/genesis.cpp b/src/engine/platform/genesis.cpp index 2925c281b..1b2fb87fb 100644 --- a/src/engine/platform/genesis.cpp +++ b/src/engine/platform/genesis.cpp @@ -9,7 +9,11 @@ void DivPlatformGenesis::acquire(int& l, int& r) { if (dacMode && dacSample!=-1) { if (--dacPeriod<1) { DivSample* s=parent->song.sample[dacSample]; - writes.emplace(0x2a,((unsigned short)s->rendData[dacPos++]+0x8000)>>8); + if (s->depth==8) { + writes.emplace(0x2a,(unsigned char)s->rendData[dacPos++]+0x80); + } else { + writes.emplace(0x2a,((unsigned short)s->rendData[dacPos++]+0x8000)>>8); + } if (dacPos>=s->rendLength) { dacSample=-1; } diff --git a/src/engine/playback.cpp b/src/engine/playback.cpp index 520f19cec..28f3c8eba 100644 --- a/src/engine/playback.cpp +++ b/src/engine/playback.cpp @@ -214,6 +214,9 @@ void DivEngine::processRow(int i, bool afterDelay) { case 0x00: // arpeggio chan[i].arp=effectVal; break; + case 0x0c: // retrigger + chan[i].rowDelay=effectVal+1; + break; case 0xe1: // portamento up chan[i].portaNote=chan[i].note+(effectVal&15); @@ -223,6 +226,9 @@ void DivEngine::processRow(int i, bool afterDelay) { chan[i].portaNote=chan[i].note-(effectVal&15); chan[i].portaSpeed=(effectVal>>4)*4; break; + case 0xe3: // vibrato direction + chan[i].vibratoDir=effectVal; + break; case 0xe5: // pitch chan[i].pitch=effectVal-0x80; dispatch->dispatch(DivCommand(DIV_CMD_PITCH,i,chan[i].pitch+((chan[i].vibratoDepth*vibTable[chan[i].vibratoPos])>>2))); @@ -313,6 +319,7 @@ void DivEngine::nextRow() { printf("| %.2x:%s | \x1b[1;33m%3d%s\x1b[m\n",curOrder,pb1,curRow,pb3); for (int i=0; i0) { chan[i].vibratoPos+=chan[i].vibratoRate; if (chan[i].vibratoPos>=64) chan[i].vibratoPos-=64; - dispatch->dispatch(DivCommand(DIV_CMD_PITCH,i,chan[i].pitch+((chan[i].vibratoDepth*vibTable[chan[i].vibratoPos])>>4))); + switch (chan[i].vibratoDir) { + case 1: // up + dispatch->dispatch(DivCommand(DIV_CMD_PITCH,i,chan[i].pitch+(MAX(0,chan[i].vibratoDepth*vibTable[chan[i].vibratoPos])>>4))); + break; + case 2: // down + dispatch->dispatch(DivCommand(DIV_CMD_PITCH,i,chan[i].pitch+(MIN(0,chan[i].vibratoDepth*vibTable[chan[i].vibratoPos])>>4))); + break; + default: // both + dispatch->dispatch(DivCommand(DIV_CMD_PITCH,i,chan[i].pitch+((chan[i].vibratoDepth*vibTable[chan[i].vibratoPos])>>4))); + break; + } + } if (chan[i].portaSpeed>0) { if (dispatch->dispatch(DivCommand(DIV_CMD_NOTE_PORTA,i,chan[i].portaSpeed,chan[i].portaNote))==2) {