Prepare to add hasSamplePtrHeader and hasSampleInstHeader in dispatch (WIP)

for refresh sample memory when loop/end pointer and instrument parameter changed. Also, this PR has minor code style fixes and add warning in MultiPCM sample map usage.
This commit is contained in:
cam900 2025-08-27 22:52:19 +09:00
parent 4ed40d37d6
commit bd8d9a56a0
10 changed files with 141 additions and 28 deletions

View file

@ -966,14 +966,14 @@ class DivDispatch {
* @param index the memory index.
* @return a pointer to sample memory, or NULL.
*/
virtual const void* getSampleMem(int index = 0);
virtual const void* getSampleMem(int index=0);
/**
* Get sample memory capacity.
* @param index the memory index.
* @return memory capacity in bytes, or 0 if memory doesn't exist.
*/
virtual size_t getSampleMemCapacity(int index = 0);
virtual size_t getSampleMemCapacity(int index=0);
/**
* get sample memory name.
@ -987,8 +987,22 @@ class DivDispatch {
* @param index the memory index.
* @return memory usage in bytes.
*/
virtual size_t getSampleMemUsage(int index = 0);
virtual size_t getSampleMemUsage(int index=0);
/**
* check whether chip has sample pointer header in sample memory.
* @param index the memory index.
* @return whether it did.
*/
virtual bool hasSamplePtrHeader(int index=0);
/**
* check whether chip has sample instrument header in sample memory.
* @param index the memory index.
* @return whether it did.
*/
virtual bool hasSampleInstHeader(int index=0);
/**
* check whether sample has been loaded in memory.
* @param index index.

View file

@ -2648,6 +2648,15 @@ int DivEngine::addInstrument(int refChan, DivInstrumentType fallbackType) {
song.insLen=insCount+1;
checkAssetDir(song.insDir,song.ins.size());
saveLock.unlock();
bool hasSampleInst=false;
for (int s=0; s<song.systemLen; s++) {
if (disCont[s].dispatch->hasSampleInstHeader()) {
hasSampleInst=true;
}
}
if (hasSampleInst) {
renderSamplesP();
}
BUSY_END;
return insCount;
}
@ -2665,6 +2674,15 @@ int DivEngine::addInstrumentPtr(DivInstrument* which) {
checkAssetDir(song.waveDir,song.wave.size());
checkAssetDir(song.sampleDir,song.sample.size());
saveLock.unlock();
bool hasSampleInst=false;
for (int s=0; s<song.systemLen; s++) {
if (disCont[s].dispatch->hasSampleInstHeader()) {
hasSampleInst=true;
}
}
if (hasSampleInst) {
renderSamplesP();
}
BUSY_END;
return song.insLen;
}
@ -2700,6 +2718,15 @@ void DivEngine::delInstrumentUnsafe(int index) {
}
removeAsset(song.insDir,index);
checkAssetDir(song.insDir,song.ins.size());
bool hasSampleInst=false;
for (int s=0; s<song.systemLen; s++) {
if (disCont[s].dispatch->hasSampleInstHeader()) {
hasSampleInst=true;
}
}
if (hasSampleInst) {
renderSamplesP();
}
}
}

View file

@ -213,6 +213,14 @@ size_t DivDispatch::getSampleMemUsage(int index) {
return 0;
}
bool DivDispatch::hasSamplePtrHeader(int index) {
return false;
}
bool DivDispatch::hasSampleInstHeader(int index) {
return false;
}
const DivMemoryComposition* DivDispatch::getMemCompo(int index) {
return NULL;
}

View file

@ -3244,6 +3244,14 @@ size_t DivPlatformOPL::getSampleMemUsage(int index) {
(index==0 && adpcmChan>=0)?adpcmBMemLen:0;
}
bool DivPlatformOPL::hasSamplePtrHeader(int index) {
return (index==0 && pcmChanOffs>=0);
}
bool DivPlatformOPL::hasSampleInstHeader(int index) {
return (index==0 && pcmChanOffs>=0);
}
bool DivPlatformOPL::isSampleLoaded(int index, int sample) {
if (index!=0) return false;
if (sample<0 || sample>32767) return false;

View file

@ -218,6 +218,8 @@ class DivPlatformOPL: public DivDispatch {
const void* getSampleMem(int index);
size_t getSampleMemCapacity(int index);
size_t getSampleMemUsage(int index);
bool hasSamplePtrHeader(int index=0);
bool hasSampleInstHeader(int index=0);
bool isSampleLoaded(int index, int sample);
const DivMemoryComposition* getMemCompo(int index);
void renderSamples(int chipID);

View file

@ -964,6 +964,10 @@ size_t DivPlatformSNES::getSampleMemUsage(int index) {
return index == 0 ? sampleMemLen : 0;
}
bool DivPlatformSNES::hasSamplePtrHeader(int index) {
return true;
}
bool DivPlatformSNES::isSampleLoaded(int index, int sample) {
if (index!=0) return false;
if (sample<0 || sample>32767) return false;

View file

@ -124,9 +124,10 @@ class DivPlatformSNES: public DivDispatch {
void poke(unsigned int addr, unsigned short val);
void poke(std::vector<DivRegWrite>& wlist);
const char** getRegisterSheet();
const void* getSampleMem(int index = 0);
size_t getSampleMemCapacity(int index = 0);
size_t getSampleMemUsage(int index = 0);
const void* getSampleMem(int index=0);
size_t getSampleMemCapacity(int index=0);
size_t getSampleMemUsage(int index=0);
bool hasSamplePtrHeader(int index=0);
bool isSampleLoaded(int index, int sample);
const DivMemoryComposition* getMemCompo(int index);
void renderSamples(int chipID);