Implement getSampleMemOffset for further optimize VGM logging (specifically OPL4 PCM)

This commit is contained in:
cam900 2025-06-04 21:16:27 +09:00
parent 9d1c10fcea
commit a5148a3441
9 changed files with 60 additions and 25 deletions

View file

@ -213,6 +213,10 @@ size_t DivDispatch::getSampleMemUsage(int index) {
return 0;
}
size_t DivDispatch::getSampleMemOffset(int index) {
return 0;
}
const DivMemoryComposition* DivDispatch::getMemCompo(int index) {
return NULL;
}

View file

@ -1433,6 +1433,10 @@ size_t DivPlatformES5506::getSampleMemUsage(int index) {
return index == 0 ? sampleMemLen : 0;
}
size_t DivPlatformES5506::getSampleMemOffset(int index) {
return index == 0 ? 128 : 0;
}
bool DivPlatformES5506::isSampleLoaded(int index, int sample) {
if (index!=0) return false;
if (sample<0 || sample>255) return false;
@ -1452,7 +1456,7 @@ void DivPlatformES5506::renderSamples(int sysID) {
memCompo=DivMemoryComposition();
memCompo.name="Sample Memory";
size_t memPos=128; // add silent at begin and end of each bank for reverse playback and add 1 for loop
size_t memPos=getSampleMemOffset(); // add silent at begin and end of each bank for reverse playback and add 1 for loop
for (int i=0; i<parent->song.sampleLen; i++) {
DivSample* s=parent->song.sample[i];
if (!s->renderOn[0][sysID]) {
@ -1462,18 +1466,18 @@ void DivPlatformES5506::renderSamples(int sysID) {
unsigned int length=s->length16;
// fit sample size to single bank size
if (length>(4194304-128)) {
length=4194304-128;
if (length>(4194304-getSampleMemOffset())) {
length=4194304-getSampleMemOffset();
}
if ((memPos&0xc00000)!=((memPos+length+128)&0xc00000)) {
memPos=((memPos+0x3fffff)&0xffc00000)+128;
if ((memPos&0xc00000)!=((memPos+length+getSampleMemOffset())&0xc00000)) {
memPos=((memPos+0x3fffff)&0xffc00000)+getSampleMemOffset();
}
if (memPos>=(getSampleMemCapacity()-128)) {
if (memPos>=(getSampleMemCapacity()-getSampleMemOffset())) {
logW("out of ES5506 memory for sample %d!",i);
break;
}
if (memPos+length>=(getSampleMemCapacity()-128)) {
memcpy(sampleMem+(memPos/sizeof(short)),s->data16,(getSampleMemCapacity()-128)-memPos);
if (memPos+length>=(getSampleMemCapacity()-getSampleMemOffset())) {
memcpy(sampleMem+(memPos/sizeof(short)),s->data16,(getSampleMemCapacity()-getSampleMemOffset())-memPos);
logW("out of ES5506 memory for sample %d!",i);
} else {
memcpy(sampleMem+(memPos/sizeof(short)),s->data16,length);

View file

@ -317,6 +317,7 @@ class DivPlatformES5506: public DivDispatch, public es550x_intf {
virtual const void* getSampleMem(int index = 0) override;
virtual size_t getSampleMemCapacity(int index = 0) override;
virtual size_t getSampleMemUsage(int index = 0) override;
virtual size_t getSampleMemOffset(int index = 0) override;
virtual bool isSampleLoaded(int index, int sample) override;
virtual const DivMemoryComposition* getMemCompo(int index) override;
virtual void renderSamples(int sysID) override;

View file

@ -468,6 +468,10 @@ size_t DivPlatformK053260::getSampleMemUsage(int index) {
return index == 0 ? sampleMemLen : 0;
}
size_t DivPlatformK053260::getSampleMemOffset(int index) {
return index == 0 ? 1 : 0;
}
bool DivPlatformK053260::isSampleLoaded(int index, int sample) {
if (index!=0) return false;
if (sample<0 || sample>255) return false;
@ -487,7 +491,7 @@ void DivPlatformK053260::renderSamples(int sysID) {
memCompo=DivMemoryComposition();
memCompo.name="Sample ROM";
size_t memPos=1; // for avoid silence
size_t memPos=getSampleMemOffset(); // for avoid silence
for (int i=0; i<parent->song.sampleLen; i++) {
DivSample* s=parent->song.sample[i];
if (!s->renderOn[0][sysID]) {
@ -499,10 +503,10 @@ void DivPlatformK053260::renderSamples(int sysID) {
if (s->depth==DIV_SAMPLE_DEPTH_ADPCM_K) {
length=MIN(65535,s->getEndPosition(DIV_SAMPLE_DEPTH_ADPCM_K));
actualLength=MIN((int)(getSampleMemCapacity()-memPos-1),length);
actualLength=MIN((int)(getSampleMemCapacity()-memPos-getSampleMemOffset()),length);
if (actualLength>0) {
sampleOffK053260[i]=memPos-1;
memCompo.entries.push_back(DivMemoryEntry(DIV_MEMORY_SAMPLE,"Sample",i,memPos,memPos+actualLength+1));
sampleOffK053260[i]=memPos-getSampleMemOffset();
memCompo.entries.push_back(DivMemoryEntry(DIV_MEMORY_SAMPLE,"Sample",i,memPos,memPos+actualLength+getSampleMemOffset()));
for (int j=0; j<actualLength; j++) {
sampleMem[memPos++]=s->dataK[j];
}
@ -510,10 +514,10 @@ void DivPlatformK053260::renderSamples(int sysID) {
}
} else {
length=MIN(65535,s->getEndPosition(DIV_SAMPLE_DEPTH_8BIT));
actualLength=MIN((int)(getSampleMemCapacity()-memPos-1),length);
actualLength=MIN((int)(getSampleMemCapacity()-memPos-getSampleMemOffset()),length);
if (actualLength>0) {
sampleOffK053260[i]=memPos-1;
memCompo.entries.push_back(DivMemoryEntry(DIV_MEMORY_SAMPLE,"Sample",i,memPos,memPos+actualLength+1));
sampleOffK053260[i]=memPos-getSampleMemOffset();
memCompo.entries.push_back(DivMemoryEntry(DIV_MEMORY_SAMPLE,"Sample",i,memPos,memPos+actualLength+getSampleMemOffset()));
for (int j=0; j<actualLength; j++) {
sampleMem[memPos++]=s->data8[j];
}

View file

@ -84,6 +84,7 @@ class DivPlatformK053260: public DivDispatch, public k053260_intf {
virtual const void* getSampleMem(int index = 0) override;
virtual size_t getSampleMemCapacity(int index = 0) override;
virtual size_t getSampleMemUsage(int index = 0) override;
virtual size_t getSampleMemOffset(int index = 0) override;
virtual bool isSampleLoaded(int index, int sample) override;
virtual const DivMemoryComposition* getMemCompo(int index) override;
virtual void renderSamples(int chipID) override;

View file

@ -3236,6 +3236,10 @@ size_t DivPlatformOPL::getSampleMemUsage(int index) {
(index==0 && adpcmChan>=0)?adpcmBMemLen:0;
}
size_t DivPlatformOPL::getSampleMemOffset(int index) {
return (index==0 && pcmChanOffs>=0 && ramSize<=0x200000)?0x200000:0;
}
bool DivPlatformOPL::isSampleLoaded(int index, int sample) {
if (index!=0) return false;
if (sample<0 || sample>255) return false;

View file

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