Reduce unnecessary changes, Volume macro fixes, calcArp

This commit is contained in:
cam900 2022-09-25 19:21:49 +09:00
parent bd08fc0193
commit 81bebc5112
4 changed files with 40 additions and 54 deletions

View File

@ -272,7 +272,7 @@ void DivPlatformES5506::e_pin(bool state)
unsigned int loopFlag=(chan[ch].pcm.bank<<14)|(chan[ch].pcm.reversed?0x0040:0x0000); unsigned int loopFlag=(chan[ch].pcm.bank<<14)|(chan[ch].pcm.reversed?0x0040:0x0000);
chan[ch].isReverseLoop=false; chan[ch].isReverseLoop=false;
switch (chan[ch].pcm.loopMode) { switch (chan[ch].pcm.loopMode) {
case DIV_SAMPLE_LOOP_MAX: // One shot (no loop) case DIV_SAMPLE_LOOP_MAX: // no loop
default: default:
break; break;
case DIV_SAMPLE_LOOP_FORWARD: // Foward loop case DIV_SAMPLE_LOOP_FORWARD: // Foward loop
@ -326,11 +326,11 @@ void DivPlatformES5506::irqb(bool state) {
void DivPlatformES5506::tick(bool sysTick) { void DivPlatformES5506::tick(bool sysTick) {
for (int i=0; i<=chanMax; i++) { for (int i=0; i<=chanMax; i++) {
chan[i].std.next(); chan[i].std.next();
DivInstrument* ins=parent->getIns(chan[i].ins); DivInstrument* ins=parent->getIns(chan[i].ins,DIV_INS_ES5506);
signed int k1=chan[i].k1Prev,k2=chan[i].k2Prev; signed int k1=chan[i].k1Prev,k2=chan[i].k2Prev;
// volume/panning macros // volume/panning macros
if (chan[i].std.vol.had) { if (chan[i].std.vol.had) {
const unsigned int nextVol=VOL_SCALE_LOG((0xffff*chan[i].vol)/0xff,(0xffff*chan[i].std.vol.val)/chan[i].volMacroMax,0xffff); const unsigned int nextVol=VOL_SCALE_LOG((0xffff*chan[i].vol)/0xff,(0xffff*(unsigned int)chan[i].std.vol.val)/chan[i].volMacroMax,0xffff);
if (chan[i].outVol!=nextVol) { if (chan[i].outVol!=nextVol) {
chan[i].outVol=nextVol; chan[i].outVol=nextVol;
if (!isMuted[i]) { if (!isMuted[i]) {
@ -339,7 +339,7 @@ void DivPlatformES5506::tick(bool sysTick) {
} }
} }
if (chan[i].std.panL.had) { if (chan[i].std.panL.had) {
const unsigned int nextLVol=VOL_SCALE_LOG((0xffff*chan[i].lVol)/0xff,(0xffff*chan[i].std.panL.val)/chan[i].panMacroMax,0xffff); const unsigned int nextLVol=VOL_SCALE_LOG((0xffff*chan[i].lVol)/0xff,(0xffff*(unsigned int)chan[i].std.panL.val)/chan[i].panMacroMax,0xffff);
if (chan[i].outLVol!=nextLVol) { if (chan[i].outLVol!=nextLVol) {
chan[i].outLVol=nextLVol; chan[i].outLVol=nextLVol;
if (!isMuted[i]) { if (!isMuted[i]) {
@ -348,7 +348,7 @@ void DivPlatformES5506::tick(bool sysTick) {
} }
} }
if (chan[i].std.panR.had) { if (chan[i].std.panR.had) {
const unsigned int nextRVol=VOL_SCALE_LOG((0xffff*chan[i].rVol)/0xff,(0xffff*chan[i].std.panR.val)/chan[i].panMacroMax,0xffff); const unsigned int nextRVol=VOL_SCALE_LOG((0xffff*chan[i].rVol)/0xff,(0xffff*(unsigned int)chan[i].std.panR.val)/chan[i].panMacroMax,0xffff);
if (chan[i].outRVol!=nextRVol) { if (chan[i].outRVol!=nextRVol) {
chan[i].outRVol=nextRVol; chan[i].outRVol=nextRVol;
if (!isMuted[i]) { if (!isMuted[i]) {
@ -359,18 +359,9 @@ void DivPlatformES5506::tick(bool sysTick) {
// arpeggio/pitch macros, frequency related // arpeggio/pitch macros, frequency related
if (chan[i].std.arp.had) { if (chan[i].std.arp.had) {
if (!chan[i].inPorta) { if (!chan[i].inPorta) {
if (chan[i].std.arp.mode) { chan[i].nextNote=parent->calcArp(chan[i].note,chan[i].std.arp.val);
chan[i].nextNote=chan[i].std.arp.val;
} else {
chan[i].nextNote=chan[i].note+chan[i].std.arp.val;
}
} }
chan[i].noteChanged.note=1; chan[i].noteChanged.note=1;
} else {
if (chan[i].std.arp.mode && chan[i].std.arp.finished) {
chan[i].nextNote=chan[i].note;
chan[i].noteChanged.note=1;
}
} }
if (chan[i].std.pitch.had) { if (chan[i].std.pitch.had) {
if (chan[i].std.pitch.mode) { if (chan[i].std.pitch.mode) {
@ -408,8 +399,7 @@ void DivPlatformES5506::tick(bool sysTick) {
chan[i].filterChanged.k1=1; chan[i].filterChanged.k1=1;
} }
break; break;
/* /*case 2: { // delta
case 2: { // delta
const signed int next_k1=CLAMP(chan[i].k1Offs+chan[i].std.ex1.val,-65535,65535); const signed int next_k1=CLAMP(chan[i].k1Offs+chan[i].std.ex1.val,-65535,65535);
if (chan[i].k1Offs!=next_k1) { if (chan[i].k1Offs!=next_k1) {
chan[i].k1Offs=next_k1; chan[i].k1Offs=next_k1;
@ -436,8 +426,7 @@ void DivPlatformES5506::tick(bool sysTick) {
chan[i].filterChanged.k2=1; chan[i].filterChanged.k2=1;
} }
break; break;
/* /*case 2: { // delta
case 2: { // delta
const signed int next_k2=CLAMP(chan[i].k2Offs+chan[i].std.ex2.val,-65535,65535); const signed int next_k2=CLAMP(chan[i].k2Offs+chan[i].std.ex2.val,-65535,65535);
if (chan[i].k2Offs!=next_k2) { if (chan[i].k2Offs!=next_k2) {
chan[i].k2Offs=next_k2; chan[i].k2Offs=next_k2;
@ -757,7 +746,7 @@ void DivPlatformES5506::tick(bool sysTick) {
unsigned int loopFlag=(chan[i].pcm.bank<<14)|(chan[i].pcm.reversed?0x0040:0x0000); unsigned int loopFlag=(chan[i].pcm.bank<<14)|(chan[i].pcm.reversed?0x0040:0x0000);
chan[i].isReverseLoop=false; chan[i].isReverseLoop=false;
switch (chan[i].pcm.loopMode) { switch (chan[i].pcm.loopMode) {
case DIV_SAMPLE_LOOP_MAX: // One shot (no loop) case DIV_SAMPLE_LOOP_MAX: // no loop
default: default:
break; break;
case DIV_SAMPLE_LOOP_FORWARD: // Foward loop case DIV_SAMPLE_LOOP_FORWARD: // Foward loop
@ -891,7 +880,7 @@ void DivPlatformES5506::tick(bool sysTick) {
unsigned int loopFlag=chan[i].pcm.reversed?0x0040:0x0000; unsigned int loopFlag=chan[i].pcm.reversed?0x0040:0x0000;
chan[i].isReverseLoop=false; chan[i].isReverseLoop=false;
switch (chan[i].pcm.loopMode) { switch (chan[i].pcm.loopMode) {
case DIV_SAMPLE_LOOP_MAX: // One shot (no loop) case DIV_SAMPLE_LOOP_MAX: // no loop
default: default:
break; break;
case DIV_SAMPLE_LOOP_FORWARD: // Foward loop case DIV_SAMPLE_LOOP_FORWARD: // Foward loop
@ -938,7 +927,7 @@ void DivPlatformES5506::tick(bool sysTick) {
int DivPlatformES5506::dispatch(DivCommand c) { int DivPlatformES5506::dispatch(DivCommand c) {
switch (c.cmd) { switch (c.cmd) {
case DIV_CMD_NOTE_ON: { case DIV_CMD_NOTE_ON: {
DivInstrument* ins=parent->getIns(chan[c.chan].ins); DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_ES5506);
bool sampleVaild=false; bool sampleVaild=false;
if (((ins->amiga.useNoteMap && !ins->amiga.transWave.enable) && (c.value>=0 && c.value<120)) || if (((ins->amiga.useNoteMap && !ins->amiga.transWave.enable) && (c.value>=0 && c.value<120)) ||
((!ins->amiga.useNoteMap && ins->amiga.transWave.enable) && (ins->amiga.transWave.ind>=0 && ins->amiga.transWave.ind<(int)ins->amiga.transWaveMap.size())) || ((!ins->amiga.useNoteMap && ins->amiga.transWave.enable) && (ins->amiga.transWave.ind>=0 && ins->amiga.transWave.ind<(int)ins->amiga.transWaveMap.size())) ||
@ -1079,7 +1068,7 @@ int DivPlatformES5506::dispatch(DivCommand c) {
return chan[c.chan].outVol; return chan[c.chan].outVol;
break; break;
case DIV_CMD_PANNING: { case DIV_CMD_PANNING: {
DivInstrument* ins=parent->getIns(chan[c.chan].ins); DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_ES5506);
// Left volume // Left volume
if (chan[c.chan].lVol!=(unsigned int)(c.value)) { if (chan[c.chan].lVol!=(unsigned int)(c.value)) {
chan[c.chan].lVol=c.value; chan[c.chan].lVol=c.value;
@ -1110,7 +1099,7 @@ int DivPlatformES5506::dispatch(DivCommand c) {
case DIV_CMD_WAVE: case DIV_CMD_WAVE:
if (!chan[c.chan].useWave) { if (!chan[c.chan].useWave) {
if (chan[c.chan].active) { if (chan[c.chan].active) {
DivInstrument* ins=parent->getIns(chan[c.chan].ins); DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_ES5506);
if (((ins->amiga.useNoteMap && !ins->amiga.transWave.enable) && (c.value>=0 && c.value<120)) || if (((ins->amiga.useNoteMap && !ins->amiga.transWave.enable) && (c.value>=0 && c.value<120)) ||
((!ins->amiga.useNoteMap && ins->amiga.transWave.enable) && (c.value>=0 && c.value<(int)ins->amiga.transWaveMap.size())) || ((!ins->amiga.useNoteMap && ins->amiga.transWave.enable) && (c.value>=0 && c.value<(int)ins->amiga.transWaveMap.size())) ||
((!ins->amiga.useNoteMap && !ins->amiga.transWave.enable) && (c.value>=0 && c.value<parent->song.sampleLen))) { ((!ins->amiga.useNoteMap && !ins->amiga.transWave.enable) && (c.value>=0 && c.value<parent->song.sampleLen))) {
@ -1221,7 +1210,7 @@ int DivPlatformES5506::dispatch(DivCommand c) {
} }
case DIV_CMD_PRE_PORTA: case DIV_CMD_PRE_PORTA:
if (chan[c.chan].active && c.value2) { if (chan[c.chan].active && c.value2) {
if (parent->song.resetMacroOnPorta) chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins)); if (parent->song.resetMacroOnPorta) chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins,DIV_INS_ES5506));
} }
chan[c.chan].inPorta=c.value; chan[c.chan].inPorta=c.value;
break; break;

View File

@ -1372,10 +1372,6 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
if (sPreview.sample>=0 && sPreview.sample<(int)song.sample.size()) { if (sPreview.sample>=0 && sPreview.sample<(int)song.sample.size()) {
DivSample* s=song.sample[sPreview.sample]; DivSample* s=song.sample[sPreview.sample];
const bool pBeginVaild=sPreview.pBegin>=0 && sPreview.pBegin<(int)s->samples;
const bool pEndVaild=sPreview.pEnd>=0 && sPreview.pEnd<(int)s->samples;
const int loopStart=pBeginVaild?sPreview.pBegin:s->loopStart;
const int loopEnd=pEndVaild?sPreview.pEnd:(int)s->loopEnd;
for (size_t i=0; i<prevtotal; i++) { for (size_t i=0; i<prevtotal; i++) {
if (sPreview.pos>=(int)s->samples || (sPreview.pEnd>=0 && sPreview.pos>=sPreview.pEnd)) { if (sPreview.pos>=(int)s->samples || (sPreview.pEnd>=0 && sPreview.pos>=sPreview.pEnd)) {
samp_temp=0; samp_temp=0;

View File

@ -546,7 +546,7 @@ bool DivSample::resampleLinear(double r) {
if (depth==DIV_SAMPLE_DEPTH_16BIT) { if (depth==DIV_SAMPLE_DEPTH_16BIT) {
for (int i=0; i<finalCount; i++) { for (int i=0; i<finalCount; i++) {
short s1=(posInt>=samples)?0:oldData16[posInt]; short s1=(posInt>=samples)?0:oldData16[posInt];
short s2=(posInt+1>=samples)?(isLoopable()?oldData16[loopStart]:0):oldData16[posInt+1]; short s2=(posInt+1>=samples)?((loopStart>=0 && loopStart<(int)samples)?oldData16[loopStart]:0):oldData16[posInt+1];
data16[i]=s1+(float)(s2-s1)*posFrac; data16[i]=s1+(float)(s2-s1)*posFrac;
@ -559,7 +559,7 @@ bool DivSample::resampleLinear(double r) {
} else if (depth==DIV_SAMPLE_DEPTH_8BIT) { } else if (depth==DIV_SAMPLE_DEPTH_8BIT) {
for (int i=0; i<finalCount; i++) { for (int i=0; i<finalCount; i++) {
short s1=(posInt>=samples)?0:oldData8[posInt]; short s1=(posInt>=samples)?0:oldData8[posInt];
short s2=(posInt+1>=samples)?(isLoopable()?oldData8[loopStart]:0):oldData8[posInt+1]; short s2=(posInt+1>=samples)?((loopStart>=0 && loopStart<(int)samples)?oldData8[loopStart]:0):oldData8[posInt+1];
data8[i]=s1+(float)(s2-s1)*posFrac; data8[i]=s1+(float)(s2-s1)*posFrac;
@ -589,8 +589,8 @@ bool DivSample::resampleCubic(double r) {
float* t=&cubicTable[n<<2]; float* t=&cubicTable[n<<2];
float s0=(posInt<1)?0:oldData16[posInt-1]; float s0=(posInt<1)?0:oldData16[posInt-1];
float s1=(posInt>=samples)?0:oldData16[posInt]; float s1=(posInt>=samples)?0:oldData16[posInt];
float s2=(posInt+1>=samples)?(isLoopable()?oldData16[loopStart]:0):oldData16[posInt+1]; float s2=(posInt+1>=samples)?((loopStart>=0 && loopStart<(int)samples)?oldData16[loopStart]:0):oldData16[posInt+1];
float s3=(posInt+2>=samples)?(isLoopable()?oldData16[loopStart]:0):oldData16[posInt+2]; float s3=(posInt+2>=samples)?((loopStart>=0 && loopStart<(int)samples)?oldData16[loopStart]:0):oldData16[posInt+2];
float result=s0*t[0]+s1*t[1]+s2*t[2]+s3*t[3]; float result=s0*t[0]+s1*t[1]+s2*t[2]+s3*t[3];
if (result<-32768) result=-32768; if (result<-32768) result=-32768;
@ -609,8 +609,8 @@ bool DivSample::resampleCubic(double r) {
float* t=&cubicTable[n<<2]; float* t=&cubicTable[n<<2];
float s0=(posInt<1)?0:oldData8[posInt-1]; float s0=(posInt<1)?0:oldData8[posInt-1];
float s1=(posInt>=samples)?0:oldData8[posInt]; float s1=(posInt>=samples)?0:oldData8[posInt];
float s2=(posInt+1>=samples)?(isLoopable()?oldData8[loopStart]:0):oldData8[posInt+1]; float s2=(posInt+1>=samples)?((loopStart>=0 && loopStart<(int)samples)?oldData8[loopStart]:0):oldData8[posInt+1];
float s3=(posInt+2>=samples)?(isLoopable()?oldData8[loopStart]:0):oldData8[posInt+2]; float s3=(posInt+2>=samples)?((loopStart>=0 && loopStart<(int)samples)?oldData8[loopStart]:0):oldData8[posInt+2];
float result=s0*t[0]+s1*t[1]+s2*t[2]+s3*t[3]; float result=s0*t[0]+s1*t[1]+s2*t[2]+s3*t[3];
if (result<-128) result=-128; if (result<-128) result=-128;

View File

@ -3792,6 +3792,7 @@ void FurnaceGUI::drawInsEdit() {
ImGui::BeginDisabled(ins->amiga.useWave||ins->amiga.transWave.enable); ImGui::BeginDisabled(ins->amiga.useWave||ins->amiga.transWave.enable);
P(ImGui::Checkbox("Use sample map (does not work yet!)",&ins->amiga.useNoteMap)); P(ImGui::Checkbox("Use sample map (does not work yet!)",&ins->amiga.useNoteMap));
if (ins->amiga.useNoteMap) { if (ins->amiga.useNoteMap) {
// TODO: frequency map?
if (ImGui::BeginTable("NoteMap",3/*4*/,ImGuiTableFlags_ScrollY|ImGuiTableFlags_Borders|ImGuiTableFlags_SizingStretchSame)) { if (ImGui::BeginTable("NoteMap",3/*4*/,ImGuiTableFlags_ScrollY|ImGuiTableFlags_Borders|ImGuiTableFlags_SizingStretchSame)) {
ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed); ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch); ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch);
@ -3809,49 +3810,49 @@ void FurnaceGUI::drawInsEdit() {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text("Reversed"); ImGui::Text("Reversed");
for (int i=0; i<120; i++) { for (int i=0; i<120; i++) {
DivInstrumentAmiga::SampleMap& sampleMap=ins->amiga.noteMap[i];
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::PushID(fmt::sprintf("NM_%d",i).c_str()); ImGui::PushID(fmt::sprintf("NM_%d",i).c_str());
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text("%s",noteNames[60+i]); ImGui::Text("%s",noteNames[60+i]);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
if (ins->amiga.noteMap[i].map<0 || ins->amiga.noteMap[i].map>=e->song.sampleLen) { if (sampleMap.map<0 || sampleMap.map>=e->song.sampleLen) {
sName="-- empty --"; sName="-- empty --";
ins->amiga.noteMap[i].map=-1; sampleMap.map=-1;
} else { } else {
sName=e->song.sample[ins->amiga.noteMap[i].map]->name; sName=e->song.sample[sampleMap.map]->name;
} }
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
if (ImGui::BeginCombo(fmt::sprintf("##SampleMap_Index_%d",i).c_str(),sName.c_str())) { if (ImGui::BeginCombo(fmt::sprintf("##SampleMap_Index_%d",i).c_str(),sName.c_str())) {
String id; String id;
if (ImGui::Selectable("-- empty --",ins->amiga.noteMap[i].map==-1)) { PARAMETER if (ImGui::Selectable("-- empty --",sampleMap.map==-1)) { PARAMETER
ins->amiga.noteMap[i].map=-1; sampleMap.map=-1;
} }
for (int j=0; j<e->song.sampleLen; j++) { for (int j=0; j<e->song.sampleLen; j++) {
id=fmt::sprintf("%d: %s",j,e->song.sample[j]->name); id=fmt::sprintf("%d: %s",j,e->song.sample[j]->name);
if (ImGui::Selectable(id.c_str(),ins->amiga.noteMap[i].map==j)) { PARAMETER if (ImGui::Selectable(id.c_str(),sampleMap.map==j)) { PARAMETER
ins->amiga.noteMap[i].map=j; sampleMap.map=j;
if (ins->amiga.noteMap[i].freq<=0) ins->amiga.noteMap[i].freq=(int)((double)e->song.sample[j]->centerRate*pow(2.0,((double)i-48.0)/12.0)); if (sampleMap.freq<=0) sampleMap.freq=(int)((double)e->song.sample[j]->centerRate*pow(2.0,((double)i-48.0)/12.0));
} }
} }
ImGui::EndCombo(); ImGui::EndCombo();
} }
/* /*ImGui::TableNextColumn();
ImGui::TableNextColumn();
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
if (ImGui::InputInt(fmt::sprintf("##SampleMap_Freq_%d",i).c_str(),&ins->amiga.noteMap[i].freq,50,500)) { PARAMETER if (ImGui::InputInt(fmt::sprintf("##SampleMap_Freq_%d",i).c_str(),&sampleMap.freq,50,500)) { PARAMETER
if (ins->amiga.noteMap[i].freq<0) ins->amiga.noteMap[i].freq=0; if (sampleMap.freq<0) sampleMap.freq=0;
if (ins->amiga.noteMap[i].freq>262144) ins->amiga.noteMap[i].freq=262144; if (sampleMap.freq>262144) sampleMap.freq=262144;
} }
*/ */
ImGui::TableNextColumn(); ImGui::TableNextColumn();
if (ImGui::RadioButton(fmt::sprintf("Disable##SampleMap_Reversed_Disable_%d",i).c_str(),ins->amiga.noteMap[i].reversed==0)) { MARK_MODIFIED if (ImGui::RadioButton(fmt::sprintf("Disable##SampleMap_Reversed_Disable_%d",i).c_str(),sampleMap.reversed==0)) { MARK_MODIFIED
ins->amiga.noteMap[i].reversed=0; sampleMap.reversed=0;
} }
if (ImGui::RadioButton(fmt::sprintf("Enable##SampleMap_Reversed_Enable_%d",i).c_str(),ins->amiga.noteMap[i].reversed==1)) { MARK_MODIFIED if (ImGui::RadioButton(fmt::sprintf("Enable##SampleMap_Reversed_Enable_%d",i).c_str(),sampleMap.reversed==1)) { MARK_MODIFIED
ins->amiga.noteMap[i].reversed=1; sampleMap.reversed=1;
} }
if (ImGui::RadioButton(fmt::sprintf("Use instrument setting##SampleMap_Reversed_Default_%d",i).c_str(),ins->amiga.noteMap[i].reversed==2)) { MARK_MODIFIED if (ImGui::RadioButton(fmt::sprintf("Use instrument setting##SampleMap_Reversed_Default_%d",i).c_str(),sampleMap.reversed==2)) { MARK_MODIFIED
ins->amiga.noteMap[i].reversed=2; sampleMap.reversed=2;
} }
ImGui::PopID(); ImGui::PopID();
} }