VGM export: why
This commit is contained in:
parent
38eed64734
commit
9f105d92a8
|
@ -807,6 +807,20 @@ void DivEngine::performVGMWrite(SafeWriter* w, DivSystem sys, DivRegWrite& write
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define CHIP_VOL(_id,_mult) { \
|
||||||
|
double _vol=fabs(song.systemVol[i])*4.0*_mult; \
|
||||||
|
if (_vol<0.0) _vol=0.0; \
|
||||||
|
if (_vol>32767.0) _vol=32767.0; \
|
||||||
|
chipVol.push_back((_id)|(0x80000000)|(((unsigned int)_vol)<<16)); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CHIP_VOL_SECOND(_id,_mult) { \
|
||||||
|
double _vol=fabs(song.systemVol[i])*4.0*_mult; \
|
||||||
|
if (_vol<0.0) _vol=0.0; \
|
||||||
|
if (_vol>32767.0) _vol=32767.0; \
|
||||||
|
chipVol.push_back((_id)|(0x80000100)|(((unsigned int)_vol)<<16)); \
|
||||||
|
}
|
||||||
|
|
||||||
SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool patternHints) {
|
SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool patternHints) {
|
||||||
if (version<0x150) {
|
if (version<0x150) {
|
||||||
lastError="VGM version is too low";
|
lastError="VGM version is too low";
|
||||||
|
@ -910,6 +924,7 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p
|
||||||
double loopFreq[DIV_MAX_CHANS];
|
double loopFreq[DIV_MAX_CHANS];
|
||||||
int loopSample[DIV_MAX_CHANS];
|
int loopSample[DIV_MAX_CHANS];
|
||||||
bool sampleDir[DIV_MAX_CHANS];
|
bool sampleDir[DIV_MAX_CHANS];
|
||||||
|
std::vector<unsigned int> chipVol;
|
||||||
|
|
||||||
for (int i=0; i<DIV_MAX_CHANS; i++) {
|
for (int i=0; i<DIV_MAX_CHANS; i++) {
|
||||||
loopTimer[i]=0;
|
loopTimer[i]=0;
|
||||||
|
@ -943,6 +958,7 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p
|
||||||
case DIV_SYSTEM_SMS:
|
case DIV_SYSTEM_SMS:
|
||||||
if (!hasSN) {
|
if (!hasSN) {
|
||||||
hasSN=disCont[i].dispatch->chipClock;
|
hasSN=disCont[i].dispatch->chipClock;
|
||||||
|
CHIP_VOL(0,1.0);
|
||||||
willExport[i]=true;
|
willExport[i]=true;
|
||||||
switch (song.systemFlags[i].getInt("chipType",0)) {
|
switch (song.systemFlags[i].getInt("chipType",0)) {
|
||||||
case 1: // real SN
|
case 1: // real SN
|
||||||
|
@ -961,6 +977,7 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p
|
||||||
} else if (!(hasSN&0x40000000)) {
|
} else if (!(hasSN&0x40000000)) {
|
||||||
isSecond[i]=true;
|
isSecond[i]=true;
|
||||||
willExport[i]=true;
|
willExport[i]=true;
|
||||||
|
CHIP_VOL_SECOND(0,1.0);
|
||||||
hasSN|=0x40000000;
|
hasSN|=0x40000000;
|
||||||
howManyChips++;
|
howManyChips++;
|
||||||
}
|
}
|
||||||
|
@ -1353,14 +1370,6 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//bool wantsExtraHeader=false;
|
|
||||||
/*for (int i=0; i<song.systemLen; i++) {
|
|
||||||
if (isSecond[i]) {
|
|
||||||
wantsExtraHeader=true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// write chips and stuff
|
// write chips and stuff
|
||||||
w->writeI(hasSN);
|
w->writeI(hasSN);
|
||||||
w->writeI(hasOPLL);
|
w->writeI(hasOPLL);
|
||||||
|
@ -1422,8 +1431,15 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p
|
||||||
w->writeC(0); // OPN
|
w->writeC(0); // OPN
|
||||||
w->writeC(0); // OPNA
|
w->writeC(0); // OPNA
|
||||||
}
|
}
|
||||||
|
if (version>=0x160) {
|
||||||
|
int calcVolume=32.0*(log(song.masterVol)/log(2.0));
|
||||||
|
if (calcVolume<-63) calcVolume=-63;
|
||||||
|
if (calcVolume>192) calcVolume=192;
|
||||||
|
w->writeC(calcVolume&0xff); // volume
|
||||||
|
} else {
|
||||||
|
w->writeC(0); // volume
|
||||||
|
}
|
||||||
// currently not used but is part of 1.60
|
// currently not used but is part of 1.60
|
||||||
w->writeC(0); // volume
|
|
||||||
w->writeC(0); // reserved
|
w->writeC(0); // reserved
|
||||||
w->writeC(0); // loop count
|
w->writeC(0); // loop count
|
||||||
// 1.51
|
// 1.51
|
||||||
|
@ -1507,15 +1523,21 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p
|
||||||
w->writeI(0);
|
w->writeI(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO
|
|
||||||
unsigned int exHeaderOff=w->tell();
|
unsigned int exHeaderOff=w->tell();
|
||||||
if (wantsExtraHeader) {
|
if (version>=0x170) {
|
||||||
w->writeI(4);
|
logD("writing extended header...");
|
||||||
|
w->writeI(8);
|
||||||
|
w->writeI(0);
|
||||||
w->writeI(4);
|
w->writeI(4);
|
||||||
|
|
||||||
// write clocks
|
// write chip volumes
|
||||||
w->writeC(howManyChips);
|
logD("writing chip volumes (%ld)...",chipVol.size());
|
||||||
}*/
|
w->writeC(chipVol.size());
|
||||||
|
for (unsigned int& i: chipVol) {
|
||||||
|
logV("- %.8x",i);
|
||||||
|
w->writeI(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int songOff=w->tell();
|
unsigned int songOff=w->tell();
|
||||||
|
|
||||||
|
@ -2015,10 +2037,10 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p
|
||||||
}
|
}
|
||||||
w->seek(0x34,SEEK_SET);
|
w->seek(0x34,SEEK_SET);
|
||||||
w->writeI(songOff-0x34);
|
w->writeI(songOff-0x34);
|
||||||
/*if (wantsExtraHeader) {
|
if (version>=0x170) {
|
||||||
w->seek(0xbc,SEEK_SET);
|
w->seek(0xbc,SEEK_SET);
|
||||||
w->writeI(exHeaderOff-0xbc);
|
w->writeI(exHeaderOff-0xbc);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
remainingLoops=-1;
|
remainingLoops=-1;
|
||||||
playing=false;
|
playing=false;
|
||||||
|
|
Loading…
Reference in New Issue