From ab532cca844d6f52bc50ccf6be3176660c75c46f Mon Sep 17 00:00:00 2001 From: cam900 Date: Sat, 14 Jan 2023 04:10:33 +0900 Subject: [PATCH] Fix free QSound ADPCM space calculation (#826) --- src/engine/platform/qsound.cpp | 6 ++++-- src/engine/platform/qsound.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/engine/platform/qsound.cpp b/src/engine/platform/qsound.cpp index 299e980a6..a75b3bfaa 100644 --- a/src/engine/platform/qsound.cpp +++ b/src/engine/platform/qsound.cpp @@ -707,11 +707,11 @@ const void* DivPlatformQSound::getSampleMem(int index) { } size_t DivPlatformQSound::getSampleMemCapacity(int index) { - return (index == 0 || index == 1) ? 16777216 : 0; + return index == 0 ? 16777216 : index == 1 ? (16777216 - sampleMemUsage) : 0; } size_t DivPlatformQSound::getSampleMemUsage(int index) { - return index == 0 ? sampleMemLen : index == 1 ? sampleMemLenBS : 0; + return index == 0 ? sampleMemLen : index == 1 ? (sampleMemLenBS - sampleMemUsage) : 0; } bool DivPlatformQSound::isSampleLoaded(int index, int sample) { @@ -766,6 +766,7 @@ void DivPlatformQSound::renderSamples(int sysID) { sampleMemLen=memPos+256; memPos=(memPos+0xffff)&0xff0000; + sampleMemUsage=memPos; for (int i=0; isong.sampleLen; i++) { DivSample* s=parent->song.sample[i]; @@ -818,6 +819,7 @@ int DivPlatformQSound::init(DivEngine* p, int channels, int sugRate, const DivCo sampleMem=new unsigned char[getSampleMemCapacity()]; sampleMemLen=0; sampleMemLenBS=0; + sampleMemUsage=0; chip.rom_data=sampleMem; chip.rom_mask=0xffffff; reset(); diff --git a/src/engine/platform/qsound.h b/src/engine/platform/qsound.h index f0b0ed03b..c04514ed8 100644 --- a/src/engine/platform/qsound.h +++ b/src/engine/platform/qsound.h @@ -50,6 +50,7 @@ class DivPlatformQSound: public DivDispatch { unsigned char* sampleMem; size_t sampleMemLen; size_t sampleMemLenBS; + size_t sampleMemUsage; bool sampleLoaded[256]; bool sampleLoadedBS[256]; struct qsound_chip chip;