new floating-point volumes and patchbay
This commit is contained in:
parent
7f5cdd6f6b
commit
6273275b47
10 changed files with 985 additions and 853 deletions
|
|
@ -1341,8 +1341,8 @@ String DivEngine::decodeSysDesc(String desc) {
|
|||
int val=0;
|
||||
int curStage=0;
|
||||
int sysID=0;
|
||||
int sysVol=0;
|
||||
int sysPan=0;
|
||||
float sysVol=0;
|
||||
float sysPan=0;
|
||||
int sysFlags=0;
|
||||
int curSys=0;
|
||||
desc+=' '; // ha
|
||||
|
|
@ -1357,24 +1357,25 @@ String DivEngine::decodeSysDesc(String desc) {
|
|||
curStage++;
|
||||
break;
|
||||
case 1:
|
||||
sysVol=val;
|
||||
sysVol=(float)val/64.0f;
|
||||
curStage++;
|
||||
break;
|
||||
case 2:
|
||||
sysPan=val;
|
||||
sysPan=(float)val/127.0f;
|
||||
curStage++;
|
||||
break;
|
||||
case 3:
|
||||
sysFlags=val;
|
||||
|
||||
if (sysID!=0) {
|
||||
if (sysVol<-128) sysVol=-128;
|
||||
if (sysVol>127) sysVol=127;
|
||||
if (sysPan<-128) sysPan=-128;
|
||||
if (sysPan>127) sysPan=127;
|
||||
if (sysVol<-1.0f) sysVol=-1.0f;
|
||||
if (sysVol>1.0f) sysVol=1.0f;
|
||||
if (sysPan<-1.0f) sysPan=-1.0f;
|
||||
if (sysPan>1.0f) sysPan=1.0f;
|
||||
newDesc.set(fmt::sprintf("id%d",curSys),sysID);
|
||||
newDesc.set(fmt::sprintf("vol%d",curSys),sysVol);
|
||||
newDesc.set(fmt::sprintf("pan%d",curSys),sysPan);
|
||||
newDesc.set(fmt::sprintf("fr%d",curSys),0.0f);
|
||||
DivConfig newFlagsC;
|
||||
newFlagsC.clear();
|
||||
convertOldFlags((unsigned int)sysFlags,newFlagsC,systemFromFileFur(sysID));
|
||||
|
|
@ -1404,7 +1405,7 @@ String DivEngine::decodeSysDesc(String desc) {
|
|||
return newDesc.toBase64();
|
||||
}
|
||||
|
||||
void DivEngine::initSongWithDesc(const char* description, bool inBase64) {
|
||||
void DivEngine::initSongWithDesc(const char* description, bool inBase64, bool oldVol) {
|
||||
int chanCount=0;
|
||||
DivConfig c;
|
||||
if (inBase64) {
|
||||
|
|
@ -1423,9 +1424,16 @@ void DivEngine::initSongWithDesc(const char* description, bool inBase64) {
|
|||
song.system[index]=DIV_SYSTEM_NULL;
|
||||
break;
|
||||
}
|
||||
song.systemVol[index]=c.getInt(fmt::sprintf("vol%d",index),DIV_SYSTEM_NULL);
|
||||
song.systemPan[index]=c.getInt(fmt::sprintf("pan%d",index),DIV_SYSTEM_NULL);
|
||||
song.systemVol[index]=c.getFloat(fmt::sprintf("vol%d",index),1.0f);
|
||||
song.systemPan[index]=c.getFloat(fmt::sprintf("pan%d",index),0.0f);
|
||||
song.systemPanFR[index]=c.getFloat(fmt::sprintf("fr%d",index),0.0f);
|
||||
song.systemFlags[index].clear();
|
||||
|
||||
if (oldVol) {
|
||||
song.systemVol[index]/=64.0f;
|
||||
song.systemPan[index]/=127.0f;
|
||||
}
|
||||
|
||||
String flags=c.getString(fmt::sprintf("flags%d",index),"");
|
||||
song.systemFlags[index].loadFromBase64(flags.c_str());
|
||||
}
|
||||
|
|
@ -1675,8 +1683,9 @@ bool DivEngine::addSystem(DivSystem which) {
|
|||
BUSY_BEGIN;
|
||||
saveLock.lock();
|
||||
song.system[song.systemLen]=which;
|
||||
song.systemVol[song.systemLen]=64;
|
||||
song.systemVol[song.systemLen]=1.0;
|
||||
song.systemPan[song.systemLen]=0;
|
||||
song.systemPanFR[song.systemLen]=0;
|
||||
song.systemFlags[song.systemLen++].clear();
|
||||
recalcChans();
|
||||
saveLock.unlock();
|
||||
|
|
@ -1721,6 +1730,7 @@ bool DivEngine::removeSystem(int index, bool preserveOrder) {
|
|||
song.system[i]=song.system[i+1];
|
||||
song.systemVol[i]=song.systemVol[i+1];
|
||||
song.systemPan[i]=song.systemPan[i+1];
|
||||
song.systemPanFR[i]=song.systemPanFR[i+1];
|
||||
song.systemFlags[i]=song.systemFlags[i+1];
|
||||
}
|
||||
recalcChans();
|
||||
|
|
@ -1835,17 +1845,21 @@ bool DivEngine::swapSystem(int src, int dest, bool preserveOrder) {
|
|||
}
|
||||
|
||||
DivSystem srcSystem=song.system[src];
|
||||
float srcVol=song.systemVol[src];
|
||||
float srcPan=song.systemPan[src];
|
||||
float srcPanFR=song.systemPanFR[src];
|
||||
|
||||
song.system[src]=song.system[dest];
|
||||
song.system[dest]=srcSystem;
|
||||
|
||||
song.systemVol[src]^=song.systemVol[dest];
|
||||
song.systemVol[dest]^=song.systemVol[src];
|
||||
song.systemVol[src]^=song.systemVol[dest];
|
||||
song.systemVol[src]=song.systemVol[dest];
|
||||
song.systemVol[dest]=srcVol;
|
||||
|
||||
song.systemPan[src]^=song.systemPan[dest];
|
||||
song.systemPan[dest]^=song.systemPan[src];
|
||||
song.systemPan[src]^=song.systemPan[dest];
|
||||
song.systemPan[src]=song.systemPan[dest];
|
||||
song.systemPan[dest]=srcPan;
|
||||
|
||||
song.systemPanFR[src]=song.systemPanFR[dest];
|
||||
song.systemPanFR[dest]=srcPanFR;
|
||||
|
||||
// I am kinda scared to use std::swap
|
||||
DivConfig oldFlags=song.systemFlags[src];
|
||||
|
|
@ -4265,13 +4279,15 @@ bool DivEngine::init() {
|
|||
if (!hasLoadedSomething) {
|
||||
logD("setting default preset");
|
||||
String preset=getConfString("initialSys2","");
|
||||
bool oldVol=getConfInt("configVersion",DIV_ENGINE_VERSION)<135;
|
||||
if (preset.empty()) {
|
||||
// try loading old preset
|
||||
preset=decodeSysDesc(getConfString("initialSys",""));
|
||||
oldVol=false;
|
||||
}
|
||||
logD("preset size %ld",preset.size());
|
||||
if (preset.size()>0 && (preset.size()&3)==0) {
|
||||
initSongWithDesc(preset.c_str());
|
||||
initSongWithDesc(preset.c_str(),true,oldVol);
|
||||
}
|
||||
String sysName=getConfString("initialSysName","");
|
||||
if (sysName=="") {
|
||||
|
|
|
|||
|
|
@ -47,8 +47,8 @@
|
|||
#define BUSY_BEGIN_SOFT softLocked=true; isBusy.lock();
|
||||
#define BUSY_END isBusy.unlock(); softLocked=false;
|
||||
|
||||
#define DIV_VERSION "dev134"
|
||||
#define DIV_ENGINE_VERSION 134
|
||||
#define DIV_VERSION "dev135"
|
||||
#define DIV_ENGINE_VERSION 135
|
||||
// for imports
|
||||
#define DIV_VERSION_MOD 0xff01
|
||||
#define DIV_VERSION_FC 0xff02
|
||||
|
|
@ -476,7 +476,7 @@ class DivEngine {
|
|||
bool deinitAudioBackend(bool dueToSwitchMaster=false);
|
||||
|
||||
void registerSystems();
|
||||
void initSongWithDesc(const char* description, bool inBase64=true);
|
||||
void initSongWithDesc(const char* description, bool inBase64=true, bool oldVol=false);
|
||||
|
||||
void exchangeIns(int one, int two);
|
||||
void swapChannels(int src, int dest);
|
||||
|
|
|
|||
|
|
@ -939,13 +939,13 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) {
|
|||
ds.systemLen=2;
|
||||
ds.system[0]=DIV_SYSTEM_YM2612;
|
||||
ds.system[1]=DIV_SYSTEM_SMS;
|
||||
ds.systemVol[1]=32;
|
||||
ds.systemVol[1]=0.5f;
|
||||
}
|
||||
if (ds.system[0]==DIV_SYSTEM_GENESIS_EXT) {
|
||||
ds.systemLen=2;
|
||||
ds.system[0]=DIV_SYSTEM_YM2612_EXT;
|
||||
ds.system[1]=DIV_SYSTEM_SMS;
|
||||
ds.systemVol[1]=32;
|
||||
ds.systemVol[1]=0.5f;
|
||||
}
|
||||
if (ds.system[0]==DIV_SYSTEM_ARCADE) {
|
||||
ds.systemLen=2;
|
||||
|
|
@ -1830,14 +1830,18 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
|
|||
|
||||
// system volume
|
||||
for (int i=0; i<DIV_MAX_CHIPS; i++) {
|
||||
ds.systemVol[i]=reader.readC();
|
||||
signed char oldSysVol=reader.readC();
|
||||
ds.systemVol[i]=(float)oldSysVol/64.0f;
|
||||
if (ds.version<59 && ds.system[i]==DIV_SYSTEM_NES) {
|
||||
ds.systemVol[i]/=4;
|
||||
}
|
||||
}
|
||||
|
||||
// system panning
|
||||
for (int i=0; i<DIV_MAX_CHIPS; i++) ds.systemPan[i]=reader.readC();
|
||||
for (int i=0; i<DIV_MAX_CHIPS; i++) {
|
||||
signed char oldSysPan=reader.readC();
|
||||
ds.systemPan[i]=(float)oldSysPan/127.0f;
|
||||
}
|
||||
|
||||
// system props
|
||||
for (int i=0; i<DIV_MAX_CHIPS; i++) {
|
||||
|
|
@ -1860,14 +1864,14 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
|
|||
ds.system[i]=DIV_SYSTEM_YM2612;
|
||||
if (i<31) {
|
||||
ds.system[i+1]=DIV_SYSTEM_SMS;
|
||||
ds.systemVol[i+1]=(((ds.systemVol[i]&127)*3)>>3)|(ds.systemVol[i]&128);
|
||||
ds.systemVol[i+1]=ds.systemVol[i]*0.375f;
|
||||
}
|
||||
}
|
||||
if (ds.system[i]==DIV_SYSTEM_GENESIS_EXT) {
|
||||
ds.system[i]=DIV_SYSTEM_YM2612_EXT;
|
||||
if (i<31) {
|
||||
ds.system[i+1]=DIV_SYSTEM_SMS;
|
||||
ds.systemVol[i+1]=(((ds.systemVol[i]&127)*3)>>3)|(ds.systemVol[i]&128);
|
||||
ds.systemVol[i+1]=ds.systemVol[i]*0.375f;
|
||||
}
|
||||
}
|
||||
if (ds.system[i]==DIV_SYSTEM_ARCADE) {
|
||||
|
|
@ -2200,6 +2204,21 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) {
|
|||
ds.autoSystem=true;
|
||||
}
|
||||
|
||||
// system output config
|
||||
if (ds.version>=135) {
|
||||
for (int i=0; i<ds.systemLen; i++) {
|
||||
ds.systemVol[i]=reader.readF();
|
||||
ds.systemPan[i]=reader.readF();
|
||||
ds.systemPanFR[i]=reader.readF();
|
||||
}
|
||||
|
||||
// patchbay
|
||||
unsigned int conns=reader.readI();
|
||||
for (unsigned int i=0; i<conns; i++) {
|
||||
ds.patchbay.push_back((unsigned int)reader.readI());
|
||||
}
|
||||
}
|
||||
|
||||
// read system flags
|
||||
if (ds.version>=119) {
|
||||
logD("reading chip flags...");
|
||||
|
|
@ -4308,11 +4327,11 @@ SafeWriter* DivEngine::saveFur(bool notPrimary) {
|
|||
}
|
||||
|
||||
for (int i=0; i<DIV_MAX_CHIPS; i++) {
|
||||
w->writeC(song.systemVol[i]);
|
||||
w->writeC(song.systemVol[i]*64.0f);
|
||||
}
|
||||
|
||||
for (int i=0; i<DIV_MAX_CHIPS; i++) {
|
||||
w->writeC(song.systemPan[i]);
|
||||
w->writeC(song.systemPan[i]*127.0f);
|
||||
}
|
||||
|
||||
// chip flags (we'll seek here later)
|
||||
|
|
@ -4456,6 +4475,17 @@ SafeWriter* DivEngine::saveFur(bool notPrimary) {
|
|||
w->writeString(song.systemNameJ,false);
|
||||
w->writeString(song.categoryJ,false);
|
||||
|
||||
// system output config
|
||||
for (int i=0; i<song.systemLen; i++) {
|
||||
w->writeF(song.systemVol[i]);
|
||||
w->writeF(song.systemPan[i]);
|
||||
w->writeF(song.systemPanFR[i]);
|
||||
}
|
||||
w->writeI(song.patchbay.size());
|
||||
for (unsigned int i: song.patchbay) {
|
||||
w->writeI(i);
|
||||
}
|
||||
|
||||
blockEndSeek=w->tell();
|
||||
w->seek(blockStartSeek,SEEK_SET);
|
||||
w->writeI(blockEndSeek-blockStartSeek-4);
|
||||
|
|
|
|||
|
|
@ -1720,10 +1720,10 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
|
|||
disCont[i].fillBuf(disCont[i].runtotal,disCont[i].lastAvail,size-disCont[i].lastAvail);
|
||||
}
|
||||
|
||||
// TODO: handle more than 2 outputs
|
||||
// TODO: patchbay
|
||||
for (int i=0; i<song.systemLen; i++) {
|
||||
float volL=((float)song.systemVol[i]/64.0f)*((float)MIN(127,127-(int)song.systemPan[i])/127.0f)*song.masterVol;
|
||||
float volR=((float)song.systemVol[i]/64.0f)*((float)MIN(127,127+(int)song.systemPan[i])/127.0f)*song.masterVol;
|
||||
float volL=song.systemVol[i]*MIN(1.0f,1.0f-song.systemPan[i])*song.masterVol;
|
||||
float volR=song.systemVol[i]*MIN(1.0f,1.0f+song.systemPan[i])*song.masterVol;
|
||||
volL*=disCont[i].dispatch->getPostAmp();
|
||||
volR*=disCont[i].dispatch->getPostAmp();
|
||||
if (disCont[i].dispatch->getOutputCount()>1) {
|
||||
|
|
|
|||
|
|
@ -238,8 +238,9 @@ struct DivSong {
|
|||
// system
|
||||
DivSystem system[DIV_MAX_CHIPS];
|
||||
unsigned char systemLen;
|
||||
signed char systemVol[DIV_MAX_CHIPS];
|
||||
signed char systemPan[DIV_MAX_CHIPS];
|
||||
float systemVol[DIV_MAX_CHIPS];
|
||||
float systemPan[DIV_MAX_CHIPS];
|
||||
float systemPanFR[DIV_MAX_CHIPS];
|
||||
DivConfig systemFlags[DIV_MAX_CHIPS];
|
||||
|
||||
// song information
|
||||
|
|
@ -334,6 +335,7 @@ struct DivSong {
|
|||
std::vector<DivSample*> sample;
|
||||
|
||||
std::vector<DivSubSong*> subsong;
|
||||
std::vector<unsigned int> patchbay;
|
||||
|
||||
DivInstrument nullIns, nullInsOPLL, nullInsOPL, nullInsOPLDrums, nullInsQSound;
|
||||
DivWavetable nullWave;
|
||||
|
|
@ -438,8 +440,9 @@ struct DivSong {
|
|||
oldArpStrategy(false) {
|
||||
for (int i=0; i<DIV_MAX_CHIPS; i++) {
|
||||
system[i]=DIV_SYSTEM_NULL;
|
||||
systemVol[i]=64;
|
||||
systemPan[i]=0;
|
||||
systemVol[i]=1.0;
|
||||
systemPan[i]=0.0;
|
||||
systemPanFR[i]=0.0;
|
||||
}
|
||||
subsong.push_back(new DivSubSong);
|
||||
system[0]=DIV_SYSTEM_YM2612;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue