PLENTY OF TODO WHEN I COME BACK

CRASHES EVERYWHERE
This commit is contained in:
tildearrow 2022-09-25 20:07:21 -05:00
parent 148d537a18
commit a6e4345863
28 changed files with 141 additions and 127 deletions

View file

@ -382,7 +382,6 @@ void DivPlatformMSM6258::renderSamples() {
} else { } else {
memcpy(adpcmMem+memPos,s->dataVOX,paddedLen); memcpy(adpcmMem+memPos,s->dataVOX,paddedLen);
} }
s->offVOX=memPos;
memPos+=paddedLen; memPos+=paddedLen;
} }
adpcmMemLen=memPos+256; adpcmMemLen=memPos+256;

View file

@ -336,7 +336,10 @@ size_t DivPlatformMSM6295::getSampleMemUsage(int index) {
} }
void DivPlatformMSM6295::renderSamples() { void DivPlatformMSM6295::renderSamples() {
unsigned int sampleOffVOX[256];
memset(adpcmMem,0,getSampleMemCapacity(0)); memset(adpcmMem,0,getSampleMemCapacity(0));
memset(sampleOffVOX,0,256*sizeof(unsigned int));
// sample data // sample data
size_t memPos=128*8; size_t memPos=128*8;
@ -355,7 +358,7 @@ void DivPlatformMSM6295::renderSamples() {
} else { } else {
memcpy(adpcmMem+memPos,s->dataVOX,paddedLen); memcpy(adpcmMem+memPos,s->dataVOX,paddedLen);
} }
s->offVOX=memPos; sampleOffVOX[i]=memPos;
memPos+=paddedLen; memPos+=paddedLen;
} }
adpcmMemLen=memPos+256; adpcmMemLen=memPos+256;
@ -363,10 +366,10 @@ void DivPlatformMSM6295::renderSamples() {
// phrase book // phrase book
for (int i=0; i<sampleCount; i++) { for (int i=0; i<sampleCount; i++) {
DivSample* s=parent->song.sample[i]; DivSample* s=parent->song.sample[i];
int endPos=s->offVOX+s->lengthVOX; int endPos=sampleOffVOX[i]+s->lengthVOX;
adpcmMem[i*8]=(s->offVOX>>16)&0xff; adpcmMem[i*8]=(sampleOffVOX[i]>>16)&0xff;
adpcmMem[1+i*8]=(s->offVOX>>8)&0xff; adpcmMem[1+i*8]=(sampleOffVOX[i]>>8)&0xff;
adpcmMem[2+i*8]=(s->offVOX)&0xff; adpcmMem[2+i*8]=(sampleOffVOX[i])&0xff;
adpcmMem[3+i*8]=(endPos>>16)&0xff; adpcmMem[3+i*8]=(endPos>>16)&0xff;
adpcmMem[4+i*8]=(endPos>>8)&0xff; adpcmMem[4+i*8]=(endPos>>8)&0xff;
adpcmMem[5+i*8]=(endPos)&0xff; adpcmMem[5+i*8]=(endPos)&0xff;

View file

@ -317,7 +317,7 @@ void DivPlatformNES::tick(bool sysTick) {
dacRate=MIN(chan[4].freq*off,32000); dacRate=MIN(chan[4].freq*off,32000);
if (chan[4].keyOn) { if (chan[4].keyOn) {
if (dpcmMode && !skipRegisterWrites && dacSample>=0 && dacSample<parent->song.sampleLen) { if (dpcmMode && !skipRegisterWrites && dacSample>=0 && dacSample<parent->song.sampleLen) {
unsigned int dpcmAddr=parent->getSample(dacSample)->offDPCM; unsigned int dpcmAddr=sampleOffDPCM[dacSample];
unsigned int dpcmLen=(parent->getSample(dacSample)->lengthDPCM+15)>>4; unsigned int dpcmLen=(parent->getSample(dacSample)->lengthDPCM+15)>>4;
if (dpcmLen>255) dpcmLen=255; if (dpcmLen>255) dpcmLen=255;
goingToLoop=parent->getSample(dacSample)->isLoopable(); goingToLoop=parent->getSample(dacSample)->isLoopable();
@ -383,7 +383,7 @@ int DivPlatformNES::dispatch(DivCommand c) {
if (dumpWrites && !dpcmMode) addWrite(0xffff0001,dacRate); if (dumpWrites && !dpcmMode) addWrite(0xffff0001,dacRate);
chan[c.chan].furnaceDac=false; chan[c.chan].furnaceDac=false;
if (dpcmMode && !skipRegisterWrites) { if (dpcmMode && !skipRegisterWrites) {
unsigned int dpcmAddr=parent->getSample(dacSample)->offDPCM; unsigned int dpcmAddr=sampleOffDPCM[dacSample];
unsigned int dpcmLen=(parent->getSample(dacSample)->lengthDPCM+15)>>4; unsigned int dpcmLen=(parent->getSample(dacSample)->lengthDPCM+15)>>4;
if (dpcmLen>255) dpcmLen=255; if (dpcmLen>255) dpcmLen=255;
goingToLoop=parent->getSample(dacSample)->isLoopable(); goingToLoop=parent->getSample(dacSample)->isLoopable();
@ -724,7 +724,7 @@ void DivPlatformNES::renderSamples() {
} else { } else {
memcpy(dpcmMem+memPos,s->dataDPCM,MIN(s->lengthDPCM,paddedLen)); memcpy(dpcmMem+memPos,s->dataDPCM,MIN(s->lengthDPCM,paddedLen));
} }
s->offDPCM=memPos; sampleOffDPCM[i]=memPos;
memPos+=paddedLen; memPos+=paddedLen;
} }
dpcmMemLen=memPos; dpcmMemLen=memPos;

View file

@ -78,6 +78,7 @@ class DivPlatformNES: public DivDispatch {
xgm::NES_APU* nes1_NP; xgm::NES_APU* nes1_NP;
xgm::NES_DMC* nes2_NP; xgm::NES_DMC* nes2_NP;
unsigned char regPool[128]; unsigned char regPool[128];
unsigned int sampleOffDPCM[256];
friend void putDispatchChip(void*,int); friend void putDispatchChip(void*,int);
friend void putDispatchChan(void*,int,int); friend void putDispatchChan(void*,int,int);

View file

@ -690,9 +690,9 @@ int DivPlatformOPL::dispatch(DivCommand c) {
if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) { if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) {
DivSample* s=parent->getSample(chan[c.chan].sample); DivSample* s=parent->getSample(chan[c.chan].sample);
immWrite(8,0); immWrite(8,0);
immWrite(9,(s->offB>>2)&0xff); immWrite(9,(sampleOffB[chan[c.chan].sample]>>2)&0xff);
immWrite(10,(s->offB>>10)&0xff); immWrite(10,(sampleOffB[chan[c.chan].sample]>>10)&0xff);
int end=s->offB+s->lengthB-1; int end=sampleOffB[chan[c.chan].sample]+s->lengthB-1;
immWrite(11,(end>>2)&0xff); immWrite(11,(end>>2)&0xff);
immWrite(12,(end>>10)&0xff); immWrite(12,(end>>10)&0xff);
if (c.value!=DIV_NOTE_NULL) { if (c.value!=DIV_NOTE_NULL) {
@ -721,9 +721,9 @@ int DivPlatformOPL::dispatch(DivCommand c) {
if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) { if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) {
DivSample* s=parent->getSample(12*sampleBank+c.value%12); DivSample* s=parent->getSample(12*sampleBank+c.value%12);
immWrite(8,0); immWrite(8,0);
immWrite(9,(s->offB>>2)&0xff); immWrite(9,(sampleOffB[chan[c.chan].sample]>>2)&0xff);
immWrite(10,(s->offB>>10)&0xff); immWrite(10,(sampleOffB[chan[c.chan].sample]>>10)&0xff);
int end=s->offB+s->lengthB-1; int end=sampleOffB[chan[c.chan].sample]+s->lengthB-1;
immWrite(11,(end>>2)&0xff); immWrite(11,(end>>2)&0xff);
immWrite(12,(end>>10)&0xff); immWrite(12,(end>>10)&0xff);
int freq=(65536.0*(double)s->rate)/(double)chipRateBase; int freq=(65536.0*(double)s->rate)/(double)chipRateBase;
@ -1760,6 +1760,7 @@ size_t DivPlatformOPL::getSampleMemUsage(int index) {
void DivPlatformOPL::renderSamples() { void DivPlatformOPL::renderSamples() {
if (adpcmChan<0) return; if (adpcmChan<0) return;
memset(adpcmBMem,0,getSampleMemCapacity(0)); memset(adpcmBMem,0,getSampleMemCapacity(0));
memset(sampleOffB,0,256*sizeof(unsigned int));
size_t memPos=0; size_t memPos=0;
for (int i=0; i<parent->song.sampleLen; i++) { for (int i=0; i<parent->song.sampleLen; i++) {
@ -1778,7 +1779,7 @@ void DivPlatformOPL::renderSamples() {
} else { } else {
memcpy(adpcmBMem+memPos,s->dataB,paddedLen); memcpy(adpcmBMem+memPos,s->dataB,paddedLen);
} }
s->offB=memPos; sampleOffB[i]=memPos;
memPos+=paddedLen; memPos+=paddedLen;
} }
adpcmBMemLen=memPos+256; adpcmBMemLen=memPos+256;

View file

@ -90,6 +90,7 @@ class DivPlatformOPL: public DivDispatch {
unsigned char* adpcmBMem; unsigned char* adpcmBMem;
size_t adpcmBMemLen; size_t adpcmBMemLen;
DivOPLAInterface iface; DivOPLAInterface iface;
unsigned int sampleOffB[256];
ymfm::adpcm_b_engine* adpcmB; ymfm::adpcm_b_engine* adpcmB;
const unsigned char** slotsNonDrums; const unsigned char** slotsNonDrums;

View file

@ -286,8 +286,8 @@ void DivPlatformQSound::tick(bool sysTick) {
uint16_t qsound_end = 0; uint16_t qsound_end = 0;
if (chan[i].sample>=0 && chan[i].sample<parent->song.sampleLen) { if (chan[i].sample>=0 && chan[i].sample<parent->song.sampleLen) {
DivSample* s=parent->getSample(chan[i].sample); DivSample* s=parent->getSample(chan[i].sample);
qsound_bank = 0x8000 | (s->offQSound >> 16); qsound_bank = 0x8000 | (offPCM[chan[i].sample] >> 16);
qsound_addr = s->offQSound & 0xffff; qsound_addr = offPCM[chan[i].sample] & 0xffff;
int loopStart=s->loopStart; int loopStart=s->loopStart;
int length = s->loopEnd; int length = s->loopEnd;
@ -295,10 +295,10 @@ void DivPlatformQSound::tick(bool sysTick) {
length = 65536 - 16; length = 65536 - 16;
} }
if (loopStart == -1 || loopStart >= length) { if (loopStart == -1 || loopStart >= length) {
qsound_end = s->offQSound + length + 15; qsound_end = offPCM[chan[i].sample] + length + 15;
qsound_loop = 15; qsound_loop = 15;
} else { } else {
qsound_end = s->offQSound + length; qsound_end = offPCM[chan[i].sample] + length;
qsound_loop = length - loopStart; qsound_loop = length - loopStart;
} }
} }
@ -644,6 +644,7 @@ size_t DivPlatformQSound::getSampleMemUsage(int index) {
return index == 0 ? sampleMemLen : 0; return index == 0 ? sampleMemLen : 0;
} }
// TODO: ADPCM... come on...
void DivPlatformQSound::renderSamples() { void DivPlatformQSound::renderSamples() {
memset(sampleMem,0,getSampleMemCapacity()); memset(sampleMem,0,getSampleMemCapacity());
@ -671,7 +672,7 @@ void DivPlatformQSound::renderSamples() {
sampleMem[(memPos+i)^0x8000]=s->data8[i]; sampleMem[(memPos+i)^0x8000]=s->data8[i];
} }
} }
s->offQSound=memPos^0x8000; offPCM[i]=memPos^0x8000;
memPos+=length+16; memPos+=length+16;
} }
sampleMemLen=memPos+256; sampleMemLen=memPos+256;

View file

@ -72,6 +72,9 @@ class DivPlatformQSound: public DivDispatch {
struct qsound_chip chip; struct qsound_chip chip;
unsigned short regPool[512]; unsigned short regPool[512];
unsigned int offPCM[256];
unsigned int offBS[256];
friend void putDispatchChip(void*,int); friend void putDispatchChip(void*,int);
friend void putDispatchChan(void*,int,int); friend void putDispatchChan(void*,int,int);

View file

@ -122,6 +122,9 @@ void DivPlatformRF5C68::tick(bool sysTick) {
} else { } else {
chan[i].audPos=0; chan[i].audPos=0;
} }
// TODO: BANG BANG BANG
// AAAAAAAAAAAAAAAAAAA
// ASGDJFJFSDGL;ASDHFKJLSHFLKAJSFHKLJVSJ
if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) { if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) {
unsigned char keyon=regPool[8]&~(1<<i); unsigned char keyon=regPool[8]&~(1<<i);
unsigned char keyoff=keyon|(1<<i); unsigned char keyoff=keyon|(1<<i);
@ -130,7 +133,7 @@ void DivPlatformRF5C68::tick(bool sysTick) {
chan[i].freq=(int)(off*parent->calcFreq(chan[i].baseFreq,chan[i].pitch,false,2,chan[i].pitch2,chipClock,CHIP_FREQBASE)); chan[i].freq=(int)(off*parent->calcFreq(chan[i].baseFreq,chan[i].pitch,false,2,chan[i].pitch2,chipClock,CHIP_FREQBASE));
if (chan[i].freq>65535) chan[i].freq=65535; if (chan[i].freq>65535) chan[i].freq=65535;
if (chan[i].keyOn) { if (chan[i].keyOn) {
unsigned int start=s->offRF5C68; unsigned int start=sampleOffRFC[chan[i].sample];
unsigned int loop=start+s->length8; unsigned int loop=start+s->length8;
if (chan[i].audPos>0) { if (chan[i].audPos>0) {
start=start+MIN(chan[i].audPos,s->length8); start=start+MIN(chan[i].audPos,s->length8);
@ -383,6 +386,7 @@ size_t DivPlatformRF5C68::getSampleMemUsage(int index) {
void DivPlatformRF5C68::renderSamples() { void DivPlatformRF5C68::renderSamples() {
memset(sampleMem,0,getSampleMemCapacity()); memset(sampleMem,0,getSampleMemCapacity());
memset(sampleOffRFC,0,256*sizeof(unsigned int));
size_t memPos=0; size_t memPos=0;
for (int i=0; i<parent->song.sampleLen; i++) { for (int i=0; i<parent->song.sampleLen; i++) {
@ -390,7 +394,7 @@ void DivPlatformRF5C68::renderSamples() {
int length=s->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT); int length=s->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT);
int actualLength=MIN((int)(getSampleMemCapacity()-memPos)-31,length); int actualLength=MIN((int)(getSampleMemCapacity()-memPos)-31,length);
if (actualLength>0) { if (actualLength>0) {
s->offRF5C68=memPos; sampleOffRFC[i]=memPos;
for (int j=0; j<actualLength; j++) { for (int j=0; j<actualLength; j++) {
// convert to signed magnitude // convert to signed magnitude
signed char val=s->data8[j]; signed char val=s->data8[j];

View file

@ -66,6 +66,7 @@ class DivPlatformRF5C68: public DivDispatch {
bool isMuted[8]; bool isMuted[8];
int chipType; int chipType;
unsigned char curChan; unsigned char curChan;
unsigned int sampleOffRFC[256];
unsigned char* sampleMem; unsigned char* sampleMem;
size_t sampleMemLen; size_t sampleMemLen;

View file

@ -159,17 +159,17 @@ void DivPlatformSegaPCM::tick(bool sysTick) {
int loopStart=s->getLoopStartPosition(DIV_SAMPLE_DEPTH_8BIT); int loopStart=s->getLoopStartPosition(DIV_SAMPLE_DEPTH_8BIT);
int actualLength=(s->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT)); int actualLength=(s->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT));
if (actualLength>0xfeff) actualLength=0xfeff; if (actualLength>0xfeff) actualLength=0xfeff;
addWrite(0x10086+(i<<3),3+((s->offSegaPCM>>16)<<3)); addWrite(0x10086+(i<<3),3+((sampleOffSegaPCM[chan[i].pcm.sample]>>16)<<3));
addWrite(0x10084+(i<<3),(s->offSegaPCM)&0xff); addWrite(0x10084+(i<<3),(sampleOffSegaPCM[chan[i].pcm.sample])&0xff);
addWrite(0x10085+(i<<3),(s->offSegaPCM>>8)&0xff); addWrite(0x10085+(i<<3),(sampleOffSegaPCM[chan[i].pcm.sample]>>8)&0xff);
addWrite(0x10006+(i<<3),MIN(255,((s->offSegaPCM&0xffff)+actualLength-1)>>8)); addWrite(0x10006+(i<<3),MIN(255,((sampleOffSegaPCM[chan[i].pcm.sample]&0xffff)+actualLength-1)>>8));
if (loopStart<0 || loopStart>=actualLength) { if (loopStart<0 || loopStart>=actualLength) {
addWrite(0x10086+(i<<3),2+((s->offSegaPCM>>16)<<3)); addWrite(0x10086+(i<<3),2+((sampleOffSegaPCM[chan[i].pcm.sample]>>16)<<3));
} else { } else {
int loopPos=(s->offSegaPCM&0xffff)+loopStart+s->loopOffP; int loopPos=(sampleOffSegaPCM[chan[i].pcm.sample]&0xffff)+loopStart+s->loopOffP;
addWrite(0x10004+(i<<3),loopPos&0xff); addWrite(0x10004+(i<<3),loopPos&0xff);
addWrite(0x10005+(i<<3),(loopPos>>8)&0xff); addWrite(0x10005+(i<<3),(loopPos>>8)&0xff);
addWrite(0x10086+(i<<3),((s->offSegaPCM>>16)<<3)); addWrite(0x10086+(i<<3),((sampleOffSegaPCM[chan[i].pcm.sample]>>16)<<3));
} }
} }
} else { } else {
@ -178,17 +178,17 @@ void DivPlatformSegaPCM::tick(bool sysTick) {
int loopStart=s->getLoopStartPosition(DIV_SAMPLE_DEPTH_8BIT); int loopStart=s->getLoopStartPosition(DIV_SAMPLE_DEPTH_8BIT);
int actualLength=(s->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT)); int actualLength=(s->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT));
if (actualLength>65536) actualLength=65536; if (actualLength>65536) actualLength=65536;
addWrite(0x10086+(i<<3),3+((s->offSegaPCM>>16)<<3)); addWrite(0x10086+(i<<3),3+((sampleOffSegaPCM[chan[i].pcm.sample]>>16)<<3));
addWrite(0x10084+(i<<3),(s->offSegaPCM)&0xff); addWrite(0x10084+(i<<3),(sampleOffSegaPCM[chan[i].pcm.sample])&0xff);
addWrite(0x10085+(i<<3),(s->offSegaPCM>>8)&0xff); addWrite(0x10085+(i<<3),(sampleOffSegaPCM[chan[i].pcm.sample]>>8)&0xff);
addWrite(0x10006+(i<<3),MIN(255,((s->offSegaPCM&0xffff)+actualLength-1)>>8)); addWrite(0x10006+(i<<3),MIN(255,((sampleOffSegaPCM[chan[i].pcm.sample]&0xffff)+actualLength-1)>>8));
if (loopStart<0 || loopStart>=actualLength) { if (loopStart<0 || loopStart>=actualLength) {
addWrite(0x10086+(i<<3),2+((s->offSegaPCM>>16)<<3)); addWrite(0x10086+(i<<3),2+((sampleOffSegaPCM[chan[i].pcm.sample]>>16)<<3));
} else { } else {
int loopPos=(s->offSegaPCM&0xffff)+loopStart+s->loopOffP; int loopPos=(sampleOffSegaPCM[chan[i].pcm.sample]&0xffff)+loopStart+s->loopOffP;
addWrite(0x10004+(i<<3),loopPos&0xff); addWrite(0x10004+(i<<3),loopPos&0xff);
addWrite(0x10005+(i<<3),(loopPos>>8)&0xff); addWrite(0x10005+(i<<3),(loopPos>>8)&0xff);
addWrite(0x10086+(i<<3),((s->offSegaPCM>>16)<<3)); addWrite(0x10086+(i<<3),((sampleOffSegaPCM[chan[i].pcm.sample]>>16)<<3));
} }
addWrite(0x10007+(i<<3),chan[i].pcm.freq); addWrite(0x10007+(i<<3),chan[i].pcm.freq);
} }
@ -451,6 +451,10 @@ void DivPlatformSegaPCM::reset() {
} }
} }
void DivPlatformSegaPCM::renderSamples() {
// TODO: THIS MESS
}
void DivPlatformSegaPCM::setFlags(unsigned int flags) { void DivPlatformSegaPCM::setFlags(unsigned int flags) {
chipClock=8000000.0; chipClock=8000000.0;
rate=31250; rate=31250;

View file

@ -92,6 +92,8 @@ class DivPlatformSegaPCM: public DivDispatch {
short oldWrites[256]; short oldWrites[256];
short pendingWrites[256]; short pendingWrites[256];
unsigned int sampleOffSegaPCM[256];
friend void putDispatchChip(void*,int); friend void putDispatchChip(void*,int);
friend void putDispatchChan(void*,int,int); friend void putDispatchChan(void*,int,int);
@ -108,6 +110,7 @@ class DivPlatformSegaPCM: public DivDispatch {
void tick(bool sysTick=true); void tick(bool sysTick=true);
void muteChannel(int ch, bool mute); void muteChannel(int ch, bool mute);
void notifyInsChange(int ins); void notifyInsChange(int ins);
void renderSamples();
void setFlags(unsigned int flags); void setFlags(unsigned int flags);
bool isStereo(); bool isStereo();
void poke(unsigned int addr, unsigned short val); void poke(unsigned int addr, unsigned short val);

View file

@ -178,6 +178,7 @@ void DivPlatformSNES::tick(bool sysTick) {
updateWave(i); updateWave(i);
} }
} }
// TODO: THIS WILL CRASH IF THE SAMPLE IS INVALID!!!
if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) { if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) {
DivSample* s=parent->getSample(chan[i].sample); DivSample* s=parent->getSample(chan[i].sample);
double off=(s->centerRate>=1)?((double)s->centerRate/8363.0):1.0; double off=(s->centerRate>=1)?((double)s->centerRate/8363.0):1.0;
@ -191,7 +192,7 @@ void DivPlatformSNES::tick(bool sysTick) {
start=waveTableAddr(i); start=waveTableAddr(i);
loop=start; loop=start;
} else { } else {
start=s->offSNES; start=sampleOff[chan[i].sample];
end=MIN(start+MAX(s->lengthBRR,1),getSampleMemCapacity()); end=MIN(start+MAX(s->lengthBRR,1),getSampleMemCapacity());
loop=MAX(start,end-1); loop=MAX(start,end-1);
if (chan[i].audPos>0) { if (chan[i].audPos>0) {
@ -567,6 +568,7 @@ size_t DivPlatformSNES::getSampleMemUsage(int index) {
void DivPlatformSNES::renderSamples() { void DivPlatformSNES::renderSamples() {
memset(sampleMem,0,getSampleMemCapacity()); memset(sampleMem,0,getSampleMemCapacity());
memset(sampleOff,0,256*sizeof(unsigned int));
// skip past sample table and wavetable buffer // skip past sample table and wavetable buffer
size_t memPos=sampleTableBase+8*4+8*9*16; size_t memPos=sampleTableBase+8*4+8*9*16;
@ -575,7 +577,7 @@ void DivPlatformSNES::renderSamples() {
int length=s->lengthBRR; int length=s->lengthBRR;
int actualLength=MIN((int)(getSampleMemCapacity()-memPos)/9*9,length); int actualLength=MIN((int)(getSampleMemCapacity()-memPos)/9*9,length);
if (actualLength>0) { if (actualLength>0) {
s->offSNES=memPos; sampleOff[i]=memPos;
memcpy(&sampleMem[memPos],s->dataBRR,actualLength); memcpy(&sampleMem[memPos],s->dataBRR,actualLength);
memPos+=actualLength; memPos+=actualLength;
} }

View file

@ -92,6 +92,7 @@ class DivPlatformSNES: public DivDispatch {
signed char sampleMem[65536]; signed char sampleMem[65536];
size_t sampleMemLen; size_t sampleMemLen;
unsigned int sampleOff[256];
unsigned char regPool[0x80]; unsigned char regPool[0x80];
SPC_DSP dsp; SPC_DSP dsp;
friend void putDispatchChan(void*,int,int); friend void putDispatchChan(void*,int,int);

View file

@ -161,10 +161,11 @@ void DivPlatformSoundUnit::tick(bool sysTick) {
if (chan[i].keyOn) { if (chan[i].keyOn) {
if (chan[i].pcm) { if (chan[i].pcm) {
DivInstrument* ins=parent->getIns(chan[i].ins,DIV_INS_SU); DivInstrument* ins=parent->getIns(chan[i].ins,DIV_INS_SU);
DivSample* sample=parent->getSample(ins->amiga.getSample(chan[i].note)); int sNum=ins->amiga.getSample(chan[i].note);
DivSample* sample=parent->getSample(sNum);
if (sample!=NULL) { if (sample!=NULL) {
unsigned int sampleEnd=sample->offSU+(sample->getLoopEndPosition()); unsigned int sampleEnd=sampleOffSU[sNum]+(sample->getLoopEndPosition());
unsigned int off=sample->offSU+chan[i].hasOffset; unsigned int off=sampleOffSU[sNum]+chan[i].hasOffset;
chan[i].hasOffset=0; chan[i].hasOffset=0;
if (sampleEnd>=getSampleMemCapacity(0)) sampleEnd=getSampleMemCapacity(0)-1; if (sampleEnd>=getSampleMemCapacity(0)) sampleEnd=getSampleMemCapacity(0)-1;
chWrite(i,0x0a,off&0xff); chWrite(i,0x0a,off&0xff);
@ -172,7 +173,7 @@ void DivPlatformSoundUnit::tick(bool sysTick) {
chWrite(i,0x0c,sampleEnd&0xff); chWrite(i,0x0c,sampleEnd&0xff);
chWrite(i,0x0d,sampleEnd>>8); chWrite(i,0x0d,sampleEnd>>8);
if (sample->isLoopable()) { if (sample->isLoopable()) {
unsigned int sampleLoop=sample->offSU+sample->getLoopStartPosition(); unsigned int sampleLoop=sampleOffSU[sNum]+sample->getLoopStartPosition();
if (sampleLoop>=getSampleMemCapacity(0)) sampleLoop=getSampleMemCapacity(0)-1; if (sampleLoop>=getSampleMemCapacity(0)) sampleLoop=getSampleMemCapacity(0)-1;
chWrite(i,0x0e,sampleLoop&0xff); chWrite(i,0x0e,sampleLoop&0xff);
chWrite(i,0x0f,sampleLoop>>8); chWrite(i,0x0f,sampleLoop>>8);
@ -547,6 +548,7 @@ size_t DivPlatformSoundUnit::getSampleMemUsage(int index) {
void DivPlatformSoundUnit::renderSamples() { void DivPlatformSoundUnit::renderSamples() {
memset(su->pcm,0,getSampleMemCapacity(0)); memset(su->pcm,0,getSampleMemCapacity(0));
memset(sampleOffSU,0,256*sizeof(unsigned int));
size_t memPos=0; size_t memPos=0;
for (int i=0; i<parent->song.sampleLen; i++) { for (int i=0; i<parent->song.sampleLen; i++) {
@ -563,7 +565,7 @@ void DivPlatformSoundUnit::renderSamples() {
} else { } else {
memcpy(su->pcm+memPos,s->data8,paddedLen); memcpy(su->pcm+memPos,s->data8,paddedLen);
} }
s->offSU=memPos; sampleOffSU[i]=memPos;
memPos+=paddedLen; memPos+=paddedLen;
} }
sampleMemLen=memPos; sampleMemLen=memPos;

View file

@ -101,6 +101,7 @@ class DivPlatformSoundUnit: public DivDispatch {
unsigned char ilCtrl, ilSize, fil1; unsigned char ilCtrl, ilSize, fil1;
unsigned char initIlCtrl, initIlSize, initFil1; unsigned char initIlCtrl, initIlSize, initFil1;
signed char echoVol, initEchoVol; signed char echoVol, initEchoVol;
unsigned int sampleOffSU[256];
int cycles, curChan, delay; int cycles, curChan, delay;
short tempL; short tempL;

View file

@ -541,14 +541,14 @@ int DivPlatformX1_010::dispatch(DivCommand c) {
DivSample* s=parent->getSample(chan[c.chan].sample); DivSample* s=parent->getSample(chan[c.chan].sample);
if (isBanked) { if (isBanked) {
chan[c.chan].bankSlot=ins->x1_010.bankSlot; chan[c.chan].bankSlot=ins->x1_010.bankSlot;
bankSlot[chan[c.chan].bankSlot]=s->offX1_010>>17; bankSlot[chan[c.chan].bankSlot]=sampleOffX1[chan[c.chan].sample]>>17;
unsigned int bankedOffs=(chan[c.chan].bankSlot<<17)|(s->offX1_010&0x1ffff); unsigned int bankedOffs=(chan[c.chan].bankSlot<<17)|(sampleOffX1[chan[c.chan].sample]&0x1ffff);
chWrite(c.chan,4,(bankedOffs>>12)&0xff); chWrite(c.chan,4,(bankedOffs>>12)&0xff);
int end=(bankedOffs+MIN(s->length8,0x1ffff)+0xfff)&~0xfff; // padded int end=(bankedOffs+MIN(s->length8,0x1ffff)+0xfff)&~0xfff; // padded
chWrite(c.chan,5,(0x100-(end>>12))&0xff); chWrite(c.chan,5,(0x100-(end>>12))&0xff);
} else { } else {
chWrite(c.chan,4,(s->offX1_010>>12)&0xff); chWrite(c.chan,4,(sampleOffX1[chan[c.chan].sample]>>12)&0xff);
int end=(s->offX1_010+s->length8+0xfff)&~0xfff; // padded int end=(sampleOffX1[chan[c.chan].sample]+s->length8+0xfff)&~0xfff; // padded
chWrite(c.chan,5,(0x100-(end>>12))&0xff); chWrite(c.chan,5,(0x100-(end>>12))&0xff);
} }
if (c.value!=DIV_NOTE_NULL) { if (c.value!=DIV_NOTE_NULL) {
@ -581,14 +581,14 @@ int DivPlatformX1_010::dispatch(DivCommand c) {
} }
DivSample* s=parent->getSample(12*sampleBank+c.value%12); DivSample* s=parent->getSample(12*sampleBank+c.value%12);
if (isBanked) { if (isBanked) {
bankSlot[chan[c.chan].bankSlot]=s->offX1_010>>17; bankSlot[chan[c.chan].bankSlot]=sampleOffX1[chan[c.chan].sample]>>17;
unsigned int bankedOffs=(chan[c.chan].bankSlot<<17)|(s->offX1_010&0x1ffff); unsigned int bankedOffs=(chan[c.chan].bankSlot<<17)|(sampleOffX1[chan[c.chan].sample]&0x1ffff);
chWrite(c.chan,4,(bankedOffs>>12)&0xff); chWrite(c.chan,4,(bankedOffs>>12)&0xff);
int end=(bankedOffs+MIN(s->length8,0x1ffff)+0xfff)&~0xfff; // padded int end=(bankedOffs+MIN(s->length8,0x1ffff)+0xfff)&~0xfff; // padded
chWrite(c.chan,5,(0x100-(end>>12))&0xff); chWrite(c.chan,5,(0x100-(end>>12))&0xff);
} else { } else {
chWrite(c.chan,4,(s->offX1_010>>12)&0xff); chWrite(c.chan,4,(sampleOffX1[chan[c.chan].sample]>>12)&0xff);
int end=(s->offX1_010+s->length8+0xfff)&~0xfff; // padded int end=(sampleOffX1[chan[c.chan].sample]+s->length8+0xfff)&~0xfff; // padded
chWrite(c.chan,5,(0x100-(end>>12))&0xff); chWrite(c.chan,5,(0x100-(end>>12))&0xff);
} }
chan[c.chan].baseFreq=(((unsigned int)s->rate)<<4)/(chipClock/512); chan[c.chan].baseFreq=(((unsigned int)s->rate)<<4)/(chipClock/512);
@ -945,6 +945,7 @@ size_t DivPlatformX1_010::getSampleMemUsage(int index) {
void DivPlatformX1_010::renderSamples() { void DivPlatformX1_010::renderSamples() {
memset(sampleMem,0,getSampleMemCapacity()); memset(sampleMem,0,getSampleMemCapacity());
memset(sampleOffX1,0,256*sizeof(unsigned int));
size_t memPos=0; size_t memPos=0;
for (int i=0; i<parent->song.sampleLen; i++) { for (int i=0; i<parent->song.sampleLen; i++) {
@ -969,7 +970,7 @@ void DivPlatformX1_010::renderSamples() {
} else { } else {
memcpy(sampleMem+memPos,s->data8,paddedLen); memcpy(sampleMem+memPos,s->data8,paddedLen);
} }
s->offX1_010=memPos; sampleOffX1[i]=memPos;
memPos+=paddedLen; memPos+=paddedLen;
} }
sampleMemLen=memPos+256; sampleMemLen=memPos+256;

View file

@ -115,6 +115,7 @@ class DivPlatformX1_010: public DivDispatch, public vgsound_emu_mem_intf {
bool isBanked=false; bool isBanked=false;
unsigned int bankSlot[8]; unsigned int bankSlot[8];
unsigned int sampleOffX1[256];
unsigned char regPool[0x2000]; unsigned char regPool[0x2000];
double NoteX1_010(int ch, int note); double NoteX1_010(int ch, int note);

View file

@ -684,9 +684,9 @@ int DivPlatformYM2608::dispatch(DivCommand c) {
chan[c.chan].sample=ins->amiga.getSample(c.value); chan[c.chan].sample=ins->amiga.getSample(c.value);
if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) { if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) {
DivSample* s=parent->getSample(chan[c.chan].sample); DivSample* s=parent->getSample(chan[c.chan].sample);
immWrite(0x102,(s->offB>>5)&0xff); immWrite(0x102,(sampleOffB[chan[c.chan].sample]>>5)&0xff);
immWrite(0x103,(s->offB>>13)&0xff); immWrite(0x103,(sampleOffB[chan[c.chan].sample]>>13)&0xff);
int end=s->offB+s->lengthB-1; int end=sampleOffB[chan[c.chan].sample]+s->lengthB-1;
immWrite(0x104,(end>>5)&0xff); immWrite(0x104,(end>>5)&0xff);
immWrite(0x105,(end>>13)&0xff); immWrite(0x105,(end>>13)&0xff);
immWrite(0x101,(isMuted[c.chan]?0:(chan[c.chan].pan<<6))|2); immWrite(0x101,(isMuted[c.chan]?0:(chan[c.chan].pan<<6))|2);
@ -715,9 +715,9 @@ int DivPlatformYM2608::dispatch(DivCommand c) {
chan[c.chan].sample=12*sampleBank+c.value%12; chan[c.chan].sample=12*sampleBank+c.value%12;
if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) { if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) {
DivSample* s=parent->getSample(chan[c.chan].sample); DivSample* s=parent->getSample(chan[c.chan].sample);
immWrite(0x102,(s->offB>>5)&0xff); immWrite(0x102,(sampleOffB[chan[c.chan].sample]>>5)&0xff);
immWrite(0x103,(s->offB>>13)&0xff); immWrite(0x103,(sampleOffB[chan[c.chan].sample]>>13)&0xff);
int end=s->offB+s->lengthB-1; int end=sampleOffB[chan[c.chan].sample]+s->lengthB-1;
immWrite(0x104,(end>>5)&0xff); immWrite(0x104,(end>>5)&0xff);
immWrite(0x105,(end>>13)&0xff); immWrite(0x105,(end>>13)&0xff);
immWrite(0x101,(isMuted[c.chan]?0:(chan[c.chan].pan<<6))|2); immWrite(0x101,(isMuted[c.chan]?0:(chan[c.chan].pan<<6))|2);
@ -1334,6 +1334,7 @@ size_t DivPlatformYM2608::getSampleMemUsage(int index) {
void DivPlatformYM2608::renderSamples() { void DivPlatformYM2608::renderSamples() {
memset(adpcmBMem,0,getSampleMemCapacity(0)); memset(adpcmBMem,0,getSampleMemCapacity(0));
memset(sampleOffB,0,256*sizeof(unsigned int));
size_t memPos=0; size_t memPos=0;
for (int i=0; i<parent->song.sampleLen; i++) { for (int i=0; i<parent->song.sampleLen; i++) {
@ -1352,7 +1353,7 @@ void DivPlatformYM2608::renderSamples() {
} else { } else {
memcpy(adpcmBMem+memPos,s->dataB,paddedLen); memcpy(adpcmBMem+memPos,s->dataB,paddedLen);
} }
s->offB=memPos; sampleOffB[i]=memPos;
memPos+=paddedLen; memPos+=paddedLen;
} }
adpcmBMemLen=memPos+256; adpcmBMemLen=memPos+256;

View file

@ -99,6 +99,7 @@ class DivPlatformYM2608: public DivPlatformOPN {
unsigned char* adpcmBMem; unsigned char* adpcmBMem;
size_t adpcmBMemLen; size_t adpcmBMemLen;
DivYM2608Interface iface; DivYM2608Interface iface;
unsigned int sampleOffB[256];
DivPlatformAY8910* ay; DivPlatformAY8910* ay;
unsigned char sampleBank; unsigned char sampleBank;

View file

@ -623,9 +623,9 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
chan[c.chan].sample=ins->amiga.getSample(c.value); chan[c.chan].sample=ins->amiga.getSample(c.value);
if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) { if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) {
DivSample* s=parent->getSample(chan[c.chan].sample); DivSample* s=parent->getSample(chan[c.chan].sample);
immWrite(0x12,(s->offB>>8)&0xff); immWrite(0x12,(sampleOffB[chan[c.chan].sample]>>8)&0xff);
immWrite(0x13,s->offB>>16); immWrite(0x13,sampleOffB[chan[c.chan].sample]>>16);
int end=s->offB+s->lengthB-1; int end=sampleOffB[chan[c.chan].sample]+s->lengthB-1;
immWrite(0x14,(end>>8)&0xff); immWrite(0x14,(end>>8)&0xff);
immWrite(0x15,end>>16); immWrite(0x15,end>>16);
immWrite(0x11,isMuted[c.chan]?0:(chan[c.chan].pan<<6)); immWrite(0x11,isMuted[c.chan]?0:(chan[c.chan].pan<<6));
@ -654,9 +654,9 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
chan[c.chan].sample=12*sampleBank+c.value%12; chan[c.chan].sample=12*sampleBank+c.value%12;
if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) { if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) {
DivSample* s=parent->getSample(12*sampleBank+c.value%12); DivSample* s=parent->getSample(12*sampleBank+c.value%12);
immWrite(0x12,(s->offB>>8)&0xff); immWrite(0x12,(sampleOffB[chan[c.chan].sample]>>8)&0xff);
immWrite(0x13,s->offB>>16); immWrite(0x13,sampleOffB[chan[c.chan].sample]>>16);
int end=s->offB+s->lengthB-1; int end=sampleOffB[chan[c.chan].sample]+s->lengthB-1;
immWrite(0x14,(end>>8)&0xff); immWrite(0x14,(end>>8)&0xff);
immWrite(0x15,end>>16); immWrite(0x15,end>>16);
immWrite(0x11,isMuted[c.chan]?0:(chan[c.chan].pan<<6)); immWrite(0x11,isMuted[c.chan]?0:(chan[c.chan].pan<<6));
@ -694,9 +694,9 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
chan[c.chan].sample=ins->amiga.getSample(c.value); chan[c.chan].sample=ins->amiga.getSample(c.value);
if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) { if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) {
DivSample* s=parent->getSample(chan[c.chan].sample); DivSample* s=parent->getSample(chan[c.chan].sample);
immWrite(0x110+c.chan-adpcmAChanOffs,(s->offA>>8)&0xff); immWrite(0x110+c.chan-adpcmAChanOffs,(sampleOffA[chan[c.chan].sample]>>8)&0xff);
immWrite(0x118+c.chan-adpcmAChanOffs,s->offA>>16); immWrite(0x118+c.chan-adpcmAChanOffs,sampleOffA[chan[c.chan].sample]>>16);
int end=s->offA+s->lengthA-1; int end=sampleOffA[chan[c.chan].sample]+s->lengthA-1;
immWrite(0x120+c.chan-adpcmAChanOffs,(end>>8)&0xff); immWrite(0x120+c.chan-adpcmAChanOffs,(end>>8)&0xff);
immWrite(0x128+c.chan-adpcmAChanOffs,end>>16); immWrite(0x128+c.chan-adpcmAChanOffs,end>>16);
immWrite(0x108+c.chan-adpcmAChanOffs,isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].outVol)); immWrite(0x108+c.chan-adpcmAChanOffs,isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].outVol));
@ -725,9 +725,9 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
chan[c.chan].sample=12*sampleBank+c.value%12; chan[c.chan].sample=12*sampleBank+c.value%12;
if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) { if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) {
DivSample* s=parent->getSample(12*sampleBank+c.value%12); DivSample* s=parent->getSample(12*sampleBank+c.value%12);
immWrite(0x110+c.chan-adpcmAChanOffs,(s->offA>>8)&0xff); immWrite(0x110+c.chan-adpcmAChanOffs,(sampleOffA[chan[c.chan].sample]>>8)&0xff);
immWrite(0x118+c.chan-adpcmAChanOffs,s->offA>>16); immWrite(0x118+c.chan-adpcmAChanOffs,sampleOffA[chan[c.chan].sample]>>16);
int end=s->offA+s->lengthA-1; int end=sampleOffA[chan[c.chan].sample]+s->lengthA-1;
immWrite(0x120+c.chan-adpcmAChanOffs,(end>>8)&0xff); immWrite(0x120+c.chan-adpcmAChanOffs,(end>>8)&0xff);
immWrite(0x128+c.chan-adpcmAChanOffs,end>>16); immWrite(0x128+c.chan-adpcmAChanOffs,end>>16);
immWrite(0x108+c.chan-adpcmAChanOffs,isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].outVol)); immWrite(0x108+c.chan-adpcmAChanOffs,isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].outVol));

View file

@ -686,9 +686,9 @@ int DivPlatformYM2610B::dispatch(DivCommand c) {
chan[c.chan].sample=ins->amiga.getSample(c.value); chan[c.chan].sample=ins->amiga.getSample(c.value);
if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) { if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) {
DivSample* s=parent->getSample(chan[c.chan].sample); DivSample* s=parent->getSample(chan[c.chan].sample);
immWrite(0x12,(s->offB>>8)&0xff); immWrite(0x12,(sampleOffB[chan[c.chan].sample]>>8)&0xff);
immWrite(0x13,s->offB>>16); immWrite(0x13,sampleOffB[chan[c.chan].sample]>>16);
int end=s->offB+s->lengthB-1; int end=sampleOffB[chan[c.chan].sample]+s->lengthB-1;
immWrite(0x14,(end>>8)&0xff); immWrite(0x14,(end>>8)&0xff);
immWrite(0x15,end>>16); immWrite(0x15,end>>16);
immWrite(0x11,isMuted[c.chan]?0:(chan[c.chan].pan<<6)); immWrite(0x11,isMuted[c.chan]?0:(chan[c.chan].pan<<6));
@ -717,9 +717,9 @@ int DivPlatformYM2610B::dispatch(DivCommand c) {
chan[c.chan].sample=12*sampleBank+c.value%12; chan[c.chan].sample=12*sampleBank+c.value%12;
if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) { if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) {
DivSample* s=parent->getSample(12*sampleBank+c.value%12); DivSample* s=parent->getSample(12*sampleBank+c.value%12);
immWrite(0x12,(s->offB>>8)&0xff); immWrite(0x12,(sampleOffB[chan[c.chan].sample]>>8)&0xff);
immWrite(0x13,s->offB>>16); immWrite(0x13,sampleOffB[chan[c.chan].sample]>>16);
int end=s->offB+s->lengthB-1; int end=sampleOffB[chan[c.chan].sample]+s->lengthB-1;
immWrite(0x14,(end>>8)&0xff); immWrite(0x14,(end>>8)&0xff);
immWrite(0x15,end>>16); immWrite(0x15,end>>16);
immWrite(0x11,isMuted[c.chan]?0:(chan[c.chan].pan<<6)); immWrite(0x11,isMuted[c.chan]?0:(chan[c.chan].pan<<6));
@ -757,9 +757,9 @@ int DivPlatformYM2610B::dispatch(DivCommand c) {
chan[c.chan].sample=ins->amiga.getSample(c.value); chan[c.chan].sample=ins->amiga.getSample(c.value);
if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) { if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) {
DivSample* s=parent->getSample(chan[c.chan].sample); DivSample* s=parent->getSample(chan[c.chan].sample);
immWrite(0x110+c.chan-adpcmAChanOffs,(s->offA>>8)&0xff); immWrite(0x110+c.chan-adpcmAChanOffs,(sampleOffA[chan[c.chan].sample]>>8)&0xff);
immWrite(0x118+c.chan-adpcmAChanOffs,s->offA>>16); immWrite(0x118+c.chan-adpcmAChanOffs,sampleOffA[chan[c.chan].sample]>>16);
int end=s->offA+s->lengthA-1; int end=sampleOffA[chan[c.chan].sample]+s->lengthA-1;
immWrite(0x120+c.chan-adpcmAChanOffs,(end>>8)&0xff); immWrite(0x120+c.chan-adpcmAChanOffs,(end>>8)&0xff);
immWrite(0x128+c.chan-adpcmAChanOffs,end>>16); immWrite(0x128+c.chan-adpcmAChanOffs,end>>16);
immWrite(0x108+c.chan-adpcmAChanOffs,isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].outVol)); immWrite(0x108+c.chan-adpcmAChanOffs,isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].outVol));
@ -788,9 +788,9 @@ int DivPlatformYM2610B::dispatch(DivCommand c) {
chan[c.chan].sample=12*sampleBank+c.value%12; chan[c.chan].sample=12*sampleBank+c.value%12;
if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) { if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) {
DivSample* s=parent->getSample(12*sampleBank+c.value%12); DivSample* s=parent->getSample(12*sampleBank+c.value%12);
immWrite(0x110+c.chan-adpcmAChanOffs,(s->offA>>8)&0xff); immWrite(0x110+c.chan-adpcmAChanOffs,(sampleOffA[chan[c.chan].sample]>>8)&0xff);
immWrite(0x118+c.chan-adpcmAChanOffs,s->offA>>16); immWrite(0x118+c.chan-adpcmAChanOffs,sampleOffA[chan[c.chan].sample]>>16);
int end=s->offA+s->lengthA-1; int end=sampleOffA[chan[c.chan].sample]+s->lengthA-1;
immWrite(0x120+c.chan-adpcmAChanOffs,(end>>8)&0xff); immWrite(0x120+c.chan-adpcmAChanOffs,(end>>8)&0xff);
immWrite(0x128+c.chan-adpcmAChanOffs,end>>16); immWrite(0x128+c.chan-adpcmAChanOffs,end>>16);
immWrite(0x108+c.chan-adpcmAChanOffs,isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].outVol)); immWrite(0x108+c.chan-adpcmAChanOffs,isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].outVol));

View file

@ -136,6 +136,9 @@ template<int ChanNum> class DivPlatformYM2610Base: public DivPlatformOPN {
size_t adpcmBMemLen; size_t adpcmBMemLen;
DivYM2610Interface iface; DivYM2610Interface iface;
unsigned int sampleOffA[256];
unsigned int sampleOffB[256];
unsigned char sampleBank; unsigned char sampleBank;
bool extMode; bool extMode;
@ -207,6 +210,8 @@ template<int ChanNum> class DivPlatformYM2610Base: public DivPlatformOPN {
void renderSamples() { void renderSamples() {
memset(adpcmAMem,0,getSampleMemCapacity(0)); memset(adpcmAMem,0,getSampleMemCapacity(0));
memset(sampleOffA,0,256*sizeof(unsigned int));
memset(sampleOffB,0,256*sizeof(unsigned int));
size_t memPos=0; size_t memPos=0;
for (int i=0; i<parent->song.sampleLen; i++) { for (int i=0; i<parent->song.sampleLen; i++) {
@ -225,7 +230,7 @@ template<int ChanNum> class DivPlatformYM2610Base: public DivPlatformOPN {
} else { } else {
memcpy(adpcmAMem+memPos,s->dataA,paddedLen); memcpy(adpcmAMem+memPos,s->dataA,paddedLen);
} }
s->offA=memPos; sampleOffA[i]=memPos;
memPos+=paddedLen; memPos+=paddedLen;
} }
adpcmAMemLen=memPos+256; adpcmAMemLen=memPos+256;
@ -249,7 +254,7 @@ template<int ChanNum> class DivPlatformYM2610Base: public DivPlatformOPN {
} else { } else {
memcpy(adpcmBMem+memPos,s->dataB,paddedLen); memcpy(adpcmBMem+memPos,s->dataB,paddedLen);
} }
s->offB=memPos; sampleOffB[i]=memPos;
memPos+=paddedLen; memPos+=paddedLen;
} }
adpcmBMemLen=memPos+256; adpcmBMemLen=memPos+256;

View file

@ -145,8 +145,9 @@ void DivPlatformYMZ280B::tick(bool sysTick) {
// ADPCM has half the range // ADPCM has half the range
if (s->depth==DIV_SAMPLE_DEPTH_YMZ_ADPCM && chan[i].freq>255) chan[i].freq=255; if (s->depth==DIV_SAMPLE_DEPTH_YMZ_ADPCM && chan[i].freq>255) chan[i].freq=255;
ctrl|=(chan[i].active?0x80:0)|((s->isLoopable())?0x10:0)|(chan[i].freq>>8); ctrl|=(chan[i].active?0x80:0)|((s->isLoopable())?0x10:0)|(chan[i].freq>>8);
// TODO: AGAIN THIS WILL CRASH IF THE SAMPLE IS INVALID!!!
if (chan[i].keyOn) { if (chan[i].keyOn) {
unsigned int start=s->offYMZ280B; unsigned int start=sampleOff[chan[i].sample];
unsigned int loopStart=0; unsigned int loopStart=0;
unsigned int loopEnd=0; unsigned int loopEnd=0;
unsigned int end=MIN(start+s->getCurBufLen(),getSampleMemCapacity()-1); unsigned int end=MIN(start+s->getCurBufLen(),getSampleMemCapacity()-1);
@ -418,6 +419,7 @@ size_t DivPlatformYMZ280B::getSampleMemUsage(int index) {
void DivPlatformYMZ280B::renderSamples() { void DivPlatformYMZ280B::renderSamples() {
memset(sampleMem,0,getSampleMemCapacity()); memset(sampleMem,0,getSampleMemCapacity());
memset(sampleOff,0,256*sizeof(unsigned int));
size_t memPos=0; size_t memPos=0;
for (int i=0; i<parent->song.sampleLen; i++) { for (int i=0; i<parent->song.sampleLen; i++) {
@ -427,7 +429,7 @@ void DivPlatformYMZ280B::renderSamples() {
int actualLength=MIN((int)(getSampleMemCapacity()-memPos),length); int actualLength=MIN((int)(getSampleMemCapacity()-memPos),length);
if (actualLength>0) { if (actualLength>0) {
memcpy(&sampleMem[memPos],src,actualLength); memcpy(&sampleMem[memPos],src,actualLength);
s->offYMZ280B=memPos; sampleOff[i]=memPos;
memPos+=length; memPos+=length;
} }
if (actualLength<length) { if (actualLength<length) {

View file

@ -66,6 +66,7 @@ class DivPlatformYMZ280B: public DivDispatch {
DivDispatchOscBuffer* oscBuf[8]; DivDispatchOscBuffer* oscBuf[8];
bool isMuted[8]; bool isMuted[8];
int chipType; int chipType;
unsigned int sampleOff[256];
unsigned char* sampleMem; unsigned char* sampleMem;
size_t sampleMemLen; size_t sampleMemLen;

View file

@ -90,6 +90,7 @@ struct DivSampleHistory {
struct DivSample { struct DivSample {
String name; String name;
// TODO: get rid of loopOffP
int rate, centerRate, loopStart, loopEnd, loopOffP; int rate, centerRate, loopStart, loopEnd, loopOffP;
// valid values are: // valid values are:
// - 0: ZX Spectrum overlay drum (1-bit) // - 0: ZX Spectrum overlay drum (1-bit)
@ -124,8 +125,6 @@ struct DivSample {
unsigned char* dataVOX; // 10 unsigned char* dataVOX; // 10
unsigned int length8, length16, length1, lengthDPCM, lengthZ, lengthQSoundA, lengthA, lengthB, lengthBRR, lengthVOX; unsigned int length8, length16, length1, lengthDPCM, lengthZ, lengthQSoundA, lengthA, lengthB, lengthBRR, lengthVOX;
unsigned int off8, off16, off1, offDPCM, offZ, offQSoundA, offA, offB, offBRR, offVOX;
unsigned int offSegaPCM, offQSound, offX1_010, offSU, offYMZ280B, offRF5C68, offSNES;
unsigned int samples; unsigned int samples;
@ -311,23 +310,6 @@ struct DivSample {
lengthB(0), lengthB(0),
lengthBRR(0), lengthBRR(0),
lengthVOX(0), lengthVOX(0),
off8(0),
off16(0),
off1(0),
offDPCM(0),
offZ(0),
offQSoundA(0),
offA(0),
offB(0),
offBRR(0),
offVOX(0),
offSegaPCM(0),
offQSound(0),
offX1_010(0),
offSU(0),
offYMZ280B(0),
offRF5C68(0),
offSNES(0),
samples(0) {} samples(0) {}
~DivSample(); ~DivSample();
}; };

View file

@ -887,6 +887,9 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p
int loopPos=-1; int loopPos=-1;
int loopTick=-1; int loopTick=-1;
unsigned int sampleOff8[256];
unsigned int sampleOffSegaPCM[256];
SafeWriter* w=new SafeWriter; SafeWriter* w=new SafeWriter;
w->init(); w->init();
@ -1501,12 +1504,16 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p
unsigned int songOff=w->tell(); unsigned int songOff=w->tell();
// initialize sample offsets
memset(sampleOff8,0,256*sizeof(unsigned int));
memset(sampleOffSegaPCM,0,256*sizeof(unsigned int));
// write samples // write samples
unsigned int sampleSeek=0; unsigned int sampleSeek=0;
for (int i=0; i<song.sampleLen; i++) { for (int i=0; i<song.sampleLen; i++) {
DivSample* sample=song.sample[i]; DivSample* sample=song.sample[i];
logI("setting seek to %d",sampleSeek); logI("setting seek to %d",sampleSeek);
sample->off8=sampleSeek; sampleOff8[i]=sampleSeek;
sampleSeek+=sample->length8; sampleSeek+=sample->length8;
} }
@ -1556,7 +1563,7 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p
} }
logV("- sample %d will be at %x with length %x",i,memPos,alignedSize); logV("- sample %d will be at %x with length %x",i,memPos,alignedSize);
if (memPos>=16777216) break; if (memPos>=16777216) break;
sample->offSegaPCM=memPos; sampleOffSegaPCM[i]=memPos;
unsigned int readPos=0; unsigned int readPos=0;
for (unsigned int j=0; j<alignedSize; j++) { for (unsigned int j=0; j<alignedSize; j++) {
if (readPos>=(unsigned int)sample->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT)) { if (readPos>=(unsigned int)sample->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT)) {
@ -1661,6 +1668,8 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p
size_t sampleMemLen=writeZ280[i]->getSampleMemUsage(); size_t sampleMemLen=writeZ280[i]->getSampleMemUsage();
unsigned char* sampleMem=new unsigned char[sampleMemLen]; unsigned char* sampleMem=new unsigned char[sampleMemLen];
memcpy(sampleMem,writeZ280[i]->getSampleMem(),sampleMemLen); memcpy(sampleMem,writeZ280[i]->getSampleMem(),sampleMemLen);
// TODO: please fix this later
/*
for (int i=0; i<song.sampleLen; i++) { for (int i=0; i<song.sampleLen; i++) {
DivSample* s=song.sample[i]; DivSample* s=song.sample[i];
if (s->depth==DIV_SAMPLE_DEPTH_16BIT) { if (s->depth==DIV_SAMPLE_DEPTH_16BIT) {
@ -1673,6 +1682,7 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p
} }
} }
} }
*/
w->writeC(0x67); w->writeC(0x67);
w->writeC(0x66); w->writeC(0x66);
w->writeC(0x86); w->writeC(0x86);
@ -1900,7 +1910,7 @@ SafeWriter* DivEngine::saveVGM(bool* sysToExport, bool loop, int version, bool p
if (sample->getLoopStartPosition(DIV_SAMPLE_DEPTH_8BIT)<sample->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT)) { if (sample->getLoopStartPosition(DIV_SAMPLE_DEPTH_8BIT)<sample->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT)) {
w->writeC(0x93); w->writeC(0x93);
w->writeC(nextToTouch); w->writeC(nextToTouch);
w->writeI(sample->off8+sample->getLoopStartPosition(DIV_SAMPLE_DEPTH_8BIT)); w->writeI(sampleOff8[loopSample[nextToTouch]]+sample->getLoopStartPosition(DIV_SAMPLE_DEPTH_8BIT));
w->writeC(0x81); w->writeC(0x81);
w->writeI(sample->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT)-sample->getLoopStartPosition(DIV_SAMPLE_DEPTH_8BIT)); w->writeI(sample->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT)-sample->getLoopStartPosition(DIV_SAMPLE_DEPTH_8BIT));
} }

View file

@ -191,23 +191,6 @@ void FurnaceGUI::drawDebug() {
ImGui::Text("lengthBRR: %d",sample->lengthBRR); ImGui::Text("lengthBRR: %d",sample->lengthBRR);
ImGui::Text("lengthVOX: %d",sample->lengthVOX); ImGui::Text("lengthVOX: %d",sample->lengthVOX);
ImGui::Text("off8: %x",sample->off8);
ImGui::Text("off16: %x",sample->off16);
ImGui::Text("off1: %x",sample->off1);
ImGui::Text("offDPCM: %x",sample->offDPCM);
ImGui::Text("offZ: %x",sample->offZ);
ImGui::Text("offQSoundA: %x",sample->offQSoundA);
ImGui::Text("offA: %x",sample->offA);
ImGui::Text("offB: %x",sample->offB);
ImGui::Text("offBRR: %x",sample->offBRR);
ImGui::Text("offVOX: %x",sample->offVOX);
ImGui::Text("offSegaPCM: %x",sample->offSegaPCM);
ImGui::Text("offQSound: %x",sample->offQSound);
ImGui::Text("offX1_010: %x",sample->offX1_010);
ImGui::Text("offSU: %x",sample->offSU);
ImGui::Text("offYMZ280B: %x",sample->offYMZ280B);
ImGui::Text("offRF5C68: %x",sample->offRF5C68);
ImGui::Text("samples: %d",sample->samples); ImGui::Text("samples: %d",sample->samples);
ImGui::TreePop(); ImGui::TreePop();
} }