sample system rewrite! **PLEASE READ**

this commit mostly rewrites the sample system.
as of now samples can be ADPCM, 8-bit, BRR or 16-bit
or something...

consider this VERY EXPERIMENTAL.
if you find any issues REPORT THEM immediately.

it's nearly 4am...
This commit is contained in:
tildearrow 2022-02-24 03:57:45 -05:00
parent 3542229448
commit 1e98f0c4a1
19 changed files with 545 additions and 390 deletions

View file

@ -72,14 +72,10 @@ void DivPlatformAmiga::acquire(short* bufL, short* bufR, size_t start, size_t le
chan[i].audSub-=AMIGA_DIVIDER;
if (chan[i].audSub<0) {
DivSample* s=parent->song.sample[chan[i].sample];
if (s->rendLength>0) {
if (s->depth==8) {
chan[i].audDat=s->rendData[chan[i].audPos++];
} else {
chan[i].audDat=s->rendData[chan[i].audPos++]>>8;
}
if (chan[i].audPos>=s->rendLength || chan[i].audPos>=131071) {
if (s->loopStart>=0 && s->loopStart<=(int)s->rendLength) {
if (s->samples>0) {
chan[i].audDat=s->data8[chan[i].audPos++];
if (chan[i].audPos>=s->samples || chan[i].audPos>=131071) {
if (s->loopStart>=0 && s->loopStart<=(int)s->samples) {
chan[i].audPos=s->loopStart;
} else {
chan[i].sample=-1;

View file

@ -90,16 +90,12 @@ void DivPlatformGenesis::acquire_nuked(short* bufL, short* bufR, size_t start, s
dacPeriod-=6;
if (dacPeriod<1) {
DivSample* s=parent->song.sample[dacSample];
if (s->rendLength>0) {
if (s->samples>0) {
if (!isMuted[5]) {
if (s->depth==8) {
immWrite(0x2a,(unsigned char)s->rendData[dacPos]+0x80);
} else {
immWrite(0x2a,((unsigned short)s->rendData[dacPos]+0x8000)>>8);
}
immWrite(0x2a,(unsigned char)s->data8[dacPos]+0x80);
}
if (++dacPos>=s->rendLength) {
if (s->loopStart>=0 && s->loopStart<=(int)s->rendLength) {
if (++dacPos>=s->samples) {
if (s->loopStart>=0 && s->loopStart<=(int)s->samples) {
dacPos=s->loopStart;
} else {
dacSample=-1;
@ -164,16 +160,12 @@ void DivPlatformGenesis::acquire_ymfm(short* bufL, short* bufR, size_t start, si
dacPeriod-=24;
if (dacPeriod<1) {
DivSample* s=parent->song.sample[dacSample];
if (s->rendLength>0) {
if (s->samples>0) {
if (!isMuted[5]) {
if (s->depth==8) {
immWrite(0x2a,(unsigned char)s->rendData[dacPos]+0x80);
} else {
immWrite(0x2a,((unsigned short)s->rendData[dacPos]+0x8000)>>8);
}
immWrite(0x2a,(unsigned char)s->data8[dacPos]+0x80);
}
if (++dacPos>=s->rendLength) {
if (s->loopStart>=0 && s->loopStart<=(int)s->rendLength) {
if (++dacPos>=s->samples) {
if (s->loopStart>=0 && s->loopStart<=(int)s->samples) {
dacPos=s->loopStart;
} else {
dacSample=-1;

View file

@ -76,16 +76,12 @@ void DivPlatformNES::acquire(short* bufL, short* bufR, size_t start, size_t len)
dacPeriod+=dacRate;
if (dacPeriod>=rate) {
DivSample* s=parent->song.sample[dacSample];
if (s->rendLength>0) {
if (s->samples>0) {
if (!isMuted[4]) {
if (s->depth==8) {
rWrite(0x4011,((unsigned char)s->rendData[dacPos]+0x80)>>1);
} else {
rWrite(0x4011,((unsigned short)s->rendData[dacPos]+0x8000)>>9);
}
rWrite(0x4011,((unsigned char)s->data8[dacPos]+0x80)>>1);
}
if (++dacPos>=s->rendLength) {
if (s->loopStart>=0 && s->loopStart<=(int)s->rendLength) {
if (++dacPos>=s->samples) {
if (s->loopStart>=0 && s->loopStart<=(int)s->samples) {
dacPos=s->loopStart;
} else {
dacSample=-1;

View file

@ -82,21 +82,16 @@ void DivPlatformPCE::acquire(short* bufL, short* bufR, size_t start, size_t len)
chan[i].dacPeriod+=chan[i].dacRate;
if (chan[i].dacPeriod>rate) {
DivSample* s=parent->song.sample[chan[i].dacSample];
if (s->rendLength<=0) {
if (s->samples<=0) {
chan[i].dacSample=-1;
continue;
}
chWrite(i,0x07,0);
if (s->depth==8) {
chWrite(i,0x04,0xdf);
chWrite(i,0x06,(((unsigned char)s->rendData[chan[i].dacPos]+0x80)>>3));
} else {
chWrite(i,0x04,0xdf);
chWrite(i,0x06,(((unsigned short)s->rendData[chan[i].dacPos]+0x8000)>>11));
}
chWrite(i,0x04,0xdf);
chWrite(i,0x06,(((unsigned char)s->data8[chan[i].dacPos]+0x80)>>3));
chan[i].dacPos++;
if (chan[i].dacPos>=s->rendLength) {
if (s->loopStart>=0 && s->loopStart<=(int)s->rendLength) {
if (chan[i].dacPos>=s->samples) {
if (s->loopStart>=0 && s->loopStart<=(int)s->samples) {
chan[i].dacPos=s->loopStart;
} else {
chan[i].dacSample=-1;

View file

@ -296,18 +296,18 @@ void DivPlatformQSound::tick() {
} else {
off=(double)s->centerRate/24038.0/16.0;
}
qsound_bank = 0x8000 | (s->rendOffQsound >> 16);
qsound_addr = s->rendOffQsound & 0xffff;
qsound_bank = 0x8000 | (s->offQSound >> 16);
qsound_addr = s->offQSound & 0xffff;
int length = s->length;
int length = s->samples;
if (length > 65536 - 16) {
length = 65536 - 16;
}
if (s->loopStart == -1 || s->loopStart >= length) {
qsound_end = s->rendOffQsound + length + 15;
qsound_end = s->offQSound + length + 15;
qsound_loop = 15;
} else {
qsound_end = s->rendOffQsound + length;
qsound_end = s->offQSound + length;
qsound_loop = length - s->loopStart;
}
}

View file

@ -44,22 +44,17 @@ void DivPlatformSegaPCM::acquire(short* bufL, short* bufR, size_t start, size_t
for (int i=0; i<16; i++) {
if (chan[i].pcm.sample>=0 && chan[i].pcm.sample<parent->song.sampleLen) {
DivSample* s=parent->song.sample[chan[i].pcm.sample];
if (s->rendLength<=0) {
if (s->samples<=0) {
chan[i].pcm.sample=-1;
continue;
}
if (!isMuted[i]) {
if (s->depth==8) {
pcmL+=(s->rendData[chan[i].pcm.pos>>8]*chan[i].chVolL);
pcmR+=(s->rendData[chan[i].pcm.pos>>8]*chan[i].chVolR);
} else {
pcmL+=(s->rendData[chan[i].pcm.pos>>8]*chan[i].chVolL)>>8;
pcmR+=(s->rendData[chan[i].pcm.pos>>8]*chan[i].chVolR)>>8;
}
pcmL+=(s->data8[chan[i].pcm.pos>>8]*chan[i].chVolL);
pcmR+=(s->data8[chan[i].pcm.pos>>8]*chan[i].chVolR);
}
chan[i].pcm.pos+=chan[i].pcm.freq;
if (chan[i].pcm.pos>=(s->rendLength<<8)) {
if (s->loopStart>=0 && s->loopStart<=(int)s->rendLength) {
if (chan[i].pcm.pos>=(s->samples<<8)) {
if (s->loopStart>=0 && s->loopStart<=(int)s->samples) {
chan[i].pcm.pos=s->loopStart<<8;
} else {
chan[i].pcm.sample=-1;
@ -152,17 +147,17 @@ int DivPlatformSegaPCM::dispatch(DivCommand c) {
chan[c.chan].furnacePCM=true;
if (dumpWrites) { // Sega PCM writes
DivSample* s=parent->song.sample[chan[c.chan].pcm.sample];
addWrite(0x10086+(c.chan<<3),3+((s->rendOffP>>16)<<3));
addWrite(0x10084+(c.chan<<3),(s->rendOffP)&0xff);
addWrite(0x10085+(c.chan<<3),(s->rendOffP>>8)&0xff);
addWrite(0x10006+(c.chan<<3),MIN(255,((s->rendOffP&0xffff)+s->rendLength-1)>>8));
if (s->loopStart<0 || s->loopStart>=(int)s->rendLength) {
addWrite(0x10086+(c.chan<<3),2+((s->rendOffP>>16)<<3));
addWrite(0x10086+(c.chan<<3),3+((s->offSegaPCM>>16)<<3));
addWrite(0x10084+(c.chan<<3),(s->offSegaPCM)&0xff);
addWrite(0x10085+(c.chan<<3),(s->offSegaPCM>>8)&0xff);
addWrite(0x10006+(c.chan<<3),MIN(255,((s->offSegaPCM&0xffff)+s->length8-1)>>8));
if (s->loopStart<0 || s->loopStart>=(int)s->length8) {
addWrite(0x10086+(c.chan<<3),2+((s->offSegaPCM>>16)<<3));
} else {
int loopPos=(s->rendOffP&0xffff)+s->loopStart+s->loopOffP;
int loopPos=(s->offSegaPCM&0xffff)+s->loopStart+s->loopOffP;
addWrite(0x10004+(c.chan<<3),loopPos&0xff);
addWrite(0x10005+(c.chan<<3),(loopPos>>8)&0xff);
addWrite(0x10086+(c.chan<<3),((s->rendOffP>>16)<<3));
addWrite(0x10086+(c.chan<<3),((s->offSegaPCM>>16)<<3));
}
}
} else {
@ -182,17 +177,17 @@ int DivPlatformSegaPCM::dispatch(DivCommand c) {
chan[c.chan].furnacePCM=false;
if (dumpWrites) { // Sega PCM writes
DivSample* s=parent->song.sample[chan[c.chan].pcm.sample];
addWrite(0x10086+(c.chan<<3),3+((s->rendOffP>>16)<<3));
addWrite(0x10084+(c.chan<<3),(s->rendOffP)&0xff);
addWrite(0x10085+(c.chan<<3),(s->rendOffP>>8)&0xff);
addWrite(0x10006+(c.chan<<3),MIN(255,((s->rendOffP&0xffff)+s->rendLength-1)>>8));
if (s->loopStart<0 || s->loopStart>=(int)s->rendLength) {
addWrite(0x10086+(c.chan<<3),2+((s->rendOffP>>16)<<3));
addWrite(0x10086+(c.chan<<3),3+((s->offSegaPCM>>16)<<3));
addWrite(0x10084+(c.chan<<3),(s->offSegaPCM)&0xff);
addWrite(0x10085+(c.chan<<3),(s->offSegaPCM>>8)&0xff);
addWrite(0x10006+(c.chan<<3),MIN(255,((s->offSegaPCM&0xffff)+s->length8-1)>>8));
if (s->loopStart<0 || s->loopStart>=(int)s->length8) {
addWrite(0x10086+(c.chan<<3),2+((s->offSegaPCM>>16)<<3));
} else {
int loopPos=(s->rendOffP&0xffff)+s->loopStart+s->loopOffP;
int loopPos=(s->offSegaPCM&0xffff)+s->loopStart+s->loopOffP;
addWrite(0x10004+(c.chan<<3),loopPos&0xff);
addWrite(0x10005+(c.chan<<3),(loopPos>>8)&0xff);
addWrite(0x10086+(c.chan<<3),((s->rendOffP>>16)<<3));
addWrite(0x10086+(c.chan<<3),((s->offSegaPCM>>16)<<3));
}
addWrite(0x10007+(c.chan<<3),chan[c.chan].pcm.freq);
}

View file

@ -437,9 +437,9 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
break;
}
DivSample* s=parent->song.sample[12*sampleBank+c.value%12];
immWrite(0x110+c.chan-7,(s->rendOff>>8)&0xff);
immWrite(0x118+c.chan-7,s->rendOff>>16);
int end=s->rendOff+s->adpcmRendLength-1;
immWrite(0x110+c.chan-7,(s->offA>>8)&0xff);
immWrite(0x118+c.chan-7,s->offA>>16);
int end=s->offA+s->lengthA-1;
immWrite(0x120+c.chan-7,(end>>8)&0xff);
immWrite(0x128+c.chan-7,end>>16);
immWrite(0x108+(c.chan-7),isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].vol));