Move renderSamples() to DivDispatch implementations.

To prevent rendering samples for systems that are not in use.

Additionally, it gives the systems more flexibility to render the samples
according to their specific configuration.
This commit is contained in:
Laurens Holst 2022-05-01 19:57:44 +02:00
parent 58fe971a3c
commit 7f0074511c
16 changed files with 327 additions and 219 deletions

View file

@ -19,6 +19,7 @@
#include "x1_010.h"
#include "../engine.h"
#include "../../ta-log.h"
#include <math.h>
//#define rWrite(a,v) pendingWrites[a]=v;
@ -909,6 +910,48 @@ void DivPlatformX1_010::poke(std::vector<DivRegWrite>& wlist) {
for (DivRegWrite& i: wlist) rWrite(i.addr,i.val);
}
const void* DivPlatformX1_010::getSampleMem(int index) {
return index == 0 ? sampleMem : 0;
}
size_t DivPlatformX1_010::getSampleMemCapacity(int index) {
return index == 0 ? 1048576 : 0;
}
size_t DivPlatformX1_010::getSampleMemUsage(int index) {
return index == 0 ? sampleMemLen : 0;
}
void DivPlatformX1_010::renderSamples() {
memset(sampleMem,0,getSampleMemCapacity());
size_t memPos=0;
for (int i=0; i<parent->song.sampleLen; i++) {
DivSample* s=parent->song.sample[i];
int paddedLen=(s->length8+4095)&(~0xfff);
// fit sample bank size to 128KB for Seta 2 external bankswitching logic (not emulated yet!)
if (paddedLen>131072) {
paddedLen=131072;
}
if ((memPos&0xfe0000)!=((memPos+paddedLen)&0xfe0000)) {
memPos=(memPos+0x1ffff)&0xfe0000;
}
if (memPos>=getSampleMemCapacity()) {
logW("out of X1-010 memory for sample %d!",i);
break;
}
if (memPos+paddedLen>=getSampleMemCapacity()) {
memcpy(sampleMem+memPos,s->data8,getSampleMemCapacity()-memPos);
logW("out of X1-010 memory for sample %d!",i);
} else {
memcpy(sampleMem+memPos,s->data8,paddedLen);
}
s->offX1_010=memPos;
memPos+=paddedLen;
}
sampleMemLen=memPos+256;
}
int DivPlatformX1_010::init(DivEngine* p, int channels, int sugRate, unsigned int flags) {
parent=p;
dumpWrites=false;
@ -919,7 +962,9 @@ int DivPlatformX1_010::init(DivEngine* p, int channels, int sugRate, unsigned in
oscBuf[i]=new DivDispatchOscBuffer;
}
setFlags(flags);
intf.parent=parent;
sampleMem=new unsigned char[getSampleMemCapacity()];
sampleMemLen=0;
intf.memory=sampleMem;
x1_010=new x1_010_core(intf);
x1_010->reset();
reset();
@ -931,6 +976,7 @@ void DivPlatformX1_010::quit() {
delete oscBuf[i];
}
delete x1_010;
delete[] sampleMem;
}
DivPlatformX1_010::~DivPlatformX1_010() {