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);
chan[ch].isReverseLoop=false;
switch (chan[ch].pcm.loopMode) {
case DIV_SAMPLE_LOOP_MAX: // One shot (no loop)
case DIV_SAMPLE_LOOP_MAX: // no loop
default:
break;
case DIV_SAMPLE_LOOP_FORWARD: // Foward loop
@ -326,11 +326,11 @@ void DivPlatformES5506::irqb(bool state) {
void DivPlatformES5506::tick(bool sysTick) {
for (int i=0; i<=chanMax; i++) {
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;
// volume/panning macros
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) {
chan[i].outVol=nextVol;
if (!isMuted[i]) {
@ -339,7 +339,7 @@ void DivPlatformES5506::tick(bool sysTick) {
}
}
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) {
chan[i].outLVol=nextLVol;
if (!isMuted[i]) {
@ -348,7 +348,7 @@ void DivPlatformES5506::tick(bool sysTick) {
}
}
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) {
chan[i].outRVol=nextRVol;
if (!isMuted[i]) {
@ -359,18 +359,9 @@ void DivPlatformES5506::tick(bool sysTick) {
// arpeggio/pitch macros, frequency related
if (chan[i].std.arp.had) {
if (!chan[i].inPorta) {
if (chan[i].std.arp.mode) {
chan[i].nextNote=chan[i].std.arp.val;
} else {
chan[i].nextNote=chan[i].note+chan[i].std.arp.val;
}
chan[i].nextNote=parent->calcArp(chan[i].note,chan[i].std.arp.val);
}
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.mode) {
@ -408,8 +399,7 @@ void DivPlatformES5506::tick(bool sysTick) {
chan[i].filterChanged.k1=1;
}
break;
/*
case 2: { // delta
/*case 2: { // delta
const signed int next_k1=CLAMP(chan[i].k1Offs+chan[i].std.ex1.val,-65535,65535);
if (chan[i].k1Offs!=next_k1) {
chan[i].k1Offs=next_k1;
@ -436,8 +426,7 @@ void DivPlatformES5506::tick(bool sysTick) {
chan[i].filterChanged.k2=1;
}
break;
/*
case 2: { // delta
/*case 2: { // delta
const signed int next_k2=CLAMP(chan[i].k2Offs+chan[i].std.ex2.val,-65535,65535);
if (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);
chan[i].isReverseLoop=false;
switch (chan[i].pcm.loopMode) {
case DIV_SAMPLE_LOOP_MAX: // One shot (no loop)
case DIV_SAMPLE_LOOP_MAX: // no loop
default:
break;
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;
chan[i].isReverseLoop=false;
switch (chan[i].pcm.loopMode) {
case DIV_SAMPLE_LOOP_MAX: // One shot (no loop)
case DIV_SAMPLE_LOOP_MAX: // no loop
default:
break;
case DIV_SAMPLE_LOOP_FORWARD: // Foward loop
@ -938,7 +927,7 @@ void DivPlatformES5506::tick(bool sysTick) {
int DivPlatformES5506::dispatch(DivCommand c) {
switch (c.cmd) {
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;
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())) ||
@ -1079,7 +1068,7 @@ int DivPlatformES5506::dispatch(DivCommand c) {
return chan[c.chan].outVol;
break;
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
if (chan[c.chan].lVol!=(unsigned int)(c.value)) {
chan[c.chan].lVol=c.value;
@ -1110,7 +1099,7 @@ int DivPlatformES5506::dispatch(DivCommand c) {
case DIV_CMD_WAVE:
if (!chan[c.chan].useWave) {
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)) ||
((!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))) {
@ -1221,7 +1210,7 @@ int DivPlatformES5506::dispatch(DivCommand c) {
}
case DIV_CMD_PRE_PORTA:
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;
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()) {
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++) {
if (sPreview.pos>=(int)s->samples || (sPreview.pEnd>=0 && sPreview.pos>=sPreview.pEnd)) {
samp_temp=0;

View File

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

View File

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